// pages/personal/helpDetail/helpDetail.js
var app = getApp()
const util = require('../../../utils/utils.js')
Page({
  data: {
    show: '',
    currentNum: 0,
    inputVal: '',
    phone:[],
    img:app.globalData.imgUrl
  },
  onLoad: function (options) {
    console.log(options.show)
    let that = this;
    var phones = wx.getStorageSync('home').customer_service_phone
    this.setData({
      phone: this.data.phone.concat(phones),
      show: options.show
    })
  },
  input(e) {
    if (e.detail.value) {
      this.setData({
        currentNum: e.detail.cursor,
        inputVal: e.detail.value
      })
    }
  },
  refund(){
    wx.navigateTo({
      url: '/pages/personal/deposit/deposit',
    })
  },
  rule(){
    wx.navigateTo({
      url: '/pages/accounting_rules/accounting_rules',
    })
  },
  card(){
    wx.navigateTo({
      url: '/pages/personal/mine/mine',
    })
  },
  submit: util.throttle(function (e) {
    var that = this;
    let len = that.data.nowLength
    if (!that.data.inputVal) {
      wx.showModal({
        title: '提示',
        content: '反馈信息不能为空',
      })
    } else {
      //提交反馈接口
      if (that.data.currentNum < 10) {
        wx.showModal({
          title: '提示',
          content: '反馈信息不能小于10个字',
        })
      } else {
        if (app.globalData.req) {
          var data = {
            question: that.data.inputVal,
            area_id: wx.getStorageSync('home').id
          }
          app.request('/question', data, 'POST', app.globalData.req).then(res => {
            console.log(res)
            200 == res.statusCode && wx.showToast({
              title: '提交成功',
            }), that.setData({
              currentNum: 0,
              inputVal: ''
            })
          }).catch(err => {
            console.log(err)
          })
        } else {
          wx.showToast({
            title: '您的操作过于频繁，请稍后再试~',
            icon: 'none'
          })
        }
      }
    }
  }, 1000),
  service(){
    var phone = this.data.phone[0];
    if(phone!==''&&phone!==undefined){
      wx.makePhoneCall({
        phoneNumber: phone,
      })
    }else{
      wx.makePhoneCall({
        phoneNumber:"037163211915",
      })
    }
  },
  onReady: function () {

  },
  onShow: function () {

  },
  onHide: function () {

  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  }
})