const app = getApp() import { chineseToPinYin } from "../../utils/china" Page({ /** * 页面的初始数据 */ data: { user: {}, workTypeList: [], // 所有 工种 array: [], // 所有 工种文字 index: 0, // 当前 工种 YhdwList: [], // 养护单位 列表 array1: [], // 养护单位 名字列表 index1: 0, //当前养护单位 checked1: false, // 选择男 checked2: false, // 选择女 checked3: false, checked4: true, // 默认选择 不开启账号 isWorkCode: null, // 是否存在 账号 flag: true, }, // 更换图片 toggleImg() { let that = this let url = app.globalData.httpsUrlServer + "/file/uploadUserFile" wx.chooseImage({ success(res) { const tempFilePaths = res.tempFilePaths ////console.log(tempFilePaths) that.data.user.fPhoto = tempFilePaths[0] that.setData({ user: that.data.user, }) wx.uploadFile({ url: url, filePath: tempFilePaths[0], name: "file", formData: { user: "test", }, success(res) { const data = res.data that.data.user.fPhoto = JSON.parse(data).data[0].fFileurl that.setData({ user: that.data.user, }) }, }) }, }) }, // 修改姓名 EditfRealname(val) { this.data.user.fRealname = val.detail.value this.setData({ user: this.data.user, }) ////console.log("当前", this.data.user) }, // 修改性别 toggleSex(val) { ////console.log(val) this.data.user.fSex = val.detail.value this.setData({ user: this.data.user, }) }, // 修改手机号 EditfPhone(val) { this.data.user.fPhone = val.detail.value this.setData({ user: this.data.user, }) ////console.log("当前", this.data.user) }, // 修改电话 EditfLinkphone(val) { this.data.user.fLinkphone = val.detail.value this.setData({ user: this.data.user, }) ////console.log("当前", this.data.user) }, // 修改身份号 EditfIdcard(val) { this.data.user.fIdcard = val.detail.value this.setData({ user: this.data.user, }) ////console.log("当前", this.data.user) }, // 修改 工种 bindPickerChange(val) { let temp = val.detail.value // 下标 let temp1 = this.data.array[temp] let obj = this.data.workTypeList.find((v, i) => { return v.fName == temp1 }) this.data.user.fExpand4 = obj.fValuecode this.setData({ index: temp, user: this.data.user, }) }, // 修改养护单位 bindPickerChange1(val) { let temp = val.detail.value // let temp1 = this.data.array1[temp] // let obj = this.data.YhdwList.find((v, i) => { // return v.fDeptname == temp1 // }) // ////console.log(obj) // this.data.user.fYhcompanyid = obj.fYhcompanyid this.setData({ index1: temp, // user: this.data.user, }) }, // 修改职务 EditfDuty(val) { this.data.user.fDuty = val.detail.value this.setData({ user: this.data.user, }) ////console.log("当前", this.data.user) }, // 修改描述 EditfExpand3(val) { this.data.user.fExpand3 = val.detail.value this.setData({ user: this.data.user, }) }, // 修改 开启账户 toggleZH(val) { if (this.data.user.fRealname == "") { return app.toast("请输入姓名") } ////console.log("val", val) if (val.detail.value == "1") { this.data.user.isAddUser = 1 this.data.user.fWorkingcode = chineseToPinYin(this.data.user.fRealname) this.setData({ user: this.data.user, flag: false, }) } else { this.data.user.isAddUser = null this.data.user.fWorkingcode = null this.setData({ user: this.data.user, flag: true, }) } }, // 修改用户名 codeInput(val) { this.data.user.fWorkingcode = val.detail.value this.setData({ user: this.data.user, }) }, // 保存方法 baocun() { if (this.data.user.fRealname == "") { return app.toast("职务不能为空") } if (this.data.user.fDuty == "") { return app.toast("职务不能为空") } if (this.data.user.fPhone == "" || this.data.user.fPhone == null) { return app.toast("请填写手机号") } if (!app.checkPhone(this.data.user.fPhone.trim())) { return app.toast("手机号格式错误") } if (this.data.user.fLinkphone) { if (!app.checkTel(this.data.user.fLinkphone.trim())) { return app.toast("电话号格式错误") } } if (this.data.user.fIdcard) { if (this.data.user.fIdcard.trim().length != 18) { return app.toast("身份证格式错误") } } // if (this.data.user.fWorkingcode != null) { // if (this.data.user.isAddUser == null) { // this.data.user.fWorkingcode = null // this.setData({ // user: this.data.user, // }) // return app.toast("修改用户名前,需开启账号") // } // } this.data.user.fLinkphone == "" ? null : this.data.user.fLinkphone this.data.user.fIdcard == "" ? null : this.data.user.fIdcard this.data.user.fExpand3 == "" ? null : this.data.user.fExpand3 this.setData({ user: this.data.user, }) let that = this ////console.log(that.data.user) wx.showModal({ title: "提示", content: "确定要修改吗", success(res) { if (res.confirm) { let url = app.globalData.httpsUrlServer + "/baseemployeeinfo/saveEmployeeinfo" app.postReq(url, that.data.user, (res) => { ////console.log("res", res) if (res.status == 200) { // wx.navigateTo({ // url: "../parkStaff/parkStaff", // }) let pages = getCurrentPages() //页面栈 ////console.log(pages) let beforePage = pages[2] ////console.log(beforePage.route) wx.navigateBack({ url: "/" + beforePage.route, success: function () { if ( beforePage.route == "packagePersonnel/pages/parkStaff/parkStaff" ) { ////console.log(1111111) beforePage.onPullDownRefresh("toast") } }, }) } else { app.toast("操作失败") return } }) } else if (res.cancel) { ////console.log("用户点击取消") } }, }) }, // 查看大图 showImg(val) { let url = val.currentTarget.dataset.url ////console.log(url) wx.previewImage({ current: url, // 当前显示图片的http链接 urls: [url], }) }, // 获得所有工种 getWorkType() { let that = this let data = { fDictionaryflag: "POSITIONTYPE", } app.getDictionaries(data, (res) => { if (res.status == 200) { that.setData({ workTypeList: res.data, }) ////console.log("所有工种", that.data.workTypeList) let arr = that.data.workTypeList.map((item) => { return item.fName }) ////console.log(arr) that.setData({ array: arr, index: that.data.user.fExpand4 - 1, }) ////console.log("array", that.data.array) ////console.log(that.data.user.fExpand4) } }) }, // 获得所有养护单位 getYhdwList() { let that = this let url = app.globalData.httpsUrlServer + "/tbaseyhcompany/selectYhCompanyList" app.getReq(url, (res) => { if (res.status == 200) { that.setData({ YhdwList: res.data, }) ////console.log("养护单位", that.data.YhdwList) let index = that.data.YhdwList.findIndex((item) => item.fYhcompanyid == this.data.user.fYhcompanyid); that.setData({ // array1: arr, index1: index, }) ////console.log("养护单位名字", that.data.array1) } }) }, onLoad: function (options) { let obj = JSON.parse(options.info) this.setData({ user: obj, }) if (obj.fSex == "男") { this.setData({ checked1: true, }) } else { this.setData({ checked2: true, }) } if (obj.fWorkingcode != null) { this.setData({ isWorkCode: true, }) } else { this.setData({ isWorkCode: false, }) } this.getWorkType() this.getYhdwList() ////console.log("用户数据", this.data.user) }, toast() { if (this.data.flag == true) { app.toast("请先开启账号") } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () {}, /** * 生命周期函数--监听页面显示 */ onShow: function () {}, /** * 生命周期函数--监听页面隐藏 */ onHide: function () {}, /** * 生命周期函数--监听页面卸载 */ onUnload: function () {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () {}, /** * 用户点击右上角分享 */ onShareAppMessage: function () {}, })