lotteryManager.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <!-- -->
  2. <template>
  3. <div class="m-container">
  4. <h2>
  5. <div class="squrt"></div>抽奖活动管理
  6. </h2>
  7. <div class="newBand" v-permission="'luckDrawGroup/add'" @click="onOperationLottery('create')">添加</div>
  8. <!-- 搜索标题 -->
  9. <save-form :inline="true"
  10. class="searchForm"
  11. @submit="getList"
  12. :model="searchForm">
  13. <el-form-item >
  14. <el-input v-model.trim="searchForm.search" clearable
  15. placeholder="请输入活动名称"></el-input>
  16. </el-form-item>
  17. <el-form-item>
  18. <el-button native-type="submit"
  19. type="danger">搜索</el-button>
  20. </el-form-item>
  21. </save-form>
  22. <!-- 列表 -->
  23. <div class="tableWrap">
  24. <el-table :data="tableList"
  25. :header-cell-style="{background:'#EDEEF0',color:'#444'}">
  26. <el-table-column align="center"
  27. prop="name"
  28. label="活动名称"></el-table-column>
  29. <el-table-column align="center"
  30. prop="startTime"
  31. label="活动开始时间">
  32. </el-table-column>
  33. <el-table-column align="center"
  34. prop="endTime"
  35. label="活动结束时间">
  36. </el-table-column>
  37. <el-table-column align="center" label="操作">
  38. <template slot-scope="scope">
  39. <el-button @click="onOperationLottery('update', scope.row)" v-permission="'luckDrawGroup/update'" type="text">修改</el-button>
  40. <el-button @click="onLook(scope.row)" v-permission="'/trophyManager'" type="text">奖品设置</el-button>
  41. <el-button @click="onLottery(scope.row)" type="text">抽奖记录</el-button>
  42. </template>
  43. </el-table-column>
  44. </el-table>
  45. <pagination sync :total.sync="pageInfo.total"
  46. :page.sync="pageInfo.page"
  47. :limit.sync="pageInfo.limit"
  48. :page-sizes="pageInfo.page_size"
  49. @pagination="getList" />
  50. </div>
  51. <el-dialog :title="formTitle[formActionTitle]"
  52. :visible.sync="lotteryStatus"
  53. @close="onFormClose('ruleForm')"
  54. width="550px">
  55. <el-form :model="form"
  56. :rules="rules"
  57. label-width="100PX"
  58. ref="ruleForm">
  59. <el-form-item label="活动名称"
  60. prop="name">
  61. <el-input v-model.trim="form.name"
  62. autocomplete="off"
  63. placeholder="请输入活动名称"></el-input>
  64. </el-form-item>
  65. <el-form-item label="活动时间"
  66. prop="time">
  67. <el-date-picker
  68. style="width: 100%"
  69. v-model="form.time"
  70. :picker-options="{ firstDayOfWeek: 1 }"
  71. type="datetimerange"
  72. :default-time="['00:00:00', '23:59:59']"
  73. range-separator="至"
  74. start-placeholder="活动开始日期"
  75. end-placeholder="活动结束日期">
  76. </el-date-picker>
  77. </el-form-item>
  78. </el-form>
  79. <span slot="footer"
  80. class="dialog-footer">
  81. <el-button @click="lotteryStatus = false">取 消</el-button>
  82. <el-button type="primary" @click="onSubmit('ruleForm')">确 定</el-button>
  83. </span>
  84. </el-dialog>
  85. </div>
  86. </template>
  87. <script>
  88. import pagination from "@/components/Pagination/index";
  89. import dayjs from 'dayjs';
  90. import cleanDeep from 'clean-deep';
  91. import { luckDrawGroupList, luckDrawGroupAdd, luckDrawGroupUpdate } from './api'
  92. export default {
  93. components: { pagination },
  94. data () {
  95. return {
  96. searchForm: {
  97. search: null,
  98. },
  99. formTitle: {
  100. create: "添加活动",
  101. update: "修改活动"
  102. },
  103. formActionTitle: 'create',
  104. lotteryStatus: false,
  105. tableList: [],
  106. form: {
  107. name: null,
  108. time: null
  109. },
  110. rules: {
  111. name: [{required: true, message:'请输入活动名称', trigger: 'blur'}],
  112. time: [{required: true, message:'请选择活动时间', trigger: 'change'}]
  113. },
  114. pageInfo: {
  115. // 分页规则
  116. limit: 10, // 限制显示条数
  117. page: 1, // 当前页
  118. total: 1, // 总条数
  119. page_size: [10, 20, 40, 50] // 选择限制显示条数
  120. }
  121. };
  122. },
  123. //生命周期 - 创建完成(可以访问当前this实例)
  124. created () {
  125. // 设置默认为当前周
  126. },
  127. //生命周期 - 挂载完成(可以访问DOM元素)
  128. mounted () {
  129. this.getList()
  130. },
  131. methods: {
  132. onOperationLottery(type, data) {
  133. this.formActionTitle = type
  134. if(type == 'update') {
  135. this.$nextTick(() => {
  136. this.form = {
  137. id: data.id,
  138. name: data.name,
  139. time: [data.startTime, data.endTime]
  140. }
  141. })
  142. }
  143. this.lotteryStatus = true
  144. },
  145. onSubmit(formName) {
  146. this.$refs[formName].validate(item => {
  147. if(item) {
  148. console.log(this.form)
  149. let form = Object.assign({}, this.form)
  150. let params = {
  151. name: form.name,
  152. consumeType: 'TIMES',
  153. consumeValue: 1,
  154. startTime: dayjs(form.time[0]).format('YYYY-MM-DD HH:mm:ss'),
  155. endTime: dayjs(form.time[1]).format('YYYY-MM-DD HH:mm:ss'),
  156. }
  157. if(this.formActionTitle == 'create') {
  158. luckDrawGroupAdd(params).then(res => {
  159. this.messageTips('添加', res)
  160. })
  161. } else if(this.formActionTitle == 'update') {
  162. params.id = form.id
  163. luckDrawGroupUpdate(params).then(res => {
  164. this.messageTips('修改', res)
  165. })
  166. }
  167. }
  168. })
  169. },
  170. onFormClose(formName) {
  171. this.$refs[formName].resetFields()
  172. },
  173. messageTips (title, res) {
  174. if (res.code == 200) {
  175. this.$message.success(title + '成功')
  176. this.lotteryStatus = false
  177. this.getList()
  178. } else {
  179. this.$message.error(res.msg)
  180. }
  181. },
  182. getList() {
  183. let params = Object.assign({}, this.searchForm)
  184. params.rows = this.pageInfo.limit
  185. params.page = this.pageInfo.page
  186. luckDrawGroupList(cleanDeep(params)).then(res => {
  187. if (res.code == 200 && res.data) {
  188. this.tableList = res.data.rows
  189. this.pageInfo.total = res.data.total
  190. }
  191. })
  192. },
  193. onLook(row) {
  194. this.$router.push({
  195. path: '/trophyManager',
  196. query: {
  197. groupId: row.id
  198. }
  199. })
  200. },
  201. onLottery(row){
  202. this.$router.push({
  203. path: '/luckyDraw/lotteryRecord',
  204. query: {
  205. groupId: row.id
  206. }
  207. })
  208. }
  209. }
  210. };
  211. </script>