123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- //引入网络请求
- import {
- ApiModel
- } from "../../utils/api.js"
- //引入文本校验
- import {
- TestVerify
- } from "../../utils/verify"
- const _Verify = new TestVerify()
- const _Http = new ApiModel()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- 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: "", //上传图片使用
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- /* 查询商户信息 */
- _Http.basic({
- "accesstoken": wx.getStorageSync('token'),
- "classname": "customer.tagents.tagents",
- "method": "query_enterpriseAgentsMain",
- "content": {}
- }).then(s => {
- if (s.msg != "成功") return;
- this.setData({
- tagentsid: s.data[0].tagentsid
- })
- })
- },
- /* 必填项,获得焦点更新状态 */
- isInputFocus(e) {
- let data = this.data.ErrRed;
- data[e.currentTarget.dataset.name] = false;
- this.setData({
- ErrRed: data
- })
- },
- /* 必填项,失去焦点更新状态 */
- isInputBlur(e) {
- let data = this.data.ErrRed;
- 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": "uploadSuccsess",
- "content": {
- "obsfilename": res.data.obsfilename
- }
- }).then(res => {
- if (res.msg != "成功") return;
- const fileList = [{
- url: res.data[0].fobsurl,
- tattachmentid: res.data[0].tattachmentid
- }]
- that.setData({
- fileList
- })
- }).catch(err => {
- console.log(err)
- })
- }
- })
- },
- /* 删除logo */
- logoDelete() {
- _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 => {
- console.log(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;
- console.log(!this.inputCertain())
- _Http.basic({
- "accesstoken": wx.getStorageSync('token'),
- "classname": "customer.tagents.tagents",
- "method": "modify_enterpriseAgent",
- "content": {
- "ftype": "商户认证",
- "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;
- this.toHomePage();
- })
- },
- /* 跳过 */
- toHomePage() {
- wx.reLaunch({
- url: '/pages/tabbarPage/Home/index'
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|