index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <template>
  2. <view class="">
  3. <!-- #ifdef MP-WEIXIN-->
  4. <view class="">
  5. <u-navbar :isBack="isBack" :title="title"></u-navbar>
  6. </view>
  7. <!-- #endif -->
  8. <view class="" v-show="!payShow">
  9. <view class="shopInfo">
  10. <image :src="shopDetail.cover" mode=""></image>
  11. <text>{{shopDetail.name}}</text>
  12. </view>
  13. <view class="data">
  14. <text style="color: #000;">付款金额</text>
  15. <view class="price">
  16. <view class="input-bar center" @tap="show">
  17. <view class="icon center">¥</view>
  18. <view class="input" style="display: flex; align-items: center;">
  19. <view style="font-size: 80rpx;">{{filterMoney(orderAmount)}}</view>
  20. <view class="cusor"></view>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="text-center text-base padding-top-20">
  25. <text>*使用联兑通付款有优惠打折</text>
  26. </view>
  27. </view>
  28. <!-- #ifdef MP-WEIXIN-->
  29. <view style="margin-top: -20rpx;">
  30. <channel-list ></channel-list>
  31. </view>
  32. <!-- #endif -->
  33. <amountInput ref="amountInput" confirmText="付款" btnColor="#ff9900" placeholder="请输入交易金额" @change="change"
  34. @confirm="debouncePay"></amountInput>
  35. <u-modal v-model="modalShow" :mask-close-able="true" :showCancelButton="true" @cancel="payOfh5"
  36. @confirm="jumpLDT" cancel-text="直接付款" confirm-color="#FF9447" confirmText="去联兑通支付"
  37. content="去联兑通小程序付款有更多优惠哟~"></u-modal>
  38. </view>
  39. <toast ref="toast" ></toast>
  40. <pay-confirm confirmText="确认" cancelText="继续支付" :type="payConfirmType" v-show="payShow" :info="info" @confirm="confirmClick" @cancel="cancelClick"></pay-confirm>
  41. </view>
  42. </template>
  43. <script>
  44. import payConfirm from '@/components/pay-confirm.vue'
  45. import channelList from '@/components/channel-list.vue'
  46. import amountInput from '../../comps/amountInput/amountInput.vue';
  47. export default {
  48. components: {
  49. payConfirm,
  50. channelList,
  51. amountInput
  52. },
  53. data() {
  54. return {
  55. isH5:false,
  56. //navbar
  57. title:"收银台",
  58. isBack:true,
  59. //第一次点击支付不需要防抖操作
  60. isFirstPay: true,
  61. orderAmount: '',
  62. //支付bills信息
  63. payShow:false,
  64. payConfirmType:'',
  65. info:{},
  66. bills:{},
  67. modalShow: false,
  68. shopId: '',
  69. shopDetail: {},
  70. //支付参数
  71. payParams: {},
  72. //支付结果
  73. payResult: {
  74. isSuccess: false,
  75. msg: "交易失败",
  76. //总价
  77. totalPrice: 0,
  78. //消耗积分值
  79. pointsNum: 0,
  80. //消耗现金值
  81. amountNum: 0,
  82. }
  83. }
  84. },
  85. async onLoad(options) {
  86. if (!this.$isEmpty(options.query)) {
  87. //h5跳转回小程序后重新赋值
  88. let params = options.query.split(";")
  89. this.shopId = params[0]
  90. this.orderAmount = params[1]
  91. this.$refs.amountInput.initialMoney(this.orderAmount)
  92. this.isH5=true
  93. } else {
  94. this.isH5=false
  95. this.shopId = options.id
  96. }
  97. // #ifdef MP-WEIXIN
  98. //如果是新用户通过h5微信支付扫码进入此页面,跳回首页
  99. if (this.$isEmpty(this.vuex_userId)) {
  100. uni.reLaunch({
  101. url: "/pages/mine/mine?query=" + this.shopId + ";" + this.orderAmount
  102. })
  103. return
  104. }
  105. //如果用户信息为空,阻断
  106. let flag = await this.fetchUserDetail()
  107. if (!flag) {
  108. this.$dialog.showModal('用户信息获取失败', false).then(() => {
  109. uni.reLaunch({
  110. url: "/pages/mine/mine"
  111. })
  112. })
  113. return
  114. }
  115. // #endif
  116. if (this.$isEmpty(this.shopId)) {
  117. this.$dialog.showModalAndBack('商户id不能为空')
  118. return
  119. }
  120. this.fetchShopDetail()
  121. },
  122. onShow() {
  123. console.log(this.orderAmount);
  124. },
  125. methods: {
  126. isWxBrowser(){
  127. let na = navigator.userAgent.toLowerCase()
  128. return na.indexOf('micromessenger') !== -1
  129. },
  130. //防抖支付
  131. debouncePay() {
  132. if (this.isFirstPay) {
  133. this.pay()
  134. this.isFirstPay = false
  135. } else {
  136. this.$u.debounce(this.pay, 500)
  137. }
  138. },
  139. //获取商户信息
  140. fetchShopDetail() {
  141. this.$api.shop.detail({
  142. id: this.shopId
  143. }).then(res => {
  144. if (this.$isEmpty(res.data)) {
  145. this.$dialog.showModalAndBack('获取不到商户信息')
  146. return
  147. }
  148. this.shopDetail = res.data
  149. if (this.$isNotEmpty(this.orderAmount)&&this.isH5) {
  150. //从h5跳转回来后,直接付款
  151. this.pay()
  152. }
  153. }).catch(err => {
  154. this.$dialog.showModalAndBack('获取不到商户信息')
  155. })
  156. },
  157. //获取用户信息
  158. async fetchUserDetail() {
  159. let res = await this.$api.loginUser.detail({
  160. id: this.vuex_userId
  161. })
  162. if (this.$isEmpty(res.data)) {
  163. return false
  164. } else {
  165. return true
  166. }
  167. },
  168. show() {
  169. this.$refs.amountInput.show()
  170. },
  171. change(e) {
  172. if (!e) {
  173. this.orderAmount = 0
  174. } else {
  175. this.orderAmount = e
  176. }
  177. },
  178. filterMoney(value) {
  179. if (!value) {
  180. return ''
  181. } else {
  182. value = value.replace(/\$\s?|(,*)/g, '')
  183. return value.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
  184. }
  185. },
  186. async jumpLDT() {
  187. this.$dialog.showLoading('打开中..')
  188. let params = {
  189. path: "/pagesC/pages/checkstand/index",
  190. query: "query=" + this.shopId + ";" + this.orderAmount
  191. }
  192. let res = await this.$api.wxApp.getGenerateScheme(params)
  193. if (!this.$isEmpty(res.data.openlink)) {
  194. location.href = res.data.openlink
  195. } else {
  196. location.href = "weixin://dl/business/?t=X2CyIQDbgtm"
  197. }
  198. uni.hideLoading()
  199. },
  200. async payOfh5() {
  201. let expireTime = this.$dateTime.getExpireTime(5)
  202. let params = {
  203. expireTime,
  204. money: this.orderAmount,
  205. shopId: this.shopId,
  206. }
  207. let resp = await this.$api.pay.getPayOrderPamamsForH5(params)
  208. let payObj = {
  209. orderType: this.$global.orderType.USER_PAY,
  210. orderId: resp.data.id
  211. }
  212. let res = await this.$api.pay.payOrderOfscanCode(payObj)
  213. let qrCodeUrl=JSON.parse(res.data.result).qrCodeUrl
  214. if (this.$isNotEmpty(qrCodeUrl)) {
  215. location.href = qrCodeUrl
  216. } else {
  217. this.$refs.toast.error('支付失败')
  218. }
  219. },
  220. async pay() {
  221. if (!this.orderAmount.length || this.orderAmount == 0) {
  222. this.$refs.toast.warn('请输入交易金额')
  223. return
  224. }
  225. // #ifdef H5
  226. if (this.$isWxBrowser()) {
  227. //如果是微信浏览器打开
  228. this.modalShow = true
  229. }else{
  230. //直接支付
  231. this.payOfh5()
  232. }
  233. // #endif
  234. // #ifdef MP-WEIXIN
  235. this.toWXPay()
  236. // #endif
  237. },
  238. async toWXPay() {
  239. let expireTime = this.$dateTime.getExpireTime(5)
  240. let params = {
  241. userId: this.vuex_userId,
  242. appId: this.$global.wxParams.APPID,
  243. billsTitle: '用户扫码支付',
  244. money: this.orderAmount,
  245. expireTime,
  246. shopId: this.shopId,
  247. openId: this.$cache.get('userInfo').openId,
  248. }
  249. if (this.$isNotEmpty(this.vuex_channel)) {
  250. params.channelId=this.vuex_channel.id
  251. }
  252. let resp = await this.$api.pay.getPayOrderPamams(params)
  253. this.payParams = resp.data
  254. this.bills=resp.data.bills
  255. if (this.bills.discount==-1) {
  256. this.bills.discount=0
  257. }
  258. if (resp.data.status == '付款成功') {
  259. this.handelResult(true)
  260. } else if (resp.data.status == '待付款') {
  261. if (this.bills.cost==this.bills.price) {
  262. this.doWxPay(this.bills.id)
  263. }else{
  264. this.info={
  265. shop:this.shopDetail,
  266. bills:this.bills,
  267. }
  268. this.payConfirmType=''
  269. this.title="支付确认"
  270. this.isBack=false
  271. this.payShow=true
  272. }
  273. } else {
  274. this.handelResult(false)
  275. }
  276. },
  277. async doWxPay(orderId) {
  278. let obj = {
  279. orderType: this.$global.orderType.USER_PAY,
  280. orderId,
  281. payStatus: this.$global.payStatus.IS_WAIT
  282. }
  283. let res = await this.$api.pay.payOrder(obj)
  284. let prePayTn = JSON.parse(res.data.prePayTn)
  285. this.$mpi.requestPayment(prePayTn).then((res) => {
  286. this.handelResult(true)
  287. }).catch(err => {
  288. this.handelResult(false)
  289. })
  290. },
  291. handelResult(flag) {
  292. if (flag) {
  293. //跳转倒支付结果页
  294. // this.payResult = {
  295. // isSuccess: true,
  296. // msg: "交易成功",
  297. // totalPrice: this.payParams.totalPrice,
  298. // amountNum: this.payParams.bills.price,
  299. // pointsNum: this.$digital.floatSub(this.payParams.totalPrice, this.payParams.bills.price),
  300. // }
  301. // uni.navigateTo({
  302. // url: "/pagesC/pages/checkstand/pay-result?payResult=" + JSON.stringify(this.payResult)
  303. // })
  304. // return
  305. //本页显示支付结果+抵扣详情
  306. this.info={
  307. shop:this.shopDetail,
  308. bills:this.bills,
  309. }
  310. this.payConfirmType='paySuccess'
  311. this.title="支付结果"
  312. this.isBack=false
  313. this.payShow=true
  314. return
  315. }
  316. this.payResult.msg = '交易失败'
  317. this.payResult.isSuccess = false
  318. uni.navigateTo({
  319. url: "/pagesC/pages/checkstand/pay-result?payResult=" + JSON.stringify(this.payResult)
  320. })
  321. },
  322. confirmClick(){
  323. if (this.payConfirmType=='paySuccess') {
  324. uni.reLaunch({
  325. url:"/pages/mine/mine"
  326. })
  327. return
  328. }
  329. this.doWxPay(this.bills.id)
  330. },
  331. cancelClick(){
  332. this.title="收银台"
  333. this.isBack=true
  334. this.payShow=false
  335. }
  336. }
  337. }
  338. </script>
  339. <style>
  340. page {
  341. background-color: #ffff;
  342. }
  343. </style>
  344. <style lang="scss" scoped>
  345. .shopInfo {
  346. margin: 60rpx 0 20rpx;
  347. display: flex;
  348. justify-content: center;
  349. align-items: center;
  350. flex-direction: column;
  351. image {
  352. border-radius: 50%;
  353. width: 140rpx;
  354. height: 140rpx;
  355. }
  356. text {
  357. margin-top: 30rpx;
  358. font-size: 32rpx;
  359. }
  360. }
  361. .data {
  362. padding: 50rpx;
  363. display: flex;
  364. justify-content: flex-start;
  365. flex-direction: column;
  366. .price {
  367. &-icon {
  368. font-size: 40rpx;
  369. font-weight: 800;
  370. }
  371. }
  372. }
  373. .center {
  374. display: flex;
  375. justify-content: center;
  376. align-items: center;
  377. }
  378. .input-bar {
  379. height: 150rpx;
  380. border-bottom: 1rpx solid #DDDDDD;
  381. .icon {
  382. width: 15%;
  383. font-size: 70rpx;
  384. font-weight: 900;
  385. height: 100%;
  386. }
  387. .input {
  388. width: 85%;
  389. height: 100%;
  390. overflow: hidden;
  391. font-size: 70rpx;
  392. }
  393. .cusor {
  394. margin-left: 10rpx;
  395. width: 6rpx;
  396. border-radius: 20rpx;
  397. height: 60%;
  398. background-color: #ff9900;
  399. animation: blink 1200ms infinite ease-in-out;
  400. }
  401. }
  402. @keyframes blink {
  403. from {
  404. opacity: 0;
  405. }
  406. }
  407. </style>