// pages/return-fee/pages/return-fee/detail.js

import {
  myHpAgencyFeeDetail,
  confirmHpAgencyFee
} from '../../../../services/index.js'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    visible: false,
    comfire: false,
    showIntegral: false,
    integral: 0,
    action: [{
      name: '稍后再说',
      color: '#327AE1',
    }, {
      name: '立即确认',
      color: '#327AE1',
      fontWeight: 'bolder'
    }]
  },
  // 提问
  question() {
    this.setData({
      visible: !this.data.visible
    })
  },
  // 拨打电话
  phone() {
    wx.makePhoneCall({
      phoneNumber: '4006900099',
      success: res => {
        this.setData({
          visible: false
        })
      }
    })
  },
  // 展示
  showComfire() {
    this.setData({
      comfire: true
    })
  },
  comfire(e) {
    if (e.detail.index) {
      confirmHpAgencyFee({
        user_id: wx.getStorageSync('user_id'),
        user_token: wx.getStorageSync('user_token'),
        member_id: wx.getStorageSync('member_id'),
        hpAgencyFeeId_id: this.data.id
      }).then(data => {
        this.setData({
          comfire: false,
          // integral: data.data.point,
          // showIntegral: Boolean(data.data.point)
        })
        wx.showToast({
          title: '确认成功',
        })
        // if (!data.data.point) {
        //   wx.showToast({
        //     title: '领取成功',
        //   })
        // }
      })
    } else {
      this.setData({
        comfire: false
      })
    }
  },
  getData(hpAgencyFeeId_id) {
    myHpAgencyFeeDetail({
      user_id: wx.getStorageSync('user_id'),
      user_token: wx.getStorageSync('user_token'),
      member_id: wx.getStorageSync('member_id'),
      hpAgencyFeeId_id
    }).then(res => {
      res.data.hpAgencyFee.onboardingDate = res.data.hpAgencyFee.onboardingDate.split(' ')[0]
      this.setData({
        ...res.data.hpAgencyFee
      })
    })
  },
  toIntegral() {
    wx.switchTab({
      url: '/pages/integral/pages/integral/integral',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    if (options.id) {
      this.getData(options.id)
    }
  },

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

  },

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

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
})