mixin.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import api from '../../config/api'
  2. import { updateTakeCouponReceiveApi } from '../../../../api/anotherTFInterface'
  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. var paramsData = {}
  74. if (this.typeId === 1) {
  75. paramsData.couponId = item.couponId
  76. } else if (this.typeId === 3) {
  77. paramsData.shopCouponId = item.shopCouponId
  78. paramsData.shopId = this.shopId
  79. }
  80. updateTakeCouponReceiveApi(paramsData).then((res) => {
  81. this.getData()
  82. uni.showToast({
  83. title: '领取成功',
  84. icon: 'success'
  85. })
  86. })
  87. }
  88. }
  89. }