familyInfo.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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"></uni-data-picker>
  21. </uni-forms-item>
  22. <uni-forms-item label="楼栋选择">
  23. <uni-data-picker v-model="formData.buildingId" :localdata="range" placeholder="请选择小区" popup-title="请选择小区" @change="selectChange"></uni-data-picker>
  24. </uni-forms-item>
  25. <uni-forms-item label="单元选择" v-if="house.unit && house.unit.length > 0">
  26. <uni-data-picker v-model="formData.unit" :localdata="house.unit" placeholder="请选择单元" popup-title="请选择单元" @change="unitChange"></uni-data-picker>
  27. </uni-forms-item>
  28. <uni-forms-item label="楼层选择" v-if="house.floor && house.unit.length > 0">
  29. <uni-data-picker v-model="formData.floor" :localdata="house.floor" placeholder="请选择楼层" popup-title="请选择楼层" @change="floorChange"></uni-data-picker>
  30. </uni-forms-item>
  31. <uni-forms-item label="门牌选择" v-if="house.number && house.number !== ''">
  32. <uni-data-picker v-model="formData.houseId" :localdata="house.number" placeholder="请选择门牌" popup-title="请选择门牌" @change="houseChange"></uni-data-picker>
  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. residentId: '',
  61. // 校验规则
  62. rules: {
  63. name: {
  64. rules: [{
  65. required: true,
  66. errorMessage: '姓名不能为空'
  67. }]
  68. },
  69. sex: {
  70. rules: [{
  71. required: true,
  72. errorMessage: '性别不能为空'
  73. }]
  74. },
  75. phone: {
  76. rules: [{
  77. required: true,
  78. errorMessage: '电话不能为空'
  79. }]
  80. },
  81. },
  82. }
  83. },
  84. async onLoad(option) {
  85. this.residentId = option.residentId;
  86. this.residentReqId = option.residentReqId;
  87. if (option.residentId) {
  88. this.queryInfo();
  89. return;
  90. }
  91. // 设置默认地址信息
  92. const userinfo = uni.getStorageSync('userinfo');
  93. const { estateId, buildingId, unit, floor, houseId } = userinfo;
  94. this.formData = { estateId, buildingId, unit, floor, houseId };
  95. this.setAddr(userinfo);
  96. },
  97. async mounted() {
  98. const res = await request.addrTreeSelect();
  99. this.items = res.data;
  100. },
  101. methods: {
  102. async queryInfo() {
  103. const userinfo = await requestFamily.getFamilyInfoDetails({ residentId: this.residentId });
  104. this.formData = userinfo.data;
  105. this.setAddr(userinfo.data);
  106. },
  107. // 设置地址
  108. async setAddr(data) {
  109. // 小区存在
  110. if (data.estateId && data.estateId !== null) {
  111. const res = await request.buildingList({ estateId: data.estateId });
  112. this.range = res.rows.map(e => ({ ...e, text: `${e.number}栋`, value: e.buildingId }));
  113. }
  114. // 楼栋存在
  115. if(data.buildingId && data.buildingId !== null) {
  116. await this.selectChange({ detail: { value: [{ value: data.buildingId }] } });
  117. }
  118. // 单元存在
  119. if(data.unit && data.unit !== null) {
  120. await this.unitChange({ detail: { value: [{ value: data.unit }] } });
  121. }
  122. // 楼层存在
  123. if(data.floor && data.floor !== null) {
  124. await this.floorChange({ detail: { value: [{ value: data.floor }] } });
  125. }
  126. // 门牌存在
  127. if(data.houseId && data.houseId !== null) {
  128. await this.houseChange({ detail: { value: [{ value: data.houseId }] } });
  129. }
  130. },
  131. async onchange(e) {
  132. const val = e.detail.value[e.detail.value.length - 1].value;
  133. const res = await request.buildingList({ estateId: val });
  134. this.range = res.rows.map(e => ({ ...e, text: `${e.number}栋`, value: e.buildingId }));
  135. },
  136. // 楼栋选择
  137. async selectChange(e) {
  138. if (!e || e == '' || e.detail.value.length <= 0) return;
  139. const res = await request.houseList({ buildingId: e.detail.value[0].value });
  140. this.building = res.rows;
  141. const list = [];
  142. const numList = [];
  143. const unit = res.rows.filter(j => j.unit !== null).map(j => ({ ...j, text: `${j.unit}单元`, value: j.unit }));
  144. const number = res.rows.filter(j => j.number !== null).map(j => ({ ...j, text: `${j.number}号`, value: j.houseId }));
  145. unit.forEach(k => {
  146. const isunit = list.find(j => j.unit == k.unit);
  147. if (!isunit) list.push(k);
  148. });
  149. this.$set(this.house, 'unit', list);
  150. number.forEach(k => {
  151. const isunit = numList.find(j => j.number == k.number);
  152. if (!isunit) numList.push(k);
  153. });
  154. this.$set(this.house, 'number', numList);
  155. },
  156. // 单元选择
  157. unitChange(e) {
  158. if (!e || e == '' || e.detail.value.length <= 0) return;
  159. this.unit = e.detail.value[0].value;
  160. const list = [];
  161. const floor = this.building.filter(j => j.unit == e.detail.value[0].value).map(j => ({ ...j, text: `${j.floor}层`, value: j.floor }));
  162. floor.forEach(k => {
  163. const isunit = list.find(j => j.floor == k.floor);
  164. if (!isunit) list.push(k);
  165. });
  166. this.$set(this.house, 'floor', list);
  167. },
  168. // 楼层选择
  169. floorChange(e) {
  170. if (!e || e == '' || e.detail.value.length <= 0) return;
  171. const list = [];
  172. 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 }));
  173. number.forEach(k => {
  174. const isunit = list.find(j => j.number == k.number);
  175. if (!isunit) list.push(k);
  176. });
  177. this.$set(this.house, 'number', list);
  178. },
  179. // 门牌选择
  180. houseChange(e) {
  181. if (!e || e == '' || e.detail.value.length <= 0) return;
  182. const dept = this.house.number.find(j => j.houseId == e.detail.value[0].value);
  183. this.formData.deptId = dept.deptId;
  184. },
  185. // 提交
  186. async submit(ref) {
  187. this.$refs[ref].validate(async (err, formdata) => {
  188. if (!err) {
  189. if (!this.formData.houseId || this.formData.houseId == '') {
  190. uni.showToast({
  191. title: '请选择地址信息',
  192. duration: 2000,
  193. });
  194. return;
  195. }
  196. // 居民修改
  197. this.formData.reqType = this.formData.residentId ? 1 : 0;
  198. const res = await requestFamily.familyInfo(this.formData);
  199. if (res.code == 200) {
  200. uni.showToast({
  201. title: this.formData.residentId ? '修改成功' : '添加成功',
  202. duration: 2000,
  203. });
  204. uni.navigateBack()
  205. }
  206. }
  207. })
  208. },
  209. }
  210. }
  211. </script>
  212. <style>
  213. .uni-section {
  214. padding-bottom: 10px;
  215. margin-bottom: 10px;
  216. }
  217. .uni-select__selector {
  218. z-index: 999 !important;
  219. }
  220. .uni-forms, .btn {
  221. width: 90%;
  222. margin: 10px auto;
  223. }
  224. </style>