多租户商城-商户小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 lines
11 KiB

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