offlinePayment.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <view class="offlinePayment">
  3. <view class="shop-info">
  4. <view class="shop-name">
  5. {{shopInfo.shopName}}
  6. </view>
  7. <view class="address">
  8. {{shopInfo.address}}
  9. </view>
  10. </view>
  11. <view class="pay-info">
  12. <view class="title">
  13. 请输入付款金额
  14. </view>
  15. <view class="input-box">
  16. <view class="icon">
  17. ¥
  18. </view>
  19. <input class="money-input" v-model.number="shopInfo.price" type="digit" />
  20. </view>
  21. <view class="coupon">
  22. <view class="label">
  23. 优惠券
  24. </view>
  25. <view class="choose-coupon" @click="choose">
  26. {{payInfo.goodsCouponName}}-¥{{payInfo.offset}}
  27. <image class="icon" src="../static/jiantou-icon.png" mode=""></image>
  28. </view>
  29. </view>
  30. <view class="explain">
  31. <view class="label">
  32. 优惠说明
  33. </view>
  34. <view class="right">
  35. 已优惠: <view class="red">¥{{payInfo.offset}} </view> 合计: <view class="red fs28">¥{{payInfo.price}}
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="btn-box">
  41. <view class="total-price">
  42. <view class="label">
  43. 合计:
  44. </view>
  45. <view class="price">
  46. ¥ {{payInfo.price}}
  47. </view>
  48. </view>
  49. <button class="btn" type="default" :loading="loading" @click="creat">提交订单</button>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. calculateByInput,
  56. creatScanOrder
  57. } from '@/api/order.js';
  58. import {
  59. creatPayOrder,
  60. queryPayOrder,
  61. close
  62. } from '@/api/payment.js'
  63. import {shopDetail} from '@/api/shop.js'
  64. import guid from '@/utils/guid.js'
  65. import {debounce} from '@/utils/tool.js'
  66. export default {
  67. data() {
  68. return {
  69. loading: false,
  70. shopInfo: {
  71. shopName:'',
  72. address:'',
  73. price:0,
  74. },
  75. info: {},
  76. realPay: {
  77. goodsCouponName: '', //优惠券名
  78. couponGoodsLogId: '', //优惠券id
  79. goodsId: '', //商品id
  80. price: '', //支付价格
  81. offset: '', //实际抵扣值
  82. discount: '', //优惠券值
  83. condition: '', //优惠条件
  84. originalPrice: '', //原价
  85. },
  86. query: {
  87. "msgType": "wx.unifiedOrder",
  88. "orderDesc": "线下扫码支付",
  89. "orderNo": "",
  90. "channel":'ZhongShu',
  91. "subOpenId": "",
  92. "userId": ""
  93. },
  94. // 支付信息
  95. payData: {
  96. }
  97. }
  98. },
  99. computed: {
  100. // 正式支付时的信息
  101. payInfo() {
  102. return {
  103. goodsCouponName: this.realPay.goodsCouponName || '', //优惠券名
  104. couponGoodsLogId: this.realPay.couponGoodsLogId || '', //优惠券id
  105. price: this.realPay.price, //支付价格
  106. offset: this.realPay.offset, //实际抵扣值
  107. discount: this.realPay.discount || 0, //优惠券值
  108. condition: this.realPay.condition || '', //优惠条件
  109. originalPrice: this.realPay.originalPrice, //原价
  110. }
  111. }
  112. },
  113. watch: {
  114. 'shopInfo.price':debounce(function(val) {
  115. if(!val){
  116. this.shopInfo.price = 0
  117. }
  118. this.calculateByInput(this.shopInfo.shopId)
  119. })
  120. },
  121. methods: {
  122. calculateByInput(shopId) {
  123. return new Promise((resolve, reject) => {
  124. calculateByInput({
  125. couponId: this.info.couponId,
  126. "price": this.shopInfo.price,
  127. "shopId": shopId,
  128. "userId": JSON.parse(uni.getStorageSync('userInfo')).userId
  129. }).then(res => {
  130. if (res.state == 'Success') {
  131. this.realPay = res.content
  132. }
  133. })
  134. })
  135. },
  136. choose() {
  137. let that = this
  138. uni.navigateTo({
  139. url: `./coupon?couponId=${this.realPay.couponGoodsLogId}&type=offlinePayment`,
  140. success: function(res) {
  141. // 通过eventChannel向被打开页面传送数据
  142. res.eventChannel.emit('pay', that.shopInfo)
  143. }
  144. })
  145. },
  146. //创建订单
  147. creat() {
  148. if (this.loading) return
  149. this.loading = true
  150. if (!this.payInfo.price) { //价格为0
  151. uni.hideLoading()
  152. this.loading = false
  153. return uni.showToast({
  154. title:'请输入付款金额',
  155. icon:'none'
  156. })
  157. }
  158. uni.showLoading({
  159. title: '支付中'
  160. })
  161. let that = this
  162. creatScanOrder({
  163. discountId: this.payInfo.couponGoodsLogId ? [this.payInfo.couponGoodsLogId] : [],
  164. extend: "",
  165. "channel":'ZhongShu',
  166. price: this.shopInfo.price,
  167. shopId: this.shopInfo.shopId
  168. }).then(res => {
  169. this.loading = false
  170. if (res.state == 'Success') {
  171. this.query.orderNo = res.content.orderNo
  172. this.query.subOpenId = JSON.parse(uni.getStorageSync('userInfo')).openId
  173. creatPayOrder(this.query).then(data => {
  174. that.payData = JSON.parse(data.content.miniPayRequest)
  175. if(data.content.miniPayRequest == null) return uni.hideLoading()
  176. uni.requestPayment({
  177. "provider": "wxpay",
  178. "orderInfo": that.payData,
  179. "appid": that.payData.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  180. "paySign": that.payData.paySign,
  181. "nonceStr": that.payData.nonceStr, // 随机字符串
  182. "package": that.payData.package, // 固定值
  183. // "prepayid": that.payData.package, // 统一下单订单号
  184. "timeStamp": that.payData.timeStamp, // 时间戳(单位:秒)
  185. "signType": that.payData.signType, //签名算法
  186. success(msg) {
  187. console.log('msg', msg,res);
  188. queryPayOrder(that.query.orderNo).then(res1 => {
  189. if (res1.state == 'Success') {
  190. uni.hideLoading()
  191. uni.reLaunch({
  192. url: '/my/order/index'
  193. })
  194. }
  195. })
  196. },
  197. fail(e) {
  198. console.log('err', e);
  199. // 取消支付后,直接关闭订单
  200. close(that.query.orderNo).then(res=>{
  201. if (res.state == 'Success') {
  202. that.loading = false
  203. uni.hideLoading()
  204. uni.showToast({
  205. title: '取消支付',
  206. icon: 'fail'
  207. })
  208. }
  209. })
  210. }
  211. })
  212. })
  213. }
  214. })
  215. },
  216. shopDetail(shopId){
  217. shopDetail({shopId}).then(res=>{
  218. if (res.state == 'Success') {
  219. this.shopInfo.shopName = res.content.shopName
  220. this.shopInfo.address = res.content.address
  221. }
  222. })
  223. }
  224. },
  225. onLoad(options) {
  226. let that = this
  227. this.shopInfo.shopId = decodeURIComponent(options.scene)
  228. this.shopDetail(this.shopInfo.shopId)
  229. if(!uni.getStorageSync('token')){
  230. return uni.showModal({
  231. title:'请登录',
  232. confirmText:'去登录',
  233. success(res){
  234. console.log(res);
  235. if(res.confirm){
  236. uni.navigateTo({
  237. url:`/login/login/login?redirect=/pay/offlinePayment&scene=${that.shopInfo.shopId}`
  238. })
  239. }
  240. }
  241. })
  242. }
  243. let userInfo = JSON.parse(uni.getStorageSync('userInfo'))
  244. this.query.userId = userInfo.userId
  245. this.calculateByInput(this.shopInfo.shopId)
  246. const eventChannel = this.getOpenerEventChannel();
  247. if(JSON.stringify(eventChannel) !=='{}'){
  248. eventChannel.on('pay', function(data) {
  249. that.shopInfo = data
  250. })
  251. }
  252. }
  253. }
  254. </script>
  255. <style lang="scss" scoped>
  256. .offlinePayment {
  257. background: #F9F9F9;
  258. min-height: 100vh;
  259. padding-top: 20rpx;
  260. .shop-info {
  261. margin: 0 30rpx 20rpx;
  262. width: 690rpx;
  263. padding: 24rpx;
  264. box-sizing: border-box;
  265. background: #FFFFFF;
  266. border-radius: 16rpx 16rpx 16rpx 16rpx;
  267. .shop-name {
  268. color: #181818;
  269. font-size: 32rpx;
  270. }
  271. .address {
  272. color: #999999;
  273. font-size: 24rpx;
  274. margin-top: 12rpx;
  275. }
  276. }
  277. .pay-info {
  278. margin: 0 30rpx;
  279. background: #FFFFFF;
  280. border-radius: 16rpx 16rpx 16rpx 16rpx;
  281. padding: 28rpx 24rpx;
  282. .title {
  283. font-size: 28rpx;
  284. color: #222222;
  285. }
  286. .input-box {
  287. position: relative;
  288. line-height: 98rpx;
  289. font-size: 36rpx;
  290. border-bottom: 2rpx solid #f3f3f3;
  291. .icon {
  292. position: absolute;
  293. left: 0%;
  294. top: 50%;
  295. transform: translateY(-50%);
  296. }
  297. .money-input {
  298. padding-left: 30rpx;
  299. width: 100%;
  300. height: 100rpx;
  301. line-height: 100rpx;
  302. box-sizing: border-box;
  303. }
  304. }
  305. .coupon {
  306. display: flex;
  307. align-items: center;
  308. justify-content: space-between;
  309. border-bottom: 2rpx dashed #f3f3f3;
  310. padding: 28rpx 0;
  311. .label {
  312. color: #222222;
  313. font-size: 28rpx;
  314. }
  315. .choose-coupon {
  316. color: #FF4848;
  317. font-size: 28rpx;
  318. display: flex;
  319. align-items: center;
  320. .icon {
  321. width: 28rpx;
  322. height: 28rpx;
  323. display: block;
  324. margin-left: 10rpx;
  325. }
  326. }
  327. }
  328. .explain {
  329. display: flex;
  330. align-items: center;
  331. justify-content: space-between;
  332. padding-top: 28rpx;
  333. .label {
  334. color: #AAAAAA;
  335. font-size: 28rpx;
  336. }
  337. .right {
  338. display: flex;
  339. align-items: center;
  340. font-size: 24rpx;
  341. .red {
  342. font-weight: 500;
  343. color: #FF4848;
  344. margin: 0 10rpx;
  345. }
  346. .fs28 {
  347. font-size: 28rpx !important;
  348. }
  349. }
  350. }
  351. }
  352. .btn-box {
  353. position: fixed;
  354. bottom: 0%;
  355. left: 0%;
  356. width: 100%;
  357. height: 98rpx;
  358. display: flex;
  359. align-items: center;
  360. justify-content: space-between;
  361. box-sizing: border-box;
  362. padding: 0 30rpx;
  363. border-top: 1rpx solid #EEEEEE;
  364. .total-price {
  365. display: flex;
  366. align-items: center;
  367. .label {
  368. color: #181818;
  369. font-size: 28rpx;
  370. }
  371. .price {
  372. font-size: 36rpx;
  373. font-weight: 800;
  374. color: #FF4848;
  375. margin-left: 10rpx;
  376. }
  377. }
  378. .btn {
  379. width: 240rpx;
  380. height: 80rpx;
  381. line-height: 80rpx;
  382. text-align: center;
  383. background: linear-gradient(265deg, #FF4A39 0%, #FC8B45 100%);
  384. box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255, 255, 255, 0.16);
  385. border-radius: 46rpx 46rpx 46rpx 46rpx;
  386. font-weight: 800;
  387. color: #FFFFFF;
  388. font-size: 28rpx;
  389. margin: 0;
  390. }
  391. }
  392. }
  393. </style>