EntryInformation.js 7.9 KB
// pages/EntryInformation/EntryInformation.js
const app = getApp();
Page({
  data: {
    sexArray: ['男', '女'],
    card_Array: ['身份证', '护照', '出生证', '军官证', '港澳通行证'],
    birth_date: '',
    addsess_current: 0,
    label_type: [],
    list: {
      name: '',
      sex: '',
      family_role: '',
      income: '',
      mobile: '',
      birthday: '',
      work: '',
      work_address: '',
      address: '',
      mail_address: 0,
      id_type: '',
      id_num: '',
      text: '',
      label_ids: []
    },
    familyid: 0, //家庭ID
    hasimg: '',
    DefId: ''
  },

  //名字
  setName(e) {
    var list = this.data.list;
    list.name = e.detail.value;
    this.setData({
      list: list
    })
  },

  //选择性别
  selectSex(e) {
    var list = this.data.list;
    var sexArray = this.data.sexArray
    list.sex = sexArray[e.detail.value];
    this.setData({
      sex_index: e.detail.value,
      list: list
    })
  },

  //选择家庭角色
  familyRole(e) {
    let list = this.data.list;
    list.family_role = e.detail.value;
    this.setData({
      list: list
    })
  },

  //选择年收入
  income(e) {
    let list = this.data.list;
    list.income = e.detail.value;
    this.setData({
      list: list
    })
  },

  //手机号
  setMobile(e) {
    let list = this.data.list;
    list.mobile = e.detail.value;
    this.setData({
      list: list
    })
  },

  //出生日期
  birthDate(e) {
    var list = this.data.list;
    list.birthday = e.detail.value;
    this.setData({
      birth_date: e.detail.value,
      list: list
    })
  },

  //选择家庭角色
  setWork(e) {
    let list = this.data.list;
    list.work = e.detail.value;
    this.setData({
      list: list
    })
  },

  //选择家庭角色
  setworkAddress(e) {
    let list = this.data.list;
    list.work_address = e.detail.value;
    this.setData({
      list: list
    })
  },


  //选择家庭角色
  setSddress(e) {
    let list = this.data.list;
    list.address = e.detail.value;
    this.setData({
      list: list
    })
  },

  //通讯切换
  addressCharge(e) {
    var that = this;
    var list = this.data.list
    list.mail_address = e.target.dataset.current
    if (this.data.addsess_current === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        addsess_current: e.target.dataset.current,
        list: list
      })
    }
  },

  //选择证件类型
  selectIdCard(e) {
    let list = this.data.list;
    var card_Array = this.data.card_Array
    list.id_type = parseInt(e.detail.value) + 1;
    this.setData({
      card_index: e.detail.value,
      list: list
    })
  },

  //选择家庭角色
  setIdNum(e) {
    let list = this.data.list;
    list.id_num = e.detail.value;
    this.setData({
      list: list
    })
  },

  //用户描述
  descript(e) {
    let list = this.data.list;
    list.text = e.detail.value;
    this.setData({
      list: list
    })
  },

  //选择用户标签
  selectLabel(e) {
    var list = this.data.list
    var id = e.currentTarget.dataset.id
    var label_ids = list.label_ids
    label_ids.push(id)
    console.log(label_ids)
    var status = e.currentTarget.dataset.status
    var label_type = this.data.label_type
    var mindex = e.currentTarget.dataset.mindex
    var sindex = e.currentTarget.dataset.sindex
    label_type[mindex].data[sindex].status = !(label_type[mindex].data[sindex].status)
    this.setData({
      label_type: label_type,
      list: list
    });
  },
  // 选择上传的图片
  chooseImg() { //这里是选取图片的方法
    var that = this;
    wx.chooseImage({
      count: 1,
      success: (res) => {
        var tempFilePaths = res.tempFilePaths
        let url = '/users/upload'
        let strtime = +new Date()
        let params = {
          picurl: tempFilePaths[0],
          strtime: strtime,
          token: app.strTime(strtime)
        }
        wx.uploadFile({
          url: 'https://insurance.w.broteam.cn/pubilc/upload', //仅为示例,非真实的接口地址
          filePath: tempFilePaths[0],
          name: 'picurl',
          formData: {
            'strtime': strtime,
            'token': app.strTime(strtime)
          },
          success: function(res) {
            var data = JSON.parse(res.data);
            var picurl = data.data.picurl;
            picurl = picurl.indexOf('http') != '-1' ? picurl : "http://" + picurl
            var list = that.data.list
            list.picurl = picurl
            that.setData({
              hasimg: picurl,
              list: list
            })
          }
        })
      }
    })
  },


  //成员信息的修改,新增
  listVerify(e) {
    var list = this.data.list;
    console.log(e)
    var idcardReg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
    let that = this;
    var warn = ""; //弹框时提示的内容
    var flag = true; //判断信息输入是否完整
    var state = that.data.state
    if (list.name == "") {
      warn = "请填写您的姓名!";
    } else if (list.family_role == '') {
      warn = '请填写您的家庭角色'
    } else if (list.status_num != '' && !idcardReg.test(list.status_num) && state == 0) {
      warn = "请填写正确的身份号"
    } else {
      flag = false; //若必要信息都填写,则不用弹框.正常调用接口
      let paramlist = {
        name: list.name,
        sex: list.sex,
        family_role: list.family_role,
        money: list.income,
        mobile: list.mobile,
        birthday: list.birthday,
        work: list.work,
        work_address: list.work_address,
        address: list.address,
        mid: list.mail_address,
        user_status: list.id_type,
        status_num: list.id_num,
        picurl: list.picurl,
        text: list.text,
        label_ids: list.label_ids,
        family_id: that.data.familyid,
        DefId: that.data.DefId,
        UserId: app.globalData.UserId
      }
      let url = 'counselor/deflistdo'
      app.post(url, paramlist).then((res) => {
        console.log(res)
        if (res.data.code == 200) {
          wx.showToast({
            title: '操作成功',
            icon: 'success',
            duration: 2000
          })
          if (this.data.flag == 'add') {
            wx.navigateBack({
              delta: 2
            })
          } else {
            wx.navigateBack({
              delta: 1
            })
          }
        }
      }).catch((errMsg) => {
        console.log(errMsg)
      })
    }
    if (flag == true) {
      wx.showToast({
        title: warn,
        icon: 'none',
        duration: 2000
      })
    }
  },
  //获取成员详细信息
  labelInfo() {
    let that = this;
    let url = 'counselor/DefAdd';
    let params = {}
    app.post(url, params).then((res) => {
      console.log(res)
      if (res.data.code == 200) {
        var list = this.data.list
        // label_type = res.data.data
        that.setData({
          label_type: res.data.data
        })

      }

    }).catch((errMsg) => {
      console.log(errMsg)
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.labelInfo()
    this.setData({
      DefId: options.DefId,
      familyid: options.familyid
    })
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})