info.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <uni-forms ref="valiForm" :rules="rules" :modelValue="form" labelWidth="80px">
  5. <uni-forms-item label="姓名" required name="name">
  6. <uni-easyinput v-model="form.name" placeholder="请输入姓名" />
  7. </uni-forms-item>
  8. <uni-forms-item label="性别" required name="gender">
  9. <uni-data-checkbox v-model="form.gender" :localdata="genderList" />
  10. </uni-forms-item>
  11. <uni-forms-item label="联系电话" required name="tel">
  12. <uni-easyinput v-model="form.tel" placeholder="请输入联系电话" />
  13. </uni-forms-item>
  14. <uni-forms-item label="角色" required name="role">
  15. <uni-data-select v-model="form.role" :localdata="roleList" @change="rolechange"></uni-data-select>
  16. </uni-forms-item>
  17. <uni-forms-item v-if="disabled" label="所属街道" required name="street">
  18. <uni-data-select v-model="form.street" :localdata="streetList" @change="streetchange">
  19. </uni-data-select>
  20. </uni-forms-item>
  21. <uni-forms-item v-if="disabled" label="所属社区">
  22. <uni-data-select v-model="form.community" :localdata="commList" @change="commchange">
  23. </uni-data-select>
  24. </uni-forms-item>
  25. </uni-forms>
  26. <button class="button" type="primary" @click="submit('valiForm')">修改</button>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. disabled: true,
  35. id:'',
  36. form: {},
  37. // 校验规则
  38. rules: {
  39. name: {
  40. rules: [{
  41. required: true,
  42. errorMessage: '姓名不能为空'
  43. }]
  44. },
  45. tel: {
  46. rules: [{
  47. required: true,
  48. errorMessage: '联系电话不能为空'
  49. }, {
  50. format: 'number',
  51. errorMessage: '联系电话只能输入数字'
  52. }]
  53. },
  54. gender: {
  55. rules: [{
  56. required: true,
  57. errorMessage: '性别不能为空'
  58. }]
  59. },
  60. role: {
  61. rules: [{
  62. required: true,
  63. errorMessage: '角色不能为空'
  64. }]
  65. },
  66. },
  67. // 字典表
  68. roleList: [],
  69. genderList: [],
  70. streetList: [],
  71. commList: []
  72. }
  73. },
  74. async onLoad() {
  75. const that = this;
  76. await that.searchToken();
  77. await that.searchOther();
  78. },
  79. methods: {
  80. async searchToken() {
  81. const that = this;
  82. uni.getStorage({
  83. key: 'token',
  84. success: function(res) {
  85. that.$set(that, `id`, res.data._id);
  86. that.$set(that, `form`, res.data);
  87. that.streetchange(res.data.street)
  88. if (res.data.role == 'cs') that.$set(that, `disabled`, false);
  89. else that.$set(that, `disabled`, true);
  90. },
  91. fail: function(err) {
  92. uni.showToast({
  93. title: err.errmsg,
  94. icon: 'error',
  95. duration: 2000
  96. });
  97. }
  98. })
  99. },
  100. // 角色选择
  101. rolechange(role) {
  102. const that = this;
  103. if (role == 'cs') that.$set(that, `disabled`, false);
  104. else that.$set(that, `disabled`, true);
  105. },
  106. // 所属街道选择
  107. async streetchange(belong) {
  108. const that = this;
  109. that.$set(that.form, `street`, belong);
  110. //所属社区
  111. const res = await that.$api('/Office', 'GET', {
  112. belong,
  113. type: '1',
  114. is_use: '0'
  115. })
  116. if (res.errcode == '0') {
  117. let commList = []
  118. for (let val of res.data) {
  119. commList.push({
  120. text: val.name,
  121. value: val._id
  122. })
  123. }
  124. that.$set(that, `commList`, commList);
  125. }
  126. },
  127. // 所属社区
  128. commchange(community) {
  129. const that = this;
  130. that.$set(that.form, `community`, community);
  131. },
  132. // 修改
  133. submit(ref) {
  134. const that = this;
  135. that.$refs[ref].validate().then(async params => {
  136. that.form.status = '0'
  137. delete that.form._id;
  138. delete that.form.iat;
  139. delete that.form.exp;
  140. const res = await that.$api(`/User/${that.id}`, 'POST', that.form);
  141. if (res.errcode == '0') {
  142. uni.showToast({
  143. title: '修改信息成功',
  144. icon: 'none'
  145. })
  146. that.toExit()
  147. } else {
  148. uni.showToast({
  149. title: res.errmsg,
  150. icon: 'none'
  151. })
  152. }
  153. }).catch(err => {
  154. console.log('err', err);
  155. })
  156. },
  157. // 退出登录
  158. toExit() {
  159. uni.removeStorage({
  160. key: 'token',
  161. success: function(res) {
  162. let url = `/pages/index/index`;
  163. uni.reLaunch({
  164. url
  165. })
  166. }
  167. });
  168. },
  169. async searchOther() {
  170. const that = this;
  171. let res;
  172. //性别
  173. res = await that.$api('/DictData', 'GET', {
  174. type: 'gender',
  175. is_use: '0'
  176. })
  177. if (res.errcode == '0') {
  178. let genderList = []
  179. for (let val of res.data) {
  180. genderList.push({
  181. text: val.label,
  182. value: val.value
  183. })
  184. }
  185. that.$set(that, `genderList`, genderList);
  186. }
  187. //角色
  188. res = await that.$api('/Role', 'GET', {
  189. is_use: '0'
  190. })
  191. if (res.errcode == '0') {
  192. let roleList = []
  193. for (let val of res.data) {
  194. roleList.push({
  195. text: val.name,
  196. value: val.code
  197. })
  198. }
  199. that.$set(that, `roleList`, roleList);
  200. }
  201. //所属街道
  202. res = await that.$api('/Office', 'GET', {
  203. type: '0',
  204. is_use: '0'
  205. })
  206. if (res.errcode == '0') {
  207. let streetList = []
  208. for (let val of res.data) {
  209. streetList.push({
  210. text: val.name,
  211. value: val._id
  212. })
  213. }
  214. that.$set(that, `streetList`, streetList);
  215. }
  216. },
  217. }
  218. }
  219. </script>
  220. <style lang="scss">
  221. .content {
  222. display: flex;
  223. flex-direction: column;
  224. .one {
  225. padding: 3vw;
  226. .button {
  227. margin: 2vw 0 0 0;
  228. background-color: var(--f3CColor);
  229. color: var(--mainColor);
  230. font-size: var(--font14Size);
  231. }
  232. }
  233. }
  234. </style>