// component/cardModal/cardModal.js
const app = getApp();
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')


Component({
  /**
   * 组件的属性列表
   */
  properties: {
    showCardModal:{
      type: Boolean,
      value: ''
    },
    cardTitle: {
      type: String,
      value: ''
    },
    cardUrl: {
      type: String,
      value: ''
    },
    cardExplain: {
      type: String,
      value: ''
    },
    pagePath: {
      type: String,
      value: ''
    },
    scene: {
      type: String,
      value: ''
    }
  },
  observers: {
    cardExplain(ex) {
      this.setData({explainList:ex ? JSON.parse(ex) : []})
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    codeImg:'',
    explainList: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    gotoPoster(){
      this.setData({
        showCardModal:false
      })
      this.getMiniCode();
    },

    //获取二维码
    getMiniCode() {
      const urls = utils.getCurrentPageUrlWithArgs()
      const page = urls && urls.split("?")[0]

      let data = {
        "autoColor": true,
        "page": this.data.pagePath,
        "scene": this.data.scene,
        "width": 100
      }
      console.log(this.data.pagePath)
      wxService.post(`/marketing/quickMark/getAppQrCodePicture`, data).then(res => {
        const { result, data } = res.data
        if (result == 0) {
          this.setData({
            codeImg: app.globalData.imageUrl + data
            // codeImg: "https://hwimagecdn.ihotwind.cn/usr/201908/miniQrCode-f00c5051fef7479395efb193431762c4.jpg"
          })
          console.log(this.data.codeImg)
          if (this.data.codeImg) {
            this.selectComponent('#getPoster').getAvaterInfo()
          }
        }
      })
    },

    _showMiniCard(e){
      console.log(e)
      this.setData({
        showCardModal: true
      })
    },

    closeCardModal(){
      this.setData({
        showCardModal: false
      })
    }

  }
})
