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

  data: {
    customerNameList: [
      // {id: 11, name: "海文牧场"}, {id: 22, name: "成宏牧场"}, {id: 32, name: "瑞福牧业"}
    ],
    customerIndex:'',
    customerId:'',
    receiverNameList: [
      // {id: 56, name: "苗舒怡"},{id: 57, name: "颛孙洋洋"},{id: 58, name: "李涛"}
    ],
    receiverIndex:'',
    receiverId:'',
    nextNameList: [
      // {id: 222, name: "拜访"}, {id: 223, name: "远程服务"}, {id: 224, name: "现场服务"}
    ],
    nextIndex:'',
    nextId:'',
    groupId: '', 
    groupName: '',
    typeNameList: [
      // {id: 225, name: "定时回访",checked:true,disabled:false},
      // {id: 226, name: "服务回访",checked:false,disabled:false},
      // {id: 227, name: "投诉回访",checked:false,disabled:false}
    ],
    

   
   
 
    rules: {
      customerName: [{ required: true, message: '客户必填', trigger: 'blur' }],
      tdate: [{ required: true, message: '日期必填', trigger: 'blur' }],
      visiterName: [{ required: true, message: '回访人必填', trigger: 'blur' }],
 
      receiverName: [{ required: true, message: '被回访人必填', trigger: 'blur' }],
      receiverTel: [{ required: true, message: '电话必填', trigger: 'blur' }],
      typeIdsArr: [{ required: true, message: '回访类型必填', trigger: 'blur' }],
      statusName: [{ required: true, message: '回访状态必填', trigger: 'blur' }],
      content: [{  required: true, message: '情况说明必填', trigger: 'blur' }],
    },
    // 新增/编辑
    create: {
        dialogStatus: '',
        temp: {
           customerId: '', 
           customerName: '', 
           groupId: '', 
           groupName: '', 
           tdate: util.getToday(), 
           visiterId: '', 
           visiterName: '', 
           receiverId: '', 
           receiverName: '', 
           receiverTel: '', 
           remark: '', 
           content: '', 
           nextId: '', 
           nextName: '', 
           statusName: '', 
           typeIdsArr:'',
           typeIds:'',

           created: util.getToday(), 
           receiverChoose: 'true' 
        },
        
    }
  },

  onLoad: function (options) {
    // 表单初始化
    wx.lin.initValidateForm(this)
 
    var id = options.id;
    //获取编辑内容
    util.getDataByName({ name:'getTelvisitById', parammaps: {"id":id} }, this.getShowList)

    
  },

  getShowList:function(res){
    console.log('展示数据======>', res.data.list)
    var customerId = res.data.list[0].customerId
    this.setData({
      ['create.temp']:  res.data.list[0],
 
      customerId: res.data.list[0].customerId, 
      receiverId: res.data.list[0].receiverId, 
      nextId: res.data.list[0].nextId
    })
    
    
    //回访类型
    util.getDataByName({ name: 'getDictListSelect2',  parammaps: { "pid": "56" } }, this.getPickerList4)
    
    
  },
 
  getPickerList4:  function (res) {
    console.log('回访类型下拉数据======>', res.data.list)
      const typeIds = this.data.create.temp.typeIds

     var Idsarr  = typeIds.split(",")
     console.log('Idsarr====>', Idsarr)
      
      res.data.list.map(function(i){
        return i.checked = false
      })
        
      res.data.list.map(function(i){
        Idsarr.forEach(function(j){
          if(i.id == j){
            return i.checked = true
          }
        })
      })
      res.data.list.map(function(i){
        return i.disabled = false
      })
    this.setData({
      typeNameList: res.data.list
    })
  },
  
  
  onReady: function () {

  },

  
  onShow: function () {

  },

 
  onHide: function () {

  },

   
  onUnload: function () {

  },

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

  },

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

  },

 
  onShareAppMessage: function () {

  }
})