index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
  4. <el-form-item label-width="120px" prop="orgIndex" v-if="userInfoVO.userType == '00'">
  5. <el-select v-model="queryParams.orgIndex" placeholder="请选择门店" clearable filterable>
  6. <el-option v-for="store in storeList" :key="store.id + store.sourceType" :label="store.name" :value="store.id + ',' + store.sourceType"> </el-option>
  7. </el-select>
  8. </el-form-item>
  9. <el-form-item prop="discountWay">
  10. <el-select v-model="queryParams.discountWay" placeholder="请选择优惠券类型" clearable>
  11. <el-option v-for="dict in dict.type.coupon_type" :key="dict.value" :label="dict.label" :value="dict.value" />
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item prop="isUsed" v-if="isUsed != 'Y'">
  15. <el-select v-model="queryParams.isUsed" placeholder="请选择是否核销" clearable>
  16. <el-option v-for="dict in dict.type.sys_yes_no" :key="dict.value" :label="dict.label" :value="dict.value" />
  17. </el-select>
  18. </el-form-item>
  19. <el-form-item>
  20. <el-date-picker v-model="queryParams.duringDate" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
  21. </el-form-item>
  22. <el-form-item prop="appUserPhoneNumber">
  23. <el-input v-model="queryParams.appUserPhoneNumber" placeholder="请输入客户手机号" clearable @keyup.enter.native="handleQuery" />
  24. </el-form-item>
  25. <el-form-item>
  26. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  27. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  28. </el-form-item>
  29. </el-form>
  30. <el-row :gutter="10" class="mb8">
  31. <el-col :span="1.5">
  32. <el-button type="primary" plain icon="el-icon-plus" @click="handleAdd" v-hasPermi="['app:couponItem:add']">手动发送优惠券</el-button>
  33. </el-col>
  34. <el-col :span="1.5">
  35. <el-button type="warning" plain icon="el-icon-download" @click="handleExport" v-hasPermi="['app:couponItem:export']">导出</el-button>
  36. </el-col>
  37. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  38. </el-row>
  39. <Page uri="/mapi/app/couponItem/list" :request-params="queryParams" ref="pagination">
  40. <el-table-column label="编号" align="center" prop="id" fixed="left" />
  41. <el-table-column label="优惠券名称" align="center" prop="couponTypeTitle" width="120" :show-overflow-tooltip="true" />
  42. <el-table-column label="优惠券类型" align="center" prop="discountWay" width="120" :show-overflow-tooltip="true">
  43. <template slot-scope="scope">
  44. <dict-tag :options="dict.type.coupon_type" :value="scope.row.discountWay" />
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="券值" align="center" prop="deductAmount" width="150">
  48. <template slot-scope="scope">
  49. <span v-if="scope.row.discountWay == 0">满{{ scope.row.minAmount }}元减{{ scope.row.deductAmount }}元</span>
  50. <span v-if="scope.row.discountWay == 1">满{{ scope.row.minAmount }}件减{{ scope.row.deductAmount }}件</span>
  51. <span v-if="scope.row.discountWay == 2">{{ scope.row.discountRate }}%折扣</span>
  52. </template>
  53. </el-table-column>
  54. <el-table-column label="所属门店" align="center" prop="orgName" width="120" :show-overflow-tooltip="true">
  55. <template slot-scope="scope">
  56. <span v-if="scope.row.orgName">{{ scope.row.orgName }}</span>
  57. <span v-else>--</span>
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="关联活动" align="center" prop="activityTitle" width="120" :show-overflow-tooltip="true">
  61. <template slot-scope="scope">
  62. <span v-if="scope.row.activityTitle">{{ scope.row.activityTitle }}</span>
  63. <span v-else>--</span>
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="客户姓名" align="center" prop="appUserName" width="150">
  67. <template slot-scope="scope"> {{ scope.row.appUserName }}/{{ scope.row.appUserPhone }} </template>
  68. </el-table-column>
  69. <el-table-column label="有效期开始时间" align="center" prop="startDate" width="140"> </el-table-column>
  70. <el-table-column label="有效期结束时间" align="center" prop="endDate" width="140"> </el-table-column>
  71. <el-table-column label="是否核销" align="center" prop="isUsed" width="80">
  72. <template slot-scope="scope">
  73. <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isUsed" />
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="核销门店" align="center" prop="usedOrgName" width="120" :show-overflow-tooltip="true">
  77. <template slot-scope="scope">
  78. <span v-if="scope.row.usedOrgName">{{ scope.row.usedOrgName }}</span>
  79. <span v-else>未核销</span>
  80. </template>
  81. </el-table-column>
  82. <el-table-column label="核销时间" align="center" prop="usedTime" width="140">
  83. <template slot-scope="scope">
  84. <span v-if="scope.row.usedTime">{{ scope.row.usedTime }}</span>
  85. <span v-else>--</span>
  86. </template>
  87. </el-table-column>
  88. <el-table-column label="核销订单编码" align="center" prop="deductOrderNo" width="150" />
  89. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="150" v-if="isUsed != 'Y'">
  90. <template slot-scope="scope">
  91. <el-button type="text" icon="el-icon-edit" v-if="scope.row.isUsed == 'N'" @click="handleUpdate(scope.row)" v-hasPermi="['app:couponItem:edit']">修改有效期</el-button>
  92. </template>
  93. </el-table-column>
  94. </Page>
  95. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  96. <!-- 发送优惠券对话框 -->
  97. <el-dialog :title="sendCouponTitle" :visible.sync="sendCouponOpen" size="30%" append-to-body>
  98. <el-row :gutter="15">
  99. <el-form ref="form" :model="sendCouponForm" :rules="rules" label-width="140px">
  100. <el-col :span="24">
  101. <el-form-item label="门店" prop="orgId">
  102. <el-select v-model="sendCouponForm.orgId" style="width: 200px" @input="getAllValidList(sendCouponForm.orgId)" placeholder="请选择门店" clearable filterable>
  103. <el-option v-for="item in storeList" :key="item.id" :label="item.name" :value="item.id" />
  104. </el-select>
  105. </el-form-item>
  106. </el-col>
  107. <el-col :span="24">
  108. <el-form-item label="优惠劵" prop="couponTypeId" v-if="sendCouponForm.orgId != null">
  109. <el-select v-model="sendCouponForm.couponTypeId" style="width: 200px" placeholder="请选择优惠劵" clearable>
  110. <el-option v-for="item in couponList" :key="item.id" :label="item.title" :value="item.id" />
  111. </el-select>
  112. </el-form-item>
  113. </el-col>
  114. <el-col :span="24">
  115. <el-form-item label="用户手机号" prop="appUserPhoneNumber">
  116. <el-input style="width: 200px" v-model.number="sendCouponForm.appUserPhoneNumber" placeholder="请输入手机号" clearable maxlength="11" />
  117. </el-form-item>
  118. </el-col>
  119. <el-col :span="24">
  120. <el-form-item label="一次性发送数量" prop="sendNum">
  121. <el-input-number v-model.number="sendCouponForm.sendNum" placeholder="请输入发送数量" :controls="false" min="1" />
  122. </el-form-item>
  123. </el-col>
  124. </el-form>
  125. </el-row>
  126. <div slot="footer" class="dialog-footer">
  127. <el-button type="primary" @click="submitSendCouponForm" style="margin-left: 5%">提交</el-button>
  128. <el-button @click="sendCouponCancel">取 消</el-button>
  129. </div>
  130. </el-dialog>
  131. <!-- 添加或修改优惠券对话框 -->
  132. <el-dialog :title="title" :visible.sync="open" size="30%" append-to-body>
  133. <el-row :gutter="15">
  134. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  135. <el-col :span="24">
  136. <el-form-item label="有效期" prop="duringDate">
  137. <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>
  138. </el-form-item>
  139. </el-col>
  140. </el-form>
  141. </el-row>
  142. <div slot="footer" class="dialog-footer">
  143. <el-button type="primary" @click="submitForm" style="margin-left: 5%">提交</el-button>
  144. <el-button @click="cancel">取 消</el-button>
  145. </div>
  146. </el-dialog>
  147. </div>
  148. </template>
  149. <script>
  150. import { listCouponItem, getCouponItem, delCouponItem, sendCoupon, updateCouponItem, updateCouponItemStatus } from '@/api/coupon/item'
  151. import { allOrg } from '@/api/system/store'
  152. import { allValidList } from '@/api/coupon/type'
  153. export default {
  154. name: 'CouponItem',
  155. dicts: ['sys_source_type', 'sys_yes_no', 'coupon_type'],
  156. data() {
  157. return {
  158. // 遮罩层
  159. loading: true,
  160. // 选中数组
  161. ids: [],
  162. // 非单个禁用
  163. single: true,
  164. // 非多个禁用
  165. multiple: true,
  166. // 显示搜索条件
  167. showSearch: true,
  168. // 总条数
  169. total: 0,
  170. // 优惠券表格数据
  171. couponItemList: [],
  172. // 弹出层标题
  173. title: '',
  174. sendCouponTitle: '',
  175. // 是否显示弹出层
  176. open: false,
  177. sendCouponOpen: false,
  178. // 查询参数
  179. queryParams: {
  180. orgIndex: null,
  181. dateRange: []
  182. },
  183. // 表单参数
  184. form: {},
  185. // 表单参数
  186. sendCouponForm: {},
  187. // 表单校验
  188. rules: {
  189. duringDate: [{ required: true, message: '有效期不能为空', trigger: 'blur' }],
  190. orgId: [{ required: true, message: '门店不能为空', trigger: 'blur' }],
  191. couponTypeId: [{ required: true, message: '优惠券不能为空', trigger: 'blur' }],
  192. appUserPhoneNumber: [{ required: true, message: '用户手机号不能为空', trigger: 'blur' }],
  193. sendNum: [{ required: true, message: '发放数量不能为空', trigger: 'blur' }]
  194. },
  195. orgList: [],
  196. isUsed: null,
  197. storeList: [],
  198. factoryList: [],
  199. couponList: [],
  200. dateRange: []
  201. }
  202. },
  203. created() {
  204. this.handleUser()
  205. this.isUsed = this.getUrlParam('isUsed')
  206. if (this.isUsed == 'Y') {
  207. this.queryParams.isUsed = this.isUsed
  208. }
  209. this.getList()
  210. allOrg().then((res) => {
  211. this.orgList = res.data
  212. this.orgList.forEach((org) => {
  213. if (org.sourceType == '01') {
  214. this.factoryList.push(org)
  215. } else {
  216. this.storeList.push(org)
  217. }
  218. })
  219. })
  220. },
  221. methods: {
  222. handleUser() {
  223. this.userInfoVO = this.getUserInfo()
  224. },
  225. /** 查询优惠券列表 */
  226. getList() {
  227. if (this.queryParams.orgIndex != null) {
  228. this.queryParams.orgId = this.queryParams.orgIndex.split(',')[0]
  229. this.queryParams.sourceType = this.queryParams.orgIndex.split(',')[1]
  230. } else {
  231. delete this.queryParams.orgId
  232. delete this.queryParams.sourceType
  233. }
  234. if (null != this.queryParams.duringDate && this.queryParams.duringDate.length > 0) {
  235. this.queryParams.startDate = this.queryParams.duringDate[0]
  236. this.queryParams.endDate = this.queryParams.duringDate[1]
  237. } else {
  238. delete this.queryParams.startDate
  239. delete this.queryParams.endDate
  240. }
  241. this.$nextTick(() => {
  242. this.$refs.pagination.handleSearch(true)
  243. })
  244. },
  245. getAllValidList(id) {
  246. this.sendCouponForm.couponTypeId = null
  247. allValidList(id).then((res) => {
  248. this.couponList = res.data
  249. })
  250. },
  251. // 取消按钮
  252. cancel() {
  253. this.open = false
  254. this.reset()
  255. },
  256. // 取消按钮
  257. sendCouponCancel() {
  258. this.sendCouponOpen = false
  259. this.reset()
  260. },
  261. // 表单重置
  262. reset() {
  263. this.form = {
  264. id: null,
  265. orderNo: null,
  266. couponTypeId: null,
  267. activityInfoId: null,
  268. orgId: null,
  269. sourceType: null,
  270. appUserId: null,
  271. isUsed: null,
  272. usedOrgId: null,
  273. usedSourceType: null,
  274. usedTime: null,
  275. startDate: null,
  276. endDate: null,
  277. isUnique: null,
  278. canManual: null,
  279. deductAmount: null,
  280. deductOrderNo: null,
  281. createById: null,
  282. createBy: null,
  283. createTime: null,
  284. updateById: null,
  285. updateBy: null,
  286. updateTime: null,
  287. remark: null
  288. }
  289. this.sendCouponForm = {
  290. couponTypeId: null,
  291. activityInfoId: null,
  292. orgId: null,
  293. sourceType: null,
  294. appUserPhoneNumber: null,
  295. sendNum: null
  296. }
  297. this.resetForm('form')
  298. },
  299. /** 搜索按钮操作 */
  300. handleQuery() {
  301. this.getList()
  302. },
  303. /** 重置按钮操作 */
  304. resetQuery() {
  305. this.resetForm('queryForm')
  306. this.handleQuery()
  307. },
  308. // 多选框选中数据
  309. handleSelectionChange(selection) {
  310. this.ids = selection.map((item) => item.id)
  311. this.single = selection.length !== 1
  312. this.multiple = !selection.length
  313. },
  314. /** 发送优惠券按钮操作 */
  315. handleAdd() {
  316. this.reset()
  317. this.sendCouponOpen = true
  318. this.sendCouponTitle = '发送优惠券'
  319. },
  320. /** 修改按钮操作 */
  321. handleUpdate(row) {
  322. this.reset()
  323. const id = row.id || this.ids
  324. getCouponItem(id).then((response) => {
  325. var duringDate = []
  326. duringDate.push(response.data.startDate)
  327. duringDate.push(response.data.endDate)
  328. response.data.duringDate = duringDate
  329. this.form = response.data
  330. this.open = true
  331. this.title = '修改优惠券'
  332. })
  333. },
  334. /** 提交按钮 */
  335. submitForm() {
  336. var params = {}
  337. if (null != this.form.duringDate && this.form.duringDate.length > 0) {
  338. params['startDate'] = this.form.duringDate[0]
  339. params['endDate'] = this.form.duringDate[1]
  340. }
  341. params.id = this.form.id
  342. this.$refs['form'].validate((valid) => {
  343. if (valid) {
  344. // if (this.form.id != null) {
  345. updateCouponItem(params).then((response) => {
  346. this.$modal.msgSuccess('修改成功')
  347. this.open = false
  348. this.getList()
  349. })
  350. // } else {
  351. // addCouponItem(this.form).then(response => {
  352. // this.$modal.msgSuccess("新增成功");
  353. // this.open = false;
  354. // this.getList();
  355. // });
  356. // }
  357. }
  358. })
  359. },
  360. /** 提交发送优惠券 */
  361. submitSendCouponForm() {
  362. this.$refs['form'].validate((valid) => {
  363. if (valid) {
  364. this.sendCouponForm.sourceType = '02'
  365. sendCoupon(this.sendCouponForm).then((response) => {
  366. this.$modal.msgSuccess('提交成功')
  367. this.sendCouponOpen = false
  368. this.getList()
  369. })
  370. }
  371. })
  372. },
  373. /** 删除按钮操作 */
  374. handleDelete(row) {
  375. const ids = row.id || this.ids
  376. this.$modal
  377. .confirm('是否确认删除优惠券编号为"' + ids + '"的数据项?')
  378. .then(function () {
  379. return delCouponItem(ids)
  380. })
  381. .then(() => {
  382. this.getList()
  383. this.$modal.msgSuccess('删除成功')
  384. })
  385. .catch(() => {})
  386. },
  387. /** 导出按钮操作 */
  388. handleExport() {
  389. this.download(
  390. 'mapi/app/couponItem/export',
  391. {
  392. ...this.queryParams
  393. },
  394. `couponItem_${new Date().getTime()}.xlsx`
  395. )
  396. },
  397. checkClose(done) {
  398. this.$confirm('是否关闭表单,关闭后数据将丢失?')
  399. .then(function () {
  400. done()
  401. })
  402. .then(() => {})
  403. .catch(() => {})
  404. }
  405. }
  406. }
  407. </script>