Ver código fonte

商户注册与个人信息修改

zhaoxiaohai 3 anos atrás
pai
commit
364064df64

+ 4 - 1
components/My_userRegister/index.js

@@ -70,7 +70,10 @@ Component({
         /* 下一步,完善商户信息 */
         userPerfectMsg() {
             this.setTacitlyApprove().then(s => {
-                console.log(s)
+                if (s.msg != "成功") return;
+                wx.reLaunch({
+                    url: '/pages/userPerfectMsg/index'
+                })
             })
         },
         /* 跳过,跳转首页 */

+ 1 - 0
pages/tabbarPage/User/index.js

@@ -42,6 +42,7 @@ Page({
             "method": "query_usermsg",
             "content": {}
         }).then(s => {
+            console.log(s)
             if (s.msg != "成功") return;
             this.setData({
                 userMsg: s.data[0]

+ 113 - 2
pages/userMessage/index.js

@@ -1,7 +1,13 @@
+//引入请求
 import {
     ApiModel
 } from "../../utils/api"
-const _Http = new ApiModel()
+//引入校验文件
+import {
+    TestVerify
+} from "../../utils/verify"
+const _Http = new ApiModel();
+const _Verify = new TestVerify();
 Page({
 
     /**
@@ -16,12 +22,18 @@ Page({
         femail: "", //邮箱
         fwechatno: "", //微信
         faddress: "", //地址
+        /* 必填项未填红色显示 */
+        inputErrRed: {
+            isFname: false, //用户名
+            isFrole: false, //角色
+        }
     },
 
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad: function (options) {
+        /* 初始化数据 */
         const data = JSON.parse(options.data)
         this.setData({
             fname: data.fname,
@@ -36,8 +48,103 @@ Page({
             fphonenumber: data.fphonenumber,
         })
     },
+    /* 修改用户头像 */
+    changeUserImg() {
+        var that = this;
+        wx.chooseMedia({
+            count: 1,
+            mediaType: ['image'],
+            sourceType: ['album', 'camera'],
+            camera: 'back',
+            success(res) {
+                const file = res.tempFiles[0];
+                var index = file.tempFilePath.lastIndexOf(".");
+                var ext = file.tempFilePath.substr(index + 1);
+                var timestamp = Date.parse(new Date());
+                wx.getFileSystemManager().readFile({
+                    filePath: file.tempFilePath,
+                    // encoding:'utf-8',
+                    success: result => {
+                        //返回临时文件路径
+                        const fileData = result.data
+                        _Http.basic({
+                            "accesstoken": wx.getStorageSync('token'),
+                            "classname": "system.system.docManage",
+                            "method": "getFileName",
+                            "content": {
+                                "filename": 'wx' + timestamp,
+                                "filetype": ext,
+                                "ownertable": "tenterprise_users",
+                                "ownerid": getApp().globalData.accountList[0].userid,
+                                "ftype": "headportrait",
+                            }
+                        }).then(res => {
+                            const a1 = _Http.uploadFile(res, fileData);
+                            console.log(a1)
+                            /* .then(res => {
+                                if (res.msg != "成功") return;
+                                console.log(res)
+                            }).catch(err => {
+                                console.log(err)
+                            }) */
+
+                        }).catch(err => {
+                            console.log(err)
+                        })
+                    },
+                    fail: console.error
+                })
+            }
+        })
+    },
+    /* input必填项获取焦点 */
+    inputEssentialFocus(e) {
+        const {
+            name
+        } = e.currentTarget.dataset;
+        let inputErrRed = this.data.inputErrRed;
+        inputErrRed[name] = false;
+        this.setData({
+            inputErrRed
+        })
+    },
+    /* input必填项失去焦点 */
+    inputEssentialBlur(e) {
+        if (e.detail.value != "" && e.detail.value != " ") return;
+        const {
+            name
+        } = e.currentTarget.dataset;
+        let inputErrRed = this.data.inputErrRed;
+        inputErrRed[name] = true;
+        this.setData({
+            inputErrRed
+        })
+    },
+    /* 校验必填项 */
+    inputCertain() {
+        let state = true,
+            inputErrRed = this.data.inputErrRed;
+        if (!_Verify.required(this.data.fname)) {
+            inputErrRed["isFname"] = true;
+            state = false;
+        };
+        if (!_Verify.required(this.data.frole)) {
+            inputErrRed["isFrole"] = true;
+            state = false;
+        };
+        this.setData({
+            inputErrRed
+        });
+        return state;
+    },
     /* 表单提交 */
     formSubmit() {
+        /* 检测是否还有为空必填项 */
+        if (!this.inputCertain()) return wx.showToast({
+            title: '必填项不可为空!',
+            icon: "none"
+        });
+        /* 发送请求 */
         _Http.basic({
             "accesstoken": wx.getStorageSync('token'),
             "classname": "customer.usercenter.usermsg.usermsg",
@@ -52,11 +159,15 @@ Page({
                 faddress: this.data.faddress,
             }
         }).then(s => {
-            console.log(s)
             if (s.msg != "成功") return;
             wx.showToast({
                 title: '保存成功',
             })
+            setTimeout(() => {
+                wx.navigateBack({
+                    delta: 1
+                })
+            }, 500)
             this.setData({
                 userMsg: s.data[0]
             })

+ 3 - 3
pages/userMessage/index.wxml

@@ -1,11 +1,11 @@
 <!-- 用户修改信息页面 -->
 <view class="head">
   <view class="user_img"></view>
-  <view class="change_img">修改头像</view>
+  <view class="change_img" bindtap="changeUserImg">修改头像</view>
 </view>
 <van-cell-group>
-  <van-field model:value="{{ fname }}" required clearable label="用户名" placeholder="点击填写" input-align="right" size="large" />
-  <van-field model:value="{{ frole }}" required clearable label="身份/职位" placeholder="点击选择" input-align="right" size="large" />
+  <van-field model:value="{{ fname }}" required clearable label="用户名" error="{{inputErrRed.isFname}}" bind:focus="inputEssentialFocus" bind:blur="inputEssentialBlur" data-name="isFname" placeholder="点击填写" input-align="right" size="large" />
+  <van-field model:value="{{ frole }}" required clearable label="身份/职位" error="{{inputErrRed.isFrole}}" bind:focus="inputEssentialFocus" bind:blur="inputEssentialBlur" data-name="isFrole" placeholder="点击选择" input-align="right" size="large" />
   <van-field model:value="{{ fphonenumber }}" required clearable label="手机" disabled placeholder="点击填写" input-align="right" size="large" />
   <van-field model:value="{{ fwechatno }}" clearable label="微信" placeholder="点击填写" input-align="right" size="large" />
   <van-field model:value="{{ faddress }}" clearable label="地址" placeholder="点击填写" input-align="right" size="large" />

+ 186 - 34
pages/userPerfectMsg/index.js

@@ -1,8 +1,14 @@
+//引入网络请求
+import {
+    ApiModel
+} from "../../utils/api.js"
 //引入文本校验
 import {
     TestVerify
 } from "../../utils/verify"
+
 const _Verify = new TestVerify()
+const _Http = new ApiModel()
 Page({
     /**
      * 页面的初始数据
@@ -19,20 +25,33 @@ Page({
         fileList: "", //logo
         //必填项状态 是否红色字体
         ErrRed: {
-            brandNameErrRed:false,//品牌名
+            brandNameErrRed: false, //品牌名
             logoErrRed: false, //logo
-            classifyErrRed: false,//经营类目
-            contactErrRed: false,//联系人
+            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) {
@@ -65,39 +84,172 @@ Page({
             telephoneErrTitle: "",
         })
     },
+    /* 上传图片 */
     afterRead(event) {
-        console.log(event)
-        // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
-        /*         wx.uploadFile({
-                    url: 'https://example.weixin.qq.com/upload', // 仅为示例,非真实的接口地址
-                    filePath: file.url,
-                    name: 'file',
-                    formData: {
-                        user: 'test'
-                    },
-                    success(res) {
-                        // 上传完成需要更新 fileList
-                        const {
-                            fileList = []
-                        } = this.data;
-                        fileList.push({
-                            ...file,
-                            url: res.data
-                        });
-                        this.setData({
-                            fileList
-                        });
-                    },
-                }); */
-    },
-    /* 完善设置商户信息 */
+        // 初始化数据
+        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() {
-        // _Verify.userName(this.data.brandName)
-        // _Verify.phoneNumber(this.data.telephone)
-        // console.log(_Verify.phoneNumber(this.data.telephone))
-        _Verify.required(this.data.classify) //经营类目
-
+        //必填项,校验
+        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'

+ 8 - 4
pages/userPerfectMsg/index.wxml

@@ -1,18 +1,22 @@
 <!-- 新用户注册完善商户信息页面 -->
 <van-cell-group>
   <van-field model:value="{{ brandName }}" required clearable label="品牌名" placeholder="点击填写" input-align="right" size="large" bindfocus="isInputFocus" bindblur="isInputBlur" data-name="brandNameErrRed" error="{{ErrRed.brandNameErrRed&&!brandName}}" />
+  <!-- 自定义上次logo -->
   <view class="logo_box">
     <view class="logo_con">
       <view class="logo_con_title">
         <text class="">*</text>品牌logo
       </view>
       <view class="logo_up">
-        <van-uploader file-list="{{ fileList }}" max-count="1" bind:after-read="afterRead" accept="image" deletable="{{ true }}" />
+        <van-uploader file-list="{{ fileList }}" max-count="1" bind:after-read="afterRead" bind:delete="logoDelete" accept="image" deletable="{{ true }}" />
+      </view>
+      <!-- 错误提示 -->
+      <view class="logo_err_tips" wx:if="{{logoErrTips}}">
+        <van-icon name="clear" /> {{logoErrTips}}
       </view>
     </view>
   </view>
-  <!--  <van-field>
-  </van-field> -->
+  <!-- Vant组件 -->
   <van-field model:value="{{ classify }}" required clearable label="经营类目" placeholder="点击选择" input-align="right" size="large" bindfocus="isInputFocus" bindblur="isInputBlur" data-name="classifyErrRed" error="{{ErrRed.classifyErrRed&&!classify}}" />
   <van-field model:value="{{ contact }}" required clearable label="联系人" placeholder="点击填写" input-align="right" size="large" bindfocus="isInputFocus" bindblur="isInputBlur" data-name="contactErrRed" error="{{ErrRed.contactErrRed&&!contact}}" />
   <van-field model:value="{{ telephone }}" error-message="{{telephoneErrTitle}}" error="{{ErrRed.telephoneErrRed}}" required clearable label="联系方式" placeholder="点击填写" input-align="right" size="large" data-name="telephoneErrRed" bindblur="inputTelephoneBlur" bindfocus="isInputFocus" />
@@ -21,7 +25,7 @@
   <van-field model:value="{{ companyAddress }}" clearable label="地址" placeholder="点击填写" input-align="right" size="large" />
   <van-field model:value="{{ userCode }}" clearable label="统一社会代码" placeholder="点击填写" input-align="right" size="large" />
 </van-cell-group>
-<!-- -->
+<!-- 按钮 -->
 <view class="login_but">
   <van-button type="info" size="large" bindtap="setUserMsg">立即创建</van-button>
 </view>

+ 5 - 1
pages/userPerfectMsg/index.wxss

@@ -20,10 +20,14 @@
     color: #EE1929;
 }
 .logo_up{
-    flex: 1;
     height: 100%;
     margin-left:15rpx;
 }
+/* logo错误提示 */
+.logo_err_tips{
+    color: red;
+    font-size: 26rpx;
+}
 /* 登录按钮 */
 .login_but{
     width: 320rpx;

+ 24 - 1
utils/api.js

@@ -16,13 +16,36 @@ class ApiModel extends HTTP {
             data
         })
     }
-    /* 查询个人信息,修改个人信息,商户信息调整申请 */
+    /* 查询个人信息,修改个人信息,商户信息调整申请,上传附件,商户信息查询,商户信息调整申请 */
     basic(data) {
         return this.request({
             url: "",
             data
         })
     }
+
+    /* 上传成功反馈 */
+    uploadFile(res, data) {
+        let that = this
+        wx.request({
+            url: res.data.obsuploadurl,
+            method: "PUT",
+            data: data,
+            header: {
+                'content-type': 'application/octet-stream' // 默认值
+            },
+            success() {
+                that.basic({
+                    "accesstoken": wx.getStorageSync('token'),
+                    "classname": "system.system.docManage",
+                    "method": "uploadSuccsess",
+                    "content": {
+                        "obsfilename": res.data.obsfilename
+                    }
+                })
+            }
+        })
+    }
 }
 export {
     ApiModel

+ 15 - 0
utils/verify.js

@@ -42,6 +42,21 @@ class TestVerify {
         }
         return true;
     }
+
+    /* 附件格式,大小校验 */
+    verifyUploader(data) {
+        const {
+            file
+        } = data;
+        //附件格式
+        const typeList = ['jpg', 'jpge', 'png', 'pdf']
+        const imgType = file.url.split(".");
+        const isType = typeList.some((value) => value == imgType[imgType.length - 1]);
+        if (!isType) return "文件格式不符合要求";
+        //附件大小,不可超过10M
+        if (file.size > 10485760) return "文件大小需小于10M"
+        return "发送请求";
+    }
 }
 export {
     TestVerify