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


  data: {
    photoShow:false,
    photoUrl:"",

    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: '',

    vdateShow:false,
   
    scenePhotoUrlList:[],
 
    rules: {
      customerName: [{ required: true, message: '客户必填', trigger: 'blur' }],
      vdate: [{ required: true, message: '拜访日期必填', trigger: 'blur' }],
      location: [{ required: true, message: '必填', trigger: 'blur' }],
      scenePhoto: [{ required: true, message: '服务单照片必填', trigger: 'blur' }],
      receiverName: [{ required: true, message: '接待人必填', trigger: 'blur' }],
      receiverTel: [{ required: true, message: '电话必填', trigger: 'blur' }],
      content: [{  required: true, message: '情况说明必填', trigger: 'blur' }],
    },
    // 新增/编辑
    create: {
        dialogStatus: '',
        temp: {
           customerId: '', 
           customerName: '', 
           groupId: '', 
           groupName: '', 
           vdate: util.getToday(), 
           visiterId: '', 
           visiterName: '', 
           receiverId: '', 
           receiverName: '', 
           receiverTel: '', 
           remark: '', 
           content: '', 
           nextId: '', 
           nextName: '', 
           location: '', 
           created: util.getToday(), 
           receiverChoose: 'true',vPhoto1: -1, vPhoto2: -1, vPhoto3: -1, vPhoto4: -1,vPhoto5: -1,vPhoto6: -1,vPhoto7: -1,vPhoto8: -1,vPhoto9: -1,
           picname1: '', picname2: '', picname3: '', picname4: '', picname5: '', picname6: '', picname7: '', picname8: '', picname9: '',
        },
        
    }
  },

  onLoad: function (options) {
    // 表单初始化
    wx.lin.initValidateForm(this)

    var id = options.id;

    
    
    //获取编辑内容
    util.getDataByName({ name:'getVisitById', 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
    })

    var picname1 = res.data.list[0].picname1
    var picname2 = res.data.list[0].picname2
    var picname3 = res.data.list[0].picname3
    var picname4 = res.data.list[0].picname4
    var picname5 = res.data.list[0].picname5
    var picname6 = res.data.list[0].picname6
    var picname7 = res.data.list[0].picname7
    var picname8 = res.data.list[0].picname8
    var picname9 = res.data.list[0].picname9
    var scenePhotoUrlList = []
 

    if(picname1 != undefined ){scenePhotoUrlList.push(app.globalData.g_url + picname1)}
    if(picname2 != undefined){scenePhotoUrlList.push(app.globalData.g_url + picname2)}
    if(picname3 != undefined ){scenePhotoUrlList.push(app.globalData.g_url + picname3)}
    if(picname4 != undefined){scenePhotoUrlList.push(app.globalData.g_url + picname4)}
    if(picname5 != undefined ){scenePhotoUrlList.push(app.globalData.g_url + picname5)}
    if(picname6 != undefined ){scenePhotoUrlList.push(app.globalData.g_url + picname6)}
    if(picname7 != undefined ){scenePhotoUrlList.push(app.globalData.g_url + picname7)}
    if(picname8 != undefined ){scenePhotoUrlList.push(app.globalData.g_url + picname8)}
    if(picname9 != undefined ){scenePhotoUrlList.push(app.globalData.g_url + picname9)}

    console.log(scenePhotoUrlList)

  
    this.setData({
      scenePhotoUrlList:scenePhotoUrlList 
    })
    
      
  },


  //查看
  on_see_tap: function (e) {
    var urlmsg = e.currentTarget.dataset.urlmsg;
    console.log(urlmsg)
 
    this.setData({
      photoShow:true,
      photoUrl:urlmsg
    })
  },

  on_close_tap: function (e) {
    console.log(222)
    this.setData({
      photoShow:false
    })
  }
   
   
 

})