ATFWXSendCoupon.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <view class="warp">
  3. <!-- #ifdef MP-WEIXIN -->
  4. <send-coupon
  5. v-if="cParams" :send_coupon_params="cParams.send_coupon_params" :sign="cParams.sign"
  6. :send_coupon_merchant="cParams.send_coupon_merchant" @sendcoupon="sendcoupon" @userconfirm="userconfirm"
  7. >
  8. <slot></slot>
  9. </send-coupon>
  10. <view v-else @click.stop="receiveCoupon">
  11. <slot></slot>
  12. </view>
  13. <!-- #endif -->
  14. <!-- #ifndef MP-WEIXIN -->
  15. <view @click.stop="receiveCoupon">
  16. <slot></slot>
  17. </view>
  18. <!-- #endif -->
  19. <!-- 优惠券领取 -->
  20. <tui-modal :show="confirmVisible" :custom="true" :fade-in="true">
  21. <view class="Put-box1">
  22. <view class="text-align fs34 fs-bold">
  23. 是否领取此优惠券
  24. </view>
  25. <view class="flex-display flex-sp-between">
  26. <view class="btn" @click="confirmVisible = false">
  27. 取消
  28. </view>
  29. <view class="btn submit" @click="receive">
  30. 确定
  31. </view>
  32. </view>
  33. </view>
  34. </tui-modal>
  35. </view>
  36. </template>
  37. <script>
  38. import { updateCouponBuildParam4PlugApi, updateCreditExchangeCouponApi, addTakeBatchCouponApi } from '../../api/anotherTFInterface'
  39. export default {
  40. name: 'ATFWXSendCoupon',
  41. props: {
  42. couponList: {
  43. type: Array,
  44. default: () => []
  45. },
  46. isExchange: {
  47. type: Boolean,
  48. default: false
  49. }
  50. // 卡券无法加询问
  51. // isConfirm: {
  52. // type: Boolean,
  53. // default: false
  54. // }
  55. },
  56. data() {
  57. return {
  58. cParams: '',
  59. confirmVisible: false,
  60. successList: []
  61. }
  62. },
  63. mounted() {
  64. // console.log(this.couponList,'couponList')
  65. const ids = []
  66. this.couponList.forEach((item) => {
  67. if (item.cardId) {
  68. ids.push(item.cardId)
  69. }
  70. // else {
  71. // this.successList.push(item)
  72. // }
  73. // 解除app h5不能领券问题
  74. this.successList.push(item)
  75. })
  76. // console.log(this.successList,'successList')
  77. // #ifdef MP-WEIXIN
  78. if (ids && ids.length > 0) {
  79. this.buildParam4Plug(ids)
  80. }
  81. // #endif
  82. },
  83. methods: {
  84. // 获取微信卡券参数
  85. buildParam4Plug(ids) {
  86. updateCouponBuildParam4PlugApi(ids).then((res) => {
  87. this.cParams = res.data
  88. })
  89. },
  90. // 领取优惠券
  91. receiveCoupon() {
  92. if (this.successList.length > 0) {
  93. if (this.isExchange) {
  94. // 积分兑换
  95. const paramsData = {
  96. couponId: this.couponList[0].couponId,
  97. source: 3
  98. }
  99. updateCreditExchangeCouponApi(paramsData).then((res) => {
  100. this.$emit('success')
  101. })
  102. } else if (this.couponList.length === 1 && this.couponList[0].ifCredit) {
  103. // 单个积分兑换的卡券去积分中心兑
  104. uni.navigateTo({
  105. url: `/another-tf/another-serve/exchangeDetail/index?data=${JSON.stringify(this.couponList[0])}`
  106. })
  107. } else {
  108. const params = []
  109. this.successList.forEach((item) => {
  110. params.push({
  111. couponId: item.couponId,
  112. couponCode: item.couponCode,
  113. source: 1
  114. })
  115. })
  116. // 领取优惠卷
  117. addTakeBatchCouponApi(params).then((res) => {
  118. if (res.code === '200') {
  119. uni.showToast({
  120. title: '领取成功'
  121. })
  122. this.$emit('success')
  123. if (!this.cParams) {
  124. this.$emit('closeAd')
  125. }
  126. }
  127. })
  128. .catch((res) => {
  129. if (res.data.code !== '200') {
  130. uni.showToast({
  131. title: res.data.message,
  132. icon: 'none'
  133. })
  134. }
  135. })
  136. }
  137. } else {
  138. this.$emit('closeAd')
  139. }
  140. },
  141. // 领取优惠券回调
  142. sendcoupon(e) {
  143. const errcode = e.detail.errcode; const resultList = e.detail.send_coupon_result
  144. switch (errcode) {
  145. case 'OK':
  146. break
  147. case 'PARAM_ERROR':
  148. console.error('参数错误,请开发者查看msg中具体的错误信息并进行修复处理')
  149. break
  150. case 'USER_NOT_EXISTS':
  151. console.error('登录态获取失效')
  152. break
  153. case 'USER_GET_FAILED':
  154. console.error('登录态获取失败')
  155. break
  156. case 'SIGN_ERROR':
  157. console.error('签名错误')
  158. break
  159. case 'SYSTEMERROR':
  160. console.error('发券超时')
  161. break
  162. case 'FREQUENCY_LIMITED':
  163. console.error('发券频率过高')
  164. break
  165. }
  166. if (errcode === 'OK') {
  167. resultList.forEach((item) => {
  168. let cName = ''
  169. this.couponList.forEach((citem) => {
  170. if (item.stock_id === citem.cardId) {
  171. cName = citem.activityName
  172. if (item.code === 'SUCCESS') {
  173. citem.couponCode = item.coupon_code
  174. this.successList.push(citem)
  175. }
  176. }
  177. })
  178. switch (item.code) {
  179. case 'FAILED':
  180. console.error('该张券发券失败,查看message中的具体错误信息')
  181. break
  182. case 'NOTENOUGH':
  183. uni.showToast({
  184. title: cName + '优惠券已被领取完',
  185. icon: 'none'
  186. })
  187. console.error('总预算用完')
  188. break
  189. case 'DAYLIMIT':
  190. uni.showToast({
  191. title: cName + '优惠券领取张数已达到上限',
  192. icon: 'none'
  193. })
  194. console.error('用户达到单天限领')
  195. break
  196. case 'NATURELIMIT':
  197. uni.showToast({
  198. title: cName + '优惠券领取张数已达到上限',
  199. icon: 'none'
  200. })
  201. console.error('用户自然人限领')
  202. break
  203. case 'MAXQUOTA':
  204. uni.showToast({
  205. title: cName + '优惠券领取张数已达到上限',
  206. icon: 'none'
  207. })
  208. console.error('用户领取张数达到上限')
  209. break
  210. case 'DUPREQUEST':
  211. uni.showToast({
  212. title: cName + '优惠券领取张数已达到上限',
  213. icon: 'none'
  214. })
  215. console.error('已通过该发券凭证给用户发券')
  216. break
  217. case 'NOTRUNNING':
  218. console.error('批次状态非运营中')
  219. break
  220. case 'EXPIRED':
  221. uni.showToast({
  222. title: cName + '优惠券已过期',
  223. icon: 'none'
  224. })
  225. console.error('该批次已过期')
  226. break
  227. case 'NOTMONEY':
  228. console.error('账户余额不足')
  229. break
  230. case 'USERLIMIT':
  231. console.error('用户已超限领额度')
  232. break
  233. case 'FREQUENCYLIMIT':
  234. console.error('超过频率限制')
  235. break
  236. }
  237. })
  238. this.receiveCoupon()
  239. } else {
  240. this.$emit('closeAd')
  241. }
  242. },
  243. // 用户确认领券事件
  244. userconfirm(e) {
  245. this.$emit('closeAd')
  246. }
  247. }
  248. }
  249. </script>