// pages/sucReception/sucReception.js
import {
  get,
} from '../../utils/http'; 
Page({

  /**
   * 页面的初始数据
   */
  data: {
    invite_info: {
      avatar_url: '',
      product_name: '',
      product_desc: '',
      price: '',
      project_id: '',
      store_id: '',
      nickname:'',
      coupon_day:''
    },
    sourceType: 1,
    source: 'project',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getReceive()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  /**
   * 获取领取数据
   * /api/invite/receive_info
   */
  getReceive() {
    get('api/invite/receive_info', {}, res => {
      this.setData({
        invite_info: res.data
      })
      this.getStoreInfo()
    })
  },
  /**
   * 获取门店信息
   */
  getStoreInfo() {
    get(
      'api/store/info', {
        store_id: this.data.invite_info.store_id
      },
      (res) => {
        getApp().globalData.storeData = res.data
      }
    )
  },
  /**
   * 获取详情页数据
   */
  getProjectInfo() {
    get(
      'api/product/info', {
        store_id: this.data.invite_info.store_id,
        product_id: this.data.invite_info.project_id,
        type: this.data.sourceType
      },
      (res) => {
        // let content = this.removeCss(res.data.content)
        // res.data.content = this.removeCss(res.data.content)
        // WxParse.wxParse('article', 'html', content, this, 5)

        this.setData({
          projectData: res.data
        })
        let _projectData = Object.assign({}, this.data.projectData)
        delete _projectData.content
        let url = `/pages/reserveProject/reserveProject?source=${
          this.data.source
        }&projectData=${encodeURIComponent(JSON.stringify(_projectData))}`
        wx.navigateTo({
          url: url
        })
      }
    )
  },
})