| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545 | import {    ApiModel} from "../../utils/api";const _Http = new ApiModel();import {    TestVerify} from "../../utils/verify"const _Verify = new TestVerify();const utilMd5 = require('../../utils/md5');let countDownTime1 = null;Page({    /**     * 页面的初始数据     */    data: {        popups: false, //弹出层控制        pageType: "login", //页面类型 login 手机登录页面 signin 注册页面 firm 商户认证 changeUser 切换用户        butText: "", //按钮文本        attinfos: [], //logo        /* 登录 */        fphonenumber: null, //手机号码        password: null, //验证码        /* 个人注册 */        fname: "", //用户名        frole: "", //用户身份        /* 商户注册 */        fbrand: "", //品牌名        saleprodclass: [], //经营类目        showSaleprodclass: "", //表单显示经营类目        fagentname: "", //公司名称        fcontact: "", //联系人        fintroduction: "", //公司介绍        faddress: "", //公司地址        fdutyparagraph: "", //统一社会代码        /* 用户选择 */        userIndex: 0, //多用户选择下标        throttle: true, //商户认证截流        /* 错误提示 */        errTips: {            fphonenumber: false, //手机号码            password: false, //验证码            fbrand: false, //品牌名            showSaleprod: false, //经营类目            tipsShow: false, //经营类目提示框            fagentname: false, //注册公司名            fcontact: false, //联系人            logoTips: false, //未上传图片提示            coverTips: false,        },        countDownTime: 60, //倒计时        dataList: ["暂无分类"], //分类列表    },    /**     * 生命周期函数--监听页面加载     */    onLoad: function (options) {        if (options.type) {            this.setData({                pageType: "changeUser"            })        };        if (wx.getStorageSync('userData').fphonenumber != null) this.setData({            fphonenumber: wx.getStorageSync('userData').fphonenumber        })        /* 设置按钮文本 */        this.changeButText()    },    /* 选择类目回调 */    saleprodChange(arr) {        let {            detail        } = arr, showSaleprodclass = "";        console.log(arr)        for (let i = 0; i < detail.length; i++) {            showSaleprodclass += (detail[i] + ',');        };        this.setData({            popups: false,            saleprodclass: detail,            showSaleprodclass: showSaleprodclass.slice(0, showSaleprodclass.length - 1),            "errTips.showSaleprod": false        })    },    /* 缓存登录用户关键数据 */    retentionOfCriticalData(index) {        //获取用户选择的信息列表        const user = getApp().globalData.account_list[index];        let data = {            token: user.token,            fisadministrator: user.fisadministrator,            tagentsid: user.tagentsid,            tenterpriseid: user.tenterpriseid,            userid: user.userid,            index: index,            fphonenumber: this.data.fphonenumber        };        /* 储存 */        wx.setStorageSync('userData', data);        console.log(wx.getStorageSync('userData'))    },    /* 登录页面提交数据 */    loginSubmit() {        //验证手机号码        if (!_Verify.phoneNumber(this.data.fphonenumber, 1)) return this.setData({            "errTips.fphonenumber": true        })        /* 验证验证码 */        if (this.data.password == null) {            this.setData({                "errTips.password": true            })            wx.showToast({                title: '无效验证码',                icon: "none"            })            return;        };        /* 发送请求 */        _Http.login({            "phonenumber": this.data.fphonenumber,            "password": utilMd5.hexMD5(this.data.password),            "client": "wechat_customer"        }).then(res => {            console.log(res)            /* 结果验证 */            if (res.msg != '成功') {                this.setData({                    "errTips.password": true                })                wx.showToast({                    title: '无效验证码',                    icon: "none"                })                return;            };            //账号列表保存到全局变量中            getApp().globalData.account_list = res.account_list;            console.log(getApp().globalData.account_list)            /* 判断账号 新 单 多  isnewregister*/            if (res.account_list.length == 1 && res.account_list[0].isnewregister == 1) {                //新账号                console.log('新账号')                this.retentionOfCriticalData(0)                //跳转到个人注册                this.setData({                    pageType: 'signin'                })                //更改按钮内容                this.changeButText()            } else if (res.account_list.length == 1 && res.account_list[0].isnewregister == 0) {                //单账号                console.log('单账号')                this.retentionOfCriticalData(0)                //跳转到首页                this.jumpOverToIndex()            } else if (res.account_list.length > 1) {                //多账号                console.log('多账号')                //跳转到账号选择                this.setData({                    pageType: 'changeUser'                })                //更改按钮内容                this.changeButText()            }        })    },    /* 提交数据 */    submitData(e) {        const {            name        } = e.currentTarget.dataset;        if (name == "login") {            //登录页面提交信息            this.loginSubmit()        } else if (name == "changeUser") {            //多账号选择            this.retentionOfCriticalData(this.data.userIndex)            //跳转到首页            this.jumpOverToIndex()        } else if (name == "signin") {            //个人注册提交数据后跳转商户认证页面            this.savePersonalInformation()            //查询类目列表            _Http.basic({                "accesstoken": wx.getStorageSync('userData').token,                "classname": "enterprise.system.prodclass",                "method": "query_typeselectList",                "content": {}            }).then(res => {                console.log(res)                if (res.msg != '成功') return;                let dataList = [];                for (let i = 0; i < res.data.length; i++) {                    dataList.push({                        value: res.data[i],                        index: i,                        checked: false                    })                }                this.setData({                    dataList                })            })            //更改按钮内容            this.changeButText()        } else if (name == "firm") {            //商户认证提交            this.merchantsToSubmit();        }    },    /* 商户提交前验证表单 */    merchantsToSubmitVerify() {        let errTips = this.data.errTips,            verify = true;        //验证品牌名称        if (!_Verify.required(this.data.fbrand)) {            errTips.fbrand = true;            verify = false;        };        // 验证图片是否上传        if (!this.selectComponent('#UploadFiles').VerifyThere()) {            errTips.logoTips = true;            verify = false;        }        // 验证图片是否上传        if (!this.selectComponent('#coverUploadFiles').VerifyThere()) {            errTips.coverTips = true;            verify = false;        }        // 经营类目验证        if (!_Verify.required(this.data.showSaleprodclass)) {            errTips.showSaleprod = true;            verify = false;        };        // 注册公司名验证        if (!_Verify.required(this.data.fagentname)) {            errTips.fagentname = true;            verify = false;        };        // 联系人验证        if (!_Verify.required(this.data.fcontact)) {            errTips.fcontact = true;            verify = false;        };        //验证联系方式        if (!_Verify.phoneNumber(this.data.fphonenumber)) {            errTips.fphonenumber = true;            verify = false;        }        this.setData({            errTips        })        return verify;    },    /* 添加图片 */    imageChange(data) {        this.setData({            attinfos: data.detail.fileList        })    },    coverImageChange(data) {        this.setData({            coverAttinfos: data.detail.fileList        })    },    /* 商户认证提交表单 */    merchantsToSubmit() {        // 验证        if (!this.merchantsToSubmitVerify()) return wx.showToast({            title: '请检查表单内容',            icon: "none"        });        //截流        if (!this.data.throttle) return;        //发送请求        _Http.basic({            "accesstoken": wx.getStorageSync('userData').token,            "classname": "customer.tagents.tagents",            "method": "modify_enterpriseAgent",            "content": {                "ftype": "商户认证",                "data": [{                    "fbrand": this.data.fbrand,                    "fagentname": this.data.fagentname,                    "fcontact": this.data.fcontact,                    "fphonenumber": this.data.fphonenumber,                    "faddress": this.data.faddress,                    "fdutyparagraph": this.data.fdutyparagraph,                    "fintroduction": this.data.fintroduction,                    "saleprodclass": this.data.saleprodclass                }]            }        }).then(res => {            if (res.msg != "成功") return wx.showToast({                title: res.data,                icon: "none"            });            this.setData({                throttle: false            })            wx.showToast({                title: "提交成功",                icon: "none"            });            setTimeout(() => {                wx.switchTab({                    url: '/pages/tabbar-pages/home/index',                })            }, 500);        })    },    /* 获取焦点 */    inputFocus(e) {        const {            name        } = e.currentTarget.dataset;        let errTips = this.data.errTips;        errTips[name] = false;        this.setData({            errTips        })    },    /* 失去焦点 */    inputBlur(e) {        const {            name        } = e.currentTarget.dataset;        const {            value        } = e.detail;        if (name == 'fphonenumber') {            if (!_Verify.phoneNumber(this.data.fphonenumber, 1)) return this.setData({                "errTips.fphonenumber": true            })        };        if (value.trim() == "") {            let errTips = this.data.errTips;            errTips[name] = true;            this.setData({                errTips            })        }    },    /* 个人注册页面保存个人信息 */    savePersonalInformation(is) {        const {            fphonenumber        } = this.data        let tail = fphonenumber.toString().substring(fphonenumber.toString().length - 4);        let data = {            fname: tail + "用户",            frole: "管理员"        }        if (this.data.fname != '') {            data.fname = this.data.fname        };        if (this.data.frole != '') {            data.frole = this.data.frole        }        _Http.basic({            "accesstoken": wx.getStorageSync('userData').token,            "classname": "customer.usercenter.usermsg.usermsg",            "method": "update_usermsg",            "content": data        }).then(res => {            if (res.msg != '成功') return wx.showToast({                title: res.data,                icon: 'none'            })            getApp().globalData.account_list = res.data            if (is) {                wx.reLaunch({                    url: '/pages/tabbar-pages/home/index'                })            } else {                this.setData({                    pageType: "firm"                })            }        })    },    /* 多用户选择下标传递 */    userChange(index) {        this.setData({            userIndex: index.detail.userIndex        })    },    /* 获取验证码 */    getVerifyCode() {        //验证手机号码        if (!_Verify.phoneNumber(this.data.fphonenumber, 1)) return this.setData({            "errTips.fphonenumber": true        });        /* 倒计时中阻止 */        if (this.data.countDownTime != 60) return;        this.setData({            countDownTime: this.data.countDownTime - 1        })        _Http.getPassword({            "phonenumber": this.data.fphonenumber,            "client": "wechat_customer"        }).then(res => {            console.log(res)            this.setData({                password: res.msg.substring(res.msg.length - 6)            })            countDownTime1 = setInterval(() => {                if (this.data.countDownTime != 0) {                    this.setData({                        countDownTime: this.data.countDownTime - 1                    })                } else {                    clearInterval(countDownTime1);                    this.setData({                        countDownTime: 60                    })                }            }, 1000);            wx.showToast({                title: res.msg.substring(res.msg.length - 6),                icon: "none",                duration: 8000            })        })    },    /* 跳转首页 */    jumpOverToIndex() {        //如果是个人注册页面,保存数据后进入首页        if (this.data.pageType == 'signin') {            const that = this;            if (this.data.fname != '' || this.data.frole != '') {                wx.showModal({                    title: '提示',                    content: '是否保存已输入的信息',                    success: (res) => {                        console.log(res)                        if (res.confirm) {                            that.savePersonalInformation(true)                        } else {                            wx.reLaunch({                                url: '/pages/tabbar-pages/home/index'                            })                        }                    }                })            } else {                wx.reLaunch({                    url: '/pages/tabbar-pages/home/index'                })            }        } else {            /* 跳转到首页 */            wx.reLaunch({                url: '/pages/tabbar-pages/home/index'            })        }    },    /* 公司介绍 */    fintroductionInput(e) {        this.setData({            fintroduction: e.detail.value        })    },    /* 修改按钮内容 */    changeButText() {        const {            pageType        } = this.data        if (pageType == 'login') {            this.setData({                butText: "登 录"            })        } else if (pageType == 'signin') {            this.setData({                butText: "下一步"            })        } else if (pageType == 'firm') {            this.setData({                butText: "立即创建"            })        } else if (pageType == 'changeUser') {            this.setData({                butText: "选择进入"            })        }    },    /* 弹出层控制 */    showPop() {        this.setData({            popups: !this.data.popups        })    },    /**     * 生命周期函数--监听页面初次渲染完成     */    onReady: function () {    },    /**     * 生命周期函数--监听页面显示     */    onShow: function () {    },    /**     * 生命周期函数--监听页面隐藏     */    onHide: function () {    },    /**     * 生命周期函数--监听页面卸载     */    onUnload: function () {        clearInterval(countDownTime1);    },    /**     * 页面相关事件处理函数--监听用户下拉动作     */    onPullDownRefresh: function () {    },    /**     * 页面上拉触底事件的处理函数     */    onReachBottom: function () {    },    /**     * 用户点击右上角分享     */    onShareAppMessage: function () {    }})
 |