index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. </el-card>
  96. <el-dialog title="发放优惠券" :visible.sync="dialogFormVisible">
  97. <el-form
  98. :model="ruleForm"
  99. :rules="rules"
  100. ref="ruleForm"
  101. label-width="100px"
  102. style="width: 400px; margin-left:50px;"
  103. >
  104. <el-form-item label="券类型" prop="category">
  105. <el-select v-model="ruleForm.category" placeholder="请选择券类型">
  106. <el-option
  107. v-for="(item, index) in couponType"
  108. :key="index"
  109. :label="item.label"
  110. :value="item.value"
  111. :disabled="item.disabled"
  112. ></el-option>
  113. </el-select>
  114. </el-form-item>
  115. <el-form-item
  116. v-if="ruleForm.category === 'reduction'"
  117. label="金额"
  118. prop="amount"
  119. >
  120. <el-input
  121. type="number"
  122. v-model="ruleForm.amount"
  123. style="width: 300px;"
  124. ></el-input>
  125. </el-form-item>
  126. <el-form-item
  127. v-if="ruleForm.category === 'discount'"
  128. label="折扣"
  129. prop="discount"
  130. >
  131. <el-input
  132. type="number"
  133. v-model="ruleForm.discount"
  134. style="width: 300px;"
  135. ></el-input>
  136. </el-form-item>
  137. <!-- <el-form-item label="过期时间" prop="duedate">
  138. <el-date-picker
  139. value-format="yyyy-MM-dd"
  140. v-model="ruleForm.duedate"
  141. type="date"
  142. placeholder="选择日期"
  143. :picker-options="pickerBeginDateBefore"
  144. ></el-date-picker>
  145. </el-form-item> -->
  146. <el-form-item label="电话号" prop="phone">
  147. <el-input v-model="ruleForm.phone" style="width: 300px;"></el-input>
  148. </el-form-item>
  149. </el-form>
  150. <div slot="footer" class="dialog-footer">
  151. <el-button @click="dialogFormVisible = false">取消</el-button>
  152. <el-button type="primary" @click="submitForm" :loading="submitLoading"
  153. >确定</el-button
  154. >
  155. </div>
  156. </el-dialog>
  157. </div>
  158. </template>
  159. <script>
  160. import { getTicketList, generate_ticket, query_by_phone } from "@/api/order";
  161. // 手机号验证
  162. const validatePhone = (rule, value, callback) => {
  163. if (value === "") {
  164. callback(new Error("请输入手机号"));
  165. } else {
  166. if (!/^1[123456789]\d{9}$/.test(value)) {
  167. callback(new Error("请输入正确的手机号"));
  168. } else {
  169. callback();
  170. }
  171. }
  172. };
  173. // 立减券金额验证
  174. const validateReduction = (rule, value, callback) => {
  175. if (value === "") {
  176. callback(new Error("请输入金额"));
  177. } else {
  178. if (!/(^[1-9]\d*$)/.test(value)) {
  179. callback(new Error("金额为正整数"));
  180. } else {
  181. callback();
  182. }
  183. }
  184. };
  185. // 折扣验证
  186. const validateDiscount = (rule, value, callback) => {
  187. if (value === "") {
  188. callback(new Error("请输入折扣"));
  189. } else {
  190. if (!/^(?=1\.[1-9]|[1-9]\.\d).{3}$|^([2-9])$/.test(value)) {
  191. callback(new Error("折扣范围为1.1~9.9"));
  192. } else {
  193. callback();
  194. }
  195. }
  196. };
  197. const couponType = [
  198. {
  199. label: "立减券",
  200. value: "reduction"
  201. },
  202. {
  203. label: "折扣券",
  204. value: "discount"
  205. },
  206. {
  207. label: "VIP免单券",
  208. value: "vip",
  209. disabled: true
  210. }
  211. ];
  212. export default {
  213. name: "ticket",
  214. data() {
  215. return {
  216. total: 0,
  217. listLoading: false,
  218. searchLoading: false,
  219. listQuery: {
  220. phone: ""
  221. },
  222. tableData: [],
  223. //发放优惠券
  224. submitLoading: false,
  225. pickerBeginDateBefore: {
  226. disabledDate: time => {
  227. return time.getTime() < Date.now() - 8.64e7;
  228. }
  229. },
  230. selectDisabled: false,
  231. dialogFormVisible: false,
  232. couponType,
  233. couponAmount: [],
  234. couponDescription: [],
  235. ruleForm: {
  236. category: "",
  237. discount: 5.8,
  238. amount: 15,
  239. // duedate: "",
  240. phone: ""
  241. },
  242. rules: {
  243. category: [
  244. { required: true, message: "请选择券类型", trigger: "change" }
  245. ],
  246. amount: [
  247. { required: true, validator: validateReduction, trigger: "blur" }
  248. ],
  249. discount: [
  250. { required: true, validator: validateDiscount, trigger: "blur" }
  251. ],
  252. // duedate: [
  253. // {
  254. // required: true,
  255. // message: "请选择过期时间",
  256. // trigger: "change"
  257. // }
  258. // ],
  259. phone: [
  260. {
  261. validator: validatePhone,
  262. required: true,
  263. trigger: "blur"
  264. }
  265. ]
  266. }
  267. };
  268. },
  269. methods: {
  270. getList() {
  271. if (!this.listQuery.phone) {
  272. return this.$message.error("请输入正确手机号!");
  273. }
  274. if (!/^1[123456789]\d{9}$/.test(this.listQuery.phone.trim())) {
  275. return this.$message.error("请输入正确手机号!");
  276. }
  277. this.listLoading = true;
  278. query_by_phone({
  279. phone: this.listQuery.phone.trim()
  280. }).then(res => {
  281. this.tableData = res.tickets;
  282. // this.total = res.total;
  283. this.listLoading = false;
  284. });
  285. },
  286. submitForm() {
  287. this.$refs["ruleForm"].validate(valid => {
  288. if (valid) {
  289. console.log(valid);
  290. console.log(this.ruleForm);
  291. this.submitLoading = true;
  292. let params = {};
  293. if (this.ruleForm.category == "reduction") {
  294. params = {
  295. category: this.ruleForm.category,
  296. amount: Number(this.ruleForm.amount),
  297. phone: this.ruleForm.phone
  298. };
  299. } else if (this.ruleForm.category == "discount") {
  300. params = {
  301. category: this.ruleForm.category,
  302. discount: Number(this.ruleForm.discount),
  303. phone: this.ruleForm.phone
  304. };
  305. } else if (this.ruleForm.category == "vip") {
  306. params = {
  307. category: this.ruleForm.category,
  308. phone: this.ruleForm.phone
  309. };
  310. }
  311. generate_ticket(params).then(() => {
  312. this.$message({
  313. message: "发放成功!",
  314. type: "success"
  315. });
  316. this.dialogFormVisible = false;
  317. this.submitLoading = false;
  318. });
  319. } else {
  320. console.log("error submit!!");
  321. return false;
  322. }
  323. });
  324. },
  325. resetTemp() {
  326. this.ruleForm = {
  327. category: "",
  328. discount: 5.8,
  329. amount: 15,
  330. // duedate: "",
  331. phone: ""
  332. };
  333. },
  334. handleUpdate() {
  335. this.resetTemp();
  336. this.dialogFormVisible = true;
  337. this.$nextTick(() => {
  338. this.$refs["ruleForm"].clearValidate();
  339. });
  340. }
  341. }
  342. };
  343. </script>
  344. <style lang="scss" scoped>
  345. .container {
  346. padding: 20px;
  347. }
  348. .pd-30 {
  349. padding: 30px 0;
  350. }
  351. .filter-container {
  352. overflow: hidden;
  353. padding: 10px 0;
  354. }
  355. .table-list {
  356. font-size: 12px;
  357. }
  358. </style>