//引入网络请求 import { ApiModel } from "../../utils/api.js" //引入文本校验 import { TestVerify } from "../../utils/verify" const _Verify = new TestVerify() const _Http = new ApiModel() Page({ /** * 页面的初始数据 */ data: { disabled: false, //是否禁用 brandName: "", //品牌名称 classify: "", //经营类目 contact: "", //联系人 telephone: "", //电话号 companyName: "", //公司名称 companyIntroduce: "", //公司介绍 companyAddress: "", //公司地址 userCode: "", //统一社会编码 fileList: "", //logo //必填项状态 是否红色字体 ErrRed: { brandNameErrRed: false, //品牌名 logoErrRed: false, //logo classifyErrRed: false, //经营类目 contactErrRed: false, //联系人 telephoneErrRed: false, //联系方式 }, logoErrTips: "", //logo格式/大小错误提示 telephoneErrTitle: "", //手机号错误提示 tagentsid: "", //上传图片使用 butText: "立即创建", //按钮显示文本 httpType:"商户认证",//请求方式 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { //判断个人中心进入 if (options.type == "edit") { //查看是否为主账号 const main = getApp().globalData.accountList[wx.getStorageSync('userIndex')]; //更改按钮显示文本并隐藏跳过按钮 this.setData({ butText: "提交修改", httpType:"普通修改" }) //非主账号禁用表单 if (main != 1) { this.setData({ disabled: true, }) } } /* 查询商户信息 */ _Http.basic({ "accesstoken": wx.getStorageSync('token'), "classname": "customer.tagents.tagents", "method": "query_enterpriseAgentsMain", "content": {} }).then(s => { if (s.msg != "成功") return; let data = s.data[0]; console.log(data) if (data.ftype == "普通商户") { this.refreshData(data) } else if (data.ftype == "个人" && data.fisauthenticating == 1) { //商户认证中 wx.showToast({ title: '商户认证审核中', icon: "none", duration: 5000 }) } else if (data.ftype == "个人" && data.fisauthenticating == 0) { //商户未认证 this.setData({ disabled: false, butText: "认证商户" }) } }) }, /* 更新数据 */ refreshData(data) { this.setData({ brandName: data.fbrand, //品牌名称 classify: data.saleprodclass, //经营类目 contact: data.fcontact, //联系人 telephone: data.fphonenumber, //电话号 companyName: data.fagentname, //公司名称 companyIntroduce: data.fintroduction, //公司介绍 companyAddress: data.faddress, //公司地址 userCode: data.fdutyparagraph, //统一社会编码 tagentsid: data.tagentsid,//id fileList:data.attinfos[0].fobsurl }) }, /* 必填项获焦 */ isInputFocus(e) { let data = this.data.ErrRed; data[e.currentTarget.dataset.name] = false; this.setData({ ErrRed: data }) }, /* 必填项失焦 */ isInputBlur(e) { let data = this.data.ErrRed; if (e.detail.value) return; data[e.currentTarget.dataset.name] = true; this.setData({ ErrRed: data }) }, //联系方式失去焦点校验 inputTelephoneBlur(e) { if (!_Verify.phoneNumber(this.data.telephone)) { let data = this.data.ErrRed; data[e.currentTarget.dataset.name] = true; this.setData({ telephoneErrTitle: "手机号格式错误", ErrRed: data }) return } this.setData({ telephoneErrTitle: "", }) }, /* 上传图片 */ afterRead(event) { // 初始化数据 this.setData({ logoErrTips: "" }) var that = this const { file } = event.detail; var index = file.url.lastIndexOf("."); var ext = file.url.substr(index + 1); const fileName = file.url.split('/'), name = fileName[fileName.length - 1]; //验证文件格式大小 const Uploader = _Verify.verifyUploader({ file }); if (Uploader == "发送请求") { wx.getFileSystemManager().readFile({ filePath: file.url, // encoding:'utf-8', success: result => { //返回临时文件路径 const fileData = result.data _Http.basic({ "accesstoken": wx.getStorageSync('token'), "classname": "system.system.docManage", "method": "getFileName", "content": { "filename": name, "filetype": ext, "ownertable": "tagents", "ownerid": that.data.tagentsid, "ftype": "brandlogo" } }).then(res => { that.uploadFile(res, fileData) }).catch(err => { console.log(err) }) }, fail: console.error }) } else { this.setData({ logoErrTips: Uploader }) } }, /* 上传成功反馈 */ uploadFile(res, data) { var that = this wx.request({ url: res.data.obsuploadurl, method: "PUT", data: data, header: { 'content-type': 'application/octet-stream' // 默认值 }, success() { _Http.basic({ "accesstoken": wx.getStorageSync('token'), "classname": "system.system.docManage", "method": "uploadSuccess", "content": { "obsfilename": res.data.obsfilename } }).then(res => { if (res.msg != "成功") return; console.log(res) const fileList = [{ url: res.data[0].fobsurl, tattachmentid: res.data[0].tattachmentid }] that.setData({ fileList }) }).catch(err => { console.log(err) }) } }) }, /* 删除logo */ logoDelete() { console.log(1) _Http.basic({ "accesstoken": wx.getStorageSync('token'), "classname": "system.system.docManage", "method": "deleteDoc", "content": { "ownertable": "tagents", "ownerid": this.data.tagentsid, "tattachmentid": this.data.fileList.tattachmentid } }).then(s => { if (s.msg != "成功") return; this.setData({ fileList: "", }) }) }, /* 必填项目检测 */ inputCertain() { let ErrRed = this.data.ErrRed, state = true; /* 品牌名 */ if (!_Verify.required(this.data.brandName)) { ErrRed.brandNameErrRed = true; state = false; }; /* logo */ if (this.data.fileList == '') { this.setData({ logoErrTips: "品牌Logo还未上传" }) state = false; }; /* 经营类目 */ if (!_Verify.required(this.data.classify)) { ErrRed.classifyErrRed = true; state = false; }; /* 联系人 */ if (!_Verify.required(this.data.contact)) { ErrRed.contactErrRed = true; state = false; }; /* 电话号 */ if (!_Verify.phoneNumber(this.data.telephone)) { ErrRed.telephoneErrRed = true; state = false; }; this.setData({ ErrRed }); return state; }, /* 立即创建--完善设置商户信息 */ setUserMsg() { //必填项,校验 if (!this.inputCertain()) return; _Http.basic({ "accesstoken": wx.getStorageSync('token'), "classname": "customer.tagents.tagents", "method": "modify_enterpriseAgent", "content": { "ftype": this.data.httpType, "data": [{ "fagentnum": this.data.companyName, "fbrand": this.data.brandName, "fcontact": this.data.contact, "fphonenumber": this.data.telephone, "faddress": this.data.companyAddress, "fdutyparagraph": this.data.userCode, "fintroduction": this.data.companyIntroduce, "saleprodclass": this.data.classify }] } }).then(s => { if (s.msg != "成功") return; console.log(s) this.toHomePage(); }) }, /* 跳过 */ toHomePage() { wx.reLaunch({ url: '/pages/tabbarPage/Home/index' }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })