index.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. import {
  5. TestVerify
  6. } from "../../utils/verify";
  7. const _Http = new ApiModel();
  8. const _Verify = new TestVerify();
  9. Component({
  10. /**
  11. * 组件的属性列表
  12. */
  13. properties: {
  14. memberMsg: {
  15. type: Object
  16. }
  17. },
  18. /**
  19. * 组件的初始数据
  20. */
  21. data: {
  22. userid: '', //tenterprise_userid
  23. userName: "", //账户名称
  24. frole: "", //身份/职位
  25. cellPhoneNum: "", //手机号码
  26. fright: "", //角色选择
  27. checked: true, //是否启用
  28. actionSheetShow: false, //弹出层显示
  29. /* 必填项目 */
  30. inputVerify: {
  31. userName: false, //用户名
  32. frole: false, //身份
  33. cellPhoneNum: false //手机号码
  34. }
  35. },
  36. lifetimes: {
  37. ready: function () {
  38. const {
  39. memberMsg
  40. } = this.data;
  41. /* 判断修改或新增 */
  42. if (!memberMsg) return this.setData({
  43. userid: 0
  44. })
  45. /* 修改数据 */
  46. this.setData({
  47. userName: memberMsg.fname,
  48. frole: memberMsg.frole,
  49. cellPhoneNum: memberMsg.fphonenumber,
  50. userid: memberMsg.tenterprise_userid
  51. })
  52. }
  53. },
  54. /**
  55. * 组件的方法列表
  56. */
  57. methods: {
  58. /* 获焦恢复 */
  59. inputFocus(e) {
  60. let inputVerify = this.data.inputVerify;
  61. const {
  62. name
  63. } = e.currentTarget.dataset;
  64. inputVerify[name] = false;
  65. this.setData({
  66. inputVerify
  67. })
  68. },
  69. /* 失焦验证 */
  70. inputBlur(e) {
  71. let inputVerify = this.data.inputVerify;
  72. const {
  73. name
  74. } = e.currentTarget.dataset;
  75. /* 手机号验证 */
  76. if (name == 'cellPhoneNum' && !_Verify.phoneNumber(this.data.cellPhoneNum, true)) {
  77. inputVerify[name] = true;
  78. this.setData({
  79. inputVerify
  80. })
  81. }
  82. /* 验证 */
  83. if (e.detail.value != "") return;
  84. inputVerify[name] = true;
  85. this.setData({
  86. inputVerify
  87. })
  88. },
  89. /* 验证 */
  90. submitVerify() {
  91. let inputVerify = this.data.inputVerify,
  92. nextStep = true;
  93. if (!_Verify.required(this.data.userName)) {
  94. inputVerify.userName = true;
  95. nextStep = false;
  96. }
  97. if (!_Verify.required(this.data.frole)) {
  98. inputVerify.frole = true
  99. nextStep = false;
  100. }
  101. if (!_Verify.phoneNumber(this.data.cellPhoneNum)) {
  102. inputVerify.cellPhoneNum = true
  103. nextStep = false;
  104. }
  105. if (!nextStep) {
  106. this.setData({
  107. inputVerify
  108. })
  109. }
  110. return nextStep;
  111. },
  112. /* 提交 */
  113. submit() {
  114. /* 验证必填项 */
  115. if (!this.submitVerify()) return wx.showToast({
  116. title: '请检查输入框内容!',
  117. icon: "none"
  118. })
  119. /* 发送请求 */
  120. _Http.basic({
  121. "accesstoken": wx.getStorageSync('token'),
  122. "classname": "customer.usercenter.teammsg.teammsg",
  123. "method": "update_userMsg",
  124. "content": {
  125. "tenterprise_userid": this.data.userid,
  126. "fname": this.data.userName,
  127. "frole": this.data.frole,
  128. "fphonenumber": this.data.cellPhoneNum,
  129. "subusers": []
  130. }
  131. }).then(s => {
  132. if (s.msg != "成功") return wx.showToast({
  133. title: "修改失败",
  134. icon: 'none'
  135. })
  136. wx.showToast({
  137. title: s.msg,
  138. })
  139. setTimeout(() => {
  140. wx.navigateBack({
  141. delta: 1
  142. })
  143. }, 500)
  144. })
  145. },
  146. /* 是否启用 */
  147. switchOnChange() {
  148. this.setData({
  149. checked: !this.data.checked
  150. })
  151. },
  152. /* 打开弹出框 */
  153. actionSheetShow() {
  154. this.setData({
  155. actionSheetShow: true
  156. })
  157. },
  158. /* 关闭弹出框 */
  159. onClose() {
  160. this.setData({
  161. actionSheetShow: false
  162. })
  163. },
  164. /* 返回权限选项 */
  165. userSelect(e) {
  166. this.setData({
  167. right: e.detail.value,
  168. actionSheetShow: false
  169. })
  170. }
  171. }
  172. })