index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
  4. <el-form-item label="优惠券名称" prop="title">
  5. <el-input
  6. v-model="queryParams.title"
  7. placeholder="请输入优惠券名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="优惠券面值" prop="couponPrice">
  14. <el-input
  15. v-model="queryParams.couponPrice"
  16. placeholder="请输入优惠券面值"
  17. clearable
  18. size="small"
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item label="优惠券类型" prop="type">
  23. <el-select v-model="queryParams.type" placeholder="请选择优惠券类型" clearable size="small" >
  24. <el-option
  25. v-for="item in couponTypeOptions"
  26. :key="item.dictValue"
  27. :label="item.dictLabel"
  28. :value="item.dictValue"
  29. />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item label="套餐分类" v-if="queryParams.type==1" prop="packageCateIds">
  33. <el-select v-model="queryParams.packageCateIds" clearable placeholder="请选择套餐分类" size="small">
  34. <el-option
  35. v-for="item in cateOptions"
  36. :key="item.dictValue"
  37. :label="item.dictLabel"
  38. :value="item.dictValue">
  39. </el-option>
  40. </el-select>
  41. </el-form-item>
  42. <el-form-item label="创建时间">
  43. <el-date-picker v-model="dateRange" size="small" style="width: 220px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
  44. </el-form-item>
  45. <el-form-item>
  46. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  47. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  48. </el-form-item>
  49. </el-form>
  50. <el-row :gutter="10" class="mb8">
  51. <el-col :span="1.5">
  52. <el-button
  53. type="primary"
  54. icon="el-icon-plus"
  55. size="mini"
  56. @click="handleAdd"
  57. v-hasPermi="['store:storeCoupon:add']"
  58. >新增</el-button>
  59. </el-col>
  60. <el-col :span="1.5">
  61. <el-button
  62. type="danger"
  63. icon="el-icon-delete"
  64. size="mini"
  65. :disabled="multiple"
  66. @click="handleDelete"
  67. v-hasPermi="['store:storeCoupon:remove']"
  68. >删除</el-button>
  69. </el-col>
  70. <el-col :span="1.5">
  71. <el-button
  72. type="success"
  73. size="mini"
  74. :disabled="multiple"
  75. @click="handleBatchPublish"
  76. v-hasPermi="['store:storeCoupon:batchPublish']"
  77. >批量发布</el-button>
  78. </el-col>
  79. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  80. </el-row>
  81. <el-table height="500" border v-loading="loading" :data="storeCouponList" @selection-change="handleSelectionChange">
  82. <el-table-column type="selection" width="55" align="center" />
  83. <el-table-column label="优惠券表ID" align="center" prop="couponId" />
  84. <el-table-column label="优惠券名称" align="center" prop="title" />
  85. <el-table-column label="优惠券面值" align="center" prop="couponPrice" />
  86. <el-table-column label="最低消费" align="center" prop="useMinPrice" />
  87. <el-table-column label="优惠券有效期限(天)" align="center" prop="couponTime" />
  88. <el-table-column label="是否无门槛" align="center" prop="isNoThreshold">
  89. <template slot-scope="scope">
  90. <span>{{ scope.row.isNoThreshold == 1 ? '是' : '否' }}</span>
  91. </template>
  92. </el-table-column>
  93. <el-table-column label="限制领取次数" align="center" prop="limitReceiveCount" />
  94. <el-table-column label="排序" align="center" prop="sort" />
  95. <el-table-column label="类型" align="center" prop="type" >
  96. <template slot-scope="scope">
  97. <el-tag prop="type" v-for="(item, index) in couponTypeOptions" v-if="scope.row.type==item.dictValue">{{item.dictLabel}}</el-tag>
  98. </template>
  99. </el-table-column>
  100. <el-table-column label="状态" align="center" prop="status" >
  101. <template slot-scope="scope">
  102. <el-tag prop="status" v-for="(item, index) in statusOptions" v-if="scope.row.status==item.dictValue">{{item.dictLabel}}</el-tag>
  103. </template>
  104. </el-table-column>
  105. <el-table-column label="创建时间" align="center" prop="createTime" />
  106. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  107. <template slot-scope="scope">
  108. <el-button
  109. v-if="scope.row.status==1"
  110. size="mini"
  111. type="text"
  112. @click="handlePublish(scope.row)"
  113. v-hasPermi="['store:storeCoupon:publish']"
  114. >发布</el-button>
  115. <el-button
  116. size="mini"
  117. type="text"
  118. icon="el-icon-edit"
  119. @click="handleUpdate(scope.row)"
  120. v-hasPermi="['store:storeCoupon:edit']"
  121. >修改</el-button>
  122. <el-button
  123. size="mini"
  124. type="text"
  125. icon="el-icon-delete"
  126. @click="handleDelete(scope.row)"
  127. v-hasPermi="['store:storeCoupon:remove']"
  128. >删除</el-button>
  129. </template>
  130. </el-table-column>
  131. </el-table>
  132. <pagination
  133. v-show="total>0"
  134. :total="total"
  135. :page.sync="queryParams.pageNum"
  136. :limit.sync="queryParams.pageSize"
  137. @pagination="getList"
  138. />
  139. <!-- 添加或修改优惠券对话框 -->
  140. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  141. <el-form ref="form" :model="form" :rules="rules" label-width="150px">
  142. <el-form-item label="优惠券名称" prop="title">
  143. <el-input v-model="form.title" placeholder="请输入优惠券名称" />
  144. </el-form-item>
  145. <el-form-item label="面值" prop="couponPrice">
  146. <el-input-number v-model="form.couponPrice" :min="0" placeholder="请输入优惠券面值" />
  147. </el-form-item>
  148. <el-form-item label="最低消费金额" prop="useMinPrice">
  149. <el-input-number v-model="form.useMinPrice" :min="0" placeholder="请输入最低消费金额" />
  150. </el-form-item>
  151. <el-form-item label="优惠券有效期限(天)" prop="couponTime">
  152. <el-input-number v-model="form.couponTime" :min="0" placeholder="请输入优惠券有效期限" />
  153. </el-form-item>
  154. <el-form-item label="排序" prop="sort">
  155. <el-input-number v-model="form.sort" :min="0" placeholder="请输入排序" />
  156. </el-form-item>
  157. <el-form-item label="类型" prop="type">
  158. <el-radio-group v-model="form.type">
  159. <el-radio :label="item.dictValue" v-for="item in couponTypeOptions" >{{item.dictLabel}}</el-radio>
  160. </el-radio-group>
  161. </el-form-item>
  162. <el-form-item label="套餐分类" v-if="form.type=='1'" prop="packageCateIds">
  163. <el-select v-model="form.packageCateIds" multiple placeholder="请选择">
  164. <el-option
  165. v-for="item in cateOptions"
  166. :key="item.dictValue"
  167. :label="item.dictLabel"
  168. :value="item.dictValue">
  169. </el-option>
  170. </el-select>
  171. </el-form-item>
  172. <el-form-item label="限制领取次数" prop="limitReceiveCount" v-if=" form.type==3">
  173. <el-input-number v-model="form.limitReceiveCount" :min="1" label="请输入限制领取次数"></el-input-number>
  174. </el-form-item>
  175. <el-form-item label="状态">
  176. <el-radio-group v-model="form.status">
  177. <el-radio :label="item.dictValue" v-for="item in statusOptions" >{{item.dictLabel}}</el-radio>
  178. </el-radio-group>
  179. </el-form-item>
  180. </el-form>
  181. <div slot="footer" class="dialog-footer">
  182. <el-button type="primary" @click="submitForm">确 定</el-button>
  183. <el-button @click="cancel">取 消</el-button>
  184. </div>
  185. </el-dialog>
  186. <el-dialog :title="publish.title" :visible.sync="publish.open" width="500px" append-to-body>
  187. <el-form ref="publishForm" :model="publishForm" :rules="publishRules" label-width="150px">
  188. <el-form-item label="优惠券名称" prop="title">
  189. <el-input v-model="publishForm.title" disabled />
  190. </el-form-item>
  191. <el-form-item label="优惠券开始时间" prop="startTime">
  192. <el-date-picker clearable size="small" style="width: 200px"
  193. v-model="publishForm.startTime"
  194. type="date"
  195. value-format="yyyy-MM-dd"
  196. placeholder="选择开始时间">
  197. </el-date-picker>
  198. </el-form-item>
  199. <el-form-item label="优惠券结束时间" prop="limitTime">
  200. <el-date-picker clearable size="small" style="width: 200px"
  201. v-model="publishForm.limitTime"
  202. type="date"
  203. value-format="yyyy-MM-dd"
  204. placeholder="选择结束时间">
  205. </el-date-picker>
  206. </el-form-item>
  207. <el-form-item label="优惠券领取数量" prop="totalCount">
  208. <el-input-number v-model="publishForm.totalCount" :min="0" placeholder="请输入优惠券领取数量" />
  209. </el-form-item>
  210. <el-form-item label="状态">
  211. <el-radio-group v-model="publishForm.status">
  212. <el-radio :label="item.dictValue" v-for="item in statusOptions" >{{item.dictLabel}}</el-radio>
  213. </el-radio-group>
  214. </el-form-item>
  215. </el-form>
  216. <div slot="footer" class="dialog-footer">
  217. <el-button type="primary" @click="submitPublishForm">确 定</el-button>
  218. <el-button @click="cancelPublish">取 消</el-button>
  219. </div>
  220. </el-dialog>
  221. <el-dialog :title="batchPublish.title" :visible.sync="batchPublish.open" width="500px" append-to-body>
  222. <add-batch-publish ref="batchPublish" @close="closeBatchPublish()"></add-batch-publish>
  223. </el-dialog>
  224. </div>
  225. </template>
  226. <script>
  227. import { publishCoupon,listStoreCoupon, getStoreCoupon, delStoreCoupon, addStoreCoupon, updateStoreCoupon, exportStoreCoupon } from "@/api/live/liveCoupon";
  228. import addBatchPublish from "../components/addBatchPublish.vue";
  229. export default {
  230. name: "StoreCoupon",
  231. components:{addBatchPublish},
  232. data() {
  233. return {
  234. cateOptions:[],
  235. couponTypeOptions:[],
  236. publish:{
  237. title:"发布",
  238. open:false,
  239. },
  240. batchPublish:{
  241. title:"批量发布",
  242. open:false,
  243. },
  244. dateRange:[],
  245. statusOptions:[],
  246. // 遮罩层
  247. loading: true,
  248. // 选中数组
  249. ids: [],
  250. // 非单个禁用
  251. single: true,
  252. // 非多个禁用
  253. multiple: true,
  254. // 显示搜索条件
  255. showSearch: true,
  256. // 总条数
  257. total: 0,
  258. // 优惠券表格数据
  259. storeCouponList: [],
  260. // 弹出层标题
  261. title: "",
  262. // 是否显示弹出层
  263. open: false,
  264. // 查询参数
  265. queryParams: {
  266. pageNum: 1,
  267. pageSize: 10,
  268. title: null,
  269. integral: null,
  270. couponPrice: null,
  271. useMinPrice: null,
  272. couponTime: null,
  273. sort: null,
  274. status: null,
  275. productIds: null,
  276. type: null,
  277. isDel: null
  278. },
  279. // 表单参数
  280. form: {},
  281. // 表单校验
  282. rules: {
  283. title: [
  284. { required: true, message: "优惠券名称不能为空", trigger: "blur" }
  285. ],
  286. integral: [
  287. { required: true, message: "兑换消耗积分值不能为空", trigger: "blur" }
  288. ],
  289. couponPrice: [
  290. { required: true, message: "兑换的优惠券面值不能为空", trigger: "blur" }
  291. ],
  292. useMinPrice: [
  293. { required: true, message: "最低消费多少金额可用优惠券不能为空", trigger: "blur" }
  294. ],
  295. couponTime: [
  296. { required: true, message: "优惠券有效期限不能为空", trigger: "blur" }
  297. ],
  298. sort: [
  299. { required: true, message: "排序不能为空", trigger: "blur" }
  300. ],
  301. status: [
  302. { required: true, message: "状态不能为空", trigger: "blur" }
  303. ],
  304. createTime: [
  305. { required: true, message: "兑换项目添加时间不能为空", trigger: "blur" }
  306. ],
  307. type: [
  308. { required: true, message: "类型不能为空", trigger: "blur" }
  309. ],
  310. packageCateIds: [
  311. { required: true, message: "套餐分类不能为空", trigger: "blur" }
  312. ],
  313. isDel: [
  314. { required: true, message: "是否删除不能为空", trigger: "blur" }
  315. ]
  316. },
  317. publishForm: {
  318. totalCount:0,
  319. status:"0"
  320. },
  321. // 表单校验
  322. publishRules: {
  323. totalCount: [
  324. { required: true, message: "数量不能为空", trigger: "blur" }
  325. ],
  326. startTime: [
  327. { required: true, message: "开始时间不能为空", trigger: "blur" }
  328. ],
  329. limitTime: [
  330. { required: true, message: "结束时间不能为空", trigger: "blur" }
  331. ],
  332. }
  333. };
  334. },
  335. created() {
  336. this.getDicts("store_product_package_cate").then((response) => {
  337. var item={dictValue:'0',dictLabel:"全部"};
  338. this.cateOptions.push(item)
  339. this.cateOptions = this.cateOptions.concat(response.data);
  340. });
  341. this.getDicts("common_status").then((response) => {
  342. this.statusOptions = response.data;
  343. });
  344. this.getDicts("store_coupon_type").then((response) => {
  345. this.couponTypeOptions = response.data;
  346. });
  347. this.getList();
  348. },
  349. methods: {
  350. /** 查询优惠券列表 */
  351. getList() {
  352. this.loading = true;
  353. listStoreCoupon(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  354. this.storeCouponList = response.rows;
  355. this.total = response.total;
  356. this.loading = false;
  357. });
  358. },
  359. // 取消按钮
  360. cancel() {
  361. this.open = false;
  362. this.reset();
  363. },
  364. // 表单重置
  365. reset() {
  366. this.form = {
  367. couponId: null,
  368. title: null,
  369. integral: null,
  370. couponPrice: null,
  371. useMinPrice: null,
  372. couponTime: null,
  373. sort: null,
  374. status: "0",
  375. type: "0",
  376. productIds: null,
  377. packageCateIds:[],
  378. createTime: null,
  379. updateTime: null,
  380. isDel: null,
  381. isNoThreshold: 0,
  382. limitReceiveCount: 1,
  383. };
  384. this.resetForm("form");
  385. },
  386. /** 搜索按钮操作 */
  387. handleQuery() {
  388. this.queryParams.pageNum = 1;
  389. this.getList();
  390. },
  391. /** 重置按钮操作 */
  392. resetQuery() {
  393. this.resetForm("queryForm");
  394. this.handleQuery();
  395. },
  396. // 多选框选中数据
  397. handleSelectionChange(selection) {
  398. this.ids = selection.map(item => item.couponId)
  399. this.single = selection.length!==1
  400. this.multiple = !selection.length
  401. },
  402. /** 新增按钮操作 */
  403. handleAdd() {
  404. this.reset();
  405. this.open = true;
  406. this.title = "添加优惠券";
  407. },
  408. /** 修改按钮操作 */
  409. handleUpdate(row) {
  410. this.reset();
  411. const couponId = row.couponId || this.ids
  412. getStoreCoupon(couponId).then(response => {
  413. this.form = response.data;
  414. this.form.status = response.data.status.toString();
  415. this.form.type = response.data.type.toString();
  416. if(this.form.packageCateIds!=null){
  417. this.form.packageCateIds=this.form.packageCateIds.split(',')
  418. }
  419. this.open = true;
  420. this.title = "修改优惠券";
  421. });
  422. },
  423. /** 提交按钮 */
  424. submitForm() {
  425. this.$refs["form"].validate(valid => {
  426. if (valid) {
  427. if(this.form.packageCateIds!=null){
  428. this.form.packageCateIds=this.form.packageCateIds.toString();
  429. }
  430. if(this.form.type==3){
  431. this.form.isNoThreshold = 1
  432. }
  433. if (this.form.couponId != null) {
  434. updateStoreCoupon(this.form).then(response => {
  435. if (response.code === 200) {
  436. this.msgSuccess("修改成功");
  437. this.open = false;
  438. this.getList();
  439. }
  440. });
  441. } else {
  442. addStoreCoupon(this.form).then(response => {
  443. if (response.code === 200) {
  444. this.msgSuccess("新增成功");
  445. this.open = false;
  446. this.getList();
  447. }
  448. });
  449. }
  450. }
  451. });
  452. },
  453. handleBatchPublish(){
  454. this.batchPublish.open = true;
  455. var that = this;
  456. setTimeout(() => {
  457. that.$refs.batchPublish.handleBatch(that.ids);
  458. }, 200);
  459. },
  460. closeBatchPublish(){
  461. this.batchPublish.open = false;
  462. this.getList();
  463. },
  464. handlePublish(row){
  465. this.publish.open=true;
  466. this.publishForm.title=row.title;
  467. this.publishForm.couponId=row.couponId;
  468. },
  469. cancelPublish() {
  470. this.publish.open = false;
  471. this.reset();
  472. },
  473. submitPublishForm() {
  474. this.$refs["publishForm"].validate(valid => {
  475. if (valid) {
  476. publishCoupon(this.publishForm).then(response => {
  477. if (response.code === 200) {
  478. this.msgSuccess("发布成功");
  479. this.publish.open = false;
  480. }
  481. });
  482. }
  483. });
  484. },
  485. /** 删除按钮操作 */
  486. handleDelete(row) {
  487. const couponIds = row.couponId || this.ids;
  488. this.$confirm('是否确认删除优惠券编号为"' + couponIds + '"的数据项?', "警告", {
  489. confirmButtonText: "确定",
  490. cancelButtonText: "取消",
  491. type: "warning"
  492. }).then(function() {
  493. return delStoreCoupon(couponIds);
  494. }).then(() => {
  495. this.getList();
  496. this.msgSuccess("删除成功");
  497. }).catch(function() {});
  498. },
  499. /** 导出按钮操作 */
  500. handleExport() {
  501. const queryParams = this.queryParams;
  502. this.$confirm('是否确认导出所有优惠券数据项?', "警告", {
  503. confirmButtonText: "确定",
  504. cancelButtonText: "取消",
  505. type: "warning"
  506. }).then(function() {
  507. return exportStoreCoupon(queryParams);
  508. }).then(response => {
  509. this.download(response.msg);
  510. }).catch(function() {});
  511. },
  512. }
  513. };
  514. </script>