familyInfo.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <view class="container">
  3. <uni-section title="基础信息" type="line">
  4. <uni-forms ref="infoForm" :rules="rules" :modelValue="formData" :label-width="90">
  5. <uni-forms-item required label="姓名" name="name">
  6. <uni-easyinput type="text" v-model="formData.name" placeholder="请输入姓名" />
  7. </uni-forms-item>
  8. <uni-forms-item required label="性别" name="sex">
  9. <uni-data-checkbox v-model="formData.sex" :localdata="sexs" />
  10. </uni-forms-item>
  11. <uni-forms-item name="birthday" label="出生日期">
  12. <uni-datetime-picker type="date" v-model="formData.birthday" />
  13. </uni-forms-item>
  14. <uni-forms-item required label="联系电话" name="phone"> <uni-easyinput type="text" v-model="formData.phone" placeholder="请输入联系电话" /> </uni-forms-item>
  15. </uni-forms>
  16. </uni-section>
  17. <uni-section title="地址信息" type="line">
  18. <uni-forms ref="addrForm" :modelValue="formData" :label-width="90">
  19. <uni-forms-item label="小区选择">
  20. <uni-data-picker v-model="formData.estateId" :map="pickerMap" :localdata="items" placeholder="请选择地址" popup-title="请选择地址" @change="onchange" @nodeclick="onnodeclick"></uni-data-picker>
  21. </uni-forms-item>
  22. <uni-forms-item label="楼栋选择">
  23. <uni-data-select :localdata="range" @change="selectChange" v-model="formData.buildingId"></uni-data-select>
  24. </uni-forms-item>
  25. <uni-forms-item label="单元选择" v-if="house.unit && house.unit !== null">
  26. <uni-data-select :localdata="house.unit" @change="unitChange" v-model="formData.unit"></uni-data-select>
  27. </uni-forms-item>
  28. <uni-forms-item label="楼层选择" v-if="house.floor && house.floor !== null">
  29. <uni-data-select :localdata="house.floor" @change="floorChange" v-model="formData.floor"></uni-data-select>
  30. </uni-forms-item>
  31. <uni-forms-item label="门牌选择" v-if="house.number && house.number !== null">
  32. <uni-data-select :localdata="house.number" v-model="formData.houseId" @change="houseChange"></uni-data-select>
  33. </uni-forms-item>
  34. </uni-forms>
  35. </uni-section>
  36. <button class="btn" type="primary" @click="submit('infoForm')">提交</button>
  37. </view>
  38. </template>
  39. <script>
  40. import request from '../../api/user.js';
  41. import requestFamily from '../../api/family.js';
  42. export default {
  43. data() {
  44. return {
  45. formData: {},
  46. sexs: [
  47. { text: '男', value: 0 },
  48. { text: '女', value: 1},
  49. ],
  50. items: [],
  51. pickerMap: {
  52. text: 'label',
  53. value: 'interId'
  54. },
  55. range: [],
  56. house: {},
  57. building: [],
  58. unit: '',
  59. residentReqId: '',
  60. // 校验规则
  61. rules: {
  62. name: {
  63. rules: [{
  64. required: true,
  65. errorMessage: '姓名不能为空'
  66. }]
  67. },
  68. sex: {
  69. rules: [{
  70. required: true,
  71. errorMessage: '性别不能为空'
  72. }]
  73. },
  74. phone: {
  75. rules: [{
  76. required: true,
  77. errorMessage: '电话不能为空'
  78. }]
  79. },
  80. },
  81. }
  82. },
  83. async onLoad(option) {
  84. this.residentId = option.residentId;
  85. if (option.residentId) this.queryInfo();
  86. },
  87. async mounted() {
  88. const res = await request.addrTreeSelect();
  89. this.items = res.data;
  90. },
  91. methods: {
  92. async queryInfo() {
  93. const userinfo = await requestFamily.getFamilyInfoDetails({ residentId: this.residentId });
  94. console.log(userinfo.data);
  95. this.formData = userinfo.data;
  96. const { estateId, buildingId, unit, floor, houseId } = userinfo.data;
  97. // 小区存在
  98. if (estateId) {
  99. const res = await request.buildingList({ estateId });
  100. this.range = res.rows.map(e => ({ ...e, text: `${e.number}栋`, value: e.buildingId }));
  101. }
  102. // 楼栋存在
  103. if(buildingId) {
  104. await this.selectChange(buildingId);
  105. }
  106. // 单元存在
  107. if(unit) {
  108. await this.unitChange(unit);
  109. }
  110. // 楼层存在
  111. if(floor) {
  112. await this.floorChange(floor);
  113. }
  114. // 门牌存在
  115. if(houseId) {
  116. console.log(houseId)
  117. await this.houseChange(houseId);
  118. }
  119. },
  120. async onchange(e) {
  121. const val = e.detail.value[e.detail.value.length - 1].value;
  122. const res = await request.buildingList({ estateId: val });
  123. this.range = res.rows.map(e => ({ ...e, text: `${e.number}栋`, value: e.buildingId }));
  124. },
  125. onnodeclick(node) {},
  126. // 楼栋选择
  127. async selectChange(e) {
  128. if (!e || e == '') return;
  129. const res = await request.houseList({ buildingId: e });
  130. this.building = res.rows;
  131. const list = [];
  132. const unit = res.rows.filter(j => j.unit !== null).map(j => ({ ...j, text: `${j.unit}单元`, value: j.unit }));
  133. const number = res.rows.filter(j => j.number !== null).map(j => ({ ...j, text: `${j.number}号`, value: j.houseId }));
  134. if (unit && unit.length > 0) {
  135. unit.forEach(k => {
  136. const isunit = list.find(j => j.unit == k.unit);
  137. if (!isunit) list.push(k);
  138. });
  139. this.$set(this.house, 'unit', list);
  140. return;
  141. }
  142. if (number && number.length > 0) {
  143. number.forEach(k => {
  144. const isunit = list.find(j => j.number == k.number);
  145. if (!isunit) list.push(k);
  146. });
  147. this.$set(this.house, 'number', list);
  148. return;
  149. }
  150. },
  151. // 单元选择
  152. unitChange(e) {
  153. this.unit = e;
  154. const list = [];
  155. const floor = this.building.filter(j => j.unit == e).map(j => ({ ...j, text: `${j.floor}层`, value: j.floor }));
  156. floor.forEach(k => {
  157. const isunit = list.find(j => j.floor == k.floor);
  158. if (!isunit) list.push(k);
  159. });
  160. this.$set(this.house, 'floor', list);
  161. },
  162. // 楼层选择
  163. floorChange(e) {
  164. const list = [];
  165. const number = this.building.filter(j => j.floor == e && j.unit == this.unit).map(j => ({ ...j, text: `${j.number}号`, value: j.houseId }));
  166. number.forEach(k => {
  167. const isunit = list.find(j => j.number == k.number);
  168. if (!isunit) list.push(k);
  169. });
  170. this.$set(this.house, 'number', list);
  171. },
  172. // 门牌选择
  173. houseChange(e) {
  174. if (!e || e == '') return;
  175. const dept = this.house.number.find(j => j.houseId == e);
  176. this.formData.deptId = dept.deptId;
  177. },
  178. // 提交
  179. async submit(ref) {
  180. this.$refs[ref].validate(async (err, formdata) => {
  181. if (!err) {
  182. if (!this.formData.houseId || this.formData.houseId == '') {
  183. uni.showToast({
  184. title: '请选择地址信息',
  185. duration: 2000,
  186. });
  187. return;
  188. }
  189. this.formData.reqType = this.formData.residentReqId ? 1 : 0;
  190. const res = await requestFamily.familyInfo(this.formData);
  191. if (res.code == 200) {
  192. uni.showToast({
  193. title: this.formData.residentReqId ? '修改成功' : '添加成功',
  194. duration: 2000,
  195. });
  196. uni.navigateBack()
  197. }
  198. }
  199. })
  200. },
  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. </style>