index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. if (!this.$isEmpty(res.data.qrCodeUrl)) {
  195. location.href = res.data.qrCodeUrl
  196. } else {
  197. this.$u.toast('支付失败')
  198. }
  199. },
  200. async pay() {
  201. if (!this.orderAmount.length || this.orderAmount == 0) {
  202. this.$u.toast('请输入交易金额')
  203. return
  204. }
  205. // #ifdef H5
  206. this.modalShow = true
  207. // #endif
  208. // #ifdef MP-WEIXIN
  209. this.toWXPay()
  210. // #endif
  211. },
  212. async toWXPay() {
  213. let expireTime = this.$dateTime.getExpireTime(5)
  214. let params = {
  215. userId: this.vuex_userId,
  216. appId: this.$global.wxParams.APPID,
  217. billsTitle: '用户扫码支付',
  218. money: this.orderAmount,
  219. expireTime,
  220. shopId: this.shopId,
  221. openId: this.$cache.get('userInfo').openId,
  222. }
  223. if (this.$isNotEmpty(this.vuex_channel)) {
  224. params.channelId=this.vuex_channel.id
  225. }
  226. let resp = await this.$api.pay.getPayOrderPamams(params)
  227. this.payParams = resp.data
  228. if (resp.data.status == '付款成功') {
  229. this.handelResult(true)
  230. } else if (resp.data.status == '待付款') {
  231. this.doWxPay(resp.data.bills.id)
  232. } else {
  233. this.handelResult(false)
  234. }
  235. },
  236. async doWxPay(orderId) {
  237. let obj = {
  238. orderType: this.$global.orderType.USER_PAY,
  239. orderId,
  240. payStatus: this.$global.payStatus.IS_WAIT
  241. }
  242. let res = await this.$api.pay.payOrder(obj)
  243. let prePayTn = JSON.parse(res.data.prePayTn)
  244. this.$mpi.requestPayment(prePayTn).then((res) => {
  245. this.handelResult(true)
  246. }).catch(err => {
  247. this.handelResult(false)
  248. })
  249. },
  250. handelResult(flag) {
  251. if (flag) {
  252. this.payResult = {
  253. isSuccess: true,
  254. msg: "交易成功",
  255. totalPrice: this.payParams.totalPrice,
  256. amountNum: this.payParams.bills.price,
  257. pointsNum: this.$digital.floatSub(this.payParams.totalPrice, this.payParams.bills.price),
  258. }
  259. } else {
  260. this.payResult.msg = '交易失败'
  261. this.payResult.isSuccess = false
  262. }
  263. uni.navigateTo({
  264. url: "/pagesC/pages/checkstand/pay-result?payResult=" + JSON.stringify(this.payResult)
  265. })
  266. },
  267. }
  268. }
  269. </script>
  270. <style>
  271. page {
  272. background-color: #ffff;
  273. }
  274. </style>
  275. <style lang="scss" scoped>
  276. .shopInfo {
  277. margin: 60rpx 0 20rpx;
  278. display: flex;
  279. justify-content: center;
  280. align-items: center;
  281. flex-direction: column;
  282. image {
  283. border-radius: 50%;
  284. width: 140rpx;
  285. height: 140rpx;
  286. }
  287. text {
  288. margin-top: 30rpx;
  289. font-size: 32rpx;
  290. }
  291. }
  292. .data {
  293. padding: 50rpx;
  294. display: flex;
  295. justify-content: flex-start;
  296. flex-direction: column;
  297. .price {
  298. &-icon {
  299. font-size: 40rpx;
  300. font-weight: 800;
  301. }
  302. }
  303. }
  304. .center {
  305. display: flex;
  306. justify-content: center;
  307. align-items: center;
  308. }
  309. .input-bar {
  310. height: 150rpx;
  311. border-bottom: 1rpx solid #DDDDDD;
  312. .icon {
  313. width: 15%;
  314. font-size: 70rpx;
  315. font-weight: 900;
  316. height: 100%;
  317. }
  318. .input {
  319. width: 85%;
  320. height: 100%;
  321. overflow: hidden;
  322. font-size: 70rpx;
  323. }
  324. .cusor {
  325. margin-left: 10rpx;
  326. width: 6rpx;
  327. border-radius: 20rpx;
  328. height: 60%;
  329. background-color: #ff9900;
  330. animation: blink 1200ms infinite ease-in-out;
  331. }
  332. }
  333. @keyframes blink {
  334. from {
  335. opacity: 0;
  336. }
  337. }
  338. </style>