wechatPay.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <template>
  2. <div class="app-content awaitPayYe awaitPayYe">
  3. <div class="callback-wrap">
  4. <div class="bg_01"></div>
  5. <div class="callback-blo">
  6. <block>
  7. <div class="icon">
  8. <i class="iconfont icondaizhifu"></i>
  9. </div>
  10. </block>
  11. <view class="wait">待付款</view>
  12. <block>
  13. <div class="price" v-if="info.reachDiscountPrice >0 || info.orderReachDiscountPrice>0">
  14. <span class="app-size-36 app-bold" style="text-decoration:line-through;color:#8a7f7f;">¥{{ parseFloat((Number(info.reachDiscountPrice)+Number(realPrice)+Number(info.orderReachDiscountPrice)).toFixed(2)) }}</span>
  15. </div>
  16. <div class="order-num app-color-3" style="color:red;font-size:30upx;margin-top:10upx;margin-bottom:10upx;font-weight:bold;"
  17. v-if="info.reachDiscountPrice && Number(info.reachDiscountPrice)>0">花材优惠 -¥{{ parseFloat(info.reachDiscountPrice) }}</div>
  18. <div class="order-num app-color-3" style="color:red;font-size:30upx;margin-top:10upx;margin-bottom:10upx;font-weight:bold;"
  19. v-if="info.orderReachDiscountPrice && Number(info.orderReachDiscountPrice)>0">整单优惠 -¥{{ parseFloat(info.orderReachDiscountPrice) }}</div>
  20. <div class="price">
  21. <span class="app-size-36 app-bold">¥{{ realPrice || '0.00'}}</span>
  22. </div>
  23. <div class="order-num app-color-3" style="margin-top:12upx;">订单号 {{ orderSn || ''}}</div>
  24. <div v-if="remainPayTime > 0" class="order-num app-color-3" style="margin-top:18upx;font-size:26upx;"><span style="font-weight:bold;padding-right:8upx;">{{remainPayTime}}</span>秒后失效</div>
  25. <div v-else class="order-num app-color-3" style="margin-top:12upx;font-size:26upx;">订单已失效</div>
  26. </block>
  27. <block>
  28. <!-- #ifdef MP-WEIXIN -->
  29. <div class="call-one-btn">
  30. <view v-if="Number(balance) >= Number(realPrice)">
  31. <button v-if="getPayType == 1" class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="wxPayFn">微信支付</button>
  32. <button v-else class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="wxPayFnOld">微信支付</button>
  33. </view>
  34. <view v-else>
  35. <button v-if="getPayType == 1" class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="wxPayFn">微信支付</button>
  36. <button v-else class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="wxPayFnOld">微信支付</button>
  37. </view>
  38. <button class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="debtPay" v-if="hasDebtPay === '1'">赊账</button>
  39. <view style="margin-top:30upx;text-align: center;">
  40. <image :src="aliPayCodeImg" mode="heightFix" style="width:290upx;height:290upx;margin:0 auto;"></image>
  41. <view style="margin-top:10upx;font-size:32upx;">支付宝扫此二维码付款</view>
  42. </view>
  43. <button class="button-com ali-btn" @click="savePayCode" style="margin-top:10upx;">保存二维码</button>
  44. <button class="button-com ali-btn" @click="goDetail" style="margin-top:10upx;">我已经付款</button>
  45. <view style="margin-top:25upx;font-size:32upx;text-decoration: underline;" @click="teachPayFn()">不会用支付宝付款?点这里教您</view>
  46. </div>
  47. <!-- #endif -->
  48. <!-- #ifdef APP-PLUS -->
  49. <div class="call-one-btn">
  50. <view>
  51. <button class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="appWxPayFn">微信支付</button>
  52. </view>
  53. <button class="button-com pay-wx" :class="[remainPayTime >0 ? 'ali-btn':'default']" :disabled="remainPayTime >0 ? false : true" @click="appAliPayFn">支付宝支付</button>
  54. <button class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="debtPay" v-if="hasDebtPay === '1'">赊账</button>
  55. </div>
  56. <!-- #endif -->
  57. </block>
  58. </div>
  59. </div>
  60. <keyboard-module :show="keyShow" @comfirm="hideKeyFn" @clickKey="clickKeyFn" :psdShow="true" :type="typeNum" @closeKey="closeKeyFn" />
  61. <alert-module>
  62. <div class="go-login-module">
  63. <div>请先设置支付密码!</div>
  64. </div>
  65. </alert-module>
  66. </div>
  67. </template>
  68. <script>
  69. import { purchaseBalancePay, purchaseDebtPay, purchaseWxPay,purchaseAliPay,getDetail } from "@/api/purchase";
  70. import keyboardModule from './components/keyboard'
  71. import { mapGetters } from "vuex";
  72. import wexinPay from "@/utils/pay/wxPay";
  73. import { postWxCode } from '@/api/mini'
  74. import { updateMiniOpenId } from '@/api/admin'
  75. import { getAliPayCode } from '@/api/purchase'
  76. export default {
  77. name: "wechatPay",
  78. components: {
  79. keyboardModule
  80. },
  81. data () {
  82. return {
  83. options: {},
  84. type: '',
  85. keyShow: false,
  86. modalForm: {
  87. payPassword: ''
  88. },
  89. psdKey: '',
  90. orderSn: '',
  91. realPrice: '',
  92. typeNum: '1',
  93. pageId: '',
  94. remainPayTime:120,
  95. hasDebtPay:0,
  96. balance:0,
  97. getPayType:1,
  98. info:[],
  99. hasRequestApi:false,
  100. needCheck:0,
  101. aliPayCodeImg:''
  102. };
  103. },
  104. onLoad (options) {
  105. this.id = options.id
  106. this.aliPayCodeImg = `${this.$constant.imgUrl}/default-img.png`
  107. },
  108. computed: {
  109. ...mapGetters(["getLoginInfo"]),
  110. ...mapGetters({ dictInfo:"getDictionariesInfo" }),
  111. },
  112. onShow(){
  113. let that = this
  114. if(that.needCheck == 1){
  115. that.needCheck = 0
  116. that.$util.confirmModal({content:'已付款成功?',okText:'是的',cancelText:'没有'},() => {
  117. that.pageTo({ url: '/pagesPurchase/particulars?id=' + that.id, type: 2 })
  118. })
  119. }
  120. },
  121. methods: {
  122. openAliPay(){
  123. this.$msg('商家还未开通此功能')
  124. },
  125. teachPayFn() {
  126. this.pageTo({ url: "/admin/ghs/teachPay"})
  127. },
  128. goDetail(){
  129. this.$util.pageTo({url: "/pagesPurchase/purDetails?id="+this.info.id,type:2})
  130. },
  131. savePayCode(){
  132. let url = this.aliPayCodeImg
  133. uni.downloadFile({
  134. url: url,
  135. success: (res) => {
  136. if (res.statusCode === 200) {
  137. uni.saveImageToPhotosAlbum({
  138. filePath: res.tempFilePath,
  139. success: function (data) {
  140. uni.showToast({title:'下载成功'})
  141. }
  142. });
  143. }
  144. }
  145. })
  146. },
  147. getAliPayCodeFn(orderSn){
  148. getAliPayCode({orderSn:orderSn}).then(res=>{
  149. if(res.code == 1){
  150. if(res.data.imgUrl){
  151. this.aliPayCodeImg = res.data.imgUrl
  152. }
  153. }
  154. })
  155. },
  156. init(){
  157. let that = this
  158. getDetail({id:this.option.id}).then(res=>{
  159. if(res.code == 1){
  160. this.realPrice = res.data.realPrice ? parseFloat(res.data.realPrice) : ''
  161. this.orderSn = res.data.orderSn
  162. this.getPayType = res.data.getPayType
  163. that.hasDebtPay = res.data.hasDebtPay
  164. that.balance = res.data.balance
  165. this.info = res.data
  166. that.remainPayTime = res.data.remainPayTime
  167. if(that.remainPayTime > 0){
  168. let t =setInterval(function(){
  169. if(that.remainPayTime > 0){
  170. that.remainPayTime--
  171. }else{
  172. clearInterval(t);
  173. }
  174. },1000);
  175. }
  176. // #ifdef MP-WEIXIN
  177. that.getAliPayCodeFn(this.orderSn)
  178. // #endif
  179. }
  180. })
  181. },
  182. debtPay(){
  183. let that = this
  184. that.confirmDebtPay()
  185. },
  186. confirmDebtPay() {
  187. let that = this
  188. that.$util.confirmModal({content:'确认赊账?'},() => {
  189. uni.showLoading({mask:true})
  190. purchaseDebtPay({ orderSn: that.orderSn }).then(res => {
  191. uni.hideLoading()
  192. if(res.code == 1){
  193. that.pageTo({ url: '/pagesPurchase/particulars?id=' + res.data.id, type: 2 })
  194. }
  195. })
  196. })
  197. },
  198. appAliPayFn(){
  199. let that = this
  200. // #ifdef MP-WEIXIN
  201. // #endif
  202. // #ifdef APP-PLUS
  203. uni.showLoading()
  204. let id = this.option.id ? this.option.id : 0
  205. purchaseAliPay({ orderSn: this.orderSn }).then(res => {
  206. uni.hideLoading()
  207. if(res.code == 1){
  208. if(res.data.payUrl){
  209. that.orderSn = res.data.orderSn
  210. that.needCheck = 1
  211. plus.runtime.openWeb(res.data.payUrl)
  212. }
  213. }
  214. })
  215. // #endif
  216. },
  217. appWxPayFn(){
  218. let that = this
  219. // #ifdef APP-PLUS
  220. uni.showLoading()
  221. let id = this.option.id ? this.option.id : 0
  222. let realPrice = this.option.realPrice ? this.option.realPrice : 0
  223. let orderSn = this.option.orderSn ? this.option.orderSn : ''
  224. if(plus.runtime.isApplicationExist({pname:'com.tencent.mm',action:'weixin://'})){
  225. plus.share.getServices(function(s){
  226. var sweixin
  227. for (var i = 0; i < s.length; i++) {
  228. var t = s[i];
  229. if (t.id == 'weixin') {
  230. sweixin = t;
  231. }
  232. }
  233. let miniOriginalId = that.dictInfo.miniOriginalId && that.dictInfo.miniOriginalId.current && that.dictInfo.miniOriginalId.current.hd ? that.dictInfo.miniOriginalId.current.hd : ''
  234. if (sweixin && sweixin.nativeClient) {
  235. sweixin.launchMiniProgram({
  236. id: miniOriginalId,
  237. path: '/pagesPurchase/wechatPay?id='+id+'&realPrice='+realPrice+'&orderSn='+orderSn,
  238. type: 0
  239. });
  240. that.needCheck = 1
  241. uni.hideLoading()
  242. } else {
  243. that.$msg("没有找到微信服务")
  244. //that.$msg("获取微信失败:" + e.message)
  245. //console.log(JSON.stringify(e));
  246. }
  247. }, function(e){
  248. that.$msg("没有找到微信服务哦")
  249. //that.$msg("获取微信失败:" + e.message)
  250. //console.log(JSON.stringify(e));
  251. });
  252. } else {
  253. that.$msg("请安装微信,再打开小程序")
  254. return false
  255. }
  256. // #endif
  257. },
  258. wxPayFn () {
  259. let that = this
  260. //解决重复提交问题
  261. if(this.hasRequestApi == true){
  262. this.$msg('正在请求,请5秒后重试')
  263. return false
  264. }
  265. that.hasRequestApi = true
  266. setTimeout(() => {
  267. that.hasRequestApi = false
  268. },7000)
  269. uni.showLoading({title: '加载中',mask:true})
  270. uni.login({
  271. provider: 'weixin',
  272. success: res => {
  273. uni.setStorageSync('code', res.code)
  274. postWxCode({ code: res.code }).then(subRes => {
  275. if(subRes.data.currentMiniOpenId){
  276. let currentMiniOpenId = subRes.data.currentMiniOpenId
  277. purchaseWxPay({ orderSn: this.orderSn,currentMiniOpenId:currentMiniOpenId }).then(res => {
  278. uni.hideLoading()
  279. if(res.code == 1){
  280. this.pageId = res.data.id
  281. this.orderSn = res.data.orderSn
  282. wexinPay(res.data, this.getSuccess, this.getError)
  283. // #ifdef MP-WEIXIN
  284. this.getAliPayCodeFn(this.orderSn)
  285. // #endif
  286. }
  287. })
  288. }
  289. })
  290. }
  291. })
  292. },
  293. wxPayFnOld () {
  294. let that = this
  295. uni.showLoading({title: '加载中',mask:true})
  296. purchaseWxPay({ orderSn: this.orderSn }).then(res => {
  297. uni.hideLoading()
  298. if(res.code == 1){
  299. if(res.data.hasNoMiniOpenId && res.data.hasNoMiniOpenId == 1){
  300. //没有miniOpenId,补miniOpenId
  301. uni.login({
  302. provider: 'weixin',
  303. success: res => {
  304. uni.setStorageSync('code', res.code)
  305. postWxCode({ code: res.code }).then(subRes => {
  306. if(subRes.data.currentMiniOpenId){
  307. let currentMiniOpenId = subRes.data.currentMiniOpenId
  308. updateMiniOpenId({miniOpenId:currentMiniOpenId}).then(subRes=>{
  309. if(subRes.code == 1){
  310. that.$util.confirmModal({content:'网络开小差了,请继续',okText:'确认',singer:true},() => {
  311. that.wxPayFn()
  312. })
  313. }
  314. })
  315. }
  316. })
  317. }
  318. })
  319. }else{
  320. this.pageId = res.data.id
  321. wexinPay(res.data, this.getSuccess, this.getError)
  322. }
  323. }
  324. })
  325. },
  326. getSuccess () {
  327. let that = this
  328. that.pageTo({ url: '/pagesPurchase/particulars?id=' + that.pageId, type: 2 })
  329. },
  330. // 关闭键盘
  331. closeKeyFn () {
  332. this.keyShow = false
  333. },
  334. getError () {
  335. },
  336. balancePay () {
  337. let self = this
  338. if(Number(this.balance) < Number(this.realPrice)){
  339. this.$msg('余额不足')
  340. return false;
  341. }
  342. if (this.getLoginInfo.payPassword) {
  343. self.keyShow = true
  344. } else {
  345. uni.showModal({
  346. title: '',
  347. content: '请先设置支付密码',
  348. success: function (res) {
  349. if (res.confirm) {
  350. self.pageTo({
  351. url: '/pagesPurchase/setPsd'
  352. })
  353. }
  354. }
  355. });
  356. }
  357. },
  358. // 点击数字键盘
  359. clickKeyFn (val) {
  360. this.psdKey = val
  361. console.log(this.psdKey)
  362. },
  363. // 点击了完成
  364. hideKeyFn () {
  365. uni.showLoading({title: '加载中',mask:true})
  366. if (this.psdKey.length === 6) {
  367. let data = {
  368. orderSn: this.orderSn,
  369. password: this.psdKey
  370. }
  371. purchaseBalancePay(data).then(res => {
  372. //关闭加载中
  373. uni.hideLoading()
  374. if(res.code == 1){
  375. this.pageTo({
  376. url: '/pagesPurchase/particulars?id=' + res.data.id,
  377. type: 2
  378. })
  379. }
  380. }).catch(err => {})
  381. } else {
  382. this.$msg('请输入六位数支付密码')
  383. }
  384. }
  385. }
  386. };
  387. </script>
  388. <style lang="scss" scoped>
  389. .app-content {
  390. .ali-btn{
  391. background-color:#3385ff;
  392. border:1upx solid #3385ff;
  393. color:white;
  394. }
  395. .callback-wrap {
  396. padding-top: 50upx;
  397. background-repeat: no-repeat;
  398. background-size: 100% auto;
  399. position: relative;
  400. .bg_01 {
  401. position: absolute;
  402. top: 0;
  403. left: 0;
  404. width: 100vw;
  405. height: 290upx;
  406. background: #3385ff;
  407. border-radius: 0upx 0upx 83upx 83upx;
  408. z-index: 1;
  409. }
  410. .callback-blo {
  411. position: absolute;
  412. z-index: 9;
  413. left: 50%;
  414. transform: translateX(-50%);
  415. width: 90%;
  416. margin: 0 auto;
  417. padding: 70upx 0;
  418. background-color: #fff;
  419. box-shadow: 2upx 2upx 16upx 0upx rgba(181, 181, 181, 0.29);
  420. border-radius: 10upx;
  421. text-align: center;
  422. // 使用icon
  423. .icon {
  424. .iconfont {
  425. font-size: 120upx;
  426. }
  427. }
  428. // 一个按钮
  429. .call-one-btn {
  430. .button-com {
  431. width: 70%;
  432. padding-top:26upx;
  433. padding-bottom:26upx;
  434. font-size: 32upx;
  435. margin-top:28upx;
  436. }
  437. }
  438. }
  439. }
  440. }
  441. .awaitPayWx,
  442. .awaitPayYe {
  443. .status-text {
  444. margin-top: 22upx;
  445. margin-bottom: 52upx;
  446. color: #ffa92e;
  447. }
  448. .surplus {
  449. margin-top: 22upx;
  450. margin-bottom: 38upx;
  451. }
  452. .icon {
  453. .iconfont {
  454. color: #ffa92e;
  455. }
  456. }
  457. }
  458. .wait {
  459. color:#ffa92e;
  460. font-size:36upx;
  461. font-weight:700;
  462. margin: 20upx 0;
  463. }
  464. .balance{
  465. margin-top:20upx;
  466. }
  467. </style>