dangerarearesidentrecord.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <template>
  2. <view class="container">
  3. <uni-nav-bar dark :fixed="true" backgroundColor="#3F9EFF" statusBar="false" left-icon="left" left-text="返回"
  4. @clickLeft="toBack">
  5. <view class="nav-title">
  6. <text>{{title}}</text>
  7. </view>
  8. </uni-nav-bar>
  9. <uni-forms ref="baseForm" :model="formData">
  10. <uni-card title="危险区" :is-shadow="false">
  11. <uni-forms-item name='dangerAreaPid' label="危险区编码" label-width="100px" required>
  12. <uni-row>
  13. <uni-col :span="24">
  14. <view v-if="formData.dangerAreaPid == ''"
  15. style="border-radius: 5px;border-width: 1px;border-color: lightgray;border-style: solid;height: 32px;width: 100%;"
  16. @click="toDangerAreaSelect">
  17. <view
  18. style="color: gray;font-size: 0.6rem;padding-left: 8px;height: 32px;display: flex;flex-direction: column;justify-content: center;">
  19. 点击选择危险区</view>
  20. </view>
  21. <view v-else
  22. style="border-radius: 5px;border-width: 1px;border-color: lightgray;border-style: solid;height: 32px;width: 100%;"
  23. @click="toDangerAreaSelect">
  24. <view
  25. style="font-size: 0.7rem;color: dimgray;padding-left: 8px;height: 32px;display: flex;flex-direction: column;justify-content: center;">
  26. {{formData.dangerAreaName}}
  27. </view>
  28. </view>
  29. <!-- <uni-easyinput v-model="formData.dangerAreaPid" placeholder="请录入危险区编码" /> -->
  30. </uni-col>
  31. <!-- <uni-col :span="7" class="view-flex-inline-end">
  32. <image class="scan-icon" mode="widthFix" src="/static/images/scan.png"
  33. @click="onQrCodeClick">
  34. </image>
  35. </uni-col> -->
  36. </uni-row>
  37. </uni-forms-item>
  38. </uni-card>
  39. <uni-card title="住址定位信息" :is-shadow="false">
  40. <uni-forms-item name='longitude' label="经度" label-width="100px">
  41. <uni-easyinput v-model="formData.longitude" placeholder="请录入经度" />
  42. </uni-forms-item>
  43. <uni-forms-item name='latitude' label="纬度" label-width="100px">
  44. <uni-easyinput v-model="formData.latitude" placeholder="请录入纬度" />
  45. </uni-forms-item>
  46. <uni-forms-item name='address' label="地址" label-width="100px">
  47. <uni-easyinput v-model="formData.address" placeholder="请录入地址" />
  48. </uni-forms-item>
  49. <view class="item-button-group">
  50. <view class="item-button mid-size" @click="onMapAddClick()">
  51. <view class="items-line">
  52. <uni-icons class="input-uni-icon" type="map-pin-ellipse" size="18" color="coral" />
  53. <text class="button-text">地图定位</text>
  54. </view>
  55. </view>
  56. </view>
  57. </uni-card>
  58. <uni-card title="群众家庭信息" :is-shadow="false">
  59. <uni-forms-item name='personName' label="户主姓名" label-width="100px" required>
  60. <uni-easyinput v-model="formData.personName" placeholder="请录入户主姓名" />
  61. </uni-forms-item>
  62. <uni-forms-item name='personId' label="手机号" label-width="100px" required>
  63. <uni-easyinput v-model="formData.personId" placeholder="请录入手机号" />
  64. </uni-forms-item>
  65. </uni-card>
  66. <uni-card title="家庭成员" :is-shadow="false">
  67. <uni-card v-for="(item, index) in familyMembersList" :key="index">
  68. <template v-slot:title>
  69. <view style="border-width: 0px 0px 1px 0px;border-color: lightgrey;border-style: solid">
  70. <uni-row>
  71. <uni-col :span="12">
  72. <view style="margin-top: 8px;font-size: 1rem;">{{index+1}}</view>
  73. </uni-col>
  74. <uni-col :span="12">
  75. <view style="display: flex;flex-direction: row;justify-content: flex-end;">
  76. <button class="button" size="mini"
  77. style="margin-left: 0px;margin-right: 0px;margin-top: 4px;margin-bottom: 3px;"
  78. type="default" @click="delFamilyMembers(index)">删除</button>
  79. </view>
  80. </uni-col>
  81. </uni-row>
  82. </view>
  83. </template>
  84. <uni-forms-item label="姓名" label-width="100px">
  85. <uni-easyinput v-model="formData.familyMembersFormData[item.personName]"
  86. placeholder="请录入户主姓名" />
  87. </uni-forms-item>
  88. <uni-forms-item label="手机号" label-width="100px">
  89. <uni-easyinput v-model="formData.familyMembersFormData[item.personId]" placeholder="请录入手机号" />
  90. </uni-forms-item>
  91. </uni-card>
  92. <view class="item-button-group">
  93. <view class="item-button" @click="onResidentAddClick()">
  94. <view class="items-line">
  95. <uni-icons class="input-uni-icon" type="plusempty" size="18" color="coral" />
  96. <text class="button-text">添加</text>
  97. </view>
  98. </view>
  99. </view>
  100. </uni-card>
  101. </uni-forms>
  102. <view class="footer">
  103. <view class="control">
  104. <view class="view-flex-rc">
  105. <view class="block"
  106. style="width: 120px;height:28px;margin-left: 10px;margin-right: 10px;border-radius:7px;background-color:lightpink"
  107. @click="toSubmit()">
  108. <view class="view-flex-cc">
  109. <uni-icons class="input-uni-icon" type="checkmarkempty" size="18" color="#999" />
  110. </view>
  111. <view class="view-flex-cc" style="padding-left:5px;">
  112. <text style="color:black;font-size:0.7rem">立即提交</text>
  113. </view>
  114. </view>
  115. </view>
  116. </view>
  117. </view>
  118. <!-- <uni-popup ref="popup">
  119. <view style="width: 100%;height: 400px;background-color: white;">
  120. <view class="view-flex-inline" style="width: 100%;height: 40px;background-color: #3F9EFF;">
  121. <text class="text" style="margin-left: 5px;font-size: 1rem;color:white">添加成员</text>
  122. </view>
  123. <uni-group>
  124. <uni-forms ref="familyMembersForm" :model="familyMembersFormData">
  125. <uni-forms-item name='personName' label="姓名" label-width="90px" required>
  126. <uni-easyinput @input="nameinput" placeholder="请录入姓名" />
  127. </uni-forms-item>
  128. <uni-forms-item name='personId' label="身份证号" label-width="90px" required>
  129. <uni-easyinput @input="idinput" placeholder="请录入身份证号" />
  130. </uni-forms-item>
  131. </uni-forms>
  132. </uni-group>
  133. <view class="item-button-group" style="padding-right: 10px;">
  134. <view class="item-button" @click="onResidentEditCloseClick()">
  135. <view class="items-line">
  136. <uni-icons class="input-uni-icon" type="closeempty" size="18" color="coral" />
  137. <text class="button-text">取消</text>
  138. </view>
  139. </view>
  140. <view class="item-button" @click="onResidentEditSubmitClick()">
  141. <view class="items-line">
  142. <uni-icons class="input-uni-icon" type="checkmarkempty" size="18" color="coral" />
  143. <text class="button-text">确定</text>
  144. </view>
  145. </view>
  146. </view>
  147. </view>
  148. </uni-popup> -->
  149. </view>
  150. </template>
  151. <script>
  152. import {
  153. role
  154. } from "@/api/role.js";
  155. import http from '@/http/api.js';
  156. import {
  157. devUrl,
  158. prodUrl
  159. } from '@/common/setting';
  160. export default {
  161. data() {
  162. return {
  163. title: '危险区群众登记',
  164. baseURL: '',
  165. warnId: '',
  166. formData: {
  167. latitude: '',
  168. longitude: '',
  169. address: '',
  170. personName: '',
  171. personId: '',
  172. dangerAreaPid: '',
  173. dangerAreaName: '',
  174. isHouseholder: 1,
  175. familyMembersFormData: {
  176. personName_1: '',
  177. personId_1: '',
  178. }
  179. },
  180. familyMembersFormData: {
  181. personName: '',
  182. personId: '',
  183. },
  184. rules: {
  185. personName: {
  186. rules: [{
  187. required: true,
  188. errorMessage: '必填项',
  189. }]
  190. },
  191. personId: {
  192. rules: [{
  193. required: true,
  194. errorMessage: '必填项',
  195. }, ]
  196. },
  197. dangerAreaPid: {
  198. rules: [{
  199. required: true,
  200. errorMessage: '必填项',
  201. }, ]
  202. },
  203. },
  204. keepPhotos: [],
  205. familyMembersList: [{
  206. personName: 'personName_1',
  207. personId: 'personId_1',
  208. }],
  209. checkItems: {
  210. items: [{
  211. 'value': 0,
  212. 'text': '否'
  213. }, {
  214. 'value': 1,
  215. 'text': '是'
  216. }],
  217. current: 0,
  218. },
  219. drawerWidth: 300,
  220. membersIndex: 1,
  221. }
  222. },
  223. onLoad(option) {
  224. let that = this;
  225. this.baseURL = process.env.NODE_ENV === 'development' ? devUrl : prodUrl;
  226. this.drawerWidth = uni.getWindowInfo().windowWidth - 100;
  227. uni.getLocation({
  228. type: 'wgs84',
  229. success: function(res) {
  230. that.formData.latitude = res.latitude;
  231. that.formData.longitude = res.longitude;
  232. that.getAddress(res.longitude, res.latitude);
  233. }
  234. });
  235. },
  236. computed: {
  237. },
  238. onShow() {
  239. let that = this;
  240. uni.$once("dangerAreaId", function(data) {
  241. //console.log("dangerAreaId "+data)
  242. let p = JSON.parse(data)
  243. that.formData.dangerAreaPid = p.dangerAreaId;
  244. that.formData.dangerAreaName = p.dangerAreaName;
  245. })
  246. uni.$once("lngLat", function(data) {
  247. //console.log("dangerAreaId "+data)
  248. let p = JSON.parse(data)
  249. that.formData.longitude = p.lng;
  250. that.formData.latitude = p.lat;
  251. that.formData.address = p.add;
  252. })
  253. },
  254. onReady() {
  255. // 需要在onReady中设置规则
  256. this.$refs.baseForm.setRules(this.rules)
  257. },
  258. methods: {
  259. //返回上一页
  260. toBack() {
  261. uni.navigateBack({
  262. delta: 1
  263. })
  264. },
  265. onBackPress() {
  266. // #ifdef APP-PLUS
  267. plus.key.hideSoftKeybord();
  268. // #endif
  269. },
  270. getAddress(lng, lat) {
  271. let that = this;
  272. let url = 'https://apis.map.qq.com/ws/geocoder/v1/?location=' + lat + ',' + lng +
  273. '&key=4HYBZ-EB23D-SLC42-HQ5R3-LP3LQ-OZFU5';
  274. // console.log(url);
  275. http.request({
  276. url: url,
  277. method: 'GET',
  278. }).then(res => {
  279. //console.log(JSON.stringify(res));
  280. }).catch(err => {
  281. //console.log(JSON.stringify(err))
  282. that.formData.address = err.data.result.address;
  283. })
  284. },
  285. onMapAddClick(){
  286. var url = '/pages/yjxt/resident/dangerarearesidentlocation?type=1';
  287. uni.navigateTo({
  288. url: url
  289. })
  290. },
  291. onResidentAddClick() {
  292. //let index = this.familyMembersList.length + 1;
  293. this.membersIndex += 1;
  294. this.familyMembersList.push({
  295. personId: 'personId_' + this.membersIndex,
  296. personName: 'personName_' + this.membersIndex,
  297. })
  298. //this.familyMembersFormData.personId = '';
  299. //this.familyMembersFormData.personName = '';
  300. // this.$refs['showRight'].open();
  301. //this.$refs.popup.open('bottom')
  302. },
  303. delFamilyMembers(index) {
  304. //let index = this.dynamicLists.findIndex(v => v.id === id)
  305. this.formData.familyMembersFormData['' + this.familyMembersList[index].personId] = '';
  306. this.formData.familyMembersFormData['' + this.familyMembersList[index].personName] = '';
  307. this.familyMembersList.splice(index, 1)
  308. },
  309. onResidentEditCloseClick() {
  310. this.$refs.popup.close();
  311. },
  312. nameinput(e) {
  313. //console.log('输入内容:', e);
  314. this.familyMembersFormData.personName = e;
  315. },
  316. idinput(e) {
  317. //console.log('输入内容:', e);
  318. this.familyMembersFormData.personId = e;
  319. },
  320. toDangerAreaSelect() {
  321. var url = '/pages/yjxt/region/region';
  322. uni.navigateTo({
  323. url: url
  324. })
  325. },
  326. onResidentEditSubmitClick() {
  327. // this.$refs['showRight'].close();
  328. this.$refs.popup.close();
  329. if (this.familyMembersFormData.personId.length > 0 && this.familyMembersFormData.personName.length > 0) {
  330. let familyMember = {};
  331. familyMember['personId'] = this.familyMembersFormData.personId;
  332. familyMember['personName'] = this.familyMembersFormData.personName;
  333. this.familyMembersList.push(familyMember);
  334. } else {
  335. uni.showModal({
  336. content: "录入错误",
  337. showCancel: false
  338. });
  339. }
  340. },
  341. onCheckPhotoAdd() {
  342. let that = this;
  343. uni.chooseImage({
  344. sourceType: ['camera'],
  345. sizeType: ['compressed'],
  346. success: (res) => {
  347. const len = res.tempFilePaths.length;
  348. if (len === 1) {
  349. res.tempFilePaths.forEach(path => {
  350. that.uploadCheckPhoto(path);
  351. })
  352. } else {
  353. uni.showModal({
  354. content: '只能选择一张图片,请确认!',
  355. showCancel: false
  356. });
  357. }
  358. }
  359. })
  360. },
  361. uploadCheckPhoto(imagePath) {
  362. let that = this;
  363. uni.showLoading({
  364. title: '上传中'
  365. });
  366. uni.uploadFile({
  367. url: this.baseURL + '/galaxy-resource/oss/endpoint/put-file-attach?Blade-Auth=' +
  368. uni.getStorageSync('accessToken'),
  369. fileType: 'image',
  370. filePath: imagePath,
  371. name: 'file',
  372. success: (uploadFileRes) => {
  373. if (uploadFileRes.statusCode == 200) {
  374. let data = JSON.parse(uploadFileRes.data);
  375. if (data.success) {
  376. let path = data.data['name'];
  377. that.keepPhotos.push(path);
  378. }
  379. }
  380. },
  381. fail: (err) => {
  382. console.log(err);
  383. reject('err')
  384. },
  385. complete() {
  386. uni.hideLoading()
  387. }
  388. });
  389. },
  390. onCheckPhotoDel(index) {
  391. this.keepPhotos.splice(index, 1);
  392. },
  393. onQrCodeClick() {
  394. let that = this;
  395. uni.scanCode({
  396. scanType: ['qrCode'],
  397. success: function(res) {
  398. console.log('条码类型:' + res.scanType);
  399. console.log('条码内容:' + res.result);
  400. that.formData.dangerAreaPid = res.result;
  401. }
  402. });
  403. },
  404. toSubmit() {
  405. let that = this;
  406. this.$refs.baseForm.validate().then(res => {
  407. console.log('表单数据信息1:', res);
  408. that.submit();
  409. }).catch(err => {
  410. console.log('表单错误信息:', err);
  411. uni.showModal({
  412. content: "内容录入错误,请根据提示信息检查录入内容!",
  413. showCancel: false,
  414. success(res) {
  415. if (res.confirm) {
  416. //that.$refs.baseForm.clearValidate();
  417. }
  418. }
  419. });
  420. })
  421. },
  422. submit() {
  423. let familyMembers = [];
  424. for (let i = 0; i < this.familyMembersList.length; i++) {
  425. let personId = this.formData.familyMembersFormData['' + this.familyMembersList[i].personId];
  426. let personName = this.formData.familyMembersFormData['' + this.familyMembersList[i].personName];
  427. if (personId != undefined && personId != null && personId != '') {
  428. if (personName != undefined && personName != null && personName != '') {
  429. let f = {};
  430. f['personId'] = personId;
  431. f['personName'] = personName;
  432. familyMembers.push(f)
  433. }
  434. }
  435. }
  436. let formdata = this.formData;
  437. formdata.familyMembersFormData = {};
  438. formdata['familyMembers'] = familyMembers;
  439. console.log('toSubmit事件:', JSON.stringify(formdata));
  440. let that = this;
  441. http.request({
  442. url: '/galaxy-business/yj/resident/record',
  443. method: 'POST',
  444. data: formdata
  445. }).then(res => {
  446. //console.log('res ', JSON.stringify(res));
  447. if (res.success) {
  448. if (res.code == 200) {
  449. //that.clearCache();
  450. uni.showModal({
  451. content: '填报信息已成功提交',
  452. showCancel: false,
  453. success(res) {
  454. if (res.confirm) {
  455. that.toBack();
  456. }
  457. }
  458. });
  459. } else {
  460. uni.showModal({
  461. content: '提交失败',
  462. showCancel: false
  463. });
  464. }
  465. } else {
  466. uni.showModal({
  467. content: '提交失败',
  468. showCancel: false
  469. });
  470. }
  471. }).catch(err => {
  472. uni.showModal({
  473. content: '' + err.data.msg,
  474. showCancel: false
  475. });
  476. })
  477. },
  478. }
  479. }
  480. </script>
  481. <style lang="scss" scoped>
  482. .container {
  483. padding: 0 0 100rpx;
  484. }
  485. .scan-icon {
  486. /* #ifndef APP-NVUE */
  487. display: block;
  488. /* #endif */
  489. // margin-right: 10px;
  490. width: 30px;
  491. height: 30px;
  492. }
  493. .close {
  494. padding: 10px;
  495. }
  496. </style>