dangerarearesidentrecord.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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='longitude' label="经度" label-width="100px">
  12. <uni-easyinput v-model="formData.longitude" placeholder="请录入经度" />
  13. </uni-forms-item>
  14. <uni-forms-item name='latitude' label="纬度" label-width="100px">
  15. <uni-easyinput v-model="formData.latitude" placeholder="请录入纬度" />
  16. </uni-forms-item>
  17. </uni-card>
  18. <uni-card title="群众家庭信息" :is-shadow="false">
  19. <uni-forms-item name='personName' label="户主姓名" label-width="100px" required>
  20. <uni-easyinput v-model="formData.personName" placeholder="请录入户主姓名" />
  21. </uni-forms-item>
  22. <uni-forms-item name='personId' label="身份证号" label-width="100px" required>
  23. <uni-easyinput v-model="formData.personId" placeholder="请录入身份证号" />
  24. </uni-forms-item>
  25. <uni-forms-item name='dangerAreaPid' label="危险区编码" label-width="100px" required>
  26. <uni-row>
  27. <uni-col :span="17">
  28. <uni-easyinput v-model="formData.dangerAreaPid" placeholder="请录入危险区编码" />
  29. </uni-col>
  30. <uni-col :span="7" class="view-flex-inline-end">
  31. <image class="scan-icon" mode="widthFix" src="/static/images/scan.png"
  32. @click="onQrCodeClick">
  33. </image>
  34. </uni-col>
  35. </uni-row>
  36. </uni-forms-item>
  37. <!-- <uni-forms-item name="isHouseholder" label="是否户主" label-width="100px" required>
  38. <uni-data-checkbox v-model="formData.isHouseholder" :localdata="checkItems.items">
  39. </uni-data-checkbox>
  40. </uni-forms-item> -->
  41. </uni-card>
  42. <uni-card title="家庭成员" :is-shadow="false">
  43. <view class="item-button-group">
  44. <view class="item-button" @click="onResidentAddClick()">
  45. <view class="items-line">
  46. <uni-icons class="input-uni-icon" type="personadd" size="18" color="coral" />
  47. <text class="button-text">添加成员</text>
  48. </view>
  49. </view>
  50. </view>
  51. <uni-list style="min-height: 40px;">
  52. <uni-list-item v-for="item in familyMembersList" :key="item.id">
  53. <template v-slot:body>
  54. <view class="list-item-block">
  55. <view class="line">
  56. <text class="text text-ellipsis" style="color: gray;">姓名:{{item.personName}}</text>
  57. </view>
  58. <view class="line">
  59. <text class="text text-ellipsis" style="color: gray;">身份证号:{{item.personId}}</text>
  60. </view>
  61. </view>
  62. </template>
  63. </uni-list-item>
  64. </uni-list>
  65. </uni-card>
  66. </uni-forms>
  67. <view class="footer">
  68. <view class="control">
  69. <view class="view-flex-rc">
  70. <view class="block"
  71. style="width: 120px;height:28px;margin-left: 10px;margin-right: 10px;border-radius:7px;background-color:lightpink"
  72. @click="toSubmit()">
  73. <view class="view-flex-cc">
  74. <uni-icons class="input-uni-icon" type="checkmarkempty" size="18" color="#999" />
  75. </view>
  76. <view class="view-flex-cc" style="padding-left:5px;">
  77. <text style="color:black;font-size:0.7rem">立即提交</text>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. <uni-drawer ref="showRight" mode="right" :mask-click="false" :width="drawerWidth">
  84. <view>
  85. <view class="view-flex-inline" style="background-color: #3F9EFF;height: 40px;padding-left: 10px;">
  86. <uni-icons class="input-uni-icon" type="personadd" size="30" color="coral" />
  87. <text style="color: white;font-size: 1rem;margin-left: 10px;">添加家庭成员</text>
  88. </view>
  89. <view style="padding-top: 20px;padding-left: 5px;padding-right: 5px;">
  90. <uni-forms ref="familyMembersForm" :model="familyMembersFormData">
  91. <uni-forms-item name='personName' label="姓名" label-width="90px" required>
  92. <uni-easyinput v-model="familyMembersFormData.personName" placeholder="请录入姓名" />
  93. </uni-forms-item>
  94. <uni-forms-item name='personId' label="身份证号" label-width="90px" required>
  95. <uni-easyinput v-model="familyMembersFormData.personId" placeholder="请录入身份证号" />
  96. </uni-forms-item>
  97. </uni-forms>
  98. </view>
  99. <view class="item-button-group" style="padding-right: 10px;">
  100. <view class="item-button" @click="onResidentEditCloseClick()">
  101. <view class="items-line">
  102. <uni-icons class="input-uni-icon" type="closeempty" size="18" color="coral" />
  103. <text class="button-text">取消</text>
  104. </view>
  105. </view>
  106. <view class="item-button" @click="onResidentEditSubmitClick()">
  107. <view class="items-line">
  108. <uni-icons class="input-uni-icon" type="checkmarkempty" size="18" color="coral" />
  109. <text class="button-text">确定</text>
  110. </view>
  111. </view>
  112. </view>
  113. </view>
  114. </uni-drawer>
  115. </view>
  116. </template>
  117. <script>
  118. import {
  119. role
  120. } from "@/api/role.js";
  121. import http from '@/http/api.js';
  122. import {
  123. devUrl,
  124. prodUrl
  125. } from '@/common/setting';
  126. export default {
  127. data() {
  128. return {
  129. title: '危险区群众登记',
  130. baseURL: '',
  131. warnId: '',
  132. formData: {
  133. latitude: '',
  134. longitude: '',
  135. personName: '',
  136. personId: '',
  137. dangerAreaPid: '',
  138. isHouseholder: 1,
  139. },
  140. familyMembersFormData: {
  141. personName: '',
  142. personId: '',
  143. },
  144. rules: {
  145. personName: {
  146. rules: [{
  147. required: true,
  148. errorMessage: '必填项',
  149. }]
  150. },
  151. personId: {
  152. rules: [{
  153. required: true,
  154. errorMessage: '必填项',
  155. }, ]
  156. },
  157. dangerAreaPid: {
  158. rules: [{
  159. required: true,
  160. errorMessage: '必填项',
  161. }, ]
  162. },
  163. },
  164. keepPhotos: [],
  165. familyMembersList: [],
  166. checkItems: {
  167. items: [{
  168. 'value': 0,
  169. 'text': '否'
  170. }, {
  171. 'value': 1,
  172. 'text': '是'
  173. }],
  174. current: 0,
  175. },
  176. drawerWidth: 300,
  177. }
  178. },
  179. onLoad(option) {
  180. let that = this;
  181. this.baseURL = process.env.NODE_ENV === 'development' ? devUrl : prodUrl;
  182. this.drawerWidth = uni.getWindowInfo().windowWidth - 100;
  183. // #ifdef APP-PLUS
  184. console.log("app")
  185. uni.getLocation({
  186. type: 'gcj02',
  187. geocode: true,
  188. success: function(res) {
  189. console.log('当前位置:' + JSON.stringify(res));
  190. that.formData.latitude = res.latitude;
  191. that.formData.longitude = res.longitude;
  192. }
  193. });
  194. // #endif
  195. // #ifdef MP-WEIXIN
  196. console.log("weixin")
  197. uni.getLocation({
  198. type: 'wgs84',
  199. success: function(res) {
  200. console.log('当前位置:' + JSON.stringify(res));
  201. that.formData.latitude = res.latitude;
  202. that.formData.longitude = res.longitude;
  203. }
  204. });
  205. // #endif
  206. },
  207. computed: {
  208. },
  209. onShow() {},
  210. onReady() {
  211. // 需要在onReady中设置规则
  212. this.$refs.baseForm.setRules(this.rules)
  213. },
  214. methods: {
  215. //返回上一页
  216. toBack() {
  217. uni.navigateBack({
  218. delta: 1
  219. })
  220. },
  221. onBackPress() {
  222. // #ifdef APP-PLUS
  223. plus.key.hideSoftKeybord();
  224. // #endif
  225. },
  226. onResidentAddClick() {
  227. this.familyMembersFormData.personId = '';
  228. this.familyMembersFormData.personName = '';
  229. this.$refs['showRight'].open();
  230. },
  231. onResidentEditCloseClick() {
  232. this.$refs['showRight'].close();
  233. },
  234. onResidentEditSubmitClick() {
  235. let familyMember = {};
  236. familyMember['personId'] = this.familyMembersFormData.personId;
  237. familyMember['personName'] = this.familyMembersFormData.personName;
  238. this.familyMembersList.push(familyMember);
  239. this.$refs['showRight'].close();
  240. },
  241. onCheckPhotoAdd() {
  242. let that = this;
  243. uni.chooseImage({
  244. sourceType: ['camera'],
  245. sizeType: ['compressed'],
  246. success: (res) => {
  247. const len = res.tempFilePaths.length;
  248. if (len === 1) {
  249. res.tempFilePaths.forEach(path => {
  250. that.uploadCheckPhoto(path);
  251. })
  252. } else {
  253. uni.showModal({
  254. content: '只能选择一张图片,请确认!',
  255. showCancel: false
  256. });
  257. }
  258. }
  259. })
  260. },
  261. uploadCheckPhoto(imagePath) {
  262. let that = this;
  263. uni.showLoading({
  264. title: '上传中'
  265. });
  266. uni.uploadFile({
  267. url: this.baseURL + '/galaxy-resource/oss/endpoint/put-file-attach?Blade-Auth=' +
  268. uni.getStorageSync('accessToken'),
  269. fileType: 'image',
  270. filePath: imagePath,
  271. name: 'file',
  272. success: (uploadFileRes) => {
  273. if (uploadFileRes.statusCode == 200) {
  274. let data = JSON.parse(uploadFileRes.data);
  275. if (data.success) {
  276. let path = data.data['name'];
  277. that.keepPhotos.push(path);
  278. }
  279. }
  280. },
  281. fail: (err) => {
  282. console.log(err);
  283. reject('err')
  284. },
  285. complete() {
  286. uni.hideLoading()
  287. }
  288. });
  289. },
  290. onCheckPhotoDel(index) {
  291. this.keepPhotos.splice(index, 1);
  292. },
  293. onQrCodeClick() {
  294. let that = this;
  295. uni.scanCode({
  296. scanType: ['qrCode'],
  297. success: function(res) {
  298. console.log('条码类型:' + res.scanType);
  299. console.log('条码内容:' + res.result);
  300. that.formData.dangerAreaPid = res.result;
  301. }
  302. });
  303. },
  304. toSubmit() {
  305. let that = this;
  306. this.$refs.baseForm.validate().then(res => {
  307. console.log('表单数据信息1:', res);
  308. that.submit();
  309. }).catch(err => {
  310. console.log('表单错误信息:', err);
  311. uni.showModal({
  312. content: "内容录入错误,请根据提示信息检查录入内容!",
  313. showCancel: false,
  314. success(res) {
  315. if (res.confirm) {
  316. //that.$refs.baseForm.clearValidate();
  317. }
  318. }
  319. });
  320. })
  321. },
  322. submit() {
  323. let formdata = this.formData;
  324. //if (this.formData.isHouseholder === 1) {
  325. formdata['familyMembers'] = this.familyMembersList;
  326. //}
  327. console.log('toSubmit事件:', JSON.stringify(formdata));
  328. let that = this;
  329. http.request({
  330. url: '/galaxy-business/yj/resident/record',
  331. method: 'POST',
  332. data: formdata
  333. }).then(res => {
  334. console.log('res ', JSON.stringify(res));
  335. if (res.success) {
  336. if (res.code == 200) {
  337. //that.clearCache();
  338. uni.showModal({
  339. content: '填报信息已成功提交',
  340. showCancel: false,
  341. success(res) {
  342. if (res.confirm) {
  343. that.toBack();
  344. }
  345. }
  346. });
  347. } else {
  348. uni.showModal({
  349. content: '提交失败',
  350. showCancel: false
  351. });
  352. }
  353. } else {
  354. uni.showModal({
  355. content: '提交失败',
  356. showCancel: false
  357. });
  358. }
  359. }).catch(err => {
  360. uni.showModal({
  361. content: '' + err.data.msg,
  362. showCancel: false
  363. });
  364. })
  365. },
  366. }
  367. }
  368. </script>
  369. <style lang="scss" scoped>
  370. .container {
  371. padding: 0 0 100rpx;
  372. }
  373. .scan-icon {
  374. /* #ifndef APP-NVUE */
  375. display: block;
  376. /* #endif */
  377. // margin-right: 10px;
  378. width: 30px;
  379. height: 30px;
  380. }
  381. .close {
  382. padding: 10px;
  383. }
  384. </style>