myCoupon.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <view class="content">
  3. <z-paging-swiper>
  4. <u-navbar
  5. slot="top"
  6. title-color="#fff"
  7. :custom-back="customBack"
  8. :border-bottom="false"
  9. back-icon-color="#CCE8FF"
  10. :background="{ background: '#008CFF' }"
  11. title="我的优惠券"
  12. >
  13. <view class="navbar-font" slot="right" @click="jumpPage('/pages/center/coupon/couponRules/couponRules')"> 规则 </view>
  14. </u-navbar>
  15. <z-tabs ref="tabs" slot="top" :list="tabList" :current="current" barWidth="90rpx" @change="tabsChange"> </z-tabs>
  16. <swiper class="swiper" :current="current" @transition="swiperTransition" @animationfinish="swiperAnimationfinish">
  17. <swiper-item class="swiper-item" v-for="(item, index) in tabList" :key="index">
  18. <!-- <view class="search-part" v-if="current === 0">
  19. <u-input class="search-part-input" v-model="form.exchangeCode" placeholder="请输入兑换码" />
  20. <u-button class="search-part-btn" type="primary" shape="circle" size="medium" @click.stop="handleExchange">兑换</u-button>
  21. </view> -->
  22. <coupon-swiper-list-item :tabIndex="index" :currentIndex="current" ref="swiperListItem" />
  23. </swiper-item>
  24. </swiper>
  25. <!-- 绑定车牌 -->
  26. <u-popup v-model="bindVehiclePop.showChangeVehicleNo" :mask-close-able="false" mode="center" border-radius="20" width="700rpx">
  27. <view class="popup-vehicleNo">
  28. <view class="popup-vehicleNo-title">绑定车牌</view>
  29. <view class="popup-vehicleNo-center"></view>
  30. <view class="popup-vehicleNo-content">
  31. <view class="new-plate-number">
  32. <view class="message-input-wrap" @click="messageInputClick">
  33. <u-message-input :maxlength="8" width="60" font-size="40" :disabled-keyboard="true" v-model="form.vehicleNo" />
  34. </view>
  35. </view>
  36. </view>
  37. <view class="popup-vehicleNo-select">
  38. <u-collapse ref="refValue" :head-style="{ fontSize: '28rpx' }">
  39. <u-collapse-item title="点击选择车牌" align="center">
  40. <scroll-view class="popup-vehicleNo-select-scroll" scroll-y="true">
  41. <u-cell-group v-if="bindVehiclePop.vehicleList.length">
  42. <u-cell-item :title="item.value" v-for="(item, index) in bindVehiclePop.vehicleList" :key="index" :arrow="false">
  43. <u-radio-group v-model="form.vehicleNo" @change="radioGroupChange">
  44. <u-radio :name="item.value" :key="index"></u-radio>
  45. </u-radio-group>
  46. </u-cell-item>
  47. </u-cell-group>
  48. <template v-else>
  49. <view class="popup-vehicleNo-select-empty">暂无绑定车牌</view>
  50. </template>
  51. </scroll-view>
  52. </u-collapse-item>
  53. </u-collapse>
  54. </view>
  55. <view class="vehicleNo-btn">
  56. <u-button type="primary" :disabled="!form.vehicleNo" :loading="bindVehiclePop.loading" @click="handleBindVehicle">确认</u-button>
  57. <u-button type="primary" plain @click="cencelBindVehicle">取消</u-button>
  58. </view>
  59. </view>
  60. </u-popup>
  61. <!-- 选择颜色 -->
  62. <u-action-sheet :list="bindVehiclePop.colorList" @click="confirmColor" v-model="bindVehiclePop.colorShow" />
  63. <!-- 车牌号键盘 -->
  64. <u-keyboard
  65. ref="uKeyboard"
  66. mode="car"
  67. @change="keyboardChange"
  68. @confirm="keyboardConfirm"
  69. @backspace="backspace"
  70. v-model="bindVehiclePop.keyboardshow"
  71. />
  72. </z-paging-swiper>
  73. <u-toast ref="uToast" />
  74. </view>
  75. </template>
  76. <script>
  77. export default {
  78. data() {
  79. return {
  80. tabList: [
  81. {
  82. name: '未使用',
  83. value: 0,
  84. list: []
  85. },
  86. {
  87. name: '已使用',
  88. value: 1,
  89. list: []
  90. },
  91. {
  92. name: '已失效',
  93. value: 2,
  94. list: []
  95. }
  96. ],
  97. current: 0,
  98. form: {
  99. exchangeCode: '',
  100. source: 1,
  101. vehicleNo: '',
  102. merchantCode: '',
  103. qrcodeNo: '',
  104. couponId: ''
  105. },
  106. // 绑定车牌
  107. bindVehiclePop: {
  108. show: false,
  109. vehicleList: [],
  110. showChangeVehicleNo: false,
  111. colorShow: false,
  112. loading: false,
  113. colorList: [
  114. {
  115. text: '蓝色',
  116. colorCode: 0
  117. },
  118. {
  119. text: '黄色',
  120. colorCode: 1
  121. },
  122. {
  123. text: '黑色',
  124. colorCode: 2
  125. },
  126. {
  127. text: '白色',
  128. colorCode: 3
  129. },
  130. {
  131. text: '绿色',
  132. colorCode: 4
  133. },
  134. {
  135. text: '其他',
  136. colorCode: 99
  137. }
  138. ],
  139. keyboardshow: false
  140. }
  141. };
  142. },
  143. onLoad(options) {
  144. const { merchantCode, qrcodeNo, couponId } = options;
  145. if (merchantCode && qrcodeNo && couponId) {
  146. this.form.merchantCode = merchantCode;
  147. this.form.couponId = couponId;
  148. this.form.qrcodeNo = qrcodeNo;
  149. this.bindVehiclePop.showChangeVehicleNo = true;
  150. this.getCarsList();
  151. }
  152. },
  153. methods: {
  154. // tabs通知swiper切换
  155. tabsChange(index) {
  156. this.current = index;
  157. },
  158. // swiper滑动中
  159. swiperTransition(e) {
  160. this.$refs.tabs.setDx(e.detail.dx);
  161. },
  162. //swiper滑动结束
  163. swiperAnimationfinish(e) {
  164. this.current = e.detail.current;
  165. this.$refs.tabs.unlockDx();
  166. },
  167. /**
  168. * 兑换
  169. * @date 2022-12-23
  170. * @returns {any}
  171. */
  172. handleExchange() {
  173. if (this.form.exchangeCode) {
  174. this.bindVehiclePop.showChangeVehicleNo = true;
  175. this.getCarsList();
  176. } else {
  177. this.$refs.uToast.show({
  178. title: '请输入兑换码',
  179. type: 'warning'
  180. });
  181. }
  182. },
  183. /**
  184. * @description: 获取我的车辆列表
  185. * @return {*}
  186. */
  187. async getCarsList() {
  188. const { data } = await this.$u.api.getMycars({ pageNum: 1, pageSize: 100 });
  189. const vehicleList = [];
  190. data.rows.forEach((item) => {
  191. const { vehicleNo } = item;
  192. vehicleList.push({ label: vehicleNo, value: vehicleNo });
  193. });
  194. this.bindVehiclePop.vehicleList = vehicleList;
  195. await this.$nextTick();
  196. this.$refs.refValue.init();
  197. },
  198. /**
  199. * 兑换优惠券
  200. * @date 2022-12-23
  201. * @returns {any}
  202. */
  203. async exchangeCoupon() {
  204. const { vehicleNo } = this.form;
  205. // const reg =
  206. // /^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[a-zA-Z](([A-Z]((?![IO])[a-zA-Z0-9](?![IO]))[0-9]{4})|([0-9]{5}[A-Z]))|[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1})$/;
  207. const reg = /^[A-Za-z0-9\u4e00-\u9fa5]{7,9}$/;
  208. if (reg.test(vehicleNo) && vehicleNo.indexOf('I') === -1) {
  209. try {
  210. this.bindVehiclePop.loading = true;
  211. const { code } = await this.$u.api.exchangeCouponApi({ ...this.form });
  212. if (code === 200) {
  213. this.$refs.uToast.show({
  214. title: '兑换成功!',
  215. type: 'success'
  216. });
  217. this.$refs['swiperListItem'][this.current].reloadData();
  218. setTimeout(() => {
  219. location.href = location.origin + location.pathname;
  220. }, 500);
  221. }
  222. this.bindVehiclePop.loading = false;
  223. } catch (error) {
  224. this.bindVehiclePop.loading = false;
  225. }
  226. } else {
  227. this.$refs.uToast.show({
  228. title: '车牌输入错误,请重新输入!',
  229. type: 'error'
  230. });
  231. }
  232. },
  233. /**
  234. * 点击输入框弹出车牌键盘
  235. * @date 2023-02-22
  236. * @returns {any}
  237. */
  238. messageInputClick() {
  239. this.bindVehiclePop.keyboardshow = true;
  240. this.form.vehicleNo = '';
  241. },
  242. /**
  243. * 颜色下拉确认
  244. * @date 2023-02-22
  245. * @param {any} e
  246. * @returns {any}
  247. */
  248. confirmColor(e) {
  249. this.bindVehiclePop.colorShow = false;
  250. },
  251. /**
  252. * 按键被点击(点击退格键不会触发此事件)
  253. * @date 2023-02-22
  254. * @param {any} val
  255. * @returns {any}
  256. */
  257. keyboardChange(val) {
  258. // 将每次按键的值拼接到value变量中,注意+=写法
  259. this.form.vehicleNo += val;
  260. },
  261. /**
  262. * 退格键被点击
  263. * @date 2023-02-22
  264. * @returns {any}
  265. */
  266. backspace() {
  267. // 删除value的最后一个字符
  268. if (this.form.vehicleNo.length) this.form.vehicleNo = this.form.vehicleNo.substr(0, this.form.vehicleNo.length - 1);
  269. },
  270. /**
  271. * 键盘输入完成后确认
  272. * @date 2023-02-22
  273. * @returns {any}
  274. */
  275. keyboardConfirm() {
  276. this.bindVehiclePop.colorShow = true;
  277. },
  278. /**
  279. * 单选点击
  280. * @date 2023-02-22
  281. * @param {any} e
  282. * @returns {any}
  283. */
  284. radioGroupChange(e) {
  285. this.form.vehicleNo = e;
  286. },
  287. /**
  288. * 关闭绑定弹框
  289. * @date 2023-02-22
  290. * @returns {any}
  291. */
  292. cencelBindVehicle() {
  293. this.form.vehicleNo = '';
  294. this.bindVehiclePop.showChangeVehicleNo = false;
  295. },
  296. /**
  297. * 提交绑定
  298. * @date 2023-02-22
  299. * @returns {any}
  300. */
  301. handleBindVehicle() {
  302. if (this.form.vehicleNo) {
  303. this.exchangeCoupon();
  304. } else {
  305. this.$refs.uToast.show({
  306. title: '请输入或选择车牌号!',
  307. type: 'warning'
  308. });
  309. }
  310. },
  311. /**
  312. * 调整页面
  313. * @date 2023-02-22
  314. * @param {any} url
  315. * @returns {any}
  316. */
  317. jumpPage(url) {
  318. this.$u.route({
  319. url
  320. });
  321. },
  322. /**
  323. * tabbar 返回
  324. * @date 2023-02-22
  325. * @returns {any}
  326. */
  327. customBack() {
  328. this.$u.route({
  329. type: 'switchTab',
  330. url: 'pages/center/index'
  331. });
  332. }
  333. }
  334. };
  335. </script>
  336. <style lang="scss" scoped>
  337. @import './myCoupon.scss';
  338. </style>