index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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>
  24. <amountInput ref="amountInput" confirmText="付款" btnColor="#ff9900" placeholder="请输入交易金额" @change="change"
  25. @confirm="debouncePay"></amountInput>
  26. <u-modal v-model="payModalShow" :showCancelButton="true" confirm-color="#FF9447">
  27. <view class="center flex-direction text-df" style="padding: 30rpx 40rpx;">
  28. <view>您的积分可足额抵扣支付</view>
  29. <view class="padding-top-10">本次支付不会扣除您的现金</view>
  30. </view>
  31. </u-modal>
  32. <u-modal v-model="modalShow" :mask-close-able="true" :showCancelButton="true" @cancel="payOfh5"
  33. @confirm="jumpLDT" cancel-text="直接付款" confirm-color="#FF9447" confirmText="去联兑通支付"
  34. content="去联兑通小程序付款会有更多优惠哟~"></u-modal>
  35. </view>
  36. </template>
  37. <script>
  38. import amountInput from '@/components/amountInput/amountInput.vue';
  39. export default {
  40. components: {
  41. amountInput
  42. },
  43. data() {
  44. return {
  45. isFirstPay: true,
  46. orderAmount: '',
  47. payModalShow: false,
  48. modalShow: false,
  49. shopId: '',
  50. shopDetail: {}
  51. }
  52. },
  53. onLoad(options) {
  54. if (!this.$isEmpty(options.query)) {
  55. let params = options.query.split(";")
  56. this.shopId = params[0]
  57. this.orderAmount = params[1]
  58. } else {
  59. this.shopId = options.id
  60. }
  61. // #ifdef MP-WEIXIN
  62. //如果是新用户通过微信支付扫码进入此页面,跳回首页
  63. if (this.$isEmpty(this.vuex_userId)) {
  64. uni.reLaunch({
  65. url: "/pages/mine/mine?query=" + this.shopId + ";" + this.orderAmount
  66. })
  67. return
  68. }
  69. // #endif
  70. if (this.$isEmpty(this.shopId)) {
  71. this.$dialog.showModal('商户id不能为空', false).then(() => {
  72. uni.navigateBack()
  73. })
  74. return
  75. }
  76. this.fetchShopDetail()
  77. },
  78. methods: {
  79. //防抖支付
  80. debouncePay() {
  81. if (this.isFirstPay) {
  82. this.pay()
  83. this.isFirstPay = false
  84. } else {
  85. this.$u.debounce(this.pay, 500)
  86. }
  87. },
  88. fetchShopDetail() {
  89. this.$api.shop.detail({
  90. id: this.shopId
  91. }).then(res => {
  92. if (this.$isEmpty(res.data)) {
  93. this.$dialog.showModal('获取不到商户信息', false).then(() => {
  94. uni.navigateBack({
  95. delta: 1
  96. })
  97. })
  98. } else {
  99. this.shopDetail = res.data
  100. }
  101. }).catch(err => {
  102. this.$dialog.showModal('获取不到商户信息', false).then(() => {
  103. uni.navigateBack({
  104. delta: 1
  105. })
  106. })
  107. })
  108. },
  109. show() {
  110. this.$refs.amountInput.show()
  111. },
  112. change(e) {
  113. if (!e) {
  114. this.orderAmount = 0
  115. } else {
  116. this.orderAmount = e
  117. }
  118. },
  119. filterMoney(value) {
  120. if (!value) {
  121. return ''
  122. } else {
  123. value = value.replace(/\$\s?|(,*)/g, '')
  124. return value.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
  125. }
  126. },
  127. async jumpLDT() {
  128. this.$dialog.showLoading('打开中..')
  129. let params = {
  130. path: "/pages/checkstand/index",
  131. query: "query=" + this.shopId + ";" + this.orderAmount
  132. }
  133. let res = await this.$api.wxApp.getGenerateScheme(params)
  134. if (res.data.openlink) {
  135. location.href = res.data.openlink
  136. } else {
  137. location.href = "weixin://dl/business/?t=X2CyIQDbgtm"
  138. }
  139. uni.hideLoading()
  140. },
  141. async payOfh5() {
  142. let expireTime = this.$dateTime.getExpireTime(5)
  143. let params = {
  144. money: this.orderAmount,
  145. shopId: this.shopId,
  146. billsTitle: '用户微信扫码支付',
  147. expireTime
  148. }
  149. let resp = await this.$api.loginUser.payBeforeForNormal(params)
  150. let payObj = {
  151. orderType: this.$global.orderType.USER_PAY,
  152. orderId: resp.data.id
  153. }
  154. let res = await this.$api.pay.payOrderOfscanCode(payObj)
  155. if (!this.$isEmpty(res.data.qrCodeUrl)) {
  156. location.href = res.data.qrCodeUrl
  157. } else {
  158. this.$u.toast('支付失败')
  159. }
  160. },
  161. isMoney(s) {
  162. var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
  163. if (reg.test(s)) {
  164. return true;
  165. }else {
  166. return false;
  167. }
  168. },
  169. async pay() {
  170. if (this.$isEmpty(this.orderAmount)
  171. || !this.isMoney(this.orderAmount)
  172. || this.orderAmount == '0'
  173. || this.orderAmount == '0.'
  174. || this.orderAmount == '0.0'
  175. || this.orderAmount == '0.00') {
  176. this.$u.toast('请输入交易金额')
  177. return
  178. }
  179. // #ifdef H5
  180. this.modalShow = true
  181. // #endif
  182. // #ifdef MP-WEIXIN
  183. let flag = false
  184. if (flag) {
  185. //可以足额支付
  186. this.payModalShow = true
  187. } else {
  188. //积分不足额支付,调易宝支付
  189. this.toWXPay()
  190. }
  191. // #endif
  192. },
  193. async toWXPay() {
  194. let expireTime = this.$dateTime.getExpireTime(5)
  195. let params = {
  196. shopId: this.shopId,
  197. loginUserId: this.vuex_userId,
  198. money: this.orderAmount,
  199. billsTitle: '用户支付',
  200. expireTime,
  201. appId: this.$global.wxParams.APPID,
  202. openId: this.$cache.get('userInfo').openId,
  203. type: 1 //type: 1-用户扫商户收款码支付 2-商户扫用户付款码支付
  204. }
  205. let resp = await this.$api.loginUser.payBefore(params)
  206. if (!resp.success) {
  207. this.$u.toast(resp.msg)
  208. return
  209. }
  210. if (resp.data.payAmount == 0) {
  211. this.$dialog.showModal('已使用积分抵扣成功', false).then(() => {
  212. uni.navigateBack({
  213. delta: 1
  214. })
  215. })
  216. return
  217. }
  218. let obj = {
  219. orderType: this.$global.orderType.USER_PAY,
  220. orderId: resp.data.id,
  221. payStatus: this.$global.payStatus.IS_WAIT
  222. }
  223. let res = await this.$api.pay.payOrder(obj)
  224. let prePayTn = JSON.parse(res.data.prePayTn)
  225. await this.$mpi.requestPayment(prePayTn)
  226. uni.navigateTo({
  227. url: "/pages/checkstand/order-res?orderId=" + resp.data.id
  228. })
  229. }
  230. }
  231. }
  232. </script>
  233. <style>
  234. page {
  235. background-color: #ffff;
  236. }
  237. </style>
  238. <style lang="scss" scoped>
  239. .shopInfo {
  240. margin: 60rpx 0 20rpx;
  241. display: flex;
  242. justify-content: center;
  243. align-items: center;
  244. flex-direction: column;
  245. image {
  246. border-radius: 50%;
  247. width: 140rpx;
  248. height: 140rpx;
  249. }
  250. text {
  251. margin-top: 30rpx;
  252. font-size: 32rpx;
  253. }
  254. }
  255. .data {
  256. padding: 50rpx;
  257. display: flex;
  258. justify-content: flex-start;
  259. flex-direction: column;
  260. .price {
  261. &-icon {
  262. font-size: 40rpx;
  263. font-weight: 800;
  264. }
  265. }
  266. }
  267. .center {
  268. display: flex;
  269. justify-content: center;
  270. align-items: center;
  271. }
  272. .input-bar {
  273. height: 150rpx;
  274. border-bottom: 1rpx solid #DDDDDD;
  275. .icon {
  276. width: 15%;
  277. font-size: 70rpx;
  278. font-weight: 900;
  279. height: 100%;
  280. }
  281. .input {
  282. width: 85%;
  283. height: 100%;
  284. overflow: hidden;
  285. font-size: 70rpx;
  286. }
  287. .cusor {
  288. margin-left: 10rpx;
  289. width: 6rpx;
  290. border-radius: 20rpx;
  291. height: 60%;
  292. background-color: #ff9900;
  293. animation: blink 1200ms infinite ease-in-out;
  294. }
  295. }
  296. @keyframes blink {
  297. from {
  298. opacity: 0;
  299. }
  300. }
  301. </style>