mixin.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import api from '../../config/api'
  2. import { funMixin } from '../../config/mixin'
  3. import { mapGetters } from 'vuex'
  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. computed: {
  30. ...mapGetters([
  31. 'couponNum'
  32. ]),
  33. },
  34. watch: {
  35. 'couponNum': {
  36. handler(newVal, oldVal) {
  37. this.getData()
  38. },
  39. deep: true
  40. }
  41. },
  42. mounted() {
  43. this.getData()
  44. },
  45. methods: {
  46. getData() {
  47. const _ = this
  48. if(_.componentContent.selectedCoupon && _.componentContent.selectedCoupon.length > 0){
  49. this.beforeGetData()
  50. let _url = ''
  51. if(_.typeId === 1){
  52. _url =`${api.getCoupons}?page=1&pageSize=99&ids=${_.componentContent.selectedCoupon}`
  53. } else if(_.typeId === 3) {
  54. _url =`${api.getShopCoupons}?page=1&pageSize=99&shopId=${_.shopId}&ids=${_.componentContent.selectedCoupon}`
  55. }
  56. const params = {
  57. method: 'GET',
  58. url: _url,
  59. }
  60. this.sendReq(params, (res) => {
  61. _.afterGetData()
  62. _.couponsData = res.data.list
  63. if(_.typeId === 1){
  64. _.couponsData.forEach(item=>{
  65. item.couponName = item.activityName
  66. item.effectiveStart = item.activityStartTime
  67. item.effectiveEnd = item.activityEndTime
  68. })
  69. }
  70. if(JSON.stringify(_.componentContent.couponList) !== JSON.stringify(_.couponsData)){
  71. _.componentContent.couponList = _.couponsData
  72. }
  73. },(err)=>{
  74. _.afterGetData()
  75. })
  76. } else {
  77. _.couponsData = []
  78. }
  79. }
  80. }
  81. }