index.vue 8.2 KB

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