
var util = require('../../../utils/util.js')
const app = getApp();
Page({
  data: {
    calcDate: util.getToday(),
    isShow: true,
    noData:'../../../images/noData.png',
    dataListTips: "暂无数据",
    g_createrId:"",
    inputvalue:"",
     

    //表格请求参数~~ 
    table: {
      getdataListParm: {
        name: 'getRemoteApp',
        page: 1,
        offset: 1,
        pagecount: 20,
        returntype: 'Map',
        parammaps: {
          inputvalue: "",
          beginDate: util.get7daysAgo(),
          endDate: util.getToday(),
          userId: "",
          roleId: "", 
        }
      },
      tableKey: 0,
      list: [
        // {"content":"想做计步器宣传，目前已让任老师帮忙做。","customerId":378,"customerName":"天津振杰","id":827,"receiverId":1497,"receiverName":"张振强","receiverTel":"","remark":"","vdate":"2020-10-16","visiterId":30,"visiterName":"高占永"},
        // {"content":"兴安盟牧场已确定安装我司饲喂系统，目前正在走流程。","customerId":255,"customerName":"原阳富源牧业","id":826,"receiverId":1341,"receiverName":"贾又春","receiverTel":"","remark":"","vdate":"2020-09-27","visiterId":30,"visiterName":"高占永"},
        // {"content":"沟通款项，已支付","customerId":643,"customerName":"木易牧场","id":825,"receiverId":1333,"receiverName":"李宝丽","receiverTel":"","remark":"","vdate":"2020-09-24","visiterId":30,"visiterName":"高占永"}
      ],
      total: 0,
      listLoading: true,
    },

  },
  onReachBottom: function () {
    console.log('下拉分页')
    var offset = this.data.table.getdataListParm.offset + 1
    this.setData({['table.getdataListParm.offset']:  offset})

    this.getList()
  },
  onLoad: function (options) {
    this.setData({
      g_createrId:app.globalData.g_createrId,
      ['table.getdataListParm.parammaps.userId']:app.globalData.g_userId,
      ['table.getdataListParm.parammaps.roleId']:app.globalData.g_roleId
     })
     util.getDataByName(this.data.table.getdataListParm, this.getListSuccess2)
  },


  //加载表格
  getList() {
    console.log("表格请求数据：", this.data.table.getdataListParm)
    util.getDataByName(this.data.table.getdataListParm, this.getListSuccess2)
  },
  getListSuccess1:  function (res) {
    console.log('table数据======>', res.data.list)
    if (res.data.list !== null) {
      this.setData({
        isShow: true,
        ['table.list']: res.data.list,
        ['table.getdataListParm.offset']: res.data.pageNum,
        ['table.total']: res.data.total
      })
    } else {
      this.setData({
        ['table.list']: [],
        ['table.getdataListParm.offset']: res.data.pageNum,
        isShow: false,
        dataListTips: "暂无数据"
      })
    }
  },

  getListSuccess2:  function (res) {
    console.log('table数据======>', res.data)
    var tempList = res.data.list;
    if (res.data.list !== null) {
      this.setData({
        isShow: true,
        ['table.list']: this.data.table.list.concat(tempList),
        ['table.getdataListParm.offset']: res.data.pageNum,
        ['table.total']: res.data.total
      })
    } else {
      this.setData({
        ['table.getdataListParm.offset']: res.data.pageNum 
      })
    }
  },

 //搜索内容
 change_inputvalue:function(e){
  var value = e.detail.value
  this.setData({
    ['table.getdataListParm.parammaps.inputvalue']: value
  })
},


//搜索按钮
on_search_tap(e) {
  this.setData({
    ['table.getdataListParm.offset']:1,
  })
  console.log("表格请求数据：", this.data.table.getdataListParm)
  util.getDataByName(this.data.table.getdataListParm, this.getListSuccess1)
},

 //清空按钮
 on_error_tap(e) {
  console.log("搜索清空")
  this.setData({
    inputvalue:"",
    ['table.getdataListParm.parammaps.inputvalue']:""
  })
  this.setData({
    ['table.getdataListParm.offset']:1,
  })
  console.log("表格请求数据：", this.data.table.getdataListParm)
  util.getDataByName(this.data.table.getdataListParm, this.getListSuccess1)
},
//日期1
bindDateChange1: function (e) {
  this.setData({
    ['table.getdataListParm.offset']:1,
    ['table.getdataListParm.parammaps.beginDate']: e.detail.value
  })
  console.log("表格请求数据：", this.data.table.getdataListParm)
  util.getDataByName(this.data.table.getdataListParm, this.getListSuccess1)
},
//日期2
bindDateChange2: function (e) {
  this.setData({
    ['table.getdataListParm.offset']:1,
    ['table.getdataListParm.parammaps.endDate']: e.detail.value
  })
  console.log("表格请求数据：", this.data.table.getdataListParm)
  util.getDataByName(this.data.table.getdataListParm, this.getListSuccess1)
},

  //查看
  on_see_tap: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({ url:"../remoteServiceSee/remoteServiceSee?id=" + id})
  },
  //编辑
  on_edit_tap: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({ url:"../remoteServiceEdit/remoteServiceEdit?id=" + id})
  },

  //新增
  on_add_tap: function (e) {
    wx.navigateTo({ url:"../remoteServiceAdd/remoteServiceAdd"})
  },
 


})