myCard.vue 14 KB

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