myCard.vue 14 KB

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