index.vue 17 KB

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