myCoupon.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 class="popup-vehicleNo" v-model="bindVehiclePop.showChangeVehicleNo" mode="center" border-radius="20" width="700rpx" height="auto">
  27. <view class="popup-vehicleNo-title">绑定车牌</view>
  28. <view class="popup-vehicleNo-center"></view>
  29. <view class="popup-vehicleNo-content">
  30. <view class="new-plate-number">
  31. <view class="message-input-wrap" @click="messageInputClick">
  32. <u-message-input :maxlength="8" width="60" font-size="40" :disabled-keyboard="true" v-model="form.vehicleNo" />
  33. </view>
  34. </view>
  35. </view>
  36. <view class="popup-vehicleNo-select">
  37. <u-collapse ref="refValue" :head-style="{ fontSize: '28rpx' }">
  38. <u-collapse-item title="点击选择车牌" align="center">
  39. <u-cell-group v-if="bindVehiclePop.vehicleList.length">
  40. <u-cell-item :title="item.value" v-for="(item, index) in bindVehiclePop.vehicleList" :key="index" :arrow="false">
  41. <u-radio-group v-model="form.vehicleNo" @change="radioGroupChange">
  42. <u-radio :name="item.value" :key="index"></u-radio>
  43. </u-radio-group>
  44. </u-cell-item>
  45. </u-cell-group>
  46. <template v-else>
  47. <view class="popup-vehicleNo-select-empty">暂无绑定车牌</view>
  48. </template>
  49. </u-collapse-item>
  50. </u-collapse>
  51. </view>
  52. <view class="vehicleNo-btn">
  53. <u-button type="primary" :disabled="!form.vehicleNo" :loading="bindVehiclePop.loading" @click="handleBindVehicle">确认</u-button>
  54. <u-button type="primary" plain @click="cencelBindVehicle">取消</u-button>
  55. </view>
  56. </u-popup>
  57. <!-- 选择颜色 -->
  58. <u-action-sheet :list="bindVehiclePop.colorList" @click="confirmColor" v-model="bindVehiclePop.colorShow" />
  59. <!-- 车牌号键盘 -->
  60. <u-keyboard
  61. ref="uKeyboard"
  62. mode="car"
  63. @change="keyboardChange"
  64. @confirm="keyboardConfirm"
  65. @backspace="backspace"
  66. v-model="bindVehiclePop.keyboardshow"
  67. />
  68. </z-paging-swiper>
  69. <u-toast ref="uToast" />
  70. </view>
  71. </template>
  72. <script>
  73. export default {
  74. data() {
  75. return {
  76. tabList: [
  77. {
  78. name: '未使用',
  79. value: 0,
  80. list: []
  81. },
  82. {
  83. name: '已使用',
  84. value: 1,
  85. list: []
  86. },
  87. {
  88. name: '已失效',
  89. value: 2,
  90. list: []
  91. }
  92. ],
  93. current: 0,
  94. form: {
  95. exchangeCode: '',
  96. source: 1,
  97. vehicleNo: '',
  98. merchantCode: '',
  99. qrcodeNo: '',
  100. couponId: ''
  101. },
  102. // 绑定车牌
  103. bindVehiclePop: {
  104. show: false,
  105. vehicleList: [],
  106. showChangeVehicleNo: false,
  107. colorShow: false,
  108. loading: false,
  109. colorList: [
  110. {
  111. text: '蓝色',
  112. colorCode: 0
  113. },
  114. {
  115. text: '黄色',
  116. colorCode: 1
  117. },
  118. {
  119. text: '黑色',
  120. colorCode: 2
  121. },
  122. {
  123. text: '白色',
  124. colorCode: 3
  125. },
  126. {
  127. text: '绿色',
  128. colorCode: 4
  129. },
  130. {
  131. text: '其他',
  132. colorCode: 99
  133. }
  134. ],
  135. keyboardshow: false
  136. }
  137. };
  138. },
  139. onLoad(options) {
  140. const { merchantCode, qrcodeNo, couponId } = options;
  141. if (merchantCode && qrcodeNo && couponId) {
  142. this.form.merchantCode = merchantCode;
  143. this.form.couponId = couponId;
  144. this.form.qrcodeNo = qrcodeNo;
  145. this.bindVehiclePop.showChangeVehicleNo = true;
  146. this.getCarsList();
  147. }
  148. },
  149. methods: {
  150. // tabs通知swiper切换
  151. tabsChange(index) {
  152. this.current = index;
  153. },
  154. // swiper滑动中
  155. swiperTransition(e) {
  156. this.$refs.tabs.setDx(e.detail.dx);
  157. },
  158. //swiper滑动结束
  159. swiperAnimationfinish(e) {
  160. this.current = e.detail.current;
  161. this.$refs.tabs.unlockDx();
  162. },
  163. /**
  164. * 兑换
  165. * @date 2022-12-23
  166. * @returns {any}
  167. */
  168. handleExchange() {
  169. if (this.form.exchangeCode) {
  170. this.bindVehiclePop.showChangeVehicleNo = true;
  171. this.getCarsList();
  172. } else {
  173. this.$refs.uToast.show({
  174. title: '请输入兑换码',
  175. type: 'warning'
  176. });
  177. }
  178. },
  179. getCarsList() {
  180. this.$u.api.getMycars().then((res) => {
  181. this.bindVehiclePop.vehicleList = res.data.rows.map((item) => {
  182. return {
  183. label: item.vehicleNo,
  184. value: item.vehicleNo
  185. };
  186. });
  187. this.$nextTick(() => {
  188. this.$refs['refValue'].init();
  189. });
  190. });
  191. },
  192. /**
  193. * 兑换优惠券
  194. * @date 2022-12-23
  195. * @returns {any}
  196. */
  197. exchangeCoupon() {
  198. this.bindVehiclePop.loading = true;
  199. this.$u.api
  200. .exchangeCouponApi(this.form)
  201. .then((res) => {
  202. if (res.code === 200) {
  203. this.$refs.uToast.show({
  204. title: '兑换成功!',
  205. type: 'success'
  206. });
  207. this.form.exchangeCode = '';
  208. this.$refs['swiperListItem'][this.current].reloadData();
  209. this.cencelBindVehicle();
  210. }
  211. this.bindVehiclePop.loading = false;
  212. })
  213. .catch(() => {
  214. this.bindVehiclePop.loading = false;
  215. });
  216. },
  217. /**
  218. * 点击输入框弹出车牌键盘
  219. * @date 2023-02-22
  220. * @returns {any}
  221. */
  222. messageInputClick() {
  223. this.bindVehiclePop.keyboardshow = true;
  224. this.form.vehicleNo = '';
  225. },
  226. /**
  227. * 颜色下拉确认
  228. * @date 2023-02-22
  229. * @param {any} e
  230. * @returns {any}
  231. */
  232. confirmColor(e) {
  233. this.bindVehiclePop.colorShow = false;
  234. },
  235. /**
  236. * 按键被点击(点击退格键不会触发此事件)
  237. * @date 2023-02-22
  238. * @param {any} val
  239. * @returns {any}
  240. */
  241. keyboardChange(val) {
  242. // 将每次按键的值拼接到value变量中,注意+=写法
  243. this.form.vehicleNo += val;
  244. },
  245. /**
  246. * 退格键被点击
  247. * @date 2023-02-22
  248. * @returns {any}
  249. */
  250. backspace() {
  251. // 删除value的最后一个字符
  252. if (this.form.vehicleNo.length) this.form.vehicleNo = this.form.vehicleNo.substr(0, this.form.vehicleNo.length - 1);
  253. },
  254. /**
  255. * 键盘输入完成后确认
  256. * @date 2023-02-22
  257. * @returns {any}
  258. */
  259. keyboardConfirm() {
  260. this.bindVehiclePop.colorShow = true;
  261. },
  262. /**
  263. * 单选点击
  264. * @date 2023-02-22
  265. * @param {any} e
  266. * @returns {any}
  267. */
  268. radioGroupChange(e) {
  269. this.form.vehicleNo = e;
  270. },
  271. /**
  272. * 关闭绑定弹框
  273. * @date 2023-02-22
  274. * @returns {any}
  275. */
  276. cencelBindVehicle() {
  277. this.form.vehicleNo = '';
  278. this.bindVehiclePop.showChangeVehicleNo = false;
  279. },
  280. /**
  281. * 提交绑定
  282. * @date 2023-02-22
  283. * @returns {any}
  284. */
  285. handleBindVehicle() {
  286. if (this.form.vehicleNo) {
  287. this.exchangeCoupon();
  288. } else {
  289. this.$refs.uToast.show({
  290. title: '请输入或选择车牌号!',
  291. type: 'warning'
  292. });
  293. }
  294. },
  295. /**
  296. * 调整页面
  297. * @date 2023-02-22
  298. * @param {any} url
  299. * @returns {any}
  300. */
  301. jumpPage(url) {
  302. this.$u.route({
  303. url
  304. });
  305. },
  306. /**
  307. * tabbar 返回
  308. * @date 2023-02-22
  309. * @returns {any}
  310. */
  311. customBack() {
  312. this.$u.route({
  313. type: 'switchTab',
  314. url: 'pages/center/index'
  315. });
  316. }
  317. }
  318. };
  319. </script>
  320. <style lang="scss" scoped>
  321. @import './myCoupon.scss';
  322. </style>