authorizer.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <!-- @format -->
  2. <template>
  3. <view class="container">
  4. <view style="color: #3c9cff" class="informationTitle"
  5. >填写被授权人信息</view
  6. >
  7. <view class="cardImage">
  8. <view class="updateContent">
  9. <view style="margin: 0 auto">
  10. <u-upload
  11. name="1"
  12. :fileList="fileList1"
  13. @afterRead="afterRead"
  14. @delete="deletePic"
  15. :maxCount="1"
  16. width="280"
  17. height="180"
  18. >
  19. <view class="uploadTipcContent">
  20. <view class="cardImg">
  21. <image
  22. style="height: 180rpx; width: 400rpx"
  23. mode="widthFix"
  24. :src="require('@/static/images/cardzm.png')"
  25. ></image>
  26. <view class="topic"> 请上传被授权人身份证人像照片 </view>
  27. </view>
  28. </view>
  29. <!-- <view class="uploadTipcContent">
  30. <view>
  31. <view style="display: flex; justify-content: center">
  32. <u-icon
  33. name="arrow-upward"
  34. color="#2979ff"
  35. size="28"
  36. ></u-icon>
  37. </view>
  38. <u-button
  39. :customStyle="{ color: '#3c9cff', fontSize: '26rpx' }"
  40. type="text"
  41. size="small"
  42. >点击上传</u-button
  43. >
  44. </view>
  45. <view class="topic"> 请上传被授权人身份证正面照片 </view>
  46. </view> -->
  47. </u-upload>
  48. </view>
  49. </view>
  50. <view class="updateContent">
  51. <view style="margin: 0 auto">
  52. <u-upload
  53. name="2"
  54. :fileList="fileList2"
  55. @afterRead="afterRead"
  56. @delete="deletePic"
  57. :maxCount="1"
  58. width="280"
  59. height="180"
  60. >
  61. <view class="uploadTipcContent">
  62. <view class="cardImg">
  63. <image
  64. style="height: 180rpx; width: 430rpx; margin-left: 30rpx"
  65. mode="widthFix"
  66. :src="require('@/static/images/cardbm.png')"
  67. ></image>
  68. <view class="topic"> 请上传被授权人身份证国徽照片 </view>
  69. </view>
  70. </view>
  71. </u-upload>
  72. </view>
  73. </view>
  74. </view>
  75. <view class="informationContent">
  76. <view class="contentItems">
  77. <u-form ref="uForm" labelWidth="150" :model="form" labelPosition="top">
  78. <view class="content">
  79. <u-form-item
  80. :required="true"
  81. style="border-bottom: 1px solid rgb(242, 242, 242)"
  82. label="被委托人身份证号码:"
  83. prop="idNum"
  84. >
  85. <u-input
  86. placeholder="请输入被委托人身份证号码"
  87. @blur="handleUpadteSync('idNum')"
  88. v-model="form.idNum"
  89. ></u-input>
  90. </u-form-item>
  91. </view>
  92. <view class="content">
  93. <u-form-item
  94. :required="true"
  95. style="border-bottom: 1px solid rgb(242, 242, 242)"
  96. label="被委托人姓名:"
  97. prop="name"
  98. >
  99. <u-input
  100. placeholder="请输入被委托人姓名"
  101. @blur="handleUpadteSync('name')"
  102. v-model="form.name"
  103. ></u-input>
  104. </u-form-item>
  105. </view>
  106. <view class="content">
  107. <u-form-item
  108. :required="true"
  109. style="border-bottom: 1px solid rgb(242, 242, 242)"
  110. label="识别结果:"
  111. >
  112. <view>
  113. <span v-if="isNextDisbaled" style="color: #ff9900"
  114. >识别结果不符,请前往电脑端注册。</span
  115. >
  116. <span v-else style="color: #19be6b"
  117. >被委托人姓名与法定代表/负责人一致</span
  118. >
  119. </view>
  120. </u-form-item>
  121. </view>
  122. <view class="content">
  123. <u-form-item
  124. :required="true"
  125. style="border-bottom: 1px solid rgb(242, 242, 242)"
  126. label="用户名:"
  127. prop="type"
  128. >
  129. <u-input
  130. disabled
  131. :value="formdData.companiesOrcResult.regNum"
  132. ></u-input>
  133. </u-form-item>
  134. </view>
  135. <view class="content">
  136. <u-form-item
  137. :required="true"
  138. style="border-bottom: 1px solid rgb(242, 242, 242)"
  139. label="单位联系电话:"
  140. prop="landline"
  141. >
  142. <u-input
  143. @input="handleLandline"
  144. v-model="form.landline"
  145. placeholder="请输入联系电话"
  146. ></u-input>
  147. </u-form-item>
  148. </view>
  149. <view class="content">
  150. <u-form-item
  151. :required="true"
  152. style="border-bottom: 1px solid rgb(242, 242, 242)"
  153. label="联系人手机号:"
  154. prop="userMobile"
  155. >
  156. <u-input
  157. @input="handleUserMobile"
  158. v-model="form.userMobile"
  159. placeholder="请输入联系人手机号"
  160. ></u-input>
  161. </u-form-item>
  162. </view>
  163. </u-form>
  164. </view>
  165. </view>
  166. </view>
  167. </template>
  168. <script>
  169. import { idcardOCR } from "@/api/companiesRegistered";
  170. export default {
  171. data() {
  172. return {
  173. showModal: false,
  174. fileList1: [],
  175. fileList2: [],
  176. form: {
  177. landline: "",
  178. userMobile: "",
  179. idNum: "",
  180. name: "",
  181. },
  182. rules: {
  183. idNum: [
  184. {
  185. validator: (rule, value, callback) => {
  186. return uni.$u.test.idCard(value);
  187. },
  188. message: "身份证号不正确",
  189. // 触发器可以同时用blur和change
  190. trigger: ["change", "blur"],
  191. },
  192. {
  193. required: true,
  194. message: "被委托人身份证号码不能为空",
  195. trigger: "blur",
  196. },
  197. ],
  198. name: [
  199. {
  200. required: true,
  201. message: "被授权人姓名不能为空",
  202. trigger: "blur",
  203. },
  204. ],
  205. landline: [
  206. {
  207. required: true,
  208. message: "单位联系电话不能为空",
  209. trigger: "blur",
  210. },
  211. {
  212. // 自定义验证函数,见上说明
  213. validator: (rule, value, callback) => {
  214. return uni.$u.test.mobile(value);
  215. },
  216. message: "手机号码不正确",
  217. // 触发器可以同时用blur和change
  218. trigger: ["change", "blur"],
  219. },
  220. ],
  221. userMobile: [
  222. {
  223. required: true,
  224. message: "联系人手机号不能为空",
  225. trigger: "blur",
  226. },
  227. {
  228. // 自定义验证函数,见上说明
  229. validator: (rule, value, callback) => {
  230. return uni.$u.test.mobile(value);
  231. },
  232. message: "手机号码不正确",
  233. // 触发器可以同时用blur和change
  234. trigger: ["change", "blur"],
  235. },
  236. ],
  237. },
  238. };
  239. },
  240. props: {
  241. formdData: {
  242. type: Object,
  243. default: () => ({}),
  244. },
  245. authorizerRef: {},
  246. },
  247. onReady() {
  248. //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
  249. this.$refs.uForm.setRules(this.rules);
  250. this.$emit("update:authorizerRef", this.$refs.uForm);
  251. },
  252. computed: {
  253. isNextDisbaled() {
  254. if (
  255. this.formdData.personCardOrcResult.name &&
  256. this.formdData.companiesOrcResult.person
  257. ) {
  258. return (
  259. this.formdData.personCardOrcResult.name !==
  260. this.formdData.companiesOrcResult.person
  261. );
  262. } else {
  263. return false;
  264. }
  265. },
  266. },
  267. created() {
  268. if (this.formdData.personCardOrcResult.cardFrontImg) {
  269. this.fileList1[0] = {
  270. url: this.$baseUrl + this.formdData.personCardOrcResult.cardFrontImg,
  271. };
  272. this.fileList2[0] = {
  273. url: this.$baseUrl + this.formdData.personCardOrcResult.cardBackImg,
  274. };
  275. }
  276. Object.keys(this.form).forEach((key) => {
  277. this.form[key] = this.formdData.personCardOrcResult[key];
  278. });
  279. },
  280. methods: {
  281. handleUpadteSync(key) {
  282. this.$emit("update:formdData", {
  283. ...this.formdData,
  284. personCardOrcResult: {
  285. ...this.formdData.personCardOrcResult,
  286. [key]: this.form[key],
  287. },
  288. });
  289. },
  290. handleLandline() {
  291. this.$emit(
  292. "update:formdData",
  293. Object.assign({
  294. ...this.formdData,
  295. personCardOrcResult: {
  296. ...this.formdData.personCardOrcResult,
  297. landline: this.form.landline,
  298. },
  299. })
  300. );
  301. },
  302. handleUserMobile() {
  303. this.$emit(
  304. "update:formdData",
  305. Object.assign({
  306. ...this.formdData,
  307. personCardOrcResult: {
  308. ...this.formdData.personCardOrcResult,
  309. userMobile: this.form.userMobile,
  310. },
  311. })
  312. );
  313. },
  314. //处理身份证ocr识别
  315. async handleCardOrc() {
  316. uni.showLoading({
  317. title: "智能识别中...",
  318. });
  319. try {
  320. let {
  321. data: { idcardDownOcrResult, idcardUpOcrResult },
  322. } = await idcardOCR([this.fileList1[0].url, this.fileList2[0].url]);
  323. this.$emit(
  324. "update:formdData",
  325. Object.assign({
  326. ...this.formdData,
  327. personCardOrcResult: {
  328. name: idcardUpOcrResult.name,
  329. idNum: idcardUpOcrResult.idNum,
  330. cardFrontImg: this.fileList1[0].url,
  331. cardBackImg: this.fileList2[0].url,
  332. },
  333. })
  334. );
  335. this.form.name = idcardUpOcrResult.name;
  336. this.form.idNum = idcardUpOcrResult.idNum;
  337. setTimeout(() => {
  338. uni.hideLoading();
  339. console.log(this.formdData);
  340. }, 2000);
  341. } catch (error) {
  342. uni.showLoading({
  343. title: "识别错误",
  344. });
  345. setTimeout(() => {
  346. uni.hideLoading();
  347. }, 2000);
  348. } finally {
  349. }
  350. },
  351. deletePic(event) {
  352. this[`fileList${event.name}`].splice(event.index, 1);
  353. },
  354. // 新增图片
  355. async afterRead(event) {
  356. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  357. let lists = [].concat(event.file);
  358. let fileListLen = this[`fileList${event.name}`].length;
  359. lists.map((item) => {
  360. this[`fileList${event.name}`].push({
  361. ...item,
  362. status: "uploading",
  363. message: "上传中",
  364. });
  365. });
  366. for (let i = 0; i < lists.length; i++) {
  367. const result = await this.uploadFilePromise(lists[i].url);
  368. let item = this[`fileList${event.name}`][fileListLen];
  369. this[`fileList${event.name}`].splice(
  370. fileListLen,
  371. 1,
  372. Object.assign(item, {
  373. status: "success",
  374. message: "",
  375. url: JSON.parse(result.data).fileName,
  376. })
  377. );
  378. fileListLen++;
  379. }
  380. this.fileList1.length && this.fileList2.length && this.handleCardOrc();
  381. },
  382. //上传
  383. uploadFilePromise(url) {
  384. return new Promise((resolve, reject) => {
  385. let a = uni.uploadFile({
  386. url: `${this.$baseUrl}/api/common/upload`, // 仅为示例,非真实的接口地址
  387. filePath: url,
  388. name: "file",
  389. success: (res) => {
  390. setTimeout(() => {
  391. resolve(res);
  392. }, 1000);
  393. },
  394. });
  395. });
  396. },
  397. },
  398. };
  399. </script>
  400. <style lang="scss">
  401. .cardImg {
  402. width: 100%;
  403. display: flex;
  404. justify-content: center;
  405. }
  406. .topic {
  407. color: #909399;
  408. font-size: 24rpx;
  409. width: 400rpx;
  410. margin: 20rpx auto 0;
  411. font-family: "宋体";
  412. position: absolute;
  413. bottom: 20rpx;
  414. left: 50%;
  415. transform: translateX(-43%);
  416. }
  417. .uploadTipcContent {
  418. width: 600rpx;
  419. height: 260rpx;
  420. position: relative;
  421. // padding: 30rpx;
  422. // border: 1px dotted#909399;
  423. }
  424. .updateContent {
  425. display: flex;
  426. background: #fff;
  427. padding: 30rpx;
  428. }
  429. .informationTitle {
  430. margin-bottom: 30rpx;
  431. font-size: 30;
  432. }
  433. .contentItems {
  434. width: 100%;
  435. border-radius: 6px;
  436. background: #fff;
  437. margin: 0rpx auto 30rpx;
  438. padding: 20rpx 30rpx 20rpx;
  439. .content {
  440. border-bottom: 1px solid rgb(242, 242, 242);
  441. }
  442. .content:last-child {
  443. border-bottom: none;
  444. }
  445. .title {
  446. font-size: 30rpx;
  447. color: black;
  448. letter-spacing: 3rpx;
  449. }
  450. .message {
  451. margin-left: 70rpx;
  452. text-align: left;
  453. // width: 420rpx;
  454. font-size: 30rpx;
  455. color: rgb(146, 146, 146);
  456. // white-space: nowrap;
  457. // /* 禁止文本换行 */
  458. // overflow: hidden;
  459. // /* 隐藏超出容器的文本 */
  460. // text-overflow: ellipsis;
  461. /* 使用省略号表示被截断的文本 */
  462. }
  463. }
  464. </style>