123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- import {
- ApiModel
- } from "../../utils/api";
- const _Http = new ApiModel();
- import {
- TestVerify
- } from "../../utils/verify"
- const _Verify = new TestVerify();
- const utilMd5 = require('../../utils/md5')
- let countDown = null;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- fname: '', //用户名称
- frole: '', //身份/职位
- fphonenumber: '', //手机号码
- subusers: [], //权限
- tenterprise_userid: 0, //用户id
- checked: true, //是否启用
- fisused: 1,
- throttle: false, //节流阀
- makeOver: false,
- showModel: false,
- codeChange: "", //验证码
- codeCount: 60,
- verificationCode: "",
- /* 必填项 */
- errTips: {
- fname: false,
- frole: false,
- fphonenumber: false
- },
- tispText: "", //验证码提示文本
- },
- /* input事件剔除特殊字符 */
- eliminate(value) {
- const {
- name
- } = value.target.dataset;
- this.setData({
- [name]: _Verify.Eliminate(value.detail)
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if (options.data) {
- const memberMessage = JSON.parse(options.data);
- console.log(memberMessage)
- const checked = (memberMessage.fisused == 1) ? true : false
- this.setData({
- fname: memberMessage.fname,
- frole: memberMessage.frole,
- fphonenumber: memberMessage.fphonenumber,
- fname: memberMessage.fname,
- subusers: memberMessage.subusers,
- fisused: memberMessage.fisused,
- tenterprise_userid: memberMessage.tenterprise_userid,
- checked,
- fisadministrator: memberMessage.fisadministrator
- })
- }
- },
- /* 获取验证码 */
- getAuthCode() {
- if (this.data.codeCount != 60) return wx.showToast({
- title: '已发送验证码,请勿重复获取',
- icon: "none"
- })
- _Http.basic({
- "accesstoken": wx.getStorageSync('userData').token,
- "classname": "customer.usercenter.teammsg.teammsg",
- "method": "getPassword",
- "content": {
- "tenterprise_userid": this.data.tenterprise_userid
- }
- }).then(res => {
- if (res.data != '成功') return;
- const that = this;
- /* 已将验证码发送到受让方 */
- wx.showToast({
- title: res.msg,
- icon: "none",
- duration: 3000
- })
- this.setData({
- tispText: "已发送到对方手机号"
- })
- that.setData({
- codeCount: this.data.codeCount - 1
- });
- countDown = setInterval(() => {
- if (this.data.codeCount == 0) {
- that.setData({
- codeCount: 60
- });
- clearInterval(countDown)
- return
- }
- that.setData({
- codeCount: this.data.codeCount - 1
- });
- }, 1000)
- })
- },
- /* 二次确认回调 */
- callBack({
- detail
- }) {
- clearInterval(countDown)
- this.setData({
- codeCount: 60,
- tispText: ''
- });
- if (detail == 'true') {
- if (this.data.verificationCode == '') return wx.showToast({
- title: '验证码不能为空',
- icon: "none"
- })
- _Http.basic({
- "accesstoken": wx.getStorageSync('userData').token,
- "classname": "customer.usercenter.teammsg.teammsg",
- "method": "changeAdministrator",
- "content": {
- "tenterprise_userid": this.data.tenterprise_userid,
- "fpassword": utilMd5.hexMD5(this.data.verificationCode)
- }
- }).then(res => {
- console.log(res)
- if (res.msg != '成功') return wx.showToast({
- title: res.msg,
- icon: "none"
- })
- wx.showToast({
- title: '转让成功!请您重新登录',
- icon: "none",
- });
- _Http.logout({
- "accesstoken": wx.getStorageSync('userData').token
- }, false)
- setTimeout(() => {
- wx.reLaunch({
- url: '/pages/login/index',
- })
- }, 1000)
- })
- } else {
- }
- },
- /* 转让主账号 */
- makeOverChange() {
- this.setData({
- showModel: true
- })
- },
- /* 验证码输入 */
- codeChange(e) {
- this.setData({
- verificationCode: e.detail.value
- })
- },
- /* 提交 */
- submit() {
- if (!this.submitVerify()) return wx.showToast({
- title: '请检查表单内容',
- icon: "none"
- });
- if (this.data.throttle) return;
- _Http.basic({
- "accesstoken": wx.getStorageSync('userData').token,
- "classname": "customer.usercenter.teammsg.teammsg",
- "method": "update_userMsg",
- "content": {
- "tenterprise_userid": this.data.tenterprise_userid,
- "fname": this.data.fname,
- "frole": this.data.frole,
- "fphonenumber": this.data.fphonenumber,
- "subusers": this.data.subusers,
- "fisused": this.data.fisused
- }
- }).then(res => {
- console.log(res)
- if (res.msg != "成功") return wx.showToast({
- title: res.data,
- icon: "none"
- });
- //节流阀
- this.setData({
- throttle: true
- })
- wx.showToast({
- title: '保存成功',
- });
- setTimeout(() => {
- wx.navigateBack({
- delta: 1
- })
- }, 500)
- })
- },
- /* 商户提交前验证表单 */
- submitVerify() {
- let errTips = this.data.errTips,
- verify = true;
- //账户名称
- if (!_Verify.required(this.data.fname)) {
- errTips.fname = true;
- verify = false;
- };
- //身份/职位
- if (!_Verify.required(this.data.frole)) {
- errTips.frole = true;
- verify = false;
- };
- //验证联系方式
- if (!_Verify.phoneNumber(this.data.fphonenumber)) {
- errTips.fphonenumber = true;
- verify = false;
- }
- this.setData({
- errTips
- })
- return verify;
- },
- /* 获取焦点 */
- 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
- })
- }
- },
- /* 开关 */
- onChange() {
- if (this.data.fisadministrator == 1) return wx.showToast({
- title: '商户主账号不可停用',
- icon: "none"
- });
- const that = this;
- if (this.data.tenterprise_userid != 0) {
- wx.showModal({
- title: "提示",
- content: (this.data.checked) ? '是否停用“' + this.data.fname + '”,停用后该角色将暂时无法登陆' : '是否启用“' + this.data.fname + '”',
- success(res) {
- if (res.confirm) {
- const checked = !that.data.checked,
- fisused = (checked) ? 1 : 0
- that.setData({
- checked,
- fisused
- })
- }
- }
- })
- } else {
- const checked = !that.data.checked,
- fisused = (checked) ? 1 : 0
- that.setData({
- checked,
- fisused
- })
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- clearInterval(countDown);
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|