lotteryManager.vue 8.2 KB

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