index.vue 18 KB

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