// 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: ''
    },
    pagePath: {
      type: String,
      value: ''
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    codeImg:''
  },

  /**
   * 组件的方法列表
   */
  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": '123',
        "width": 100
      }
      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"
          })
          if (this.data.codeImg) {
            this.selectComponent('#getPoster').getAvaterInfo()
          }
        }
      })
    },

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

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

  }
})
