familyInfo.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view class="container">
  3. <uni-card v-if="formData && formData.reqStatus == 2">
  4. <uni-section title="驳回原因" type="line">
  5. <text class="msg">{{ formData.rejectReason }}</text>
  6. </uni-section>
  7. </uni-card>
  8. <uni-section title="基础信息" type="line">
  9. <uni-forms ref="infoForm" :rules="rules" :modelValue="formData" :label-width="90">
  10. <uni-forms-item required label="姓名" name="name">
  11. <uni-easyinput type="text" v-model="formData.name" placeholder="请输入姓名" />
  12. </uni-forms-item>
  13. <uni-forms-item required label="性别" name="sex">
  14. <uni-data-checkbox v-model="formData.sex" :localdata="sexs" />
  15. </uni-forms-item>
  16. <uni-forms-item name="birthday" label="出生日期">
  17. <uni-datetime-picker type="date" v-model="formData.birthday" />
  18. </uni-forms-item>
  19. <uni-forms-item required label="联系电话" name="phone"> <uni-easyinput type="text" v-model="formData.phone" placeholder="请输入联系电话" /> </uni-forms-item>
  20. </uni-forms>
  21. </uni-section>
  22. <uni-section title="地址信息" type="line">
  23. <uni-forms ref="addrForm" :modelValue="formData" :label-width="90">
  24. <uni-forms-item label="小区选择">
  25. <uni-data-picker v-model="formData.estateId" :map="pickerMap" :localdata="items" placeholder="请选择地址" popup-title="请选择地址" @change="onchange"></uni-data-picker>
  26. </uni-forms-item>
  27. <uni-forms-item label="楼栋选择" v-if="house.range && house.range.length > 0">
  28. <uni-data-picker v-model="formData.buildingId" :localdata="house.range" placeholder="请选择小区" popup-title="请选择小区" @change="selectChange"></uni-data-picker>
  29. </uni-forms-item>
  30. <uni-forms-item label="单元选择" v-if="house.unit && house.unit.length > 0">
  31. <uni-data-picker v-model="formData.unit" :localdata="house.unit" placeholder="请选择单元" popup-title="请选择单元" @change="unitChange"></uni-data-picker>
  32. </uni-forms-item>
  33. <uni-forms-item label="楼层选择" v-if="house.floor && house.unit.length > 0">
  34. <uni-data-picker v-model="formData.floor" :localdata="house.floor" placeholder="请选择楼层" popup-title="请选择楼层" @change="floorChange"></uni-data-picker>
  35. </uni-forms-item>
  36. <uni-forms-item label="门牌选择" v-if="house.number && house.number.length > 0">
  37. <uni-data-picker v-model="formData.houseId" :localdata="house.number" placeholder="请选择门牌" popup-title="请选择门牌" @change="houseChange"></uni-data-picker>
  38. </uni-forms-item>
  39. </uni-forms>
  40. </uni-section>
  41. <button class="btn" type="primary" @click="submit('infoForm')">提交</button>
  42. </view>
  43. </template>
  44. <script>
  45. import request from '../../api/user.js';
  46. import requestFamily from '../../api/family.js';
  47. export default {
  48. data() {
  49. return {
  50. formData: {},
  51. sexs: [
  52. { text: '男', value: 1 },
  53. { text: '女', value: 0 },
  54. ],
  55. items: [],
  56. pickerMap: {
  57. text: 'label',
  58. value: 'interId'
  59. },
  60. range: [],
  61. house: {},
  62. building: [],
  63. unit: '',
  64. residentReqId: '',
  65. residentId: '',
  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 onLoad(option) {
  90. this.residentId = option.residentId;
  91. this.residentReqId = option.residentReqId;
  92. if (option.residentId) {
  93. this.queryInfo();
  94. return;
  95. }
  96. if (option.residentReqId) {
  97. this.queryReqInfo();
  98. return;
  99. }
  100. // 设置默认地址信息
  101. const userinfo = uni.getStorageSync('userinfo');
  102. const { estateId, buildingId, unit, floor, houseId } = userinfo;
  103. this.formData = { estateId, buildingId, unit, floor, houseId };
  104. this.setAddr(userinfo);
  105. },
  106. async mounted() {
  107. const res = await request.addrTreeSelect();
  108. this.items = res.data;
  109. },
  110. methods: {
  111. async queryReqInfo() {
  112. const userinfo = await requestFamily.getReqInfoDetails({ residentReqId: this.residentReqId });
  113. this.formData = userinfo.data;
  114. this.setAddr(userinfo.data);
  115. },
  116. async queryInfo() {
  117. const userinfo = await requestFamily.getFamilyInfoDetails({ residentId: this.residentId });
  118. this.formData = userinfo.data;
  119. this.setAddr(userinfo.data);
  120. },
  121. // 设置地址
  122. async setAddr(data) {
  123. // 小区存在
  124. if (data.estateId && data.estateId !== null) {
  125. await this.onchange({ detail: { value: [{ value: data.estateId }] }, isUpdate: true });
  126. }
  127. // 楼栋存在
  128. if(data.buildingId && data.buildingId !== null) {
  129. await this.selectChange({ detail: { value: [{ value: data.buildingId }] }, isUpdate: true });
  130. }
  131. // 单元存在
  132. if(data.unit && data.unit !== null) {
  133. await this.unitChange({ detail: { value: [{ value: data.unit }] }, isUpdate: true });
  134. }
  135. // 楼层存在
  136. if(data.floor && data.floor !== null) {
  137. await this.floorChange({ detail: { value: [{ value: data.floor }] }, isUpdate: true });
  138. }
  139. // 门牌存在
  140. if(data.houseId && data.houseId !== null) {
  141. await this.houseChange({ detail: { value: [{ value: data.houseId }] } });
  142. }
  143. },
  144. // 初始化选择器
  145. initPicker(e) {
  146. if (e.includes('range')) this.$set(this.house, 'range', []);
  147. if (e.includes('unit')) this.$set(this.house, 'unit', []);
  148. if (e.includes('floor')) this.$set(this.house, 'floor', []);
  149. if (e.includes('number')) this.$set(this.house, 'number', []);
  150. },
  151. // 小区选择
  152. async onchange(e) {
  153. if (!e || e == '' || e.detail.value.length <= 0) {
  154. this.initPicker(['range', 'unit', 'floor', 'number']);
  155. return;
  156. }
  157. const val = e.detail.value[e.detail.value.length - 1].value;
  158. const res = await request.buildingList({ estateId: val });
  159. const range = res.rows.map(e => ({ ...e, text: `${e.number}栋`, value: e.buildingId }));
  160. this.$set(this.house, 'range', range);
  161. // 删除选项
  162. if (e.isUpdate) return;
  163. delete this.formData.buildingId
  164. delete this.formData.unit
  165. delete this.formData.floor
  166. delete this.formData.houseId
  167. },
  168. // 楼栋选择
  169. async selectChange(e) {
  170. if (!e || e == '' || e.detail.value.length <= 0) {
  171. this.initPicker(['unit', 'floor', 'number']);
  172. return;
  173. };
  174. const res = await request.houseList({ buildingId: e.detail.value[0].value });
  175. this.building = res.rows;
  176. const list = [];
  177. const numList = [];
  178. const unit = res.rows.filter(j => j.unit !== null).map(j => ({ ...j, text: `${j.unit}单元`, value: j.unit }));
  179. const number = res.rows.filter(j => j.number !== null).map(j => ({ ...j, text: `${j.number}号`, value: j.houseId }));
  180. unit.forEach(k => {
  181. const isunit = list.find(j => j.unit == k.unit);
  182. if (!isunit) list.push(k);
  183. });
  184. this.$set(this.house, 'unit', list);
  185. number.forEach(k => {
  186. const isunit = numList.find(j => j.number == k.number);
  187. if (!isunit) numList.push(k);
  188. });
  189. this.$set(this.house, 'number', numList);
  190. // 删除选项
  191. if (e.isUpdate) return;
  192. delete this.formData.unit
  193. delete this.formData.floor
  194. delete this.formData.houseId
  195. },
  196. // 单元选择
  197. unitChange(e) {
  198. if (!e || e == '' || e.detail.value.length <= 0) {
  199. this.initPicker([ 'floor', 'number']);
  200. return;
  201. }
  202. this.unit = e.detail.value[0].value;
  203. const list = [];
  204. const floor = this.building.filter(j => j.unit == e.detail.value[0].value).map(j => ({ ...j, text: `${j.floor}层`, value: j.floor }));
  205. floor.forEach(k => {
  206. const isunit = list.find(j => j.floor == k.floor);
  207. if (!isunit) list.push(k);
  208. });
  209. this.$set(this.house, 'floor', list);
  210. // 删除选项
  211. if (e.isUpdate) return;
  212. // delete this.formData.unit
  213. delete this.formData.floor
  214. delete this.formData.houseId
  215. },
  216. // 楼层选择
  217. floorChange(e) {
  218. if (!e || e == '' || e.detail.value.length <= 0) return;
  219. const list = [];
  220. 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 }));
  221. number.forEach(k => {
  222. const isunit = list.find(j => j.number == k.number);
  223. if (!isunit) list.push(k);
  224. });
  225. this.$set(this.house, 'number', list);
  226. // 删除选项
  227. if (e.isUpdate) return;
  228. // delete this.formData.unit
  229. // delete this.formData.floor
  230. delete this.formData.houseId
  231. },
  232. // 门牌选择
  233. houseChange(e) {
  234. if (!e || e == '' || e.detail.value.length <= 0) return;
  235. const dept = this.house.number.find(j => j.houseId == e.detail.value[0].value);
  236. this.formData.deptId = dept.deptId;
  237. },
  238. // 提交
  239. async submit(ref) {
  240. this.$refs[ref].validate(async (err, formdata) => {
  241. if (!err) {
  242. // 判断勾选后是否添加地址
  243. if (!this.formData.estateId || !this.formData.buildingId || !this.formData.houseId == null) {
  244. uni.showToast({
  245. title: '请填写完整地址信息',
  246. icon: 'error',
  247. duration: 2000,
  248. });
  249. return;
  250. }
  251. // 居民修改
  252. this.formData.reqType = this.formData.residentId || this.formData.residentReqId ? 1 : 0;
  253. const res = await requestFamily.familyInfo(this.formData);
  254. if (res.code && res.code == 200) {
  255. uni.showToast({
  256. title: this.formData.residentId ? '修改成功' : '添加成功',
  257. duration: 2000,
  258. });
  259. uni.navigateBack()
  260. }
  261. uni.showToast({
  262. title: res.details,
  263. icon: 'error',
  264. duration: 2000,
  265. });
  266. }
  267. })
  268. },
  269. }
  270. }
  271. </script>
  272. <style>
  273. .uni-section {
  274. padding-bottom: 10px;
  275. margin-bottom: 10px;
  276. }
  277. .uni-select__selector {
  278. z-index: 999 !important;
  279. }
  280. .uni-forms, .btn {
  281. width: 90%;
  282. margin: 10px auto;
  283. }
  284. .msg {
  285. color: red;
  286. display: block;
  287. width: 90%;
  288. margin: 0 auto;
  289. font-size: 14px;
  290. font-weight: 600;
  291. }
  292. </style>