index.vue 12 KB

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