info.vue 6.0 KB

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