myCard.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <template>
  2. <view>
  3. <view>
  4. <u-navbar placeholder title="我的证件" @leftClick="leftClick">
  5. </u-navbar>
  6. <view class="flex">
  7. <!-- <view :style="{'margin-top':navHeight +'px'}" class="flex"> -->
  8. <view @click='addclick' class="button">新增</view>
  9. <view @click='share' class="button">分享</view>
  10. <!-- <button ref='share' open-type="share" class="button">分享</button> -->
  11. <view @click='imageOCR' class="button">识别号码</view>
  12. </view>
  13. <mescroll-body v-if='!addstatus&&cardList.length==0||cardList.length>0' ref="mescrollRef"
  14. @init="mescrollInit" @up="upCallback" @down="downCallback">
  15. <view v-if='cardList.length>0' class="">
  16. <view v-for='(item,index) in cardList' class="">
  17. <view v-if='!item.editstatus'>
  18. {{item.certificateName}}
  19. <text v-if='item.personNo'>({{item.personNo1}})</text>
  20. <u-icon v-if='item.personNo' @click='clip(0,item)' name="file-text-fill" color="#2979ff"
  21. size="28"></u-icon>
  22. <text v-if='item.bankNo'>({{item.bankNo1}})</text>
  23. <u-icon v-if='item.bankNo' @click='clip(1,item)' name="file-text-fill" color="#2979ff"
  24. size="28"></u-icon>
  25. </view>
  26. <u--input v-else v-model="item.certificateName" placeholder="输入证件名称" border="none"></u--input>
  27. <view @click='edit(item)'>{{!item.editstatus?'编辑':'完成'}}</view>
  28. <u-checkbox-group v-model="item.checked" placement="column"
  29. @change="checkboxChange($event,index,item)">
  30. <u-checkbox :name='index+1' :customStyle="{marginBottom: '8px'}">
  31. </u-checkbox>
  32. </u-checkbox-group>
  33. <image v-if='!item.editstatus' :src="item.certificateImage" mode=""></image>
  34. <u-upload v-else @afterRead="afterRead" :fileList="fileList2" @delete="deletePic" name="2"
  35. multiple :maxCount="1"></u-upload>
  36. <u-icon @click="del(item)" name="trash-fill" color="#2979ff" size="28"></u-icon>
  37. </view>
  38. <view></view>
  39. </view>
  40. </mescroll-body>
  41. <view v-if='addstatus' class="">
  42. <view class="">
  43. <u--input v-model="cardData.certificateName" placeholder="输入证件名称" border="none"></u--input>
  44. </view>
  45. <view @click='add'>提交</view>
  46. <view>
  47. <u-upload @afterRead="afterRead" :fileList="fileList1" @delete="deletePic" name="1" multiple
  48. :maxCount="1"></u-upload>
  49. </view>
  50. </view>
  51. </view>
  52. <u-picker @cancel='show=false' @confirm='pickerConfirm' title='识别类型' :show="show" :columns="columns"></u-picker>
  53. <u-popup :show="popupshow" mode="bottom">
  54. <view>
  55. <view class="share-to">
  56. <text>分享到</text>
  57. </view>
  58. <view class="content">
  59. <view class="block">
  60. <button class="wechat" open-type="share">
  61. <text class="iconfont icon-pengyouquan"></text>
  62. <!-- <image src="/static/img/wechat.png" mode="aspectFill"></image> -->
  63. <button class="shareBtn" type="default" data-name="shareBtn">
  64. 分享微信</button>
  65. </button>
  66. </view>
  67. <view class="block" @click="toUrl()">
  68. <button class="moment">
  69. <text class="iconfont icon-weixin"></text>
  70. <!-- <image src="/static/img/moment.png" mode="aspectFill"></image> -->
  71. <text>朋友圈</text>
  72. </button>
  73. </view>
  74. </view>
  75. <view class="cancel" @click.stop="handleHiddenShare">
  76. <text>取消</text>
  77. </view>
  78. </view>
  79. </u-popup>
  80. <u-modal @cancel='modalshow=false' confirmText='删除' showCancelButton='true' @confirm='delConfirm'
  81. :show="modalshow" title="提示" content='确定删除证件?'></u-modal>
  82. <u-modal @cancel='credentialscancel' cancelText='重新识别' confirmText='确认号码' showCancelButton='true'
  83. @confirm='credentialsConfirm' :show="credentialsShow" title="提示">
  84. <view class="slot-content">
  85. 证件号码
  86. <u--input v-if='shibie=="识别身份证号"' v-model="credentials.recPersonNo" placeholder="输入证件名称"
  87. border="none"></u--input>
  88. <u--input v-if='shibie=="识别银行卡号"' v-model="credentials.bankNo" placeholder="输入证件名称"
  89. border="none"></u--input>
  90. </view>
  91. </u-modal>
  92. <u-modal :show="modalstatusshow" confirmText='继续返回' cancelText='取消' @confirm='confirm' @cancel='cancel'
  93. showCancelButton='true' title="提示" content='有证件处于编辑状态未提交。'></u-modal>
  94. <u-toast ref="uToast"></u-toast>
  95. </view>
  96. </template>
  97. <script>
  98. import uploadImage from '@/components/ossutil/uploadFile.js';
  99. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  100. export default {
  101. mixins: [MescrollMixin],
  102. data() {
  103. return {
  104. show: false,
  105. modalshow: false,
  106. modalstatusshow: false,
  107. popupshow: false,
  108. columns: [
  109. ['识别身份证号', '识别银行卡号']
  110. ],
  111. userInfo: {},
  112. cardData: {},
  113. cardList: [],
  114. fileList1: [],
  115. fileList2: [],
  116. checkedList: [],
  117. addstatus: false,
  118. id: '',
  119. credentialsShow: false,
  120. credentials: {},
  121. shibie: '',
  122. shibieList: [],
  123. canReset: false
  124. };
  125. },
  126. onLoad() {
  127. // this.getList()
  128. },
  129. onShow() {
  130. this.userInfo = uni.getStorageSync("userInfo")
  131. this.cardData.commonId = uni.getStorageSync("userInfo").id
  132. this.$nextTick(function() {
  133. this.canReset && this.mescroll.resetUpScroll() // 重置列表数据为第一页
  134. this.canReset && this.mescroll.scrollTo(0, 0) // 重置列表数据为第一页时,建议把滚动条也重置到顶部,避免无法再次翻页的问题
  135. this.canReset = true // 过滤第一次的onShow事件,避免初始化界面时重复触发upCallback, 无需配置auto:false
  136. });
  137. },
  138. methods: {
  139. clip(status, item) {
  140. uni.setClipboardData({
  141. data: status == 1 ? item.bankNo : item.personNo, // e是你要保存的内容
  142. success: function() {
  143. uni.showToast({
  144. title: '复制成功',
  145. icon: 'none'
  146. })
  147. }
  148. })
  149. },
  150. toUrl() {
  151. // this.carInfo.car_id
  152. // uni.navigateTo({
  153. // url: '/pages/mySet/lookCard',
  154. // })
  155. // this.handleHiddenShare()
  156. },
  157. edit(item) {
  158. if (item.editstatus) {
  159. this.$request.baseRequest('admin.unimall.certificateManagementInfo', 'update', {
  160. certificateManagementInfo: JSON.stringify(item)
  161. }, failres => {
  162. console.log('res+++++', failres.errmsg)
  163. this.$refs.uToast.show({
  164. type: 'error',
  165. message: failres.errmsg,
  166. })
  167. uni.hideLoading()
  168. }).then(res => {
  169. this.$refs.uToast.show({
  170. type: 'success',
  171. message: '编辑成功',
  172. })
  173. this.modalshow = false
  174. this.checkedList = []
  175. uni.hideLoading()
  176. this.mescroll.resetUpScroll()
  177. })
  178. } else {
  179. item.editstatus = true
  180. this.fileList2 = [{
  181. url: item.certificateImage
  182. }]
  183. }
  184. },
  185. delConfirm() {
  186. this.$request.baseRequest('admin.unimall.certificateManagementInfo', 'delete', {
  187. id: this.id
  188. }, failres => {
  189. console.log('res+++++', failres.errmsg)
  190. this.$refs.uToast.show({
  191. type: 'error',
  192. message: failres.errmsg,
  193. })
  194. uni.hideLoading()
  195. }).then(res => {
  196. this.$refs.uToast.show({
  197. type: 'success',
  198. message: '删除成功',
  199. })
  200. this.modalshow = false
  201. this.checkedList = []
  202. uni.hideLoading()
  203. this.mescroll.resetUpScroll()
  204. })
  205. },
  206. pickerConfirm(e) {
  207. this.show = false
  208. console.log(e)
  209. uni.showLoading({
  210. title: '数据加载中',
  211. mask: true
  212. })
  213. var type = '',
  214. type1 = ''
  215. this.shibie = e.value[0]
  216. this.shibieList = JSON.parse(JSON.stringify(this.cardList[this.checkedList[0]]))
  217. if (e.value[0] == '识别身份证号') {
  218. type = 'admin.unimall.certificateManagementInfo'
  219. type1 = 'personShibie'
  220. } else if (e.value[0] == '识别银行卡号') {
  221. type = 'admin.unimall.certificateManagementInfo'
  222. type1 = 'bankShibie'
  223. }
  224. this.$request.baseRequest(type, type1, {
  225. certificateImage: this.cardList[this.checkedList[0]].certificateImage
  226. }, failres => {
  227. console.log('res+++++', failres.errmsg)
  228. this.$refs.uToast.show({
  229. type: 'error',
  230. message: failres.errmsg,
  231. })
  232. uni.hideLoading()
  233. }).then(res => {
  234. console.log(res.data)
  235. this.$refs.uToast.show({
  236. type: 'success',
  237. message: '识别成功',
  238. })
  239. uni.hideLoading()
  240. this.credentials = res.data
  241. this.credentialsShow = true
  242. })
  243. },
  244. checkboxChange(e, i) {
  245. console.log(e[0], i)
  246. if (e[0]) {
  247. this.checkedList.push(i)
  248. } else {
  249. var index = this.checkedList.findIndex((item) => {
  250. return item == i
  251. })
  252. this.checkedList.splice(index, 1)
  253. }
  254. // for(var i=0;i<this.cardList.length;i++){
  255. // console.log(this.cardList[i].checked)
  256. // // if(this.cardList[i].checkedList.length>0){
  257. // // this.checkedList.push(i)
  258. // // }
  259. // }
  260. console.log(this.checkedList)
  261. },
  262. share() {
  263. if (this.checkedList.length == 0) {
  264. this.$refs.uToast.show({
  265. type: 'error',
  266. message: '请勾选想要识别的证件!',
  267. })
  268. return
  269. }
  270. this.popupshow = true
  271. },
  272. imageOCR() {
  273. console.log(this.cardList, this.checkedList)
  274. if (this.checkedList.length == 0) {
  275. this.$refs.uToast.show({
  276. type: 'error',
  277. message: '请勾选想要识别的证件!',
  278. })
  279. return
  280. }
  281. if (this.checkedList.length > 1) {
  282. this.$refs.uToast.show({
  283. type: 'error',
  284. message: '一次只能勾选一张证件!',
  285. })
  286. return
  287. }
  288. this.show = true
  289. },
  290. credentialsConfirm() {
  291. var type = '',
  292. type1 = ''
  293. if (this.shibie == '识别身份证号') {
  294. this.shibieList.personNo = this.credentials.recPersonNo
  295. } else if (this.shibie == '识别银行卡号') {
  296. this.shibieList.bankNo = this.credentials.bankNo
  297. }
  298. // if(this.shibie=='识别身份证号'){
  299. // type='admin.unimall.certificateManagementInfo'
  300. // type1='personShibie'
  301. // }else if(this.shibie=='识别银行卡号'){
  302. // type='admin.unimall.certificateManagementInfo'
  303. // type1='bankShibie'
  304. // }
  305. this.$request.baseRequest('admin.unimall.certificateManagementInfo', 'update', {
  306. certificateManagementInfo: JSON.stringify(this.shibieList)
  307. }, failres => {
  308. console.log('res+++++', failres.errmsg)
  309. this.$refs.uToast.show({
  310. type: 'error',
  311. message: failres.errmsg,
  312. })
  313. uni.hideLoading()
  314. }).then(res => {
  315. this.$refs.uToast.show({
  316. type: 'success',
  317. message: '编辑成功',
  318. })
  319. this.credentialsShow = false
  320. this.checkedList = []
  321. uni.hideLoading()
  322. this.mescroll.resetUpScroll()
  323. })
  324. },
  325. confirm() {
  326. uni.navigateBack()
  327. },
  328. cancel() {
  329. this.modalstatusshow = false
  330. },
  331. leftClick() {
  332. if (this.cardData.certificateImage) {
  333. console.log(22222)
  334. this.modalstatusshow = true
  335. } else {
  336. uni.navigateBack()
  337. }
  338. },
  339. del(item) {
  340. this.modalshow = true
  341. this.id = item.id
  342. },
  343. addclick() {
  344. this.addstatus = true
  345. },
  346. add() {
  347. if (!this.cardData.certificateImage) {
  348. this.$refs.uToast.show({
  349. type: 'error',
  350. message: '请上传证件照片!',
  351. })
  352. return
  353. }
  354. uni.showLoading({
  355. title: '数据加载中'
  356. })
  357. this.$request.baseRequest('admin.unimall.certificateManagementInfo', 'add', {
  358. certificateManagementInfo: JSON.stringify(this.cardData)
  359. }, failres => {
  360. console.log('res+++++', failres.errmsg)
  361. this.$refs.uToast.show({
  362. type: 'error',
  363. message: failres.errmsg,
  364. })
  365. uni.hideLoading()
  366. }).then(res => {
  367. this.$refs.uToast.show({
  368. type: 'success',
  369. message: '提交成功',
  370. })
  371. // if (res.errno == 200) {
  372. uni.hideLoading()
  373. this.fileList1 = []
  374. this.addstatus = false
  375. this.cardData = {
  376. commonId: uni.getStorageSync("userInfo").id
  377. }
  378. this.mescroll.resetUpScroll()
  379. // }
  380. })
  381. },
  382. deletePic(event) {
  383. this[`fileList${event.name}`].splice(event.index, 1)
  384. this.cardData.certificateImage = this[`fileList${event.name}`].toString()
  385. },
  386. // 新增图片
  387. async afterRead(event) {
  388. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  389. let lists = [].concat(event.file)
  390. let fileListLen = this[`fileList${event.name}`].length
  391. lists.map((item) => {
  392. this[`fileList${event.name}`].push({
  393. ...item,
  394. status: 'uploading',
  395. message: '上传中'
  396. })
  397. })
  398. // console.log(event,111111,fileListLen)
  399. for (let i = 0; i < lists.length; i++) {
  400. const result = await this.uploadFilePromise(lists[i].url)
  401. this.cardData.certificateImage = result
  402. this[`fileList${event.name}`][fileListLen] = {}
  403. let item = this[`fileList${event.name}`][fileListLen]
  404. console.log(item)
  405. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  406. status: 'success',
  407. message: '',
  408. url: result
  409. }))
  410. fileListLen++
  411. }
  412. console.log(this[`fileList${event.name}`])
  413. },
  414. uploadFilePromise(url) {
  415. console.log(url)
  416. return new Promise((resolve, reject) => {
  417. uploadImage(url, 'cardImages/',
  418. result => {
  419. console.log(result, 22222)
  420. resolve(result)
  421. }
  422. )
  423. })
  424. },
  425. mescrollInit() {
  426. },
  427. downCallback() {
  428. var that = this
  429. this.$nextTick(() => {
  430. // mescroll.endSuccess(data.result);
  431. that.mescroll.resetUpScroll()
  432. });
  433. },
  434. upCallback(page) {
  435. var that = this
  436. uni.showLoading({
  437. title: '数据加载中'
  438. })
  439. this.$request.baseRequest('admin.unimall.certificateManagementInfo', 'list', {
  440. page: page.num,
  441. limit: page.size,
  442. commonId: uni.getStorageSync("userInfo").id
  443. }, failres => {
  444. console.log('res+++++', failres.errmsg)
  445. this.$refs.uToast.show({
  446. type: 'error',
  447. message: failres.errmsg,
  448. })
  449. this.mescroll.endBySize(curPageLen, totalPage)
  450. uni.hideLoading()
  451. }).then(res => {
  452. console.log(res)
  453. if (page.num == 1) this.cardList = [];
  454. let curPageLen = res.data.items.length;
  455. let totalPage = res.data.total;
  456. if (res.data.items.length > 0) {
  457. for (var i = 0; i < res.data.items.length; i++) {
  458. res.data.items[i].editstatus = false
  459. if (res.data.items[i].personNo) res.data.items[i].personNo1 = '*' + (res.data.items[i]
  460. .personNo.substring(res.data.items[i].personNo.length - 4))
  461. if (res.data.items[i].bankNo) res.data.items[i].bankNo1 = '*' + (res.data.items[i]
  462. .bankNo.substring(res.data.items[i].bankNo.length - 4))
  463. }
  464. }
  465. this.cardList = this.cardList.concat(res.data.items)
  466. this.cardData.certificateName = '证件' + '-' + (this.cardList.length + 1)
  467. this.$nextTick(() => {
  468. console.log(that)
  469. // mescroll.endSuccess(data.result);
  470. that.mescroll.endBySize(curPageLen, totalPage)
  471. });
  472. // if (res.errno == 200) {
  473. uni.hideLoading()
  474. // }
  475. })
  476. },
  477. }
  478. }
  479. </script>
  480. <style lang="scss" scoped>
  481. button::after {
  482. border: initial;
  483. }
  484. .share {
  485. width: 100%;
  486. height: 100%;
  487. }
  488. .share-box {
  489. width: 100%;
  490. height: 100%;
  491. position: fixed;
  492. top: 0rpx;
  493. left: 0rpx;
  494. bottom: 0rpx;
  495. right: 0rpx;
  496. background-color: rgba(0, 0, 0, 0.4);
  497. transition: .3s;
  498. z-index: 999;
  499. }
  500. .block>button {
  501. display: flex;
  502. flex-direction: column;
  503. justify-content: center;
  504. align-items: center;
  505. background-color: white;
  506. border-style: none;
  507. width: 300rpx;
  508. height: 180rpx;
  509. // outline:none;
  510. // opacity: 0;
  511. }
  512. // 进入分享动画
  513. .share-show {
  514. transition: all 0.3s ease;
  515. transform: translateY(0%) !important;
  516. }
  517. // 离开分享动画
  518. .share-item {
  519. .share-to {
  520. width: 100%;
  521. height: 3rem;
  522. display: flex;
  523. justify-content: center;
  524. align-items: center;
  525. &::after {
  526. content: '';
  527. width: 240rpx;
  528. height: 0rpx;
  529. border-top: 1px solid #E4E7ED;
  530. -webkit-transform: scaleY(0.5);
  531. transform: scaleY(0.5);
  532. margin-left: 30rpx;
  533. }
  534. &::before {
  535. content: '';
  536. width: 240rpx;
  537. height: 0rpx;
  538. border-top: 1px solid #E4E7ED;
  539. -webkit-transform: scaleY(0.5);
  540. transform: scaleY(0.5);
  541. margin-right: 30rpx;
  542. }
  543. }
  544. .content {
  545. width: 100%;
  546. height: auto;
  547. display: flex;
  548. flex-wrap: wrap;
  549. .block {
  550. width: 50%;
  551. display: flex;
  552. flex-direction: column;
  553. justify-content: center;
  554. align-items: center;
  555. height: 180rpx;
  556. image {
  557. width: 80rpx;
  558. height: 80rpx;
  559. }
  560. text {
  561. margin-top: 16rpx;
  562. font-size: 28rpx;
  563. color: #606266;
  564. }
  565. }
  566. }
  567. .cancel {
  568. width: 100%;
  569. height: 3rem;
  570. display: flex;
  571. justify-content: center;
  572. align-items: center;
  573. border-top: 1rpx solid #E4E7ED;
  574. }
  575. }
  576. </style>