change.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. if (res.data != '成功') return;
  82. const that = this;
  83. /* 已将验证码发送到受让方 */
  84. wx.showToast({
  85. title: res.msg,
  86. icon: "none",
  87. duration: 3000
  88. })
  89. this.setData({
  90. tispText: "已发送到对方手机号"
  91. })
  92. that.setData({
  93. codeCount: this.data.codeCount - 1
  94. });
  95. countDown = setInterval(() => {
  96. if (this.data.codeCount == 0) {
  97. that.setData({
  98. codeCount: 60
  99. });
  100. clearInterval(countDown)
  101. return
  102. }
  103. that.setData({
  104. codeCount: this.data.codeCount - 1
  105. });
  106. }, 1000)
  107. })
  108. },
  109. /* 二次确认回调 */
  110. callBack({
  111. detail
  112. }) {
  113. clearInterval(countDown)
  114. this.setData({
  115. codeCount: 60,
  116. tispText: ''
  117. });
  118. if (detail == 'true') {
  119. if (this.data.verificationCode == '') return wx.showToast({
  120. title: '验证码不能为空',
  121. icon: "none"
  122. })
  123. _Http.basic({
  124. "accesstoken": wx.getStorageSync('userData').token,
  125. "classname": "customer.usercenter.teammsg.teammsg",
  126. "method": "changeAdministrator",
  127. "content": {
  128. "tenterprise_userid": this.data.tenterprise_userid,
  129. "fpassword": utilMd5.hexMD5(this.data.verificationCode)
  130. }
  131. }).then(res => {
  132. console.log(res)
  133. if (res.msg != '成功') return wx.showToast({
  134. title: res.msg,
  135. icon: "none"
  136. })
  137. wx.showToast({
  138. title: '转让成功!请您重新登录',
  139. icon: "none",
  140. });
  141. _Http.logout({
  142. "accesstoken": wx.getStorageSync('userData').token
  143. }, false)
  144. setTimeout(() => {
  145. wx.reLaunch({
  146. url: '/pages/login/index',
  147. })
  148. }, 1000)
  149. })
  150. } else {
  151. }
  152. },
  153. /* 转让主账号 */
  154. makeOverChange() {
  155. this.setData({
  156. showModel: true
  157. })
  158. },
  159. /* 验证码输入 */
  160. codeChange(e) {
  161. this.setData({
  162. verificationCode: e.detail.value
  163. })
  164. },
  165. /* 提交 */
  166. submit() {
  167. if (!this.submitVerify()) return wx.showToast({
  168. title: '请检查表单内容',
  169. icon: "none"
  170. });
  171. if (this.data.throttle) return;
  172. _Http.basic({
  173. "accesstoken": wx.getStorageSync('userData').token,
  174. "classname": "customer.usercenter.teammsg.teammsg",
  175. "method": "update_userMsg",
  176. "content": {
  177. "tenterprise_userid": this.data.tenterprise_userid,
  178. "fname": this.data.fname,
  179. "frole": this.data.frole,
  180. "fphonenumber": this.data.fphonenumber,
  181. "subusers": this.data.subusers,
  182. "fisused": this.data.fisused
  183. }
  184. }).then(res => {
  185. console.log(res)
  186. if (res.msg != "成功") return wx.showToast({
  187. title: res.data,
  188. icon: "none"
  189. });
  190. //节流阀
  191. this.setData({
  192. throttle: true
  193. })
  194. wx.showToast({
  195. title: '保存成功',
  196. });
  197. setTimeout(() => {
  198. wx.navigateBack({
  199. delta: 1
  200. })
  201. }, 500)
  202. })
  203. },
  204. /* 商户提交前验证表单 */
  205. submitVerify() {
  206. let errTips = this.data.errTips,
  207. verify = true;
  208. //账户名称
  209. if (!_Verify.required(this.data.fname)) {
  210. errTips.fname = true;
  211. verify = false;
  212. };
  213. //身份/职位
  214. if (!_Verify.required(this.data.frole)) {
  215. errTips.frole = true;
  216. verify = false;
  217. };
  218. //验证联系方式
  219. if (!_Verify.phoneNumber(this.data.fphonenumber)) {
  220. errTips.fphonenumber = true;
  221. verify = false;
  222. }
  223. this.setData({
  224. errTips
  225. })
  226. return verify;
  227. },
  228. /* 获取焦点 */
  229. inputFocus(e) {
  230. const {
  231. name
  232. } = e.currentTarget.dataset;
  233. let errTips = this.data.errTips;
  234. errTips[name] = false;
  235. this.setData({
  236. errTips
  237. })
  238. },
  239. /* 失去焦点 */
  240. inputBlur(e) {
  241. const {
  242. name
  243. } = e.currentTarget.dataset;
  244. const {
  245. value
  246. } = e.detail;
  247. if (name == 'fphonenumber') {
  248. if (!_Verify.phoneNumber(this.data.fphonenumber, 1)) return this.setData({
  249. "errTips.fphonenumber": true
  250. })
  251. };
  252. if (value.trim() == "") {
  253. let errTips = this.data.errTips;
  254. errTips[name] = true;
  255. this.setData({
  256. errTips
  257. })
  258. }
  259. },
  260. /* 开关 */
  261. onChange() {
  262. if (this.data.fisadministrator == 1) return wx.showToast({
  263. title: '商户主账号不可停用',
  264. icon: "none"
  265. });
  266. const that = this;
  267. if (this.data.tenterprise_userid != 0) {
  268. wx.showModal({
  269. title: "提示",
  270. content: (this.data.checked) ? '是否停用“' + this.data.fname + '”,停用后该角色将暂时无法登陆' : '是否启用“' + this.data.fname + '”',
  271. success(res) {
  272. if (res.confirm) {
  273. const checked = !that.data.checked,
  274. fisused = (checked) ? 1 : 0
  275. that.setData({
  276. checked,
  277. fisused
  278. })
  279. }
  280. }
  281. })
  282. } else {
  283. const checked = !that.data.checked,
  284. fisused = (checked) ? 1 : 0
  285. that.setData({
  286. checked,
  287. fisused
  288. })
  289. }
  290. },
  291. /**
  292. * 生命周期函数--监听页面初次渲染完成
  293. */
  294. onReady: function () {
  295. },
  296. /**
  297. * 生命周期函数--监听页面显示
  298. */
  299. onShow: function () {
  300. },
  301. /**
  302. * 生命周期函数--监听页面隐藏
  303. */
  304. onHide: function () {
  305. },
  306. /**
  307. * 生命周期函数--监听页面卸载
  308. */
  309. onUnload: function () {
  310. clearInterval(countDown);
  311. },
  312. /**
  313. * 页面相关事件处理函数--监听用户下拉动作
  314. */
  315. onPullDownRefresh: function () {
  316. },
  317. /**
  318. * 页面上拉触底事件的处理函数
  319. */
  320. onReachBottom: function () {
  321. },
  322. /**
  323. * 用户点击右上角分享
  324. */
  325. onShareAppMessage: function () {
  326. }
  327. })