index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <div class="app-container">
  3. <!-- <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">-->
  4. <!-- <el-form-item>-->
  5. <!-- <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>-->
  6. <!-- <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>-->
  7. <!-- </el-form-item>-->
  8. <!-- </el-form>-->
  9. <el-row :gutter="10" class="mb8">
  10. <el-col :span="1.5">
  11. <el-button type="primary" plain icon="el-icon-plus" @click="handleAdd" v-hasPermi="['activity:couponInfo:add', 'activity:groupInfo:add']">新增</el-button>
  12. </el-col>
  13. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  14. </el-row>
  15. <Page uri="/mapi/activity/couponItem/list" :request-params="queryParams" ref="pagination">
  16. <el-table-column type="selection" width="55" align="center" fixed="left" />
  17. <el-table-column label="编号" align="center" prop="id" width="80" />
  18. <el-table-column label="优惠券名称" align="center" prop="couponTypeTitle" />
  19. <el-table-column label="优惠券库存" align="center" prop="couponStock" width="120" />
  20. <el-table-column label="发放数量" align="center" prop="couponSendNum" width="120" />
  21. <el-table-column label="核销数量" align="center" prop="couponUsedNum" width="120" />
  22. <!-- <el-table-column label="是否自定义有效期" align="center" prop="isCustomValidityPeriod" width="150">-->
  23. <!-- <template slot-scope="scope">-->
  24. <!-- <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isCustomValidityPeriod" />-->
  25. <!-- </template>-->
  26. <!-- </el-table-column>-->
  27. <el-table-column label="优惠券有效期开始日期" align="center" prop="startDate" width="180">
  28. <template slot-scope="scope">
  29. <span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="优惠券有效期结束日期" align="center" prop="endDate" width="180">
  33. <template slot-scope="scope">
  34. <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
  38. <template slot-scope="scope">
  39. <el-button type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['activity:couponInfo:edit', 'activity:groupInfo:edit']">修改</el-button>
  40. <el-button type="text" icon="el-icon-plus" @click="handleAddCoupon(scope.row)" v-hasPermi="['activity:couponInfo:edit', 'activity:groupInfo:edit']">添加库存</el-button>
  41. <el-button type="text" icon="el-icon-minus" @click="handleMinuteCoupon(scope.row)" v-hasPermi="['activity:couponInfo:edit', 'activity:groupInfo:edit']">减少库存</el-button>
  42. <el-button type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['activity:couponInfo:remove', 'activity:groupInfo:remove']">删除</el-button>
  43. </template>
  44. </el-table-column>
  45. </Page>
  46. <!-- 添加或修改注册送券活动优惠券明细对话框 -->
  47. <el-dialog :title="title" :visible.sync="open" size="30%" append-to-body>
  48. <el-row :gutter="15">
  49. <el-form ref="form" :model="form" :rules="rules" label-width="180px">
  50. <el-col :span="24">
  51. <el-form-item label="选择优惠券" prop="couponTypeId">
  52. <el-select v-model="form.couponTypeId" placeholder="请选择优惠券" :style="{ width: '100%' }" :disabled="form.id != null">
  53. <el-option v-for="item in couponTypes" :label="item.title" :value="item.id" :key="item.title"> </el-option>
  54. </el-select>
  55. </el-form-item>
  56. </el-col>
  57. <el-col :span="24">
  58. <el-form-item label="设置库存" prop="couponStock">
  59. <el-input-number v-model="form.couponStock" placeholder="请输入优惠券库存" :disabled="form.id != null" :precision="0" :min="1" :max="999999" />
  60. </el-form-item>
  61. <el-form-item label="是否自定义有效期" prop="isCustomValidityPeriod">
  62. <el-radio-group v-model="form.isCustomValidityPeriod">
  63. <el-radio-button v-for="dict in dict.type.sys_yes_no" :key="dict.value" :label="dict.value">{{ dict.label }}</el-radio-button>
  64. </el-radio-group>
  65. </el-form-item>
  66. <el-form-item label="有效期" prop="duringDate" v-if="form.isCustomValidityPeriod == 'Y'">
  67. <el-date-picker v-model="form.duringDate" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
  68. </el-form-item>
  69. </el-col>
  70. </el-form>
  71. </el-row>
  72. <div slot="footer" class="dialog-footer">
  73. <el-button type="primary" @click="submitForm" style="margin-left: 5%">提交</el-button>
  74. <el-button @click="cancel">取 消</el-button>
  75. </div>
  76. </el-dialog>
  77. <el-dialog :title="stockTitle" :visible.sync="stockOpen" width="500px" append-to-body>
  78. <el-form ref="stockForm" :model="stockForm" :rules="stockRoles" label-width="180px">
  79. <el-form-item :label="stockTitle + '数量'" prop="stockNum">
  80. <el-input-number v-model="stockForm.stockNum" placeholder="请输入库存数量" :min="0" />
  81. </el-form-item>
  82. </el-form>
  83. <div slot="footer" class="dialog-footer">
  84. <el-button type="primary" @click="submitStockForm">确 定</el-button>
  85. <el-button @click="cancelStock">取 消</el-button>
  86. </div>
  87. </el-dialog>
  88. </div>
  89. </template>
  90. <script>
  91. import { listCouponItem, getCouponItem, delCouponItem, addCouponItem, updateCouponItem, editStock } from '@/api/activity/couponItem'
  92. import { allList } from '@/api/coupon/type'
  93. export default {
  94. name: 'CouponItem',
  95. dicts: ['sys_yes_no'],
  96. data() {
  97. return {
  98. stockTitle: '',
  99. stockOpen: false,
  100. activityCouponItemId: null,
  101. stockForm: {},
  102. // 遮罩层
  103. loading: true,
  104. // 选中数组
  105. ids: [],
  106. // 非单个禁用
  107. single: true,
  108. // 非多个禁用
  109. multiple: true,
  110. // 显示搜索条件
  111. showSearch: true,
  112. // 总条数
  113. total: 0,
  114. // 注册送券活动优惠券明细表格数据
  115. couponItemList: [],
  116. // 弹出层标题
  117. title: '',
  118. // 是否显示弹出层
  119. open: false,
  120. // 查询参数
  121. queryParams: {},
  122. // 表单参数
  123. form: {
  124. isCustomValidityPeriod: 'N'
  125. },
  126. // 表单校验
  127. rules: {
  128. couponTypeId: [{ required: true, message: '优惠券类型ID不能为空', trigger: 'change' }],
  129. couponStock: [{ required: true, message: '优惠券库存不能为空', trigger: 'blur' }],
  130. isCustomValidityPeriod: [{ required: true, message: '是否自定义有效期不能为空', trigger: 'blur' }],
  131. duringDate: [{ required: true, message: '优惠券有效期不能为空', trigger: 'blur' }]
  132. },
  133. stockRoles: {
  134. stockNum: [{ required: true, message: '库存数量不能为空', trigger: 'blur' }]
  135. },
  136. couponTypes: []
  137. }
  138. },
  139. created() {
  140. this.activityId = this.$route.params && this.$route.params.activityId
  141. allList(2).then((res) => {
  142. this.couponTypes = res.data
  143. console.log('couponTypes', this.couponTypes)
  144. })
  145. this.getList()
  146. },
  147. methods: {
  148. /** 查询注册送券活动优惠券明细列表 */
  149. getList() {
  150. this.queryParams.activityId = this.activityId
  151. this.$nextTick(() => {
  152. this.$refs.pagination.handleSearch(true)
  153. })
  154. },
  155. // 取消按钮
  156. cancel() {
  157. this.open = false
  158. this.reset()
  159. },
  160. cancelStock() {
  161. this.stockOpen = false
  162. this.stockReset()
  163. },
  164. stockReset() {
  165. this.stockForm = {
  166. stockNum: null
  167. }
  168. this.resetForm('stockForm')
  169. },
  170. // 表单重置
  171. reset() {
  172. this.form = {
  173. id: null,
  174. activityId: null,
  175. couponTypeId: null,
  176. couponStock: null,
  177. isCustomValidityPeriod: 'N',
  178. startDate: null,
  179. endDate: null,
  180. duringDate: null,
  181. createById: null,
  182. createBy: null,
  183. createTime: null,
  184. updateById: null,
  185. updateBy: null,
  186. updateTime: null,
  187. remark: null,
  188. delFlag: null
  189. }
  190. this.resetForm('form')
  191. },
  192. /** 搜索按钮操作 */
  193. handleQuery() {
  194. this.getList()
  195. },
  196. /** 重置按钮操作 */
  197. resetQuery() {
  198. this.resetForm('queryForm')
  199. this.handleQuery()
  200. },
  201. // 多选框选中数据
  202. handleSelectionChange(selection) {
  203. this.ids = selection.map((item) => item.id)
  204. this.single = selection.length !== 1
  205. this.multiple = !selection.length
  206. },
  207. /** 新增按钮操作 */
  208. handleAdd() {
  209. this.reset()
  210. this.open = true
  211. this.title = '添加注册送券活动优惠券明细'
  212. },
  213. /** 修改按钮操作 */
  214. handleUpdate(row) {
  215. this.reset()
  216. const id = row.id
  217. getCouponItem(id).then((response) => {
  218. if (response.data.isCustomValidityPeriod == 'Y') {
  219. var duringDate = []
  220. duringDate.push(response.data.startDate)
  221. duringDate.push(response.data.endDate)
  222. response.data.duringDate = duringDate
  223. }
  224. this.form = response.data
  225. this.open = true
  226. this.title = '修改注册送券活动优惠券明细'
  227. })
  228. },
  229. /** 提交按钮 */
  230. submitForm() {
  231. if (null != this.form.duringDate && this.form.duringDate.length > 0) {
  232. this.form['startDate'] = this.form.duringDate[0]
  233. this.form['endDate'] = this.form.duringDate[1]
  234. } else {
  235. delete this.form.startDate
  236. delete this.form.endDate
  237. }
  238. this.$refs['form'].validate((valid) => {
  239. if (valid) {
  240. if (this.form.id != null) {
  241. updateCouponItem({ ...this.form, ...{ activityId: this.activityId } }).then((response) => {
  242. this.$modal.msgSuccess('修改成功')
  243. this.open = false
  244. this.getList()
  245. })
  246. } else {
  247. addCouponItem({ ...this.form, ...{ activityId: this.activityId } }).then((response) => {
  248. this.$modal.msgSuccess('新增成功')
  249. this.open = false
  250. this.getList()
  251. })
  252. }
  253. }
  254. })
  255. },
  256. /** 删除按钮操作 */
  257. handleDelete(row) {
  258. const ids = row.id || this.ids
  259. this.$modal
  260. .confirm('是否确认删除注册送券活动优惠券明细编号为"' + ids + '"的数据项?')
  261. .then(function () {
  262. return delCouponItem(ids)
  263. })
  264. .then(() => {
  265. this.getList()
  266. this.$modal.msgSuccess('删除成功')
  267. })
  268. .catch(() => {})
  269. },
  270. /** 导出按钮操作 */
  271. handleExport() {
  272. this.download(
  273. 'mapi/activity/couponItem/export',
  274. {
  275. ...this.queryParams
  276. },
  277. `couponItem_${new Date().getTime()}.xlsx`
  278. )
  279. },
  280. checkClose(done) {
  281. this.$confirm('是否关闭表单,关闭后数据将丢失?')
  282. .then(function () {
  283. done()
  284. })
  285. .then(() => {})
  286. .catch(() => {})
  287. },
  288. handleAddCoupon(row) {
  289. this.stockTitle = '添加库存'
  290. this.stockOpen = true
  291. this.activityCouponItemId = row.id
  292. this.stockReset()
  293. },
  294. handleMinuteCoupon(row) {
  295. this.stockTitle = '减少库存'
  296. this.stockOpen = true
  297. this.activityCouponItemId = row.id
  298. this.stockReset()
  299. },
  300. submitStockForm() {
  301. this.$refs['stockForm'].validate((valid) => {
  302. if (valid) {
  303. editStock({ ...{ isAdd: this.stockTitle == '添加库存' ? 'Y' : 'N', activityCouponItemId: this.activityCouponItemId }, ...this.stockForm }).then((res) => {
  304. this.$modal.msgSuccess('提交成功')
  305. this.stockOpen = false
  306. this.getList()
  307. })
  308. }
  309. })
  310. }
  311. }
  312. }
  313. </script>