uni-OCRUploadPopup.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. <template>
  2. <view class='uni-page'>
  3. <u-popup :show="OCRUploadPopup" @close="close" closeable round="20rpx">
  4. <view class="dis dis header a-end j-c">
  5. <u-tabs :list="list" @click="click" :activeStyle="{color:'#333',fontWeight:'bold'}"
  6. :inactiveStyle="{color:'#999'}" :current="current" :scrollable="false" lineColor="#FDE935"
  7. lineWidth="150rpx"></u-tabs>
  8. </view>
  9. <view class="content">
  10. <template v-if="checkType=='carInfo'">
  11. <view class="img" v-if="current==0">
  12. <image :src="carfrontImg?carfrontImg:'/static/image/carbackimg.png'" mode=""
  13. @click="carfrontChange"></image>
  14. </view>
  15. <view class="img" v-else>
  16. <image :src="carbackImg?carbackImg:'/static/image/carbackimg.png'" mode=""
  17. @click="carbackChange">
  18. </image>
  19. </view>
  20. </template>
  21. <template v-else>
  22. <view class="img" v-if="current==0">
  23. <image :src="userfrontImg?userfrontImg:'/static/image/carbackimg.png'" mode=""
  24. @click="userfrontChange"></image>
  25. </view>
  26. <view class="img" v-else>
  27. <image :src="userbackImg?userbackImg:'/static/image/carbackimg.png'" mode=""
  28. @click="userbackChange">
  29. </image>
  30. </view>
  31. </template>
  32. <view class="footer dis a-c j-s mt-2">
  33. <u-button class="btn" type="primary" text="关闭" shape="circle" plain color="#FDE935"
  34. :hairline="false" style="margin-right: 20px;" @click="close"></u-button>
  35. <u-button class="btn" type="primary" text="确定" shape="circle" color="#FDE935"
  36. v-if="checkType=='carInfo'" :disabled="!carfrontImg && !carbackImg" :hairline="false"
  37. @click="ocrInt"></u-button>
  38. <u-button class="btn" type="primary" text="确定" shape="circle" color="#FDE935"
  39. v-if="checkType=='ownerInfo'" :disabled="!userfrontImg && !userbackImg" :hairline="false"
  40. @click="ownerInfoInt"></u-button>
  41. <u-button class="btn" type="primary" text="确定" shape="circle" color="#FDE935"
  42. v-if="checkType=='policyHolderInfo'" :disabled="!userfrontImg && !userbackImg" :hairline="false"
  43. @click="policyHolderInfoInt"></u-button>
  44. <u-button class="btn" type="primary" text="确定" shape="circle" color="#FDE935"
  45. v-if="checkType=='insuredPersonInfo'" :disabled="!userfrontImg && !userbackImg"
  46. :hairline="false" @click="insuredPersonInfoInt"></u-button>
  47. </view>
  48. </view>
  49. </u-popup>
  50. </view>
  51. </template>
  52. <script>
  53. import store from '@/store';
  54. export default {
  55. props: {
  56. show: {
  57. type: Boolean,
  58. default: false
  59. },
  60. list: {
  61. type: Array,
  62. default: () => []
  63. },
  64. checkType: {
  65. type: String,
  66. default: 'carInfo'
  67. }
  68. },
  69. data() {
  70. return {
  71. OCRUploadPopup: this.show,
  72. current: 0,
  73. carfrontImg: null,
  74. carbackImg: null,
  75. carInfoPositiveList: [],
  76. carfront: {},
  77. carback: {},
  78. userfront: {},
  79. userback: {},
  80. userfrontImg: null,
  81. userbackImg: null,
  82. ownerInfoPositiveList: [],
  83. applicantInfoPositiveList: [],
  84. InsuredInfoPositiveList: [],
  85. }
  86. },
  87. watch: {
  88. show(newVal) {
  89. this.OCRUploadPopup = newVal
  90. }
  91. },
  92. onShow() {},
  93. onLoad() {
  94. },
  95. methods: {
  96. ocrInt() {
  97. let Info = Object.assign({}, this.carfront, this.carback)
  98. if (this.isEmptyObject(Info)) {
  99. uni.showToast({
  100. icon: 'none',
  101. title: '未检测到图片',
  102. duration: 1500
  103. });
  104. } else {
  105. let ImgList = this.carInfoPositiveList;
  106. let frontImg = this.carfrontImg;
  107. let backImg = this.carbackImg;
  108. this.$emit('carCallback', {
  109. Info,
  110. ImgList,
  111. frontImg,
  112. backImg,
  113. });
  114. this.userfrontImg = '';
  115. this.userbackImg = '';
  116. this.carfrontImg = '';
  117. this.carbackImg = '';
  118. this.current = 0;
  119. }
  120. },
  121. ownerInfoInt() {
  122. let Info = Object.assign({}, this.userfront, this.userback)
  123. if (this.isEmptyObject(Info)) {
  124. uni.showToast({
  125. icon: 'none',
  126. title: '未检测到图片',
  127. duration: 1500
  128. });
  129. } else {
  130. let ImgList = this.ownerInfoPositiveList;
  131. let frontImg = this.userfrontImg;
  132. let backImg = this.userbackImg;
  133. this.$emit('ownerInfoCallback', {
  134. Info,
  135. ImgList,
  136. frontImg,
  137. backImg,
  138. });
  139. this.userfrontImg = '';
  140. this.userbackImg = '';
  141. this.carfrontImg = '';
  142. this.carbackImg = '';
  143. this.current = 0;
  144. }
  145. },
  146. policyHolderInfoInt() {
  147. let Info = Object.assign({}, this.userfront, this.userback)
  148. if (this.isEmptyObject(Info)) {
  149. uni.showToast({
  150. icon: 'none',
  151. title: '未检测到图片',
  152. duration: 1500
  153. });
  154. } else {
  155. let ImgList = this.applicantInfoPositiveList;
  156. let frontImg = this.userfrontImg;
  157. let backImg = this.userbackImg;
  158. this.$emit('applicantInfoCallback', {
  159. Info,
  160. ImgList,
  161. frontImg,
  162. backImg,
  163. });
  164. this.userfrontImg = '';
  165. this.userbackImg = '';
  166. this.carfrontImg = '';
  167. this.carbackImg = '';
  168. this.current = 0;
  169. }
  170. },
  171. insuredPersonInfoInt() {
  172. let Info = Object.assign({}, this.userfront, this.userback)
  173. if (this.isEmptyObject(Info)) {
  174. uni.showToast({
  175. icon: 'none',
  176. title: '未检测到图片',
  177. duration: 1500
  178. });
  179. } else {
  180. let ImgList = this.InsuredInfoPositiveList;
  181. let frontImg = this.userfrontImg;
  182. let backImg = this.userbackImg;
  183. this.$emit('InsuredInfoCallback', {
  184. Info,
  185. ImgList,
  186. frontImg,
  187. backImg,
  188. });
  189. this.userfrontImg = '';
  190. this.userbackImg = '';
  191. this.carfrontImg = '';
  192. this.carbackImg = '';
  193. this.current = 0;
  194. }
  195. },
  196. click(item) {
  197. this.current = item.index;
  198. },
  199. close() {
  200. this.current = 0;
  201. this.$emit('close')
  202. },
  203. isEmptyObject(obj) {
  204. return JSON.stringify(obj) === '{}';
  205. },
  206. //car正面
  207. async carfrontChange() {
  208. console.log(store.state);
  209. let [chooseImageErr, chooseImageRes] = await uni.chooseImage({
  210. count: 1,
  211. sizeType: ['compressed']
  212. });
  213. let size = chooseImageRes.tempFiles[0].size / 1024 / 1024 < 5;
  214. if (!size) {
  215. this.$refs.uToast.show({
  216. title: '上传图片大小不能超过 5MB!',
  217. type: 'error',
  218. })
  219. return false
  220. }
  221. if (chooseImageRes) {
  222. this.carfrontImg = chooseImageRes.tempFilePaths[0];
  223. uni.uploadFile({
  224. url: this.$base.baseUrl + '/file/upload',
  225. filePath: chooseImageRes.tempFilePaths[0],
  226. name: "file",
  227. formData: {
  228. 'type': 'image',
  229. },
  230. header: {
  231. Authorization: store.state.token,
  232. system_code: store.state.system_code ? store.state.system_code : ''
  233. },
  234. success: (imgRes) => {
  235. let data = JSON.parse(imgRes.data);
  236. console.log(data);
  237. if (data.code == '200') {
  238. if (this.carInfoPositiveList.some(v => v.imageCode == 'C01')) {
  239. this.carInfoPositiveList.map(val => {
  240. if (val.imageCode == 'C01') {
  241. val.imageBase64List[0].imageId = data.data.id;
  242. }
  243. })
  244. } else {
  245. this.carInfoPositiveList.push({
  246. imageBase64List: [{
  247. imageId: data.data.id
  248. }],
  249. imageCode: "C01",
  250. })
  251. }
  252. uni.uploadFile({
  253. url: this.$base.baseUrl + '/order/identify/drivingPermit',
  254. filePath: chooseImageRes.tempFilePaths[0],
  255. name: "image1",
  256. header: {
  257. Authorization: store.state.token,
  258. system_code: store.state.system_code ? store.state
  259. .system_code : ''
  260. },
  261. success: (uploadFileRes) => {
  262. let data = JSON.parse(uploadFileRes.data).data;
  263. let rdate = '';
  264. if (!!data.carInfo.registerDate) {
  265. rdate = data.carInfo.registerDate.substr(0,
  266. 4) +
  267. '-' + data.carInfo
  268. .registerDate.substr(4, 2) + '-' + data
  269. .carInfo
  270. .registerDate
  271. .substr(6,
  272. 2)
  273. }
  274. let isdate = '';
  275. if (!!data.carInfo.issueDate) {
  276. isdate = data.carInfo.issueDate.substr(0, 4) +
  277. '-' + data.carInfo
  278. .issueDate.substr(4, 2) + '-' + data
  279. .carInfo
  280. .issueDate.substr(6, 2)
  281. }
  282. this.carfront = {
  283. carOwner: data.carInfo.carOwner, //车主
  284. licenseNo: data.carInfo.plateNo, //车牌号
  285. brandName: data.carInfo.backOcrID, //品牌型号
  286. frameNo: data.carInfo.vin, //车架号
  287. engineNo: data.carInfo.engine, //发动机号
  288. vinNo: data.carInfo.vin, //车架号
  289. issueDate: isdate, //发证日期
  290. registerDate: rdate, //注册日期
  291. carKindCode: data.carInfo
  292. .plateType, //车辆种类
  293. carTypeCode: data.carInfo.category, //车辆类型
  294. carnature: data.carInfo.useNature,
  295. vehicleUseCode: data.carInfo
  296. .vehicleUse, //车辆用途
  297. }
  298. }
  299. });
  300. }
  301. }
  302. });
  303. } else {}
  304. },
  305. async carbackChange() {
  306. let [chooseImageErr, chooseImageRes] = await uni.chooseImage({
  307. count: 1,
  308. sizeType: ['compressed']
  309. });
  310. let size = chooseImageRes.tempFiles[0].size / 1024 / 1024 < 5;
  311. if (!size) {
  312. this.$refs.uToast.show({
  313. title: '上传图片大小不能超过 5MB!',
  314. type: 'error',
  315. })
  316. return false
  317. }
  318. if (chooseImageRes) {
  319. this.carbackImg = chooseImageRes.tempFilePaths[0];
  320. uni.uploadFile({
  321. url: this.$base.baseUrl + '/file/upload',
  322. filePath: chooseImageRes.tempFilePaths[0],
  323. name: "file",
  324. formData: {
  325. 'type': 'image',
  326. },
  327. header: {
  328. Authorization: store.state.token,
  329. system_code: store.state.system_code ? store.state.system_code : ''
  330. },
  331. success: (imgRes) => {
  332. let data = JSON.parse(imgRes.data);
  333. if (data.code == '200') {
  334. if (this.carInfoPositiveList.some(v => v.imageCode == 'D01')) {
  335. this.carInfoPositiveList.map(val => {
  336. if (val.imageCode == 'C01') {
  337. val.imageBase64List[0].imageId = data.data.id;
  338. }
  339. })
  340. } else {
  341. this.carInfoPositiveList.push({
  342. imageBase64List: [{
  343. imageId: data.data.id
  344. }],
  345. imageCode: "D01",
  346. })
  347. }
  348. uni.uploadFile({
  349. url: this.$base.baseUrl + '/order/identify/drivingPermit',
  350. filePath: chooseImageRes.tempFilePaths[0],
  351. name: "image2",
  352. header: {
  353. Authorization: store.state.token,
  354. system_code: store.state.system_code ? store.state
  355. .system_code : ''
  356. },
  357. success: (uploadFileRes) => {
  358. let data1 = JSON.parse(uploadFileRes.data).data;
  359. this.carback = {
  360. vehicleweight: data1.carInfo
  361. .grossMass, //总质量
  362. completeKerbMass: data1.carInfo
  363. .unladenMass, //整备质量
  364. seatCount: data1.carInfo
  365. .approvedPassengersCapacity, //核定载客数
  366. limitLoad: data1.carInfo
  367. .limitLoad, //核定载质量
  368. }
  369. }
  370. });
  371. }
  372. }
  373. });
  374. } else {}
  375. },
  376. async userfrontChange() {
  377. let [chooseImageErr, chooseImageRes] = await uni.chooseImage({
  378. count: 1,
  379. sizeType: ['compressed']
  380. });
  381. let size = chooseImageRes.tempFiles[0].size / 1024 / 1024 < 5;
  382. if (!size) {
  383. this.$refs.uToast.show({
  384. title: '上传图片大小不能超过 5MB!',
  385. type: 'error',
  386. })
  387. return false
  388. }
  389. if (chooseImageRes) {
  390. this.userfrontImg = chooseImageRes.tempFilePaths[0];
  391. uni.uploadFile({
  392. url: this.$base.baseUrl + '/file/upload',
  393. filePath: chooseImageRes.tempFilePaths[0],
  394. name: "file",
  395. formData: {
  396. 'type': 'image',
  397. },
  398. header: {
  399. Authorization: store.state.token,
  400. system_code: store.state.system_code ? store.state.system_code : ''
  401. },
  402. success: (imgRes) => {
  403. let data = JSON.parse(imgRes.data);
  404. if (data.code == '200') {
  405. switch (this.checkType) {
  406. case 'ownerInfo':
  407. if (this.ownerInfoPositiveList.some(v => v.imageCode == 'C02')) {
  408. this.ownerInfoPositiveList.map(val => {
  409. if (val.imageCode == 'C02') {
  410. val.imageBase64List[0].imageId = data.data.id;
  411. }
  412. })
  413. } else {
  414. this.ownerInfoPositiveList.push({
  415. imageBase64List: [{
  416. imageId: data.data.id
  417. }],
  418. imageCode: "C02",
  419. })
  420. }
  421. break;
  422. case 'policyHolderInfo':
  423. if (this.applicantInfoPositiveList.some(v => v.imageCode ==
  424. 'C03')) {
  425. this.applicantInfoPositiveList.map(val => {
  426. if (val.imageCode == 'C03') {
  427. val.imageBase64List[0].imageId = data.data.id;
  428. }
  429. })
  430. } else {
  431. this.applicantInfoPositiveList.push({
  432. imageBase64List: [{
  433. imageId: data.data.id
  434. }],
  435. imageCode: "C03",
  436. })
  437. }
  438. break;
  439. case 'insuredPersonInfo':
  440. if (this.InsuredInfoPositiveList.some(v => v.imageCode == 'C04')) {
  441. this.InsuredInfoPositiveList.map(val => {
  442. if (val.imageCode == 'C04') {
  443. val.imageBase64List[0].imageId = data.data.id;
  444. }
  445. })
  446. } else {
  447. this.InsuredInfoPositiveList.push({
  448. imageBase64List: [{
  449. imageId: data.data.id
  450. }],
  451. imageCode: "C04",
  452. })
  453. }
  454. break;
  455. default:
  456. break;
  457. };
  458. uni.uploadFile({
  459. url: this.$base.baseUrl + '/order/identify/idCard',
  460. filePath: chooseImageRes.tempFilePaths[0],
  461. name: "image1",
  462. header: {
  463. Authorization: store.state.token,
  464. system_code: store.state.system_code ? store.state
  465. .system_code : ''
  466. },
  467. success: (uploadFileRes) => {
  468. let data = JSON.parse(uploadFileRes.data).data;
  469. this.userfront = {
  470. name: data.customerInfo.name,
  471. identifyNumber: data.customerInfo
  472. .identifyNumber,
  473. addr: data.customerInfo.addr,
  474. }
  475. }
  476. });
  477. }
  478. }
  479. });
  480. } else {}
  481. },
  482. async userbackChange() {
  483. let [chooseImageErr, chooseImageRes] = await uni.chooseImage({
  484. count: 1,
  485. sizeType: ['compressed']
  486. });
  487. let size = chooseImageRes.tempFiles[0].size / 1024 / 1024 < 5;
  488. if (!size) {
  489. this.$refs.uToast.show({
  490. title: '上传图片大小不能超过 5MB!',
  491. type: 'error',
  492. })
  493. return false
  494. }
  495. if (chooseImageRes) {
  496. this.userbackImg = chooseImageRes.tempFilePaths[0];
  497. uni.uploadFile({
  498. url: this.$base.baseUrl + '/file/upload',
  499. filePath: chooseImageRes.tempFilePaths[0],
  500. name: "file",
  501. formData: {
  502. 'type': 'image',
  503. },
  504. header: {
  505. Authorization: store.state.token,
  506. system_code: store.state.system_code ? store.state.system_code : ''
  507. },
  508. success: (imgRes) => {
  509. let data = JSON.parse(imgRes.data);
  510. if (data.code == '200') {
  511. switch (this.checkType) {
  512. case 'ownerInfo':
  513. if (this.ownerInfoPositiveList.some(v => v.imageCode == 'D02')) {
  514. this.ownerInfoPositiveList.map(val => {
  515. if (val.imageCode == 'D02') {
  516. val.imageBase64List[0].imageId = data.data.id;
  517. }
  518. })
  519. } else {
  520. this.ownerInfoPositiveList.push({
  521. imageBase64List: [{
  522. imageId: data.data.id
  523. }],
  524. imageCode: "D02",
  525. })
  526. }
  527. break;
  528. case 'policyHolderInfo':
  529. if (this.applicantInfoPositiveList.some(v => v.imageCode ==
  530. 'D03')) {
  531. this.applicantInfoPositiveList.map(val => {
  532. if (val.imageCode == 'D03') {
  533. val.imageBase64List[0].imageId = data.data.id;
  534. }
  535. })
  536. } else {
  537. this.applicantInfoPositiveList.push({
  538. imageBase64List: [{
  539. imageId: data.data.id
  540. }],
  541. imageCode: "D03",
  542. })
  543. }
  544. break;
  545. case 'insuredPersonInfo':
  546. if (this.InsuredInfoPositiveList.some(v => v.imageCode == 'D04')) {
  547. this.InsuredInfoPositiveList.map(val => {
  548. if (val.imageCode == 'D04') {
  549. val.imageBase64List[0].imageId = data.data.id;
  550. }
  551. })
  552. } else {
  553. this.InsuredInfoPositiveList.push({
  554. imageBase64List: [{
  555. imageId: data.data.id
  556. }],
  557. imageCode: "D04",
  558. })
  559. }
  560. break;
  561. default:
  562. break;
  563. };
  564. uni.uploadFile({
  565. url: this.$base.baseUrl + '/order/identify/idCard',
  566. filePath: chooseImageRes.tempFilePaths[0],
  567. name: "image2",
  568. header: {
  569. Authorization: store.state.token,
  570. system_code: store.state.system_code ? store.state
  571. .system_code : ''
  572. },
  573. success: (uploadFileRes) => {
  574. let data1 = JSON.parse(uploadFileRes.data).data;
  575. let identifyValidDate = '';
  576. if (!!data1.customerInfo
  577. .identifyValidDate) {
  578. identifyValidDate = data1
  579. .customerInfo
  580. .identifyValidDate
  581. .substr(0, 4) +
  582. '-' + data1
  583. .customerInfo
  584. .identifyValidDate
  585. .substr(4, 2) + '-' +
  586. data1
  587. .customerInfo
  588. .identifyValidDate
  589. .substr(6,
  590. 2)
  591. }
  592. let identifyValidEndDate = '';
  593. if (!!data1.customerInfo
  594. .identifyValidEndDate) {
  595. identifyValidEndDate =
  596. data1.customerInfo
  597. .identifyValidEndDate
  598. .substr(0,
  599. 4) + '-' + data1
  600. .customerInfo
  601. .identifyValidEndDate
  602. .substr(4, 2) + '-' +
  603. data1
  604. .customerInfo
  605. .identifyValidEndDate
  606. .substr(6, 2)
  607. }
  608. this.userback = {
  609. identifyValidDate: identifyValidDate, //起期
  610. identifyValidEndDate: identifyValidEndDate ==
  611. '长期--' ? '9999-12-31' :
  612. identifyValidEndDate, //止期
  613. }
  614. }
  615. });
  616. }
  617. }
  618. });
  619. } else {}
  620. },
  621. }
  622. }
  623. </script>
  624. <style lang="scss" scoped>
  625. .header {
  626. padding: 4rpx 27rpx;
  627. }
  628. .content {
  629. padding: 40rpx 60rpx;
  630. .img {
  631. image {
  632. width: 100%;
  633. height: 360rpx;
  634. }
  635. }
  636. .footer {
  637. .btn {
  638. color: #1F1F1F !important;
  639. }
  640. }
  641. }
  642. </style>