parkingFeePaperCoupon.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. import uni from '@/utils/uniHooks';
  2. import { Toast } from 'vant';
  3. // const app = getApp()
  4. const app = {};
  5. import { mapState } from 'vuex';
  6. import fuiToast from '@/components/fui-toast/fui-toast.vue';
  7. import { initWxJsSdkConfig } from '@/utils/login';
  8. import { getPlatform, theCommunicationBetweenWechatAndH5IsNormal } from '@/utils';
  9. import { paperCoupon } from '@/api/parking'
  10. export default {
  11. components: {
  12. fuiToast,
  13. },
  14. created() {
  15. },
  16. data() {
  17. return {
  18. // parkFee: {}, // 停车规则相关信息
  19. // // parkPaperCouponRemark: '', // 纸质优惠券说明
  20. // servicefee: 0, // 应缴金额
  21. // paperDiscountFee: 0, // 纸质优惠券减免金额
  22. // paperDiscountTime: 0, // 纸质优惠券减免时长
  23. // parkDiscountTotal: {}, // 总停车优惠
  24. paperCouponList: [], // 纸质券list
  25. // paperCouponInfo: {}, // 页面缓存
  26. // maxonetimediscountFee: 0, // 每次优惠上限金额
  27. // maxonedaydiscountFee: 0, // 每天优惠上限金额
  28. // parkMallCode: 1, // 0静安 1浦东 2杭州 3北京 4沈阳 5深圳
  29. // parkInfo: {},
  30. };
  31. },
  32. async mounted() {
  33. setTimeout(() => {
  34. uni.setNavigationBarTitle({
  35. title: '纸质优惠券减免',
  36. });
  37. },300);
  38. const platform = getPlatform();
  39. if ( platform === 'micromessenger' ) {
  40. // this.getTicket();
  41. await initWxJsSdkConfig(['checkJsApi','scanQRCode']);
  42. // await initWxJsSdkConfig(['checkJsApi', 'scanQRCode']);
  43. // if (window.wxJsSdkConfigInitPromise) {
  44. // await window.wxJsSdkConfigInitPromise;
  45. // }
  46. }
  47. this.pageInit()
  48. setTimeout(() => {
  49. uni.setNavigationBarTitle({
  50. title: '优惠券',
  51. });
  52. },300);
  53. setTimeout(() => {
  54. window?.toWXSendMsg({
  55. type: 'uni_func',
  56. funcName: 'setNavigationBarColor',
  57. options: {
  58. frontColor: '#000000',
  59. backgroundColor: '#FBFCFF',
  60. },
  61. });
  62. }, 500)
  63. },
  64. computed: {
  65. ...mapState({
  66. custTypeId: ( state ) => state.custTypeId,
  67. mallid: ( state ) => state.mallId,
  68. openId: ( state ) => state.openid,
  69. member: ( state ) => state.member,
  70. groupId: ( state ) => state.groupId,
  71. orderDetail: ( state ) => state.order.orderDetail,
  72. paperCoupons: ( state ) => state.order.paperCoupons,
  73. paperDiscountFee: ( state ) => state.order.paperDiscountFee,
  74. paperDiscountTime: ( state ) => state.order.paperDiscountTime,
  75. paperCouponsDesc: ( state ) => state.order.paperCouponsDesc,
  76. }),
  77. },
  78. methods: {
  79. pageInit() {
  80. this.paperCouponList = [...this.paperCoupons]
  81. },
  82. showToast( text ) {
  83. let options = {};
  84. options.text = text;
  85. this.$refs.toast.show(options);
  86. },
  87. // 扫码
  88. async scanCode() {
  89. const runScanFn = ( res ) => {
  90. if ( res.scanType == 'QR_CODE' && res.scanType || (window.isAlipayClient && res.scanType == 'QR')) {
  91. console.log(res.result);
  92. const url = res.result;
  93. if ( url.indexOf('auth/') === -1 ) {
  94. this.getPaperCouponInfo(res.result);
  95. } else {
  96. const start = url.indexOf('auth/');
  97. const end = url.indexOf('?');
  98. const params = url.slice(start,end).split('/');
  99. if ( params && params.length ) {
  100. const couponCode = params[1];
  101. this.getPaperCouponInfo(couponCode);
  102. }
  103. }
  104. }
  105. };
  106. // 微信小程序
  107. const platform = getPlatform();
  108. if ( platform === 'miniprogram' ) {
  109. // 判断微信小程序与 h5 是否正常通信
  110. const isReload = await theCommunicationBetweenWechatAndH5IsNormal()
  111. if(!isReload) {
  112. uni.setStorageSync('isReload', 1)
  113. window.location.reload()
  114. return
  115. }
  116. window.toWXSendMsg({
  117. type: 'scanQRCode',
  118. });
  119. window.subscribe('scanQRCodeOver',( options ) => {
  120. console.log('微信扫码结束之后的返回参数',options);
  121. runScanFn(window.isAlipayClient ? options.options : options);
  122. });
  123. } else {
  124. this.$wx.scanQRCode({
  125. desc: 'scanQRCode desc',
  126. needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
  127. // scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
  128. success: ( res ) => {
  129. console.log(237,res);
  130. runScanFn(res);
  131. // this.formMsg.deviceCode = res.resultStr;
  132. },
  133. error: ( res ) => {
  134. console.log(242,res);
  135. },
  136. });
  137. }
  138. },
  139. // 根据卡券ID查询卡券信息
  140. async getPaperCouponInfo( couponCode ) {
  141. uni.showLoading({
  142. title: '加载中',
  143. });
  144. const res = await paperCoupon(couponCode, this.orderDetail.parkingRecord.vehicleNo);
  145. /*const res = {
  146. "status": "1",
  147. "discountCode": "91354260",
  148. "discountFee": 1,
  149. "used": "0",
  150. "content": "嘉里卡券测试"
  151. }*/
  152. /* [DE][C端]临时停车,静安纸质优惠券过期以后,扫码,依然可以扫出来金额 https://kerryprops.atlassian.net/browse/SCRM-5671 */
  153. if ( res.hasOwnProperty('expired') && /1/.test(res?.expired)) {
  154. return Toast({
  155. message: '该纸质优惠已过期',
  156. });
  157. }
  158. if ( /0/.test(res.status)) {
  159. return Toast({
  160. message: '该纸质优惠券未激活',
  161. });
  162. }
  163. if (/1/.test(res.used)) {
  164. return Toast({
  165. message: '该纸质优惠券已领取',
  166. });
  167. }
  168. if (/2/.test(res.used)) {
  169. return Toast({
  170. message: '该纸质优惠券已使用',
  171. });
  172. }
  173. if (/3/.test(res.used)) {
  174. return Toast({
  175. message: '该纸质优惠券已核销',
  176. });
  177. }
  178. // console.log(157, res)
  179. if(res.code === "300000") {
  180. return Toast({
  181. message: res.message,
  182. });
  183. }
  184. // console.log(158, this.paperCoupons)
  185. // console.log(158, this.paperCoupons.findIndex(item => {
  186. // console.log(160, item.discountCode, couponCode)
  187. // return item.discountCode === couponCode
  188. // }))
  189. // 如果纸质优惠券不存在的话,则往 paperCoupons 添加
  190. if ( this.paperCouponList.findIndex(item => item.couponCode === couponCode) < 0 ) {
  191. // const {hourPrice} = this.orderDetail.parkingRule
  192. // const discountTime = Number(res.discountFee) / hourPrice
  193. const paperCouponList = [
  194. ...this.paperCouponList,
  195. {
  196. ...res,
  197. couponCode: couponCode
  198. // discountTime: res.discountFee / hourPrice
  199. }
  200. ]
  201. this.paperCouponList = paperCouponList
  202. this.$store.commit('order/setPaperCoupons',paperCouponList)
  203. // 金额
  204. this.$store.commit('order/setPaperDiscountFee',this.paperDiscountFee + Number(res.discountFee))
  205. // 时间
  206. // this.$store.commit('order/setPaperDiscountTime',this.paperDiscountTime + discountTime)
  207. } else {
  208. return Toast({
  209. message: '优惠券已添加,请勿重复扫码',
  210. });
  211. }
  212. },
  213. // 删除
  214. deleteCoupon( item ) {
  215. this.paperCouponList = this.paperCouponList.filter(elm => elm.couponCode !== item.couponCode)
  216. // const {hourPrice} = this.orderDetail.parkingRule
  217. // const discountTime = Number(item.discountFee) / hourPrice
  218. this.$store.commit('order/setPaperCoupons',this.paperCouponList)
  219. // 金额
  220. this.$store.commit('order/setPaperDiscountFee',this.paperDiscountFee - Number(item.discountFee))
  221. // 时间
  222. // this.$store.commit('order/setPaperDiscountTime',this.paperDiscountTime + discountTime)
  223. },
  224. // 确认
  225. confirm() {
  226. console.log(310,this.orderDetail);
  227. this.$store.dispatch('order/savePaperCoupon', {
  228. paperCoupons: this.paperCoupons,
  229. callback: () => {
  230. this.$router.back();
  231. },
  232. });
  233. },
  234. },
  235. };