let common = getApp().globalData.commonFun; let util = getApp().globalData.utilFun; Page({ /** * 页面的初始数据 */ data: { obj: {}, name: "", // 客户姓名 tel: "", // 联系人电话 car_model: "", // 车型 p_number: "", // 车牌号 j_number: "", // 车架号 f_number: "", // 发动机号 yes_Line: "", // 设备编码有线 no_Line: "", // 设备编码无线 product: "售后回租", // 产品 date: "", //日期 time: "", //时间 region: "", // 区域 city: "", // 安装地址 startTime: "", remakes: "", // 备注 num: "", form: {} }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { this.setData({ startTime: this.formatDate(new Date().getTime()), obj: options.item ? JSON.parse(options.item) : '', num: options.num ? options.num : '' }) this.getForm() if (options.item) { this.assignment() } }, esc_tisp(e) { //双向绑定 let name = e.currentTarget.dataset.name; let value = e.currentTarget.dataset.value ? e.currentTarget.dataset.value : e.detail.value; this.setData({ [name]: value }) }, getForm() { let url = 'api/form-gps' util.httpRequest(url).then((res) => { if (res.code == '200') { for (let i in res.data) { res.data[i].text_center = ''; //装文字内容 res.data[i].option = false; //装选项内容 if (res.data[i].tip == '' || !res.data[i].tip) { res.data[i].is_show = false } else { res.data[i].is_show = true } } this.setData({ form: res.data }) console.log(this.data.form) } }) }, // 赋值 assignment() { this.setData({ name: this.data.obj.lessee_name, tel: this.data.obj.lessee_phone, car_model: this.data.obj.car_model, p_number: this.data.obj.car_license, j_number: this.data.obj.frame_number, f_number: this.data.obj.engine_number, yes_Line: this.data.obj.wired_equipment, no_Line: this.data.obj.wireless_equipment, product: this.data.obj.product, date: this.data.obj.setup_time?.slice(0, 10), time: this.data.obj.setup_time?.slice(11, 16), region: this.data.obj.area, city: this.data.obj.setup_address, remakes: this.data.obj.remakes }) }, is_judge() { if (this.data.name == '') { wx.showToast({ title: '请输入客服姓名', icon: 'none', duration: 1500, }) return false; } if (this.data.tel == '' || !(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.data.tel))) { wx.showToast({ title: '请输入正确的手机号', icon: 'none', duration: 1500, }) return false; } if (this.data.car_model == '') { wx.showToast({ title: '请输入车型', icon: 'none', duration: 1500, }) return false; } if (this.data.p_number == '') { wx.showToast({ title: '请输入车牌号', icon: 'none', duration: 1500, }) return false; } if (this.data.j_number == '') { wx.showToast({ title: '请输入车架号', icon: 'none', duration: 1500, }) return false; } if (this.data.f_number == '') { wx.showToast({ title: '请输入发动机号', icon: 'none', duration: 1500, }) return false; } if (this.data.yes_Line == '') { wx.showToast({ title: '请输入设备编码(有线)', icon: 'none', duration: 1500, }) return false; } if (this.data.no_Line == '') { wx.showToast({ title: '请输入设备编码(无线)', icon: 'none', duration: 1500, }) return false; } if (this.data.product == '') { wx.showToast({ title: '请输入产品', icon: 'none', duration: 1500, }) return false; } if (this.data.date == '') { wx.showToast({ title: '请选择安装日期', icon: 'none', duration: 1500, }) return false; } if (this.data.time == '') { wx.showToast({ title: '请选择安装时间', icon: 'none', duration: 1500, }) return false; } if (this.data.time == '') { wx.showToast({ title: '请选择安装时间', icon: 'none', duration: 1500, }) return false; } if (this.data.region == '') { wx.showToast({ title: '请选择区域', icon: 'none', duration: 1500, }) return false; } if (this.data.city == '') { wx.showToast({ title: '请输入安装地址', icon: 'none', duration: 1500, }) return false; } return true; }, getAdd() { if (!this.is_judge()) { return false; } wx.showLoading({ title: '提交中...', mask: true }) console.log(this.data.remakes) let url = 'api/gps-add' let data = { salesman_id: wx.getStorageSync('userInfo').id, lessee_name: this.data.name, lessee_phone: this.data.tel, car_model: this.data.car_model, car_license: this.data.p_number, frame_number: this.data.j_number, engine_number: this.data.f_number, wired_equipment: this.data.yes_Line, wireless_equipment: this.data.no_Line, product: this.data.product, setup_time: this.data.date + ' ' + this.data.time, area: this.data.region, setup_address: this.data.city, remakes: this.data.remakes } util.httpRequest(url, data, 'post').then((res) => { console.log(res) wx.hideLoading() if (res.code == '200') { wx.showToast({ title: '提交成功!', icon: 'success', duration: 1500, mask: true }) setTimeout(() => { wx.navigateTo({ url: '../../pages/GPS/GPS', }) }, 1500) } }) }, biderInput(e) { let name = e.currentTarget.dataset.name console.log(1111111111111111111111111111,name) this.setData({ [name]: e.detail.value }) }, bindDateChange: function(e) { console.log('picker发送选择改变,携带值为', e.detail.value) this.setData({ date: e.detail.value }) }, bindTimeChange: function(e) { console.log('picker发送选择改变,携带值为', e.detail.value) this.setData({ time: e.detail.value }) }, bindRegionChange: function(e) { console.log('picker发送选择改变,携带值为', e.detail.value) this.setData({ region: e.detail.value[0] + '-' + e.detail.value[1] + '-' + e.detail.value[2] }) }, // 时间戳转YY-MM-DD hh:mm:ss formatDate(date) { var date = new Date(date); var YY = date.getFullYear() + '-'; var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'; var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()); var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'; var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'; var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()); return YY + MM + DD; }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, /** * 生命周期函数--监听页面显示 */ onShow: function() { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { } })