index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template> 
  2. <div class="app-container">
  3. <el-card class="filter-container" shadow="never">
  4. <div>
  5. <i class="el-icon-search"></i>
  6. <span>筛选搜索</span>
  7. <el-button
  8. style="float:right"
  9. type="primary"
  10. @click="handleSearchList()"
  11. size="small">
  12. 查询搜索
  13. </el-button>
  14. <el-button
  15. style="float:right;margin-right: 15px"
  16. @click="handleResetSearch()"
  17. size="small">
  18. 重置
  19. </el-button>
  20. </div>
  21. <div style="margin-top: 15px">
  22. <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
  23. <el-form-item label="活动名称:">
  24. <el-input v-model="listQuery.keyword" class="input-width" placeholder="活动名称" clearable></el-input>
  25. </el-form-item>
  26. </el-form>
  27. </div>
  28. </el-card>
  29. <el-card class="operate-container" shadow="never">
  30. <i class="el-icon-tickets"></i>
  31. <span>数据列表</span>
  32. <el-button size="mini" class="btn-add" @click="handleAdd()" style="margin-left: 20px">添加活动</el-button>
  33. <el-button size="mini" class="btn-add" @click="handleShowSessionList()">秒杀时间段列表</el-button>
  34. </el-card>
  35. <div class="table-container">
  36. <el-table ref="flashTable"
  37. :data="list"
  38. style="width: 100%;"
  39. v-loading="listLoading" border>
  40. <el-table-column type="selection" width="60" align="center"></el-table-column>
  41. <el-table-column label="编号" width="100" align="center">
  42. <template slot-scope="scope">{{scope.row.id}}</template>
  43. </el-table-column>
  44. <el-table-column label="活动标题" align="center">
  45. <template slot-scope="scope">{{scope.row.title}}</template>
  46. </el-table-column>
  47. <el-table-column label="活动状态" width="140" align="center">
  48. <template slot-scope="scope">{{scope.row |formatActiveStatus}}</template>
  49. </el-table-column>
  50. <el-table-column label="开始时间" width="140" align="center">
  51. <template slot-scope="scope">{{scope.row.startDate | formatDate}}</template>
  52. </el-table-column>
  53. <el-table-column label="结束时间" width="140" align="center">
  54. <template slot-scope="scope">{{scope.row.endDate | formatDate}}</template>
  55. </el-table-column>
  56. <el-table-column label="上线/下线" width="200" align="center">
  57. <template slot-scope="scope">
  58. <el-switch
  59. @change="handleStatusChange(scope.$index, scope.row)"
  60. :active-value="1"
  61. :inactive-value="0"
  62. v-model="scope.row.status">
  63. </el-switch>
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="操作" width="180" align="center">
  67. <template slot-scope="scope">
  68. <el-button size="mini"
  69. type="text"
  70. @click="handleView(scope.$index, scope.row)">设置商品
  71. </el-button>
  72. <el-button size="mini"
  73. type="text"
  74. @click="handleUpdate(scope.$index, scope.row)">
  75. 编辑
  76. </el-button>
  77. <el-button size="mini"
  78. type="text"
  79. @click="handleDelete(scope.$index, scope.row)">删除
  80. </el-button>
  81. </template>
  82. </el-table-column>
  83. </el-table>
  84. </div>
  85. <div class="pagination-container">
  86. <el-pagination
  87. background
  88. @size-change="handleSizeChange"
  89. @current-change="handleCurrentChange"
  90. layout="total, sizes,prev, pager, next,jumper"
  91. :current-page.sync="listQuery.pageNum"
  92. :page-size="listQuery.pageSize"
  93. :page-sizes="[5,10,15]"
  94. :total="total">
  95. </el-pagination>
  96. </div>
  97. <el-dialog
  98. title="添加活动"
  99. :visible.sync="dialogVisible"
  100. width="40%">
  101. <el-form :model="flashPromotion"
  102. ref="flashPromotionForm"
  103. label-width="150px" size="small">
  104. <el-form-item label="活动标题:">
  105. <el-input v-model="flashPromotion.title" style="width: 250px"></el-input>
  106. </el-form-item>
  107. <el-form-item label="开始时间:">
  108. <el-date-picker
  109. v-model="flashPromotion.startDate"
  110. type="date"
  111. placeholder="请选择时间">
  112. </el-date-picker>
  113. </el-form-item>
  114. <el-form-item label="结束时间:">
  115. <el-date-picker
  116. v-model="flashPromotion.endDate"
  117. type="date"
  118. placeholder="请选择时间">
  119. </el-date-picker>
  120. </el-form-item>
  121. <el-form-item label="上线/下线">
  122. <el-radio-group v-model="flashPromotion.status">
  123. <el-radio :label="1">上线</el-radio>
  124. <el-radio :label="0">下线</el-radio>
  125. </el-radio-group>
  126. </el-form-item>
  127. </el-form>
  128. <span slot="footer" class="dialog-footer">
  129. <el-button @click="dialogVisible = false" size="small">取 消</el-button>
  130. <el-button type="primary" @click="handleDialogConfirm()" size="small">确 定</el-button>
  131. </span>
  132. </el-dialog>
  133. </div>
  134. </template>
  135. <script>
  136. import {fetchList, updateStatus, deleteFlash, createFlash, updateFlash} from '@/api/flash';
  137. import {formatDate} from '@/utils/date';
  138. const defaultListQuery = {
  139. pageNum: 1,
  140. pageSize: 5,
  141. keyword: null
  142. };
  143. const defaultFlashPromotion = {
  144. id: null,
  145. title: null,
  146. startDate: null,
  147. endDate: null,
  148. status: 0
  149. };
  150. export default {
  151. name: 'flashPromotionList',
  152. data() {
  153. return {
  154. listQuery: Object.assign({}, defaultListQuery),
  155. list: null,
  156. total: null,
  157. listLoading: false,
  158. dialogVisible: false,
  159. flashPromotion: Object.assign({}, defaultFlashPromotion),
  160. isEdit: false
  161. }
  162. },
  163. created() {
  164. this.getList();
  165. },
  166. filters: {
  167. formatActiveStatus(row) {
  168. let nowTime = new Date().getTime();
  169. if (nowTime >= row.startDate && nowTime <= row.endDate) {
  170. return '活动进行中';
  171. } else if (nowTime > row.endDate) {
  172. return '活动已结束';
  173. } else {
  174. return '活动未开始';
  175. }
  176. },
  177. formatDate(time) {
  178. if (time == null || time === '') {
  179. return 'N/A';
  180. }
  181. let date = new Date(time);
  182. return formatDate(date, 'yyyy-MM-dd')
  183. },
  184. },
  185. methods: {
  186. handleResetSearch() {
  187. this.listQuery = Object.assign({}, defaultListQuery);
  188. },
  189. handleSearchList() {
  190. this.listQuery.pageNum = 1;
  191. this.getList();
  192. },
  193. handleSizeChange(val) {
  194. this.listQuery.pageNum = 1;
  195. this.listQuery.pageSize = val;
  196. this.getList();
  197. },
  198. handleCurrentChange(val) {
  199. this.listQuery.pageNum = val;
  200. this.getList();
  201. },
  202. handleAdd() {
  203. this.dialogVisible = true;
  204. this.isEdit = false;
  205. this.flashPromotion = Object.assign({},defaultFlashPromotion);
  206. },
  207. handleShowSessionList() {
  208. console.log("handleShowSessionList");
  209. },
  210. handleStatusChange(index, row) {
  211. this.$confirm('是否要修改该状态?', '提示', {
  212. confirmButtonText: '确定',
  213. cancelButtonText: '取消',
  214. type: 'warning'
  215. }).then(() => {
  216. updateStatus(row.id, {status: row.status}).then(response => {
  217. this.$message({
  218. type: 'success',
  219. message: '修改成功!'
  220. });
  221. });
  222. }).catch(() => {
  223. this.$message({
  224. type: 'info',
  225. message: '取消修改'
  226. });
  227. this.getList();
  228. });
  229. },
  230. handleDelete(index, row) {
  231. this.$confirm('是否要删除该活动?', '提示', {
  232. confirmButtonText: '确定',
  233. cancelButtonText: '取消',
  234. type: 'warning'
  235. }).then(() => {
  236. deleteFlash(row.id).then(response => {
  237. this.$message({
  238. type: 'success',
  239. message: '删除成功!'
  240. });
  241. this.getList();
  242. });
  243. });
  244. },
  245. handleUpdate(index, row) {
  246. this.dialogVisible = true;
  247. this.isEdit = true;
  248. this.flashPromotion = row;
  249. },
  250. handleDialogConfirm() {
  251. this.$confirm('是否要确认?', '提示', {
  252. confirmButtonText: '确定',
  253. cancelButtonText: '取消',
  254. type: 'warning'
  255. }).then(() => {
  256. if (this.isEdit) {
  257. updateFlash(this.flashPromotion.id,this.flashPromotion).then(response => {
  258. this.$message({
  259. message: '修改成功!',
  260. type: 'success'
  261. });
  262. this.dialogVisible =false;
  263. this.getList();
  264. })
  265. } else {
  266. createFlash(this.flashPromotion).then(response => {
  267. this.$message({
  268. message: '添加成功!',
  269. type: 'success'
  270. });
  271. this.dialogVisible =false;
  272. this.getList();
  273. })
  274. }
  275. })
  276. },
  277. getList() {
  278. this.listLoading = true;
  279. fetchList(this.listQuery).then(response => {
  280. this.listLoading = false;
  281. this.list = response.data.list;
  282. this.total = response.data.total;
  283. });
  284. }
  285. }
  286. }
  287. </script>
  288. <style></style>