change.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel();
  5. import {
  6. TestVerify
  7. } from "../../utils/verify"
  8. const _Verify = new TestVerify();
  9. const utilMd5 = require('../../utils/md5')
  10. let countDown = null;
  11. Page({
  12. /**
  13. * 页面的初始数据
  14. */
  15. data: {
  16. fname: '', //用户名称
  17. frole: '', //身份/职位
  18. fphonenumber: '', //手机号码
  19. subusers: [], //权限
  20. tenterprise_userid: 0, //用户id
  21. checked: true, //是否启用
  22. fisused: 1,
  23. throttle: false, //节流阀
  24. makeOver: false,
  25. showModel: false,
  26. codeChange: "", //验证码
  27. codeCount: 60,
  28. verificationCode: "",
  29. /* 必填项 */
  30. errTips: {
  31. fname: false,
  32. frole: false,
  33. fphonenumber: false
  34. },
  35. tispText: "", //验证码提示文本
  36. },
  37. /* input事件剔除特殊字符 */
  38. eliminate(value) {
  39. const {
  40. name
  41. } = value.target.dataset;
  42. this.setData({
  43. [name]: _Verify.Eliminate(value.detail)
  44. })
  45. },
  46. /**
  47. * 生命周期函数--监听页面加载
  48. */
  49. onLoad: function (options) {
  50. if (options.data) {
  51. const memberMessage = JSON.parse(options.data);
  52. console.log(memberMessage)
  53. const checked = (memberMessage.fisused == 1) ? true : false
  54. this.setData({
  55. fname: memberMessage.fname,
  56. frole: memberMessage.frole,
  57. fphonenumber: memberMessage.fphonenumber,
  58. fname: memberMessage.fname,
  59. subusers: memberMessage.subusers,
  60. fisused: memberMessage.fisused,
  61. tenterprise_userid: memberMessage.tenterprise_userid,
  62. checked,
  63. fisadministrator: memberMessage.fisadministrator
  64. })
  65. }
  66. },
  67. /* 获取验证码 */
  68. getAuthCode() {
  69. if (this.data.codeCount != 60) return wx.showToast({
  70. title: '已发送验证码,请勿重复获取',
  71. icon: "none"
  72. })
  73. _Http.basic({
  74. "accesstoken": wx.getStorageSync('userData').token,
  75. "classname": "customer.usercenter.teammsg.teammsg",
  76. "method": "getPassword",
  77. "content": {
  78. "tenterprise_userid": this.data.tenterprise_userid
  79. }
  80. }).then(res => {
  81. console.log("转让主账号", res)
  82. if (res.data != '成功') return;
  83. const that = this;
  84. /* 已将验证码发送到受让方 */
  85. wx.showToast({
  86. title: res.msg,
  87. icon: "none",
  88. duration: 3000
  89. })
  90. this.setData({
  91. tispText: "已发送到对方手机号"
  92. })
  93. that.setData({
  94. codeCount: this.data.codeCount - 1
  95. });
  96. countDown = setInterval(() => {
  97. if (this.data.codeCount == 0) {
  98. that.setData({
  99. codeCount: 60
  100. });
  101. clearInterval(countDown)
  102. return
  103. }
  104. that.setData({
  105. codeCount: this.data.codeCount - 1
  106. });
  107. }, 1000)
  108. })
  109. },
  110. /* 二次确认回调 */
  111. callBack({
  112. detail
  113. }) {
  114. clearInterval(countDown)
  115. this.setData({
  116. codeCount: 60,
  117. tispText: ''
  118. });
  119. if (detail == 'true') {
  120. if (this.data.verificationCode == '') return wx.showToast({
  121. title: '验证码不能为空',
  122. icon: "none"
  123. })
  124. _Http.basic({
  125. "accesstoken": wx.getStorageSync('userData').token,
  126. "classname": "customer.usercenter.teammsg.teammsg",
  127. "method": "changeAdministrator",
  128. "content": {
  129. "tenterprise_userid": this.data.tenterprise_userid,
  130. "fpassword": utilMd5.hexMD5(this.data.verificationCode)
  131. }
  132. }).then(res => {
  133. console.log(res)
  134. if (res.msg != '成功') return wx.showToast({
  135. title: res.msg,
  136. icon: "none"
  137. })
  138. wx.showToast({
  139. title: '转让成功!请您重新登录',
  140. icon: "none",
  141. });
  142. setTimeout(() => {
  143. wx.reLaunch({
  144. url: '/pages/login/index',
  145. })
  146. }, 1000)
  147. })
  148. } else {
  149. }
  150. },
  151. /* 转让主账号 */
  152. makeOverChange() {
  153. this.setData({
  154. showModel: true
  155. })
  156. },
  157. /* 验证码输入 */
  158. codeChange(e) {
  159. this.setData({
  160. verificationCode: e.detail.value
  161. })
  162. },
  163. /* 提交 */
  164. submit() {
  165. if (!this.submitVerify()) return wx.showToast({
  166. title: '请检查表单内容',
  167. icon: "none"
  168. });
  169. if (this.data.throttle) return;
  170. _Http.basic({
  171. "accesstoken": wx.getStorageSync('userData').token,
  172. "classname": "customer.usercenter.teammsg.teammsg",
  173. "method": "update_userMsg",
  174. "content": {
  175. "tenterprise_userid": this.data.tenterprise_userid,
  176. "fname": this.data.fname,
  177. "frole": this.data.frole,
  178. "fphonenumber": this.data.fphonenumber,
  179. "subusers": this.data.subusers,
  180. "fisused": this.data.fisused
  181. }
  182. }).then(res => {
  183. console.log(res)
  184. if (res.msg != "成功") return wx.showToast({
  185. title: res.data,
  186. icon: "none"
  187. });
  188. //节流阀
  189. this.setData({
  190. throttle: true
  191. })
  192. wx.showToast({
  193. title: '保存成功',
  194. });
  195. setTimeout(() => {
  196. wx.navigateBack({
  197. delta: 1
  198. })
  199. }, 500)
  200. })
  201. },
  202. /* 商户提交前验证表单 */
  203. submitVerify() {
  204. let errTips = this.data.errTips,
  205. verify = true;
  206. //账户名称
  207. if (!_Verify.required(this.data.fname)) {
  208. errTips.fname = true;
  209. verify = false;
  210. };
  211. //身份/职位
  212. if (!_Verify.required(this.data.frole)) {
  213. errTips.frole = true;
  214. verify = false;
  215. };
  216. //验证联系方式
  217. if (!_Verify.phoneNumber(this.data.fphonenumber)) {
  218. errTips.fphonenumber = true;
  219. verify = false;
  220. }
  221. this.setData({
  222. errTips
  223. })
  224. return verify;
  225. },
  226. /* 获取焦点 */
  227. inputFocus(e) {
  228. const {
  229. name
  230. } = e.currentTarget.dataset;
  231. let errTips = this.data.errTips;
  232. errTips[name] = false;
  233. this.setData({
  234. errTips
  235. })
  236. },
  237. /* 失去焦点 */
  238. inputBlur(e) {
  239. const {
  240. name
  241. } = e.currentTarget.dataset;
  242. const {
  243. value
  244. } = e.detail;
  245. if (name == 'fphonenumber') {
  246. if (!_Verify.phoneNumber(this.data.fphonenumber, 1)) return this.setData({
  247. "errTips.fphonenumber": true
  248. })
  249. };
  250. if (value.trim() == "") {
  251. let errTips = this.data.errTips;
  252. errTips[name] = true;
  253. this.setData({
  254. errTips
  255. })
  256. }
  257. },
  258. /* 开关 */
  259. onChange() {
  260. if (this.data.fisadministrator == 1) return wx.showToast({
  261. title: '商户主账号不可停用',
  262. icon: "none"
  263. });
  264. const that = this;
  265. if (this.data.tenterprise_userid != 0) {
  266. wx.showModal({
  267. title: "提示",
  268. content: (this.data.checked) ? '是否停用“' + this.data.fname + '”,停用后该角色将暂时无法登陆' : '是否启用“' + this.data.fname + '”',
  269. success(res) {
  270. if (res.confirm) {
  271. const checked = !that.data.checked,
  272. fisused = (checked) ? 1 : 0
  273. that.setData({
  274. checked,
  275. fisused
  276. })
  277. }
  278. }
  279. })
  280. } else {
  281. const checked = !that.data.checked,
  282. fisused = (checked) ? 1 : 0
  283. that.setData({
  284. checked,
  285. fisused
  286. })
  287. }
  288. },
  289. /**
  290. * 生命周期函数--监听页面初次渲染完成
  291. */
  292. onReady: function () {
  293. },
  294. /**
  295. * 生命周期函数--监听页面显示
  296. */
  297. onShow: function () {
  298. },
  299. /**
  300. * 生命周期函数--监听页面隐藏
  301. */
  302. onHide: function () {
  303. },
  304. /**
  305. * 生命周期函数--监听页面卸载
  306. */
  307. onUnload: function () {
  308. clearInterval(countDown);
  309. },
  310. /**
  311. * 页面相关事件处理函数--监听用户下拉动作
  312. */
  313. onPullDownRefresh: function () {
  314. },
  315. /**
  316. * 页面上拉触底事件的处理函数
  317. */
  318. onReachBottom: function () {
  319. },
  320. /**
  321. * 用户点击右上角分享
  322. */
  323. onShareAppMessage: function () {
  324. }
  325. })