index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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>
  33. </view>
  34. </view>
  35. <view class="bottomTab flex">
  36. <view class="item1" @click="clickItem(0)" :class="{ action: actionInd == 0 }">
  37. <view><image class="img" src="../../static/icon/pay2.png" mode=" widthFix"></image></view>
  38. <view class="text">付款码</view>
  39. </view>
  40. <view class="item1" @click="clickItem(1)" :class="{ action: actionInd == 1 }">
  41. <view><image class="img" src="../../static/icon/pay1.png" mode=" widthFix"></image></view>
  42. <view class="text">收款码</view>
  43. </view>
  44. <view class="item1" @click="clickItem(2)" :class="{ action: actionInd == 2 }">
  45. <view><image class="img" src="../../static/icon/pay3.png" mode=" widthFix"></image></view>
  46. <view class="text">扫一扫</view>
  47. </view>
  48. <view class="item1" @click="openList" :class="{ action: actionInd == 3 }">
  49. <view><image class="img" src="../../static/icon/pay4.png" mode=" widthFix"></image></view>
  50. <view class="text">记录</view>
  51. </view>
  52. </view>
  53. <uniPopup ref="popup1" type="dialog">
  54. <uni-popup-dialog
  55. mode="input"
  56. type="input"
  57. title="支付"
  58. placeholder="请输入支付金额"
  59. :duration="2000"
  60. :before-close="true"
  61. @close="close"
  62. @confirm="confirm"
  63. ></uni-popup-dialog>
  64. </uniPopup>
  65. <uniPopup ref="popup2" type="message"><uni-popup-message type="success" message="支付成功" :duration="2000"></uni-popup-message></uniPopup>
  66. </view>
  67. </template>
  68. <script>
  69. import tkiQrcodes from '@/components/tki-qrcode/tki-qrcode.vue';
  70. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  71. import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue';
  72. import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue';
  73. import { getUserInfo } from '@/api/login.js';
  74. import { receivedCollectionCode, receivedPaymentCode, receivedCodeState, receivedPaymentCreate, receivedLst, collectionLst, collectionSetTip } from '@/api/received.js';
  75. // #ifdef H5
  76. import { mapState } from 'vuex';
  77. import { weixindata } from '@/utils/wxAuthorized';
  78. // #endif
  79. import Voice from '@/utils/QS-baiduyy.js';
  80. export default {
  81. components: { tkiQrcodes, uniPopup, uniPopupDialog, uniPopupMessage },
  82. // #ifdef H5
  83. computed: {
  84. ...mapState(['weichatObj'])
  85. },
  86. // #endif
  87. data() {
  88. return {
  89. url: '',
  90. uid: '',
  91. qrsize: 80, // 二维码大小
  92. cid: 'tki-qrcode-canvas', //canvasId,页面存在多个二维码组件时需设置不同的ID
  93. size: 500, //生成的二维码大小
  94. unit: 'upx', //大小单位尺寸
  95. // show: true,//默认使用组件中的image标签显示二维码
  96. val: '', //要生成的内容
  97. background: '#ffffff', //二维码背景色
  98. foreground: '#333333', //二维码前景色
  99. pdground: '#333333', //二维码角标色
  100. icon: '', //二维码图标URL(必须是本地图片,网络图需要先下载至本地)
  101. iconSize: 40, //二维码图标大小
  102. lv: 3, //容错级别
  103. onval: true, //监听val值变化自动重新生成二维码
  104. loadMake: false, //组件初始化完成后自动生成二维码,val需要有值
  105. usingComponents: false, //是否使用了自定义组件模式(主要是为了修复非自定义组件模式时 v-if 无法生成二维码的问题)
  106. showLoading: false, //是否显示loading
  107. loadingText: '二维码生成中', //loading文字
  108. src: '', // 二维码生成后的图片地址或base64
  109. ratio: 1, //页面比例用于计算
  110. ctxSrc: '', //要显示的图片
  111. loading: true, //是否载入图片中
  112. canHeight: '',
  113. canWeidth: '',
  114. userinfo: {}, //用户信息
  115. actionInd: 1, //默认展示收款码
  116. setTimeOutPay: null, //付款倒计时
  117. getMoneyList: null, //收款记录倒计时倒计时
  118. showSqr: true,
  119. code: '', //保存扫码code
  120. indexNum: 0 //默认没有商品
  121. };
  122. },
  123. onLoad(option) {
  124. this.loadlist;
  125. this.userinfo = uni.getStorageSync('userInfo');
  126. // 加载用户数据
  127. this.getUserInfo();
  128. // #ifdef H5
  129. // 获取是否为微信内核浏览器
  130. this.showSqr = uni.getStorageSync('weichatBrowser') || false;
  131. weixindata();
  132. // #endif
  133. },
  134. onReady() {
  135. // Voice('成功收款100000000元')
  136. },
  137. onShow() {
  138. // 开启倒计时
  139. this.setTimePay();
  140. },
  141. onHide() {
  142. clearInterval(this.setTimeOutPay);
  143. clearInterval(this.getMoneyList);
  144. },
  145. // 监听页面卸载
  146. onUnload() {
  147. // 关闭倒计时
  148. clearInterval(this.setTimeOutPay);
  149. clearInterval(this.getMoneyList);
  150. },
  151. // 监听页面后退
  152. onBackPress() {
  153. // 关闭倒计时
  154. clearInterval(this.setTimeOutPay);
  155. clearInterval(this.getMoneyList);
  156. },
  157. methods: {
  158. // 获取收款记录
  159. collectionLst() {
  160. collectionLst()
  161. .then(e => {
  162. console.log(e);
  163. // 循环处理播报语音
  164. e.data.data.forEach((d, ind) => {
  165. Voice({
  166. voiceSet: {
  167. tex: '满园春收款' + (+d.amount - d.service_charge) + '元'
  168. },
  169. audioSet: {
  170. volume: 1
  171. },
  172. lineUp: true // 加入语音队列
  173. });
  174. //清除记录
  175. collectionSetTip({ id: d.id });
  176. });
  177. })
  178. .catch(e => {});
  179. },
  180. // 获取用户信息
  181. getUserInfo() {
  182. let obj = this;
  183. getUserInfo({})
  184. .then(({ data }) => {
  185. obj.userinfo = data;
  186. // 加载收款码
  187. obj.receivedCollectionCode();
  188. // 调用循环
  189. // obj.setTimePay();
  190. // #ifdef H5
  191. uni.showModal({
  192. title: '提示',
  193. content: '打开支付提示成功!',
  194. showCancel: false,
  195. });
  196. // #endif
  197. })
  198. .catch(e => {
  199. console.log(e);
  200. });
  201. },
  202. /**
  203. * 点击取消按钮触发
  204. * @param {Object} done
  205. */
  206. close(done) {
  207. // TODO 做一些其他的事情,before-close 为true的情况下,手动执行 done 才会关闭对话框
  208. // ...
  209. done();
  210. },
  211. /**
  212. * 点击确认按钮触发
  213. * @param {Object} done
  214. * @param {Object} value
  215. */
  216. confirm(done, value) {
  217. // 输入框的值
  218. receivedPaymentCreate({
  219. code: this.code,
  220. amount: value
  221. })
  222. .then(({ data }) => {
  223. uni.showModal({
  224. title: '提示',
  225. content: '成功',
  226. showCancel: false
  227. });
  228. })
  229. .catch(e => {
  230. uni.showModal({
  231. title: '提示',
  232. content: e.message,
  233. showCancel: false
  234. });
  235. console.log(e);
  236. });
  237. // TODO 做一些其他的事情,手动执行 done 才会关闭对话框
  238. // ...
  239. done();
  240. },
  241. // payVdeo(){
  242. // var mess = document.getElementById('ttsText').value;
  243. // var msg = new SpeechSynthesisUtterance(mess);
  244. // msg.volume = 100;
  245. // msg.rate = 1;
  246. // msg.pitch = 1.5;
  247. // console.log(msg);
  248. // window.speechSynthesis.speak(msg);
  249. // },
  250. // 开启循环倒计时
  251. setTimePay() {
  252. // 判断当前是否为付款码
  253. if (this.actionInd == 0) {
  254. this.setTimeOutPay = setInterval(() => {
  255. this.receivedCodeState();
  256. }, 5000);
  257. }
  258. // 获取首付款信息
  259. this.getMoneyList = setInterval(e => {
  260. this.collectionLst();
  261. }, 5000);
  262. },
  263. // 判断付款码是否可以使用
  264. receivedCodeState() {
  265. let obj = this;
  266. // 查询是否过期
  267. receivedCodeState({
  268. code: obj.val
  269. })
  270. .then(e => {
  271. // 无效
  272. if (e.msg == 'overdue') {
  273. obj.receivedPaymentCode();
  274. }
  275. // 已使用
  276. else if (e.msg == 'use') {
  277. uni.showModal({
  278. title: '提示',
  279. content: '已支付成功',
  280. showCancel: false
  281. });
  282. obj.receivedPaymentCode();
  283. }
  284. })
  285. .catch(e => {
  286. console.log(e);
  287. });
  288. },
  289. // 开启验证是否已经过期或使用付款成功
  290. // receivedCodeState(){
  291. // },
  292. // 跳转到记录页面
  293. openList() {
  294. clearInterval(this.setTimeOutPay);
  295. clearInterval(this.getMoneyList);
  296. // this.$refs.popup1.open();
  297. // uni.navigateTo({
  298. // url: '/pages/wallet/wallet'
  299. // });
  300. uni.navigateTo({
  301. url: './list'
  302. });
  303. },
  304. //点击首付款事件
  305. clickItem(item) {
  306. // 更新付款码
  307. if (item === 0) {
  308. this.receivedPaymentCode();
  309. this.setTimePay();
  310. uni.setNavigationBarColor({
  311. backgroundColor:'#4b8fdb',
  312. frontColor:'#ffffff',
  313. success:(e) => {
  314. console.log(e);
  315. },
  316. fail:function (e) {
  317. console.log(e);
  318. }
  319. })
  320. }
  321. // 更新收款码
  322. if (item === 1) {
  323. clearInterval(this.setTimeOutPay);
  324. uni.setNavigationBarColor({
  325. backgroundColor:'#5DBC7C',
  326. frontColor:'#ffffff',
  327. success:(e) => {
  328. console.log(e);
  329. },
  330. fail:function (e) {
  331. console.log(e);
  332. }
  333. })
  334. this.receivedCollectionCode();
  335. }
  336. // 扫码收付款
  337. if (item === 2) {
  338. clearInterval(this.setTimeOutPay);
  339. this.ToChangeInto();
  340. return;
  341. }
  342. // 赋值
  343. this.actionInd = item;
  344. },
  345. // 扫码
  346. ToChangeInto() {
  347. let obj = this;
  348. // #ifdef H5
  349. this.weichatObj.scanQRCode({
  350. needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
  351. scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
  352. success: function(res) {
  353. obj.code = res.resultStr;
  354. obj.$refs.popup1.open();
  355. }
  356. });
  357. // #endif
  358. // #ifndef H5
  359. uni.scanCode({
  360. onlyFromCamera: true,
  361. success: function(e) {
  362. let result = JSON.parse(e.result);
  363. uni.showModal({
  364. title: '扫描二维码',
  365. content: e.result
  366. });
  367. }
  368. });
  369. // #endif
  370. },
  371. // 扫码成功数据处理
  372. scanQR(e) {},
  373. // 获取付款码
  374. receivedPaymentCode() {
  375. receivedPaymentCode()
  376. .then(e => {
  377. this.val = e.data.code;
  378. console.log(e);
  379. })
  380. .catch(e => {
  381. console.log(e);
  382. });
  383. },
  384. // 获取收款码
  385. receivedCollectionCode() {
  386. receivedCollectionCode()
  387. .then(e => {
  388. this.val = e.msg;
  389. console.log(e);
  390. })
  391. .catch(e => {
  392. console.log(e);
  393. });
  394. },
  395. // 創建二维码
  396. creatQrcode() {
  397. console.log(this.$refs.qrcode._makeCode);
  398. this.$refs.qrcode._makeCode();
  399. },
  400. // 保存二维码到图库
  401. saveQrcode() {
  402. this.$refs.qrcode._saveCode();
  403. },
  404. // 生成二维码后返回base64
  405. qrR(res) {
  406. this.src = res;
  407. },
  408. //清空二维码(清空二维码会触发result回调 返回值为空)
  409. clearQrcode(e) {
  410. this.$refs.qrcode._clearCode();
  411. this.val = '';
  412. },
  413. // 保存二维码
  414. upload() {
  415. this.$refs.qrcode._saveCode();
  416. },
  417. openApp() {
  418. let weixinObj = require('jweixin-module');
  419. }
  420. }
  421. };
  422. </script>
  423. <style lang="scss">
  424. .content,
  425. page {
  426. // border-top: 2rpx solid #f2f3f5;
  427. background-color: $base-color;
  428. height: 100%;
  429. }
  430. // 共有底部高度
  431. $btHeight: 100rpx;
  432. .btHeight {
  433. height: $btHeight;
  434. }
  435. .greenBg{
  436. background-color: $base-color;
  437. }
  438. .blueBg{
  439. background-color: #4b8fdb;
  440. }
  441. .coupon_transfer {
  442. // background-color: #ffffff;
  443. padding: 20rpx 25rpx;
  444. padding-top: 50rpx;
  445. // padding-bottom: 130rpx;
  446. width: 100%;
  447. // margin-top: 25rpx;
  448. .user {
  449. margin-bottom: -125rpx;
  450. height: 200rpx;
  451. line-height: 1;
  452. .imgbox {
  453. margin: 0 auto;
  454. text-align: center;
  455. .img {
  456. width: 150rpx;
  457. height: 150rpx;
  458. border-radius: 999rpx;
  459. }
  460. }
  461. .niceName {
  462. text-align: center;
  463. font-size: $font-lg;
  464. margin-top: 15rpx;
  465. font-weight: bold;
  466. color: $font-color-dark;
  467. }
  468. }
  469. }
  470. .erwema {
  471. width: 686rpx;
  472. height: 817rpx;
  473. background-color: #ffffff;
  474. padding-top: 100rpx;
  475. display: flex;
  476. justify-content: center;
  477. align-items: center;
  478. margin: 0rpx auto;
  479. .qrbox {
  480. width: 500rpx;
  481. text-align: center;
  482. font-weight: bold;
  483. .payMoney {
  484. font-size: 50rpx;
  485. // margin-top: 80rpx;
  486. color: $font-color-dark;
  487. font-weight: bold;
  488. }
  489. .setMoney {
  490. font-size: $font-base;
  491. color: $base-color;
  492. margin-top: 20rpx;
  493. }
  494. }
  495. }
  496. /deep/ .qrbox .img {
  497. margin-top: -500rpx !important;
  498. }
  499. /deep/ .tki-qrcode {
  500. // height: 500rpx;
  501. line-height: 0;
  502. margin-top: 10rpx;
  503. }
  504. .bottomTab {
  505. padding: 50rpx;
  506. padding-top: 20rpx;
  507. // position: fixed;
  508. // padding-bottom: 50rpx;
  509. // left: 0;
  510. // bottom: 0;
  511. width: 100%;
  512. .item1 {
  513. text-align: center;
  514. color: #ffffff;
  515. opacity: 0.7;
  516. flex-grow: 1;
  517. line-height: 1;
  518. .img {
  519. width: 80rpx;
  520. height: 80rpx;
  521. }
  522. .text {
  523. font-size: $font-lg;
  524. }
  525. &.action {
  526. opacity: 1;
  527. }
  528. }
  529. }
  530. </style>