index.vue 8.1 KB

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