myCoupon.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. <swiper-list-item :tabIndex="index" :currentIndex="current" ref="swiperListItem"></swiper-list-item>
  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. },
  99. // 绑定车牌
  100. bindVehiclePop: {
  101. show: false,
  102. vehicleList: [],
  103. showChangeVehicleNo: false,
  104. colorShow: false,
  105. loading: false,
  106. colorList: [
  107. {
  108. text: '蓝色',
  109. colorCode: 0
  110. },
  111. {
  112. text: '黄色',
  113. colorCode: 1
  114. },
  115. {
  116. text: '黑色',
  117. colorCode: 2
  118. },
  119. {
  120. text: '白色',
  121. colorCode: 3
  122. },
  123. {
  124. text: '绿色',
  125. colorCode: 4
  126. },
  127. {
  128. text: '其他',
  129. colorCode: 99
  130. }
  131. ],
  132. keyboardshow: false
  133. }
  134. };
  135. },
  136. methods: {
  137. // tabs通知swiper切换
  138. tabsChange(index) {
  139. this.current = index;
  140. },
  141. // swiper滑动中
  142. swiperTransition(e) {
  143. this.$refs.tabs.setDx(e.detail.dx);
  144. },
  145. //swiper滑动结束
  146. swiperAnimationfinish(e) {
  147. this.current = e.detail.current;
  148. this.$refs.tabs.unlockDx();
  149. },
  150. /**
  151. * 兑换
  152. * @date 2022-12-23
  153. * @returns {any}
  154. */
  155. handleExchange() {
  156. if (this.form.exchangeCode) {
  157. this.bindVehiclePop.showChangeVehicleNo = true;
  158. this.getCarsList();
  159. } else {
  160. this.$refs.uToast.show({
  161. title: '请输入兑换码',
  162. type: 'warning'
  163. });
  164. }
  165. },
  166. getCarsList() {
  167. this.$u.api.getMycars().then((res) => {
  168. this.bindVehiclePop.vehicleList = res.data.rows.map((item) => {
  169. return {
  170. label: item.vehicleNo,
  171. value: item.vehicleNo
  172. };
  173. });
  174. this.$nextTick(() => {
  175. this.$refs['refValue'].init();
  176. });
  177. });
  178. },
  179. /**
  180. * 兑换优惠券
  181. * @date 2022-12-23
  182. * @returns {any}
  183. */
  184. exchangeCoupon() {
  185. this.bindVehiclePop.loading = true;
  186. this.$u.api
  187. .exchangeCouponApi(this.form)
  188. .then((res) => {
  189. if (res.code === 200) {
  190. this.$refs.uToast.show({
  191. title: '兑换成功!',
  192. type: 'success'
  193. });
  194. this.form.exchangeCode = '';
  195. this.$refs['swiperListItem'][this.current].reloadData();
  196. this.cencelBindVehicle();
  197. }
  198. this.bindVehiclePop.loading = false;
  199. })
  200. .catch(() => {
  201. this.bindVehiclePop.loading = false;
  202. });
  203. },
  204. /**
  205. * 点击输入框弹出车牌键盘
  206. * @date 2023-02-22
  207. * @returns {any}
  208. */
  209. messageInputClick() {
  210. this.bindVehiclePop.keyboardshow = true;
  211. this.form.vehicleNo = '';
  212. },
  213. /**
  214. * 颜色下拉确认
  215. * @date 2023-02-22
  216. * @param {any} e
  217. * @returns {any}
  218. */
  219. confirmColor(e) {
  220. this.bindVehiclePop.colorShow = false;
  221. },
  222. /**
  223. * 按键被点击(点击退格键不会触发此事件)
  224. * @date 2023-02-22
  225. * @param {any} val
  226. * @returns {any}
  227. */
  228. keyboardChange(val) {
  229. // 将每次按键的值拼接到value变量中,注意+=写法
  230. this.form.vehicleNo += val;
  231. },
  232. /**
  233. * 退格键被点击
  234. * @date 2023-02-22
  235. * @returns {any}
  236. */
  237. backspace() {
  238. // 删除value的最后一个字符
  239. if (this.form.vehicleNo.length) this.form.vehicleNo = this.form.vehicleNo.substr(0, this.form.vehicleNo.length - 1);
  240. },
  241. /**
  242. * 键盘输入完成后确认
  243. * @date 2023-02-22
  244. * @returns {any}
  245. */
  246. keyboardConfirm() {
  247. this.bindVehiclePop.colorShow = true;
  248. },
  249. /**
  250. * 单选点击
  251. * @date 2023-02-22
  252. * @param {any} e
  253. * @returns {any}
  254. */
  255. radioGroupChange(e) {
  256. this.form.vehicleNo = e;
  257. },
  258. /**
  259. * 关闭绑定弹框
  260. * @date 2023-02-22
  261. * @returns {any}
  262. */
  263. cencelBindVehicle() {
  264. this.form.vehicleNo = '';
  265. this.bindVehiclePop.showChangeVehicleNo = false;
  266. },
  267. /**
  268. * 提交绑定
  269. * @date 2023-02-22
  270. * @returns {any}
  271. */
  272. handleBindVehicle() {
  273. if (this.form.vehicleNo) {
  274. this.exchangeCoupon();
  275. } else {
  276. this.$refs.uToast.show({
  277. title: '请输入或选择车牌号!',
  278. type: 'warning'
  279. });
  280. }
  281. },
  282. /**
  283. * 调整页面
  284. * @date 2023-02-22
  285. * @param {any} url
  286. * @returns {any}
  287. */
  288. jumpPage(url) {
  289. this.$u.route({
  290. url
  291. });
  292. },
  293. /**
  294. * tabbar 返回
  295. * @date 2023-02-22
  296. * @returns {any}
  297. */
  298. customBack() {
  299. this.$u.route({
  300. type: 'switchTab',
  301. url: 'pages/index/index'
  302. });
  303. }
  304. }
  305. };
  306. </script>
  307. <style lang="scss" scoped>
  308. @import './myCoupon.scss';
  309. </style>