myCoupon.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. exchangeCoupon() {
  204. this.bindVehiclePop.loading = true;
  205. this.$u.api
  206. .exchangeCouponApi(this.form)
  207. .then((res) => {
  208. if (res.code === 200) {
  209. this.$refs.uToast.show({
  210. title: '兑换成功!',
  211. type: 'success'
  212. });
  213. this.form.exchangeCode = '';
  214. this.$refs['swiperListItem'][this.current].reloadData();
  215. // this.cencelBindVehicle();
  216. setTimeout(() => {
  217. this.bindVehiclePop.loading = false;
  218. location.href = location.origin + location.pathname;
  219. }, 500);
  220. }
  221. })
  222. .catch(() => {
  223. this.bindVehiclePop.loading = false;
  224. });
  225. },
  226. /**
  227. * 点击输入框弹出车牌键盘
  228. * @date 2023-02-22
  229. * @returns {any}
  230. */
  231. messageInputClick() {
  232. this.bindVehiclePop.keyboardshow = true;
  233. this.form.vehicleNo = '';
  234. },
  235. /**
  236. * 颜色下拉确认
  237. * @date 2023-02-22
  238. * @param {any} e
  239. * @returns {any}
  240. */
  241. confirmColor(e) {
  242. this.bindVehiclePop.colorShow = false;
  243. },
  244. /**
  245. * 按键被点击(点击退格键不会触发此事件)
  246. * @date 2023-02-22
  247. * @param {any} val
  248. * @returns {any}
  249. */
  250. keyboardChange(val) {
  251. // 将每次按键的值拼接到value变量中,注意+=写法
  252. this.form.vehicleNo += val;
  253. },
  254. /**
  255. * 退格键被点击
  256. * @date 2023-02-22
  257. * @returns {any}
  258. */
  259. backspace() {
  260. // 删除value的最后一个字符
  261. if (this.form.vehicleNo.length) this.form.vehicleNo = this.form.vehicleNo.substr(0, this.form.vehicleNo.length - 1);
  262. },
  263. /**
  264. * 键盘输入完成后确认
  265. * @date 2023-02-22
  266. * @returns {any}
  267. */
  268. keyboardConfirm() {
  269. this.bindVehiclePop.colorShow = true;
  270. },
  271. /**
  272. * 单选点击
  273. * @date 2023-02-22
  274. * @param {any} e
  275. * @returns {any}
  276. */
  277. radioGroupChange(e) {
  278. this.form.vehicleNo = e;
  279. },
  280. /**
  281. * 关闭绑定弹框
  282. * @date 2023-02-22
  283. * @returns {any}
  284. */
  285. cencelBindVehicle() {
  286. this.form.vehicleNo = '';
  287. this.bindVehiclePop.showChangeVehicleNo = false;
  288. },
  289. /**
  290. * 提交绑定
  291. * @date 2023-02-22
  292. * @returns {any}
  293. */
  294. handleBindVehicle() {
  295. if (this.form.vehicleNo) {
  296. this.exchangeCoupon();
  297. } else {
  298. this.$refs.uToast.show({
  299. title: '请输入或选择车牌号!',
  300. type: 'warning'
  301. });
  302. }
  303. },
  304. /**
  305. * 调整页面
  306. * @date 2023-02-22
  307. * @param {any} url
  308. * @returns {any}
  309. */
  310. jumpPage(url) {
  311. this.$u.route({
  312. url
  313. });
  314. },
  315. /**
  316. * tabbar 返回
  317. * @date 2023-02-22
  318. * @returns {any}
  319. */
  320. customBack() {
  321. this.$u.route({
  322. type: 'switchTab',
  323. url: 'pages/center/index'
  324. });
  325. }
  326. }
  327. };
  328. </script>
  329. <style lang="scss" scoped>
  330. @import './myCoupon.scss';
  331. </style>