info.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. if (res.data.role == 'cs') that.$set(that, `disabled`, false);
  88. else that.$set(that, `disabled`, true);
  89. },
  90. fail: function(err) {
  91. uni.showToast({
  92. title: err.errmsg,
  93. icon: 'error',
  94. duration: 2000
  95. });
  96. }
  97. })
  98. },
  99. // 角色选择
  100. rolechange(role) {
  101. const that = this;
  102. if (role == 'cs') that.$set(that, `disabled`, false);
  103. else that.$set(that, `disabled`, true);
  104. },
  105. // 所属街道选择
  106. async streetchange(belong) {
  107. const that = this;
  108. that.$set(that.form, `street`, belong);
  109. //所属社区
  110. const res = await that.$api('/Office', 'GET', {
  111. belong,
  112. type: '1',
  113. is_use: '0'
  114. })
  115. if (res.errcode == '0') {
  116. let commList = []
  117. for (let val of res.data) {
  118. commList.push({
  119. text: val.name,
  120. value: val._id
  121. })
  122. }
  123. that.$set(that, `commList`, commList);
  124. }
  125. },
  126. // 所属社区
  127. commchange(community) {
  128. const that = this;
  129. that.$set(that.form, `community`, community);
  130. },
  131. // 修改
  132. submit(ref) {
  133. const that = this;
  134. that.$refs[ref].validate().then(async params => {
  135. that.form.status = '0'
  136. delete that.form._id;
  137. delete that.form.iat;
  138. delete that.form.exp;
  139. const res = await that.$api(`/User/${that.id}`, 'POST', that.form);
  140. if (res.errcode == '0') {
  141. uni.showToast({
  142. title: '修改信息成功',
  143. icon: 'none'
  144. })
  145. that.toExit()
  146. } else {
  147. uni.showToast({
  148. title: res.errmsg,
  149. icon: 'none'
  150. })
  151. }
  152. }).catch(err => {
  153. console.log('err', err);
  154. })
  155. },
  156. // 退出登录
  157. toExit() {
  158. uni.removeStorage({
  159. key: 'token',
  160. success: function(res) {
  161. let url = `/pages/index/index`;
  162. uni.reLaunch({
  163. url
  164. })
  165. }
  166. });
  167. },
  168. async searchOther() {
  169. const that = this;
  170. let res;
  171. //性别
  172. res = await that.$api('/DictData', 'GET', {
  173. type: 'gender',
  174. is_use: '0'
  175. })
  176. if (res.errcode == '0') {
  177. let genderList = []
  178. for (let val of res.data) {
  179. genderList.push({
  180. text: val.label,
  181. value: val.value
  182. })
  183. }
  184. that.$set(that, `genderList`, genderList);
  185. }
  186. //角色
  187. res = await that.$api('/Role', 'GET', {
  188. is_use: '0'
  189. })
  190. if (res.errcode == '0') {
  191. let roleList = []
  192. for (let val of res.data) {
  193. roleList.push({
  194. text: val.name,
  195. value: val.code
  196. })
  197. }
  198. that.$set(that, `roleList`, roleList);
  199. }
  200. //所属街道
  201. res = await that.$api('/Office', 'GET', {
  202. type: '0',
  203. is_use: '0'
  204. })
  205. if (res.errcode == '0') {
  206. let streetList = []
  207. for (let val of res.data) {
  208. streetList.push({
  209. text: val.name,
  210. value: val._id
  211. })
  212. }
  213. that.$set(that, `streetList`, streetList);
  214. }
  215. },
  216. }
  217. }
  218. </script>
  219. <style lang="scss">
  220. .content {
  221. display: flex;
  222. flex-direction: column;
  223. .one {
  224. padding: 3vw;
  225. .button {
  226. margin: 2vw 0 0 0;
  227. background-color: var(--f3CColor);
  228. color: var(--mainColor);
  229. font-size: var(--font14Size);
  230. }
  231. }
  232. }
  233. </style>