userAddr.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view class="container">
  3. <uni-notice-bar v-if="formData.status == '2'" :text="`驳回原因:${formData.remarks}`" />
  4. <uni-section title="基础信息" type="line">
  5. <uni-forms ref="infoForm" :rules="rules" :modelValue="formData" :label-width="90">
  6. <uni-forms-item required label="姓名" name="name">
  7. <uni-easyinput type="text" v-model="formData.name" placeholder="请输入姓名" />
  8. </uni-forms-item>
  9. <uni-forms-item required label="性别" name="sex">
  10. <uni-data-checkbox v-model="formData.sex" :localdata="sexs" />
  11. </uni-forms-item>
  12. <uni-forms-item required label="手机号" name="phone">
  13. <view class="phoneBox">
  14. <uni-easyinput disabled type="text" v-model="formData.phone" placeholder="手机号" />
  15. <button type="primary" :plain="true" style="border: none;" size="mini" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">获取手机号</button>
  16. </view>
  17. </uni-forms-item>
  18. <uni-forms-item name="birthday" label="出生日期">
  19. <uni-datetime-picker type="date" v-model="formData.birthday" />
  20. </uni-forms-item>
  21. </uni-forms>
  22. </uni-section>
  23. <uni-section title="我的住址" type="line">
  24. <uni-forms ref="addrForm" :modelValue="formData" :label-width="90">
  25. <uni-forms-item label="小区选择">
  26. <uni-data-picker v-model="formData.estateId" :map="pickerMap" :localdata="items" placeholder="请选择地址" popup-title="请选择地址" @change="onchange"></uni-data-picker>
  27. </uni-forms-item>
  28. <uni-forms-item label="楼栋选择">
  29. <uni-data-picker v-model="formData.buildingId" :localdata="range" placeholder="请选择小区" popup-title="请选择小区" @change="villageChange"></uni-data-picker>
  30. </uni-forms-item>
  31. <uni-forms-item label="单元选择" v-if="house.unit && house.unit.length > 0">
  32. <uni-data-picker v-model="formData.unit" :localdata="house.unit" placeholder="请选择单元" popup-title="请选择单元" @change="unitChange"></uni-data-picker>
  33. </uni-forms-item>
  34. <uni-forms-item label="楼层选择" v-if="house.floor && house.unit.length > 0">
  35. <uni-data-picker v-model="formData.floor" :localdata="house.floor" placeholder="请选择楼层" popup-title="请选择楼层" @change="floorChange"></uni-data-picker>
  36. </uni-forms-item>
  37. <uni-forms-item label="门牌选择" v-if="house.number && house.number !== ''">
  38. <uni-data-picker v-model="formData.houseId" :localdata="house.number" placeholder="请选择门牌" popup-title="请选择门牌" @change="houseChange"></uni-data-picker>
  39. </uni-forms-item>
  40. </uni-forms>
  41. </uni-section>
  42. <button class="btn" type="primary" @click="submit()">提交</button>
  43. </view>
  44. </template>
  45. <script>
  46. import request from '../../api/resident.js';
  47. export default {
  48. data() {
  49. return {
  50. role: '',
  51. residentId: null,
  52. formData: {},
  53. items: [],
  54. pickerMap: {
  55. text: 'label',
  56. value: 'interId'
  57. },
  58. range: [],
  59. house: {},
  60. building: [],
  61. unit: '',
  62. sexs: [
  63. { text: '男', value: 1 },
  64. { text: '女', value: 0 },
  65. ],
  66. // 校验规则
  67. rules: {
  68. name: {
  69. rules: [{
  70. required: true,
  71. errorMessage: '姓名不能为空'
  72. }]
  73. },
  74. sex: {
  75. rules: [{
  76. required: true,
  77. errorMessage: '性别不能为空'
  78. }]
  79. },
  80. phone: {
  81. rules: [{
  82. required: true,
  83. errorMessage: '电话不能为空'
  84. }]
  85. },
  86. },
  87. }
  88. },
  89. async mounted() {
  90. const res = await request.addrTreeSelect();
  91. this.items = res.data;
  92. if (this.residentId !== null && this.residentId) this.queryInfo();
  93. },
  94. methods: {
  95. async queryInfo() {
  96. const userinfo = await request.getUser();
  97. this.formData = userinfo.data;
  98. this.setAddr(userinfo.data);
  99. },
  100. // 设置地址
  101. async setAddr(data) {
  102. // 小区存在
  103. if (data.estateId && data.estateId !== null) {
  104. const res = await request.buildingList({ estateId: data.estateId });
  105. this.range = res.rows.map(e => ({ ...e, text: `${e.number}栋`, value: e.buildingId }));
  106. }
  107. // 楼栋存在
  108. if(data.buildingId && data.buildingId !== null) {
  109. await this.villageChange(data.buildingId);
  110. }
  111. // 单元存在
  112. if(data.unit && data.unit !== null) {
  113. await this.unitChange(data.unit);
  114. }
  115. // 楼层存在
  116. if(data.floor && data.floor !== null) {
  117. await this.floorChange(data.floor);
  118. }
  119. // 门牌存在
  120. if(data.houseId && data.houseId !== null) {
  121. await this.houseChange(data.houseId);
  122. }
  123. },
  124. // 小区选择
  125. async onchange(e) {
  126. if (!e || e == '' || e.detail.value.length <= 0) return;
  127. const val = e.detail.value[e.detail.value.length - 1].value;
  128. const res = await request.buildingList({ estateId: val });
  129. this.range = res.rows.map(e => ({ ...e, text: `${e.number}栋`, value: e.buildingId }));
  130. },
  131. // 楼栋选择
  132. async villageChange(e) {
  133. if (!e || e == '' || e.detail.value.length <= 0) return;
  134. const res = await request.houseList({ buildingId: e.detail.value[0].value });
  135. this.building = res.rows;
  136. const list = [];
  137. const numList = [];
  138. const unit = res.rows.filter(j => j.unit !== null).map(j => ({ ...j, text: `${j.unit}单元`, value: j.unit }));
  139. const number = res.rows.filter(j => j.number !== null).map(j => ({ ...j, text: `${j.number}号`, value: j.houseId }));
  140. unit.forEach(k => {
  141. const isunit = list.find(j => j.unit == k.unit);
  142. if (!isunit) list.push(k);
  143. });
  144. this.$set(this.house, 'unit', list);
  145. number.forEach(k => {
  146. const isunit = numList.find(j => j.number == k.number);
  147. if (!isunit) numList.push(k);
  148. });
  149. this.$set(this.house, 'number', numList);
  150. },
  151. // 单元选择
  152. unitChange(e) {
  153. if (!e || e == '' || e.detail.value.length <= 0) return;
  154. this.unit = e.detail.value[0].value;
  155. const list = [];
  156. const floor = this.building.filter(j => j.unit == this.unit).map(j => ({ ...j, text: `${j.floor}层`, value: j.floor }));
  157. floor.forEach(k => {
  158. const isunit = list.find(j => j.floor == k.floor);
  159. if (!isunit) list.push(k);
  160. });
  161. this.$set(this.house, 'floor', list);
  162. },
  163. // 楼层选择
  164. floorChange(e) {
  165. if (!e || e == '' || e.detail.value.length <= 0) return;
  166. const list = [];
  167. const number = this.building.filter(j => j.floor == e.detail.value[0].value && j.unit == this.unit).map(j => ({ ...j, text: `${j.number}号`, value: j.houseId }));
  168. number.forEach(k => {
  169. const isunit = list.find(j => j.number == k.number);
  170. if (!isunit) list.push(k);
  171. });
  172. this.$set(this.house, 'number', list);
  173. },
  174. // 门牌选择
  175. houseChange(e) {
  176. if (!e || e == '' || e.detail.value.length <= 0) return;
  177. const dept = this.house.number.find(j => j.houseId == e.detail.value[0].value);
  178. if (dept) this.formData.deptId = dept.deptId;
  179. },
  180. // 提交
  181. async submit() {
  182. if (!this.formData.deptId || !this.formData.houseId || this.formData.houseId == '') {
  183. uni.showToast({
  184. title: '请选择完整信息',
  185. icon: 'error',
  186. duration: 2000,
  187. });
  188. return;
  189. }
  190. await request.registerUser(this.formData);
  191. const msg = this.residentId && this.residentId !== null ? '修改成功' : '添加成功';
  192. uni.showToast({
  193. title: msg,
  194. duration: 2000,
  195. });
  196. uni.navigateBack()
  197. },
  198. },
  199. onLoad(option) {
  200. this.residentId == option.residentId;
  201. }
  202. }
  203. </script>
  204. <style>
  205. .uni-section {
  206. padding-bottom: 10px;
  207. margin-bottom: 10px;
  208. }
  209. .uni-select__selector {
  210. z-index: 999 !important;
  211. }
  212. .uni-forms, .btn {
  213. width: 90%;
  214. margin: 10px auto;
  215. }
  216. .phoneBox {
  217. display: flex;
  218. }
  219. </style>