index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. <template>
  2. <view class="content" :class="{ blueBg: actionInd!=1,greenBg:actionInd==1}">
  3. <view class="coupon_transfer" >
  4. <view class="user">
  5. <view class="imgbox"><image class="img" :src="userinfo.avatar" mode=" scaleToFill"></image></view>
  6. <view class="niceName">{{ userinfo.nickname }}</view>
  7. </view>
  8. <view class="erwema">
  9. <view class="qrbox">
  10. <view class="payMoney" v-if="actionInd == 1">收款码</view>
  11. <view class="payMoney" v-if="actionInd == 0">付款码</view>
  12. <tki-qrcodes
  13. :cid="cid"
  14. ref="qrcode"
  15. :val="val"
  16. :size="size"
  17. :unit="unit"
  18. :background="background"
  19. :foreground="foreground"
  20. :pdground="pdground"
  21. :icon="icon"
  22. :iconSize="iconSize"
  23. :lv="lv"
  24. :onval="onval"
  25. :loadMake="loadMake"
  26. :usingComponents="usingComponents"
  27. @result="qrR"
  28. ></tki-qrcodes>
  29. <!-- <view class="setMoney" @click="openApp">
  30. 设置金额
  31. </view> -->
  32. <view class="setType flex" v-if="actionInd == 0" @click="showChooseType">
  33. <image src="../../static/icon/jf.png" mode="" class="type-logo"></image>
  34. <view class="type-wrapper">
  35. <view class="type-tit">积分</view>
  36. <view class="type-info">使用积分支付</view>
  37. </view>
  38. <view class="sele-wrap">
  39. <image src="../../static/img/back.png" mode="" class="selecte-ic"></image>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="bottomTab flex">
  46. <view class="item1" @click="clickItem(0)" :class="{ action: actionInd == 0 }">
  47. <view><image class="img" src="../../static/icon/pay2.png" mode=" widthFix"></image></view>
  48. <view class="text">付款码</view>
  49. </view>
  50. <view class="item1" @click="clickItem(1)" :class="{ action: actionInd == 1 }">
  51. <view><image class="img" src="../../static/icon/pay1.png" mode=" widthFix"></image></view>
  52. <view class="text">收款码</view>
  53. </view>
  54. <view class="item1" @click="clickItem(2)" :class="{ action: actionInd == 2 }">
  55. <view><image class="img" src="../../static/icon/pay3.png" mode=" widthFix"></image></view>
  56. <view class="text">扫一扫</view>
  57. </view>
  58. <view class="item1" @click="openList" :class="{ action: actionInd == 3 }">
  59. <view><image class="img" src="../../static/icon/pay4.png" mode=" widthFix"></image></view>
  60. <view class="text">记录</view>
  61. </view>
  62. </view>
  63. <uniPopup ref="popup1" type="dialog">
  64. <uni-popup-dialog
  65. mode="input"
  66. type="input"
  67. title="支付"
  68. placeholder="请输入支付金额"
  69. :duration="2000"
  70. :before-close="true"
  71. @close="close"
  72. @confirm="confirm"
  73. ></uni-popup-dialog>
  74. </uniPopup>
  75. <uniPopup ref="popup2" type="message"><uni-popup-message type="success" message="支付成功" :duration="2000"></uni-popup-message></uniPopup>
  76. <uniPopup ref="popupPay" type="bottom">
  77. <view class="popup-box">
  78. <view class="popup-pay">
  79. <view class="paybox-top flex">
  80. <view class="type">选择支付方式</view>
  81. <view class="image" @click="close"><image src="../../static/img/x.png" mode="aspectFill"></image></view>
  82. </view>
  83. <view class="paybox-main flex">
  84. <view class="zftype flex">
  85. <image src="../../static/img/yue.png" mode="aspectFill"></image>
  86. <view class="zf">余额支付</view>
  87. </view>
  88. <label class="radio" @click="changePayType(1)">
  89. <radio style="transform:scale(0.7)" class="rad" value="" :checked="payType == 1" color="#5dbc7c"></radio>
  90. </label>
  91. </view>
  92. <view class="paybox-main flex">
  93. <view class="zftype flex">
  94. <image src="../../static/icon/jf.png" mode="aspectFill"></image>
  95. <view class="zf">积分支付</view>
  96. </view>
  97. <label class="radio1" @click="changePayType(2)"><radio style="transform:scale(0.7)" value="" :checked="payType == 2" color="#5dbc7c"></radio></label>
  98. </view>
  99. <view class="paybox-main flex">
  100. <view class="zftype flex">
  101. <image src="../../static/icon/xfq.png" mode="aspectFill"></image>
  102. <view class="zf">消费券支付</view>
  103. </view>
  104. <label class="radio1" @click="changePayType(3)"><radio style="transform:scale(0.7)" value="" :checked="payType == 3" color="#5dbc7c"></radio></label>
  105. </view>
  106. <view class="paybtn">
  107. 确定切换
  108. </view>
  109. </view>
  110. </view>
  111. </uniPopup>
  112. </view>
  113. </template>
  114. <script>
  115. import tkiQrcodes from '@/components/tki-qrcode/tki-qrcode.vue';
  116. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  117. import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue';
  118. import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue';
  119. import { getUserInfo } from '@/api/login.js';
  120. import { receivedCollectionCode, receivedPaymentCode, receivedCodeState, receivedPaymentCreate, receivedLst, collectionLst, collectionSetTip } from '@/api/received.js';
  121. // #ifdef H5
  122. import { mapState } from 'vuex';
  123. import { weixindata } from '@/utils/wxAuthorized';
  124. // #endif
  125. import Voice from '@/utils/QS-baiduyy.js';
  126. export default {
  127. components: { tkiQrcodes, uniPopup, uniPopupDialog, uniPopupMessage },
  128. // #ifdef H5
  129. computed: {
  130. ...mapState(['weichatObj'])
  131. },
  132. // #endif
  133. data() {
  134. return {
  135. url: '',
  136. uid: '',
  137. qrsize: 80, // 二维码大小
  138. cid: 'tki-qrcode-canvas', //canvasId,页面存在多个二维码组件时需设置不同的ID
  139. size: 500, //生成的二维码大小
  140. unit: 'upx', //大小单位尺寸
  141. // show: true,//默认使用组件中的image标签显示二维码
  142. val: '', //要生成的内容
  143. background: '#ffffff', //二维码背景色
  144. foreground: '#333333', //二维码前景色
  145. pdground: '#333333', //二维码角标色
  146. icon: '', //二维码图标URL(必须是本地图片,网络图需要先下载至本地)
  147. iconSize: 40, //二维码图标大小
  148. lv: 3, //容错级别
  149. onval: true, //监听val值变化自动重新生成二维码
  150. loadMake: false, //组件初始化完成后自动生成二维码,val需要有值
  151. usingComponents: false, //是否使用了自定义组件模式(主要是为了修复非自定义组件模式时 v-if 无法生成二维码的问题)
  152. showLoading: false, //是否显示loading
  153. loadingText: '二维码生成中', //loading文字
  154. src: '', // 二维码生成后的图片地址或base64
  155. ratio: 1, //页面比例用于计算
  156. ctxSrc: '', //要显示的图片
  157. loading: true, //是否载入图片中
  158. canHeight: '',
  159. canWeidth: '',
  160. userinfo: {}, //用户信息
  161. actionInd: 1, //默认展示收款码
  162. setTimeOutPay: null, //付款倒计时
  163. getMoneyList: null, //收款记录倒计时倒计时
  164. showSqr: true,
  165. code: '', //保存扫码code
  166. indexNum: 0, //默认没有商品
  167. payType: 0,
  168. };
  169. },
  170. onLoad(option) {
  171. this.loadlist;
  172. this.userinfo = uni.getStorageSync('userInfo');
  173. // 加载用户数据
  174. this.getUserInfo();
  175. // #ifdef H5
  176. // 获取是否为微信内核浏览器
  177. this.showSqr = uni.getStorageSync('weichatBrowser') || false;
  178. weixindata();
  179. // #endif
  180. },
  181. onReady() {
  182. // Voice('成功收款100000000元')
  183. },
  184. onShow() {
  185. // 开启倒计时
  186. this.setTimePay();
  187. },
  188. onHide() {
  189. clearInterval(this.setTimeOutPay);
  190. clearInterval(this.getMoneyList);
  191. },
  192. // 监听页面卸载
  193. onUnload() {
  194. // 关闭倒计时
  195. clearInterval(this.setTimeOutPay);
  196. clearInterval(this.getMoneyList);
  197. },
  198. // 监听页面后退
  199. onBackPress() {
  200. // 关闭倒计时
  201. clearInterval(this.setTimeOutPay);
  202. clearInterval(this.getMoneyList);
  203. },
  204. methods: {
  205. // 获取收款记录
  206. collectionLst() {
  207. collectionLst()
  208. .then(e => {
  209. console.log(e);
  210. // 循环处理播报语音
  211. e.data.data.forEach((d, ind) => {
  212. Voice({
  213. voiceSet: {
  214. tex: '满园春收款' + (+d.amount - d.service_charge) + '元'
  215. },
  216. audioSet: {
  217. volume: 1
  218. },
  219. lineUp: true // 加入语音队列
  220. });
  221. //清除记录
  222. collectionSetTip({ id: d.id });
  223. });
  224. })
  225. .catch(e => {});
  226. },
  227. // 获取用户信息
  228. getUserInfo() {
  229. let obj = this;
  230. getUserInfo({})
  231. .then(({ data }) => {
  232. obj.userinfo = data;
  233. // 加载收款码
  234. obj.receivedCollectionCode();
  235. // 调用循环
  236. // obj.setTimePay();
  237. // #ifdef H5
  238. uni.showModal({
  239. title: '提示',
  240. content: '打开支付提示成功!',
  241. showCancel: false,
  242. });
  243. // #endif
  244. })
  245. .catch(e => {
  246. console.log(e);
  247. });
  248. },
  249. /**
  250. * 点击取消按钮触发
  251. * @param {Object} done
  252. */
  253. close(done) {
  254. // TODO 做一些其他的事情,before-close 为true的情况下,手动执行 done 才会关闭对话框
  255. // ...
  256. done();
  257. },
  258. /**
  259. * 点击确认按钮触发
  260. * @param {Object} done
  261. * @param {Object} value
  262. */
  263. confirm(done, value) {
  264. // 输入框的值
  265. receivedPaymentCreate({
  266. code: this.code,
  267. amount: value
  268. })
  269. .then(({ data }) => {
  270. uni.showModal({
  271. title: '提示',
  272. content: '成功',
  273. showCancel: false
  274. });
  275. })
  276. .catch(e => {
  277. uni.showModal({
  278. title: '提示',
  279. content: e.message,
  280. showCancel: false
  281. });
  282. console.log(e);
  283. });
  284. // TODO 做一些其他的事情,手动执行 done 才会关闭对话框
  285. // ...
  286. done();
  287. },
  288. // payVdeo(){
  289. // var mess = document.getElementById('ttsText').value;
  290. // var msg = new SpeechSynthesisUtterance(mess);
  291. // msg.volume = 100;
  292. // msg.rate = 1;
  293. // msg.pitch = 1.5;
  294. // console.log(msg);
  295. // window.speechSynthesis.speak(msg);
  296. // },
  297. // 开启循环倒计时
  298. setTimePay() {
  299. // 判断当前是否为付款码
  300. if (this.actionInd == 0) {
  301. this.setTimeOutPay = setInterval(() => {
  302. this.receivedCodeState();
  303. }, 5000);
  304. }
  305. // 获取首付款信息
  306. this.getMoneyList = setInterval(e => {
  307. this.collectionLst();
  308. }, 5000);
  309. },
  310. // 判断付款码是否可以使用
  311. receivedCodeState() {
  312. let obj = this;
  313. // 查询是否过期
  314. receivedCodeState({
  315. code: obj.val
  316. })
  317. .then(e => {
  318. // 无效
  319. if (e.msg == 'overdue') {
  320. obj.receivedPaymentCode();
  321. }
  322. // 已使用
  323. else if (e.msg == 'use') {
  324. uni.showModal({
  325. title: '提示',
  326. content: '已支付成功',
  327. showCancel: false
  328. });
  329. obj.receivedPaymentCode();
  330. }
  331. })
  332. .catch(e => {
  333. console.log(e);
  334. });
  335. },
  336. // 开启验证是否已经过期或使用付款成功
  337. // receivedCodeState(){
  338. // },
  339. // 跳转到记录页面
  340. openList() {
  341. clearInterval(this.setTimeOutPay);
  342. clearInterval(this.getMoneyList);
  343. // this.$refs.popup1.open();
  344. // uni.navigateTo({
  345. // url: '/pages/wallet/wallet'
  346. // });
  347. uni.navigateTo({
  348. url: './list'
  349. });
  350. },
  351. //点击首付款事件
  352. clickItem(item) {
  353. // 更新付款码
  354. if (item === 0) {
  355. this.receivedPaymentCode();
  356. this.setTimePay();
  357. uni.setNavigationBarColor({
  358. backgroundColor:'#4b8fdb',
  359. frontColor:'#ffffff',
  360. success:(e) => {
  361. console.log(e);
  362. },
  363. fail:function (e) {
  364. console.log(e);
  365. }
  366. })
  367. }
  368. // 更新收款码
  369. if (item === 1) {
  370. clearInterval(this.setTimeOutPay);
  371. uni.setNavigationBarColor({
  372. backgroundColor:'#5DBC7C',
  373. frontColor:'#ffffff',
  374. success:(e) => {
  375. console.log(e);
  376. },
  377. fail:function (e) {
  378. console.log(e);
  379. }
  380. })
  381. this.receivedCollectionCode();
  382. }
  383. // 扫码收付款
  384. if (item === 2) {
  385. clearInterval(this.setTimeOutPay);
  386. this.ToChangeInto();
  387. return;
  388. }
  389. // 赋值
  390. this.actionInd = item;
  391. },
  392. // 扫码
  393. ToChangeInto() {
  394. let obj = this;
  395. // #ifdef H5
  396. this.weichatObj.scanQRCode({
  397. needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
  398. scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
  399. success: function(res) {
  400. obj.code = res.resultStr;
  401. obj.$refs.popup1.open();
  402. }
  403. });
  404. // #endif
  405. // #ifndef H5
  406. uni.scanCode({
  407. onlyFromCamera: true,
  408. success: function(e) {
  409. let result = JSON.parse(e.result);
  410. uni.showModal({
  411. title: '扫描二维码',
  412. content: e.result
  413. });
  414. }
  415. });
  416. // #endif
  417. },
  418. // 扫码成功数据处理
  419. scanQR(e) {},
  420. // 获取付款码
  421. receivedPaymentCode() {
  422. receivedPaymentCode()
  423. .then(e => {
  424. this.val = e.data.code;
  425. console.log(e);
  426. })
  427. .catch(e => {
  428. console.log(e);
  429. });
  430. },
  431. // 获取收款码
  432. receivedCollectionCode() {
  433. receivedCollectionCode()
  434. .then(e => {
  435. this.val = e.msg;
  436. console.log(e);
  437. })
  438. .catch(e => {
  439. console.log(e);
  440. });
  441. },
  442. // 創建二维码
  443. creatQrcode() {
  444. console.log(this.$refs.qrcode._makeCode);
  445. this.$refs.qrcode._makeCode();
  446. },
  447. // 保存二维码到图库
  448. saveQrcode() {
  449. this.$refs.qrcode._saveCode();
  450. },
  451. // 生成二维码后返回base64
  452. qrR(res) {
  453. this.src = res;
  454. },
  455. //清空二维码(清空二维码会触发result回调 返回值为空)
  456. clearQrcode(e) {
  457. this.$refs.qrcode._clearCode();
  458. this.val = '';
  459. },
  460. // 保存二维码
  461. upload() {
  462. this.$refs.qrcode._saveCode();
  463. },
  464. openApp() {
  465. let weixinObj = require('jweixin-module');
  466. },
  467. showChooseType() {
  468. this.$refs.popupPay.open()
  469. },
  470. changePayType(index) {
  471. this.payType = index
  472. }
  473. }
  474. };
  475. </script>
  476. <style lang="scss">
  477. .content,
  478. page {
  479. // border-top: 2rpx solid #f2f3f5;
  480. background-color: $base-color;
  481. height: 100%;
  482. }
  483. // 共有底部高度
  484. $btHeight: 100rpx;
  485. .btHeight {
  486. height: $btHeight;
  487. }
  488. .greenBg{
  489. background-color: $base-color;
  490. }
  491. .blueBg{
  492. background-color: #4b8fdb;
  493. }
  494. .coupon_transfer {
  495. // background-color: #ffffff;
  496. padding: 20rpx 25rpx;
  497. padding-top: 50rpx;
  498. // padding-bottom: 130rpx;
  499. width: 100%;
  500. // margin-top: 25rpx;
  501. .user {
  502. margin-bottom: -125rpx;
  503. height: 200rpx;
  504. line-height: 1;
  505. .imgbox {
  506. margin: 0 auto;
  507. text-align: center;
  508. .img {
  509. width: 150rpx;
  510. height: 150rpx;
  511. border-radius: 999rpx;
  512. }
  513. }
  514. .niceName {
  515. text-align: center;
  516. font-size: $font-lg;
  517. margin-top: 15rpx;
  518. font-weight: bold;
  519. color: $font-color-dark;
  520. }
  521. }
  522. }
  523. .erwema {
  524. width: 686rpx;
  525. // height: 817rpx;
  526. height: 900rpx;
  527. background-color: #ffffff;
  528. padding-top: 100rpx;
  529. display: flex;
  530. justify-content: center;
  531. align-items: center;
  532. margin: 0rpx auto;
  533. .setType {
  534. height: 130rpx;
  535. justify-content: flex-start;
  536. .type-wrapper {
  537. text-align: left;
  538. flex-grow: 1;
  539. }
  540. .type-logo {
  541. width: 56rpx;
  542. height: 54rpx;
  543. flex-shrink: 0;
  544. margin-right: 10rpx;
  545. }
  546. .sele-wrap {
  547. width: 50rpx;
  548. height: 100%;
  549. flex-shrink: 0;
  550. display: flex;
  551. align-items: center;
  552. .selecte-ic {
  553. justify-items: flex-end;
  554. width: 13rpx;
  555. height: 36rpx;
  556. transform: rotate(-90deg);
  557. }
  558. }
  559. }
  560. .qrbox {
  561. width: 500rpx;
  562. text-align: center;
  563. font-weight: bold;
  564. .payMoney {
  565. font-size: 50rpx;
  566. // margin-top: 80rpx;
  567. color: $font-color-dark;
  568. font-weight: bold;
  569. }
  570. .setMoney {
  571. font-size: $font-base;
  572. color: $base-color;
  573. margin-top: 20rpx;
  574. }
  575. }
  576. }
  577. /deep/ .qrbox .img {
  578. margin-top: -500rpx !important;
  579. }
  580. /deep/ .tki-qrcode {
  581. // height: 500rpx;
  582. line-height: 0;
  583. margin-top: 10rpx;
  584. }
  585. .bottomTab {
  586. padding: 50rpx;
  587. padding-top: 20rpx;
  588. // position: fixed;
  589. // padding-bottom: 50rpx;
  590. // left: 0;
  591. // bottom: 0;
  592. width: 100%;
  593. .item1 {
  594. text-align: center;
  595. color: #ffffff;
  596. opacity: 0.7;
  597. flex-grow: 1;
  598. line-height: 1;
  599. .img {
  600. width: 80rpx;
  601. height: 80rpx;
  602. }
  603. .text {
  604. font-size: $font-lg;
  605. }
  606. &.action {
  607. opacity: 1;
  608. }
  609. }
  610. }
  611. .popup-box {
  612. position: relative;
  613. z-index: 100;
  614. width: 100%;
  615. height: auto;
  616. background: #ffffff;
  617. .popup-pay {
  618. position: relative;
  619. justify-content: space-between;
  620. // padding: 0rpx 25rpx 32rpx 25rpx;
  621. .paybox-top {
  622. padding-top: 38rpx;
  623. padding-left: 32rpx;
  624. width: 100%;
  625. .type {
  626. font-size: 28rpx;
  627. font-family: PingFang SC;
  628. font-weight: bold;
  629. color: #333333;
  630. }
  631. .image {
  632. padding-right: 24rpx;
  633. padding-bottom: 10rpx;
  634. image {
  635. width: 16rpx;
  636. height: 16rpx;
  637. }
  638. }
  639. }
  640. .paybox-main {
  641. padding-left: 40rpx;
  642. width: 100%;
  643. margin-top: 54rpx;
  644. margin-bottom: 54rpx;
  645. .zftype {
  646. padding-left: 5rpx;
  647. image {
  648. width: 38rpx;
  649. height: 40rpx;
  650. }
  651. .zf {
  652. padding-left: 18rpx;
  653. font-size: 28rpx;
  654. font-family: PingFang SC;
  655. font-weight: 400;
  656. color: #3f454b;
  657. }
  658. }
  659. }
  660. .paybtn {
  661. width: 750rpx;
  662. line-height: 93rpx;
  663. background: #75BA82;
  664. font-size: 32rpx;
  665. font-family: PingFang SC;
  666. font-weight: bold;
  667. color: #FFFFFF;
  668. text-align: center;
  669. }
  670. }
  671. .buttom {
  672. position: relative;
  673. z-index: 100;
  674. width: 100%;
  675. height: 113rpx;
  676. padding-top: 20rpx;
  677. align-items: center;
  678. .heji {
  679. height: 100%;
  680. width: 50%;
  681. padding-left: 23rpx;
  682. padding-top: 20rpx;
  683. font-size: 28rpx;
  684. font-family: PingFang SC;
  685. font-weight: 400;
  686. color: #3f454b;
  687. text {
  688. font-size: 24rpx;
  689. font-family: PingFang SC;
  690. font-weight: bold;
  691. color: #ff0000;
  692. .money {
  693. font-size: 36rpx;
  694. }
  695. }
  696. }
  697. .zhifu {
  698. width: 50%;
  699. height: 92rpx;
  700. background: #5dbc7c;
  701. text-align: center;
  702. line-height: 92rpx;
  703. font-size: 32rpx;
  704. font-family: PingFang SC;
  705. font-weight: bold;
  706. color: #ffffff;
  707. }
  708. }
  709. }
  710. </style>