detail.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="form" ref="form" :rules="rules" label-width="auto" :disabled="disabled">
  4. <el-form-item label="活动名称:" prop="name">
  5. <el-input v-model="form.name" placeholder="请输入活动名称" maxlength="20" show-word-limit />
  6. </el-form-item>
  7. <el-form-item label="活动时间:" prop="startTime">
  8. <el-date-picker v-model="date" type="datetimerange" range-separator="至" start-placeholder="开始日期"
  9. end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" @change="handleChange">
  10. </el-date-picker>
  11. </el-form-item>
  12. <el-form-item label="抽奖积分:" prop="lotteryConsumePoint">
  13. <el-input-number v-model="form.lotteryConsumePoint" :min="1" :max="999" :controls="false" placeholder="请输入抽奖积分" />
  14. <span class="input-number">积分</span>
  15. </el-form-item>
  16. <el-form-item label="每日限抽次数:" prop="lotteryLimitCount">
  17. <el-input-number v-model="form.lotteryLimitCount" :min="1" :max="999" :controls="false" placeholder="请输入每日限抽次数" />
  18. <span class="input-number">次</span>
  19. </el-form-item>
  20. <el-form-item label="活动规则:" prop="rule">
  21. <el-input v-model="form.rule" type="textarea" :autosize="{ minRows: 5, maxRows: 10 }" :maxlength="150"
  22. show-word-limit placeholder="请输入活动规则" />
  23. </el-form-item>
  24. <el-form-item label="转盘数量:" prop="goodNum">
  25. <el-select v-model.number="form.goodNum" placeholder="请选择转盘数量" :disabled="form.id ? true : false"
  26. @change="getChange">
  27. <el-option v-for="item in numOptions" :key="item.value" :value="item.value" :label="item.label" />
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item style="width: 100%">
  31. <el-table :data="form.lotteryConfigGoodList">
  32. <el-table-column label="顺序" type="index" align="center" />
  33. <el-table-column label="奖品类型" align="center">
  34. <template slot-scope="scope">
  35. <el-select v-model="scope.row.type" :disabled="form.id ? true : false">
  36. <el-option v-for="item in rewardOptions" :key="item.value" :value="item.value" :label="item.label" />
  37. </el-select>
  38. </template>
  39. </el-table-column>
  40. <el-table-column label="奖品" align="center">
  41. <template slot-scope="scope">
  42. <el-input v-if="scope.row.type === 4" v-model="scope.row.rewardPoint" :disabled="form.id ? true : false">
  43. <span slot="suffix" style="line-height: 36px">积分</span>
  44. </el-input>
  45. <el-input v-else v-model="scope.row.name" :disabled="form.id ? true : false" />
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="奖品数量" align="center">
  49. <template slot-scope="scope">
  50. <el-input v-model="scope.row.totalNum" />
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="已发放数量" prop="useNum" align="center" />
  54. <el-table-column label="奖品图片" align="center">
  55. <template slot-scope="scope">
  56. <Upload listType="picture-card" :url="scope.row.pic" @upload="upload($event, scope.$index)"
  57. :disabled="disabled" />
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="中奖概率 / %" align="center">
  61. <template slot-scope="scope">
  62. <el-input-number style="width: 120px" v-model="scope.row.rate" :controls="false" />
  63. </template>
  64. </el-table-column>
  65. </el-table>
  66. </el-form-item>
  67. </el-form>
  68. <div class="form-btn">
  69. <el-button @click="cancel">取消</el-button>
  70. <el-button v-if="!disabled" type="primary" @click="getSubmit">确定</el-button>
  71. </div>
  72. </div>
  73. </template>
  74. <script>
  75. import { detail, create, checkTime, edit } from '@/api/registration/lottery'
  76. export default {
  77. data() {
  78. return {
  79. // 表单
  80. form: {
  81. lotteryConfigGoodList: [],
  82. status: 0
  83. },
  84. // 活动时间
  85. date: [],
  86. // 只读
  87. disabled: false,
  88. // 转盘数量
  89. numOptions: [{
  90. value: 6,
  91. label: '6'
  92. }, {
  93. value: 8,
  94. label: '8'
  95. }],
  96. // 奖品类型
  97. rewardOptions: [{
  98. value: 3,
  99. label: '音响实物'
  100. }, {
  101. value: 4,
  102. label: '积分'
  103. }, {
  104. value: 5,
  105. label: '谢谢参与'
  106. }],
  107. // 校验
  108. rules: {
  109. name: [{
  110. required: true, message: '请输入活动名称', trigger: 'blur'
  111. }],
  112. startTime: [{
  113. required: true, message: '请选择活动时间', trigger: 'change'
  114. }],
  115. lotteryConsumePoint: [{
  116. required: true, message: '请输入抽奖积分', trigger: 'blur'
  117. }],
  118. lotteryLimitCount: [{
  119. required: true, message: '请输入每日限抽次数', trigger: 'blur'
  120. }],
  121. rule: [{
  122. required: true, message: '请输入活动规则', trigger: 'blur'
  123. }],
  124. goodNum: [{
  125. required: true, message: '请选择转盘数量', trigger: 'change'
  126. }]
  127. }
  128. }
  129. },
  130. watch: {
  131. date(val) {
  132. if (val) {
  133. this.form.startTime = val[0]
  134. this.form.endTime = val[1]
  135. }
  136. }
  137. },
  138. mounted() {
  139. if (this.$route.query.id || this.$route.query.copyId) {
  140. this.getList(this.$route.query.id || this.$route.query.copyId)
  141. this.disabled = Boolean(this.$route.query.disabled)
  142. }
  143. },
  144. methods: {
  145. // 详情
  146. getList(id) {
  147. detail({
  148. id: id
  149. }).then(res => {
  150. if (res.code === 0) {
  151. this.form = res.data
  152. this.date = [res.data.startTime, res.data.endTime]
  153. if (this.$route.query.copyId) {
  154. delete this.form.id
  155. this.form.status = 1
  156. }
  157. }
  158. })
  159. },
  160. // 校验时间
  161. handleChange(e) {
  162. checkTime({
  163. startTime: e[0],
  164. endTime: e[1]
  165. }).then(res => {
  166. if (res.code === 0) {
  167. if (!res.data) {
  168. this.$message.error('已有其他活动在此活动时间内!')
  169. this.form.date = []
  170. }
  171. }
  172. })
  173. },
  174. // 更改转盘数量
  175. getChange() {
  176. this.form.lotteryConfigGoodList = []
  177. for (let i = 0; i < this.form.goodNum; i++) {
  178. this.form.lotteryConfigGoodList.push({
  179. pic: ''
  180. })
  181. }
  182. },
  183. // 上传
  184. upload(e, index) {
  185. this.form.lotteryConfigGoodList[index].pic = e.file
  186. },
  187. // 取消
  188. cancel() {
  189. this.$tab.closeOpenPage('/registration/lotteryConfig')
  190. },
  191. // 确定
  192. getSubmit() {
  193. let rate = 0
  194. this.form.lotteryConfigGoodList.map(i => {
  195. rate += i.rate
  196. })
  197. this.$refs.form.validate((valid) => {
  198. if (valid) {
  199. if (rate !== 100) {
  200. this.$message.error('中奖概率总和要满足100%')
  201. } else {
  202. if (this.form.id) {
  203. edit(this.form).then(res => {
  204. if (res.code === 0) {
  205. this.$message.success('编辑成功!')
  206. this.getList(this.$route.query.id)
  207. }
  208. })
  209. } else {
  210. create(this.form).then(res => {
  211. if (res.code === 0) {
  212. this.$message.success('新增成功!')
  213. this.cancel()
  214. }
  215. })
  216. }
  217. }
  218. } else {
  219. return false
  220. }
  221. })
  222. }
  223. }
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .el-form-item {
  228. width: 500px;
  229. }
  230. ::v-deep .upload {
  231. .el-upload {
  232. width: 100px;
  233. height: 100px;
  234. line-height: 100px;
  235. }
  236. .upload-image {
  237. width: 100px;
  238. height: 100px;
  239. }
  240. .el-icon-plus {
  241. line-height: 100px;
  242. }
  243. }
  244. .form-btn {
  245. margin-left: 120px;
  246. }
  247. .input-number {
  248. margin-left: 10px;
  249. }
  250. </style>