多租户商城-商户小程序端
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.

109 lines
2.7 KiB

2 years ago
  1. import api from '../../config/api'
  2. import NET from '../../../../utils/request'
  3. import { funMixin } from '../../config/mixin'
  4. export const commonMixin = {
  5. name: 'textComponent',
  6. mixins: [funMixin],
  7. data () {
  8. return {
  9. couponsData: []
  10. }
  11. },
  12. props: {
  13. terminal: {
  14. type: Number,
  15. default: 4
  16. },
  17. typeId: {
  18. type: Number,
  19. default: 1
  20. },
  21. shopId: {
  22. type: Number,
  23. default: 0
  24. },
  25. componentContent: {
  26. type: Object
  27. }
  28. },
  29. watch: {
  30. 'componentContent': {
  31. handler(newVal, oldVal) {
  32. this.getData()
  33. },
  34. deep: true
  35. }
  36. },
  37. created() {
  38. this.getData()
  39. },
  40. methods: {
  41. getData() {
  42. const _ = this
  43. if(_.componentContent.selectedCoupon && _.componentContent.selectedCoupon.length > 0){
  44. let _url = ''
  45. if(_.typeId === 1){
  46. _url =`${api.getCoupons}?page=1&pageSize=99&ids=${_.componentContent.selectedCoupon}`
  47. } else if(_.typeId === 3) {
  48. _url =`${api.getShopCoupons}?page=1&pageSize=99&shopId=${_.shopId}&ids=${_.componentContent.selectedCoupon}`
  49. }
  50. const params = {
  51. method: 'GET',
  52. url: _url,
  53. }
  54. this.sendReq(params, (res) => {
  55. _.couponsData = res.data.list
  56. if(_.typeId === 1){
  57. _.couponsData.forEach(item=>{
  58. item.couponName = item.activityName
  59. item.effectiveStart = item.activityStartTime
  60. item.effectiveEnd = item.activityEndTime
  61. })
  62. }
  63. if(JSON.stringify(_.componentContent.couponList) !== JSON.stringify(_.couponsData)){
  64. _.componentContent.couponList = _.couponsData
  65. }
  66. })
  67. } else {
  68. _.couponsData = []
  69. }
  70. },
  71. // 领取优惠券
  72. receiveCoupon(item) {
  73. const res = uni.getStorageSync('storage_key');
  74. const token = res.token
  75. if (token) {
  76. var paramsData = {}
  77. if(this.typeId === 1){
  78. paramsData.couponId = item.couponId
  79. } else if(this.typeId === 3) {
  80. paramsData.shopCouponId = item.shopCouponId
  81. paramsData.shopId = this.shopId
  82. }
  83. NET.request(api.takeCoupon, paramsData, 'POST').then(res => {
  84. this.getData()
  85. uni.showToast({
  86. title:'领取成功',
  87. icon:"success"
  88. })
  89. }).catch(res => {
  90. if(res.data.code !== '200'){
  91. uni.showToast({
  92. title:res.data.message,
  93. icon:"none"
  94. })
  95. }
  96. })
  97. } else {
  98. uni.showToast({
  99. title:'请先登录',
  100. icon:"none"
  101. })
  102. uni.navigateTo({
  103. url:'/pages_category_page2/userModule/login'
  104. })
  105. }
  106. }
  107. }
  108. }