index.vue 6.7 KB

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