indexMixin.js 5.98 KB
import { equity } from '@r/api.js'
import shopList from './list'
export default {
  data() {
    return {
      ServiceList: {},
      goodsServiceList: {},
      goodsServiceKey: [],
      carServiceList: [],
      merchantId: sessionStorage.getItem('GL_WX_MERCHANTID'),
      notice: '',
      phone_range: ['134', '135', '136', '137', '138', '139', '147', '150', '151', '152', '157', '158', '159', '182', '183', '184', '187', '188', '130', '131', '132', '145', '155', '156', '185', '186', '133', '153', '180', '181', '189', '170', '176', '177', '178'],
      travelList: [{
          name: '优惠加油',
          icon: 'tuanyou',
          description: '7折起',
          id: 54
        },
        {
          name: '道路救援',
          icon: 'jiuyuan',
          description: '非事故免费',
          route: 'road'
        },
      ],
      hotelList: [{
          name: '今日特惠',
          icon: 'today',
          description: '超性价比'
        },
        {
          name: '景区门票',
          icon: 'tickets',
          description: '全国3000+景点'
        }
      ],
      cateringList2: [{
          name: '肯德基',
          icon: 'kfc',
          description: '最高省81元',
          typeId: 23
        },
        {
          name: '麦当劳',
          icon: 'm',
          description: '最高省44元',
          typeId: 64
        },
        {
          name: '星巴克',
          icon: 'xbk',
          description: '最高省17元',
          typeId: 21
        },
        {
          name: '瑞幸咖啡',
          icon: 'ruixing',
          description: '最高省10元',
          typeId: 148
        }
      ],
      gasList: [{
          name: '覆盖城市',
          icon: 'city',
          subIcon: '400'
        },
        {
          name: '加油站',
          icon: 'gas',
          subIcon: '10000'
        }
      ],
      ...shopList
    }
  },
  mounted() {
    this.setNoticeInfo();
    this.getMerchantid();
    if (this.isMiniprogram) wx.miniProgram.postMessage({})
  },
  methods: {
    setNoticeInfo() {
      let { phone_range } = this
      let start = this.setRandom(0, phone_range.length, 'floor')
      let end = `${this.setRandom(0, 9, 'floor')}${this.setRandom(0, 9, 'floor')}${this.setRandom(0, 9, 'floor')}${this.setRandom(0, 9, 'floor')}`
      let phone = `${phone_range[start]}***${end}`
      let price = this.setRandom(25.99, 45.99).toFixed(2)
      this.notice = `距离您当前位置的油站有优惠,点击加油,用户${phone}刚通过加油优惠${price}元。`
    },
    setRandom(start, end, type) {
      if (type == 'floor') {
        return Math.floor(Math.random() * (end - start)) + start
      }
      return Math.random() * (end - start) + start
    },
    updataNotice() {
      this.setNoticeInfo()
    },
    CarLink(e) {
      let supplier = e.supplier;
      switch(supplier) {
        case 'GL_OIL':
          window.vm.$router.push({ path: '/oilStation/index'});
          break;
        case 'GL_ROAD_RESCUE':
          window.vm.$router.push({ path: '/equity/road'});
          break;
        case 'GL_TIRE_PROTECTION':
          window.vm.$router.push({ path: '/equity/tyre'});
          break;
        case 'GL_ROBBERY_PROTECTION':
          window.vm.$router.push({ path: '/equity/compensate'});
          break;
        case 'GL_COLLISION_REPAIR':
          window.vm.$router.push({ path: '/equity/collision'});
          break;
        case 'GL_CAR_TOTAL_LOSS':
          window.vm.$router.push({ path: '/equity/loss'});
          break;
        case 'EDJ':
          this.jumpDEJ();
          break;
        default:
          this.showToast('即将上线,敬请期待')
      }
    },
    jumpDEJ() {
      let {sessionId} = JSON.parse(sessionStorage.getItem('GL_EQUITY_USER_INFO'));
      let para = {
        sessionId
      }
      equity.getEdjUrl(para).then(res => {
        let {code, data, message} = res
        if (code == 0){
          this.openWindows(data)
        } else {
          this.showToast(message)
        }
      })
    },
    jumpLink(e) {
      if(e.appearance == 1) {
        window.vm.$router.push({ path: '/commodity/business/',query:{
            brandId: e.brandId,
            supplier: e.supplier
          }
        });
      }else {
        window.vm.$router.push({
          path: '/commodity/recharge/', query: {
            brandId: e.brandId,
            supplier: e.supplier
          }
        })
      }
    },
    // jumpLink(e) {
    //   let params = {
    //     ...e
    //   }
    //   delete params.name
    //   delete params.icon
    //   delete params.description
    //   console.log(params)
    //   if (params.route) {
    //     let [href] = window.location.href.split('/#/')
    //     let url = `${href}/#/equity/${params.route}`
    //     this.openWindows(url, `equity.${params.route}`)
    //     return
    //   }
    //   equity.getCouponList({
    //     requestSource: this.getChannel(), //1.小程序,2.APP,3.公众号
    //     ...params
    //   }).then(res => {
    //     console.log(res)
    //     let { code, data, message } = res
    //     if (code == 0) {
    //       this.openWindows(data)
    //     } else {
    //       this.showToast(message)
    //     }
    //
    //   })
    // }
    getMerchantid() {
      this.carServiceList = []
      let para = {
        merchantId: this.merchantId
      }
      equity.getMerchantid(para).then(res => {
        let {code, data, message} = res
        if (code == 0){
          this.goodsServiceKey = Object.keys(data.goodsServiceList)
          this.carServiceList = data.carServiceList
          this.goodsServiceList = data.goodsServiceList;
        } else {
          this.showToast(message)
        }
      })
    },
    jumpMore() {
      equity.getCouponList({
        requestSource: this.getChannel() //1.小程序,2.APP,3.公众号
      }).then(res => {
        let { code, data, message } = res
        if (code == 0) {
          this.openWindows(data)
        } else {
          this.showToast(message)
        }
      })
    }
  },

}