const app = getApp();
const api = require('../../../../utils/api.js');
const Constants = require('../../../../utils/Constants.js');
const util = require('../../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    minDate: new Date().getTime(),
    nextFollowTimeSearch: new Date().getTime() + 100,
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      }
      if (type === 'month') {
        return `${value}月`;
      }
      if (type === 'day') {
        return `${value}日`;
      }
      if (type === 'hour') {
        return `${value}时`;
      }
      if (type === 'minute') {
        return `${value}分`;
      }
      return value;
    },
  },
  /**
   * 下次跟进计划
   * @param {} event 
   */
  onNextFollowUpPlanChange(event) {
    let item = this.data.item
    item.nextFollowPlan = event.detail
    this.setData({
      item: item
    })
  },
  /**
     * 生命周期函数--监听页面加载
     */
  onLoad: function (options) {
    let  item = {
        "address": "小四川水煮鱼(鑫丰中心里店)12313123122",
        "addressArea": {
          "city": "沈阳市",
          "district": "铁西区",
          "province": "辽宁省"
        },
        "addressFull": "辽宁省沈阳市铁西区小四川水煮鱼(鑫丰中心里店)12313123122",
        "addressName": "小四川水煮鱼(鑫丰中心里店)",
        "addressNo": "12313123122",
        "callStatus": 0,
        "cpId": 20760,
        "customerCode": "12313123122-100310",
        "customerId": 3924,
        "customerName": "12313123122",
        "customerPhone": "13112122111",
        "flgValid": true,
        "followCount": 2,
        "followId": 1930,
        "followStatus": "跟进状态-跟进",
        "followUser": null,
        "followUserName": "无库有ERP999",
        "nextFollowPlan": "1",
        "nextFollowTime": "2024-01-27 14:50:00",
        "orgName": "无库有ERP999店面",
        "planId": 1384,
        "remarks": null,
        "saleStatus": "客成状态-成交",
        "userName": null,
        "xxlJobId": 306
      }
    this.setData({
      item,
     
    })
  },

  /**
   * 提醒时间关闭
   * 
   */
  onCloseChooseDate() {
    this.setData({
      show: false
    })
  },
  onChangePickDate() {
    this.setData({
      show: true,
      nextFollowTimeSearch: this.data.nextFollowTimeSearchTemp
    })
  },

  onConfirmChooseDate(e) {
    let item = this.data.item
    item.nextFollowTime = util.formatDataTime(new Date(this.data.nextFollowTimeSearch))
    this.setData({
      item: item,
      show: false
    })
  },
  changeDate(e) {
    let key = e.currentTarget.dataset.key

    //提醒时间
    if (key === 'nextFollowTime') {
      this.setData({
        nextFollowTimeSearch: e.detail
      })
    }

  },
  toEdit() {
    this.setData({
      loading: true
    })
    let param = {}
    param.planId = this.data.item.planId
    param.nextFollowTime = this.data.item.nextFollowTime
    param.nextFollowPlan = this.data.item.nextFollowPlan
    api.request(Constants.SALE_CUSTOMERFOLLOW_PLAN_API + 'update_follow_plan', 'POST', param).then(res => {
      this.setData({
        loading: false
      })
      if (res.data.code === 200) {

        wx.showToast({
          title: '操作成功',
          image: '/static/image/success.png',
          duration: 2000
        })
        var pages = getCurrentPages();
        var prevPage = pages[pages.length -2];
        prevPage.setData({
          selectflag: true
        })
        setTimeout(function () {
          wx.navigateBack({
            delta: 1
          })
        }, 1000)
      }
    })
  },
})