change.js 9.3 KB

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