index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. <template>
  2. <div class="container">
  3. <el-card class="box-card">
  4. <!-- <div class="filter-container">
  5. <el-input
  6. prefix-icon="el-icon-search"
  7. v-model="listQuery.phone"
  8. style="width: 300px;"
  9. placeholder="请输入手机号"
  10. clearable
  11. @keyup.enter.native="getDetail"
  12. />
  13. <el-button
  14. style="margin-left: 10px;"
  15. :loading="searchLoading"
  16. type="primary"
  17. icon="el-icon-search"
  18. @click="getDetail"
  19. >搜索</el-button>
  20. <el-button type="primary" plain style="float:right;" @click="handleUpdate">发放优惠券</el-button>
  21. </div>-->
  22. <!-- show-overflow-tooltip -->
  23. <el-table
  24. :data="tableData"
  25. v-loading="listLoading"
  26. highlight-current-row
  27. fit
  28. class="table-list"
  29. :cell-style="{ padding: '6px 0' }"
  30. >
  31. <el-table-column prop="id" label="ID" width="100"></el-table-column>
  32. <el-table-column
  33. prop="title"
  34. label="title"
  35. width="120"
  36. show-overflow-tooltip
  37. ></el-table-column>
  38. <el-table-column
  39. prop="amount"
  40. label="amount"
  41. width="100"
  42. ></el-table-column>
  43. <el-table-column
  44. prop="description"
  45. label="description"
  46. show-overflow-tooltip
  47. ></el-table-column>
  48. <el-table-column
  49. prop="category"
  50. label="category"
  51. width="100"
  52. show-overflow-tooltip
  53. ></el-table-column>
  54. <el-table-column
  55. prop="coffee"
  56. label="coffee"
  57. width="100"
  58. show-overflow-tooltip
  59. ></el-table-column>
  60. <el-table-column
  61. prop="discount"
  62. label="discount"
  63. width="100"
  64. ></el-table-column>
  65. <el-table-column
  66. prop="startdate"
  67. label="startdate"
  68. width="120"
  69. ></el-table-column>
  70. <el-table-column
  71. prop="duedate"
  72. label="duedate"
  73. width="120"
  74. ></el-table-column>
  75. <el-table-column
  76. prop="phone"
  77. label="phone"
  78. width="120"
  79. show-overflow-tooltip
  80. ></el-table-column>
  81. <el-table-column prop="used" label="used" width="100"></el-table-column>
  82. <el-table-column
  83. prop="useropenid"
  84. label="useropenid"
  85. show-overflow-tooltip
  86. ></el-table-column>
  87. </el-table>
  88. <div class="pd-30">
  89. <el-pagination
  90. v-show="total > 0"
  91. background
  92. layout="prev, pager, next"
  93. :total="total"
  94. @current-change="handleCurrentChange"
  95. :current-page.sync="listQuery.page"
  96. :page-size="listQuery.limit"
  97. ></el-pagination>
  98. </div>
  99. </el-card>
  100. <el-dialog title="发放优惠券" :visible.sync="dialogFormVisible">
  101. <el-form
  102. :model="ruleForm"
  103. :rules="rules"
  104. ref="ruleForm"
  105. label-width="100px"
  106. style="width: 400px; margin-left:50px;"
  107. >
  108. <el-form-item label="券类型" prop="title">
  109. <el-select
  110. v-model="ruleForm.title"
  111. placeholder="请选择券类型"
  112. @change="titleChange"
  113. >
  114. <el-option
  115. v-for="(item, index) in couponType"
  116. :key="index"
  117. :label="item.label"
  118. :value="item.value"
  119. ></el-option>
  120. </el-select>
  121. </el-form-item>
  122. <el-form-item label="金额" prop="amount">
  123. <el-select
  124. v-model="ruleForm.amount"
  125. placeholder="请选择金额"
  126. @change="amountChange"
  127. >
  128. <el-option
  129. v-for="(item, index) in couponAmount"
  130. :key="index"
  131. :label="item.label"
  132. :value="item.value"
  133. ></el-option>
  134. </el-select>
  135. </el-form-item>
  136. <el-form-item label="描述">
  137. <!-- <el-select v-model="ruleForm.description" disabled>
  138. <el-option
  139. v-for="(item,index) in couponDescription"
  140. :key="index"
  141. :label="item.label"
  142. :value="item.value"
  143. ></el-option>
  144. </el-select>-->
  145. <el-input
  146. v-model="ruleForm.description"
  147. disabled
  148. style="width: 300px;"
  149. ></el-input>
  150. </el-form-item>
  151. <el-form-item
  152. label="过期时间"
  153. prop="duedate"
  154. v-if="ruleForm.title == '立减券' || ruleForm.title == 'VIP免单券'"
  155. >
  156. <el-date-picker
  157. value-format="yyyy-MM-dd"
  158. v-model="ruleForm.duedate"
  159. type="date"
  160. placeholder="选择日期"
  161. :picker-options="pickerBeginDateBefore"
  162. ></el-date-picker>
  163. </el-form-item>
  164. <el-form-item label="电话号" prop="phone">
  165. <el-input v-model="ruleForm.phone" style="width: 300px;"></el-input>
  166. </el-form-item>
  167. <!-- <el-form-item>
  168. <el-button type="primary" @click="submitForm('ruleForm')">立即发放</el-button>
  169. <el-button @click="resetForm('ruleForm')">重置</el-button>
  170. </el-form-item>-->
  171. </el-form>
  172. <div slot="footer" class="dialog-footer">
  173. <el-button @click="dialogFormVisible = false">取消</el-button>
  174. <el-button type="primary" @click="submitForm" :loading="submitLoading"
  175. >确定</el-button
  176. >
  177. </div>
  178. </el-dialog>
  179. </div>
  180. </template>
  181. <script>
  182. import { getTicketList, generate_ticket, query_by_phone } from "@/api/order";
  183. // 手机号验证
  184. const validatePhone = (rule, value, callback) => {
  185. if (value === "") {
  186. callback(new Error("请输入手机号"));
  187. } else {
  188. if (!/^1[123456789]\d{9}$/.test(value)) {
  189. callback(new Error("请输入正确的手机号"));
  190. } else {
  191. callback();
  192. }
  193. }
  194. };
  195. const couponType = [
  196. {
  197. label: "立减券",
  198. value: "立减券"
  199. },
  200. {
  201. label: "月卡券",
  202. value: "月卡券"
  203. },
  204. {
  205. label: "VIP免单券",
  206. value: "VIP免单券"
  207. }
  208. ];
  209. const couponAmount = [
  210. {
  211. label: 15,
  212. value: 15
  213. },
  214. {
  215. label: 12,
  216. value: 12
  217. },
  218. {
  219. label: 30,
  220. value: 30
  221. }
  222. ];
  223. const couponDescription = [
  224. {
  225. label: "立减15元,回馈老用户",
  226. value: "立减15元,回馈老用户"
  227. },
  228. {
  229. label: "立减12元,回馈老用户",
  230. value: "立减12元,回馈老用户"
  231. },
  232. {
  233. label: "立减15元,每天限用1次",
  234. value: "立减15元,每天限用1次"
  235. },
  236. {
  237. label: "任意咖啡(一杯)免单,VIP用户专享",
  238. value: "任意咖啡(一杯)免单,VIP用户专享"
  239. }
  240. ];
  241. export default {
  242. name: "ticket",
  243. data() {
  244. return {
  245. total: 0,
  246. listLoading: true,
  247. searchLoading: false,
  248. listQuery: {
  249. page: 1,
  250. limit: 100
  251. },
  252. tableData: [],
  253. //发放优惠券
  254. submitLoading: false,
  255. pickerBeginDateBefore: {
  256. disabledDate: time => {
  257. return time.getTime() < Date.now() - 8.64e7;
  258. }
  259. },
  260. selectDisabled: false,
  261. dialogFormVisible: false,
  262. couponType,
  263. couponAmount: [],
  264. couponDescription: [],
  265. ruleForm: {
  266. title: "",
  267. amount: "",
  268. description: "",
  269. duedate: "",
  270. phone: ""
  271. },
  272. rules: {
  273. title: [{ required: true, message: "请选择券类型", trigger: "change" }],
  274. amount: [{ required: true, message: "请选择金额", trigger: "change" }],
  275. duedate: [
  276. {
  277. required: true,
  278. message: "请选择过期时间",
  279. trigger: "change"
  280. }
  281. ],
  282. phone: [
  283. {
  284. validator: validatePhone,
  285. required: true,
  286. trigger: "blur"
  287. }
  288. ]
  289. }
  290. };
  291. },
  292. watch: {
  293. // ruleForm: {
  294. // handler: function (val, oldval) {
  295. // console.log(val);
  296. // if (val.title == "月卡券") {
  297. // this.ruleForm.amount = 15;
  298. // this.selectDisabled = true;
  299. // this.ruleForm.description = "立减15元,每天限用1次";
  300. // } else if (val.title == "立减券") {
  301. // this.selectDisabled = false;
  302. // this.couponAmount = couponAmount;
  303. // this.ruleForm.description = "";
  304. // } else if (val.title == "立减券" && val.amount == 15) {
  305. // this.ruleForm.description = "立减15元,回馈老用户";
  306. // } else if (val.title == "立减券" && val.amount == 12) {
  307. // this.ruleForm.description = "立减12元,回馈老用户";
  308. // }
  309. // },
  310. // deep: true, //对象内部的属性监听,也叫深度监听
  311. // },
  312. },
  313. created() {
  314. this.getList();
  315. },
  316. methods: {
  317. getList() {
  318. this.listLoading = true;
  319. getTicketList({
  320. page: this.listQuery.page
  321. }).then(res => {
  322. this.tableData = res.tickets;
  323. this.total = res.total;
  324. this.listLoading = false;
  325. });
  326. },
  327. handleCurrentChange(val) {
  328. this.listQuery.page = val;
  329. //刷新页面
  330. console.log(`当前页: ${val}`);
  331. this.getList();
  332. },
  333. //发放优惠券
  334. titleChange(title) {
  335. this.ruleForm.amount = "";
  336. this.ruleForm.description = "";
  337. if (title == "立减券") {
  338. this.ruleForm.description = "";
  339. this.couponAmount = [
  340. {
  341. label: 15,
  342. value: 15
  343. },
  344. {
  345. label: 12,
  346. value: 12
  347. }
  348. ];
  349. }
  350. if (title == "月卡券") {
  351. this.couponAmount = [
  352. {
  353. label: 15,
  354. value: 15
  355. }
  356. ];
  357. this.ruleForm.amount = 15;
  358. this.ruleForm.description = "立减15元,每天限用1次";
  359. }
  360. if (title == "VIP免单券") {
  361. this.couponAmount = [
  362. {
  363. label: 30,
  364. value: 30
  365. }
  366. ];
  367. this.ruleForm.amount = 30;
  368. this.ruleForm.description = "任意咖啡(一杯)免单,VIP用户专享";
  369. }
  370. },
  371. amountChange(amount) {
  372. if (amount == 15 && this.ruleForm.title == "立减券") {
  373. this.ruleForm.description = "立减15元,回馈老用户";
  374. }
  375. if (amount == 12 && this.ruleForm.title == "立减券") {
  376. this.ruleForm.description = "立减12元,回馈老用户";
  377. }
  378. },
  379. submitForm() {
  380. this.$refs["ruleForm"].validate(valid => {
  381. if (valid) {
  382. this.submitLoading = true;
  383. let params = {};
  384. if (this.ruleForm.title == "月卡券") {
  385. params = {
  386. title: "月卡券",
  387. phone: this.ruleForm.phone
  388. };
  389. } else if (this.ruleForm.title == "立减券") {
  390. params = {
  391. title: "立减券",
  392. amount: this.ruleForm.amount,
  393. description: this.ruleForm.description,
  394. duedate: this.ruleForm.duedate,
  395. phone: this.ruleForm.phone
  396. };
  397. } else if (this.ruleForm.title == "VIP免单券") {
  398. params = {
  399. title: "VIP免单券",
  400. amount: this.ruleForm.amount,
  401. description: this.ruleForm.description,
  402. duedate: this.ruleForm.duedate,
  403. phone: this.ruleForm.phone
  404. };
  405. }
  406. generate_ticket(params).then(() => {
  407. this.$message({
  408. message: "发放成功!",
  409. type: "success"
  410. });
  411. this.dialogFormVisible = false;
  412. this.submitLoading = false;
  413. });
  414. } else {
  415. console.log("error submit!!");
  416. return false;
  417. }
  418. });
  419. },
  420. resetTemp() {
  421. this.ruleForm = {
  422. title: "",
  423. amount: "",
  424. description: "",
  425. duedate: "",
  426. phone: ""
  427. };
  428. },
  429. handleUpdate() {
  430. this.resetTemp();
  431. this.dialogFormVisible = true;
  432. this.$nextTick(() => {
  433. this.$refs["ruleForm"].clearValidate();
  434. });
  435. }
  436. }
  437. };
  438. </script>
  439. <style lang="scss" scoped>
  440. .box-card {
  441. overflow: hidden;
  442. }
  443. .container {
  444. padding: 20px;
  445. }
  446. .pd-30 {
  447. padding: 30px 0;
  448. }
  449. .filter-container {
  450. overflow: hidden;
  451. padding: 10px 0;
  452. }
  453. .table-list {
  454. font-size: 12px;
  455. }
  456. </style>