// pages/validComment/validComment.ts
import { evaluateLaunch } from "../../apis/phone";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // form: {
    name: "",
    phone: "",
    sponsorName: "",
    sponsorPhone: "",
    // },
    commentParams: {}
  },
  submit() {
    const { name, phone, sponsorName, sponsorPhone, commentParams } = this.data
    if (!name) {
      wx.showToast({
        icon: 'none',
        title: '请输入对方姓名'
      })
      return
    }
    if (!phone) {
      wx.showToast({
        icon: 'none',
        title: '请输入对方手机号'
      })
      return
    }
    if (!sponsorName) {
      wx.showToast({
        icon: 'none',
        title: '请输入您的姓名'
      })
      return
    }
    if (!sponsorPhone) {
      wx.showToast({
        icon: 'none',
        title: '请输入您的手机号'
      })
      return
    }
    const payload = {
      evaluateLabelIds: commentParams.evaluateLabelIds,
      score: commentParams.score,
      name,
      phone,
      sponsorName,
      sponsorPhone
    }
    // console.log(payload);

    evaluateLaunch(payload).then(res => {
      // console.log(res);
      if (res.c === 200) {
        wx.navigateTo({
          url: `/pages/commentResult/commentResult?phone=${payload.phone}&status=success`
        })
      } else if (res.c === 501007) {
        wx.showToast({
          icon: 'none',
          // image: '/assets/images/comment/fail.png',
          title: res.m,
          duration: 2000
        })
      } else {
        wx.navigateTo({
          url: `/pages/commentResult/commentResult?status=faild`
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options, wx.getStorageSync('commentParams'));
    this.setData({
      commentParams: wx.getStorageSync('commentParams'),
      sponsorPhone: options.sponsorPhone,
      phone: options.phone,
    })
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})