pay.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <template>
  2. <view class="food-pay">
  3. <view class="content shop-box">
  4. <view class="shop-name">
  5. {{shopName}}
  6. </view>
  7. <view class="address">
  8. {{address}}
  9. </view>
  10. </view>
  11. <view class="content goods-box">
  12. <view class="title">
  13. 订单信息
  14. </view>
  15. <view class="goods-item" v-for="(item,index) in createQuery.products" :key="index">
  16. <view class="left">
  17. <image class="icon" :src="item.imageUrl" mode=""></image>
  18. <view class="name">
  19. {{item.nameCn}}
  20. </view>
  21. <view class="num">
  22. x{{item.quantity}}
  23. </view>
  24. </view>
  25. <view class="right">
  26. ¥{{item.sellPrice}}
  27. </view>
  28. </view>
  29. <view class="total-box">
  30. <view class="num">
  31. 共{{totalNum}}件
  32. </view>
  33. <view class="price">
  34. 小计¥{{total}}
  35. </view>
  36. </view>
  37. </view>
  38. <view class="content">
  39. <view class="item">
  40. <view class="label">
  41. 联系号码
  42. </view>
  43. <input class="value input" :maxlength="11" type="text" placeholder="请填写手机号" v-model="createQuery.phone" />
  44. </view>
  45. </view>
  46. <view class="content">
  47. <view class="item">
  48. <view class="label">
  49. 备注
  50. </view>
  51. <input class="value input" type="text" placeholder="请填写备注" v-model="createQuery.remark" />
  52. </view>
  53. </view>
  54. <view class="type-box content">
  55. <view class="title">
  56. 就餐方式
  57. </view>
  58. <view class="type-btn-box">
  59. <view class="btn" :class="[createQuery.eatType == 0?'active':'']" @click="handleType(0)">
  60. 店内就餐
  61. </view>
  62. <view class="btn" :class="[createQuery.eatType == 1?'active':'']" @click="handleType(1)">
  63. 打包带走
  64. </view>
  65. </view>
  66. </view>
  67. <view class="notice-box content">
  68. <view class="title">
  69. 温馨提示
  70. </view>
  71. <view class="notice">
  72. 1.付款成功后预计5-10分钟为您出餐(具体出餐时间以门店实际出餐时间为准)
  73. </view>
  74. <view class="notice">
  75. 2.此订单为特价产品,付款成功后将无法退款。请确认后购买
  76. </view>
  77. <view class="notice">
  78. 3.由于门店餐品库存不稳定等因素,存在少量出餐失败的情况,
  79. 会自动退款
  80. </view>
  81. <view class="notice">
  82. 4.出餐失败,3个工作日内自动退款到您付款账户
  83. </view>
  84. </view>
  85. <view class="btn-box">
  86. <view class="left">
  87. <view class="total">
  88. 合计 <view class="price-box">
  89. <view class="unit">
  90. </view>
  91. <view class="price">
  92. {{total}}
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. <button class="btn" @click="handleBuy" :loading="loading">
  98. 去支付
  99. </button>
  100. </view>
  101. <u-modal :show="show" title="请你再次确认门店" showCancelButton cancelColor="#AAAAAA" confirmColor="#FF4D3A" cancelText="返回修改" confirmText="确认门店" @confirm="buy" @cancel="cancel">
  102. <view class="modal-box">
  103. <view class="shopName">
  104. {{shopName}}
  105. </view>
  106. <view class="address">
  107. {{address}}
  108. </view>
  109. <view class="notice">
  110. 支付订单后无法退换,请确认下单门店!
  111. </view>
  112. </view>
  113. </u-modal>
  114. </view>
  115. </template>
  116. <script>
  117. import {createOrder} from '@/api/orderFood.js';
  118. import {
  119. creatPayOrder,
  120. queryPayOrder,
  121. payDetails
  122. } from '@/api/payment.js'
  123. export default {
  124. data() {
  125. return {
  126. totalNum:0,
  127. show:false,
  128. openTime:'',
  129. closeTime:'',
  130. active:0,
  131. loading:false,
  132. shopName:'',
  133. address:'',
  134. total:0,
  135. createQuery:{
  136. ot:uni.getStorageSync('ot'),
  137. "channel": "ZhongShu",
  138. "cityId": 0,
  139. "eatType": 0,
  140. "entPara": "",
  141. "goodsName": "",
  142. "imageCnUrl": "",
  143. "mealTime": 0,
  144. "phone": JSON.parse(uni.getStorageSync('userInfo')).phoneNum,
  145. "products": [
  146. {
  147. "imageUrl": "",
  148. "nameCn": "",
  149. "pid": "",
  150. "productId": "",
  151. "quantity": 0,
  152. "sellPrice": 0,
  153. }
  154. ],
  155. // "recAddr": {
  156. // "addr": "",
  157. // "contact": "",
  158. // "createTime": "",
  159. // "gender": "",
  160. // "id": "",
  161. // "lat": 0,
  162. // "lon": 0,
  163. // "number": "",
  164. // "phone": "",
  165. // "userId": ""
  166. // },
  167. "remark": "",
  168. "shopId": "",
  169. "shopName": "",
  170. "tableWare": true
  171. },
  172. query: {
  173. "msgType": "wx.unifiedOrder",
  174. "orderDesc": "测试",
  175. "orderNo": "",
  176. "channel":'ZhongShu',
  177. "subOpenId": "",
  178. "userId": ""
  179. },
  180. }
  181. },
  182. methods: {
  183. handleType(val){
  184. this.createQuery.eatType = val
  185. },
  186. cancel(){
  187. this.show = false
  188. },
  189. handleBuy(){
  190. this.show = true
  191. },
  192. buy(){
  193. this.show = false
  194. if (this.loading) return
  195. this.loading = true
  196. uni.showLoading({
  197. title: '支付中'
  198. })
  199. let that = this
  200. createOrder(this.createQuery).then(res => {
  201. this.loading = false
  202. if (res.state == 'Success') {
  203. this.query.orderNo = res.content.orderNo
  204. this.query.subOpenId = JSON.parse(uni.getStorageSync('userInfo')).openId
  205. this.query.orderDesc = '点餐'
  206. creatPayOrder(this.query).then(data => {
  207. that.payData = JSON.parse(data.content.miniPayRequest)
  208. if (data.content.miniPayRequest == null) return uni.hideLoading()
  209. uni.requestPayment({
  210. "provider": "wxpay",
  211. "orderInfo": that.payData,
  212. "appid": that.payData
  213. .appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  214. "paySign": that.payData.paySign,
  215. "nonceStr": that.payData.nonceStr, // 随机字符串
  216. "package": that.payData.package, // 固定值
  217. // "prepayid": that.payData.package, // 统一下单订单号
  218. "timeStamp": that.payData.timeStamp, // 时间戳(单位:秒)
  219. "signType": that.payData.signType, //签名算法
  220. success(msg) {
  221. console.log('msg', msg, res);
  222. queryPayOrder(that.query.orderNo).then(res1 => {
  223. if (res1.state == 'Success') {
  224. uni.hideLoading()
  225. uni.reLaunch({
  226. url: '/my/order/index'
  227. })
  228. }
  229. })
  230. },
  231. fail(e) {
  232. console.log('err', e);
  233. that.loading = false
  234. uni.hideLoading()
  235. uni.showToast({
  236. title: '取消支付',
  237. icon: 'fail'
  238. })
  239. // 取消支付后
  240. uni.reLaunch({
  241. url:'/my/order/foodOrder/detail?id='+that.query.orderNo
  242. })
  243. }
  244. })
  245. })
  246. // }
  247. }
  248. })
  249. }
  250. },
  251. onLoad() {
  252. let userInfo = JSON.parse(uni.getStorageSync('userInfo'))
  253. this.query.userId = userInfo.userId
  254. let that = this
  255. const eventChannel = this.getOpenerEventChannel();
  256. eventChannel.on('pay', function(data) {
  257. that.createQuery.products = data.products
  258. that.createQuery.shopId = data.shopId
  259. that.createQuery.goodsName = data.products[0].nameCn
  260. that.createQuery.imageCnUrl = data.products[0].imageCnUrl
  261. that.shopName = data.shopName
  262. that.createQuery.shopName = data.shopName
  263. that.address = data.address
  264. that.total = data.total
  265. that.openTime=data.openTime
  266. that.closeTime=data.closeTime
  267. that.totalNum = data.totalNum
  268. console.log('data', data);
  269. })
  270. }
  271. }
  272. </script>
  273. <style lang="scss" scoped>
  274. .food-pay{
  275. background: #F9F9F9;
  276. min-height: 100vh;
  277. padding: 20rpx 24rpx 100rpx;
  278. .content{
  279. margin-bottom: 20rpx;
  280. padding: 24rpx;
  281. border-radius: 16rpx;
  282. background: #fff;
  283. .title{
  284. font-weight: 600;
  285. font-size: 28rpx;
  286. color: #222222;
  287. }
  288. .item{
  289. display: flex;
  290. align-items: center;
  291. justify-content: space-between;
  292. .label{
  293. font-size: 24rpx;
  294. color: #AAAAAA;
  295. }
  296. .value{
  297. font-size: 24rpx;
  298. color: #222222;
  299. }
  300. .input{
  301. text-align: right;
  302. }
  303. }
  304. }
  305. .shop-box{
  306. // margin: 0 30rpx;
  307. // padding: 24rpx 24rpx 30rpx;
  308. background: #fff;
  309. border-radius: 16rpx;
  310. box-sizing: border-box;
  311. .shop-name{
  312. font-weight: 600;
  313. font-size: 32rpx;
  314. color: #181818;
  315. width: 100%;
  316. white-space: nowrap;
  317. overflow: hidden;
  318. text-overflow: ellipsis;
  319. }
  320. .address{
  321. font-weight: 300;
  322. font-size: 24rpx;
  323. color: #AAAAAA;
  324. margin-top: 20rpx;
  325. width: 100%;
  326. white-space: nowrap;
  327. overflow: hidden;
  328. text-overflow: ellipsis;
  329. }
  330. }
  331. .goods-box{
  332. .goods-item{
  333. display: flex;
  334. align-items: center;
  335. justify-content: space-between;
  336. padding: 12rpx 0;
  337. .left{
  338. display: flex;
  339. align-items: center;
  340. .icon{
  341. width: 80rpx;
  342. height: 80rpx;
  343. border-radius: 16rpx 16rpx 16rpx 16rpx;
  344. }
  345. .name{
  346. font-size: 28rpx;
  347. color: #222222;
  348. margin-left: 20rpx;
  349. max-width: 400rpx;
  350. white-space: nowrap;
  351. overflow: hidden;
  352. text-overflow: ellipsis;
  353. }
  354. .num{
  355. font-size: 24rpx;
  356. color: #AAAAAA;
  357. margin-left: 20rpx;
  358. }
  359. }
  360. .right{
  361. font-size: 28rpx;
  362. color: #222222;
  363. }
  364. }
  365. .total-box{
  366. display: flex;
  367. align-items: center;
  368. justify-content: flex-end;
  369. font-size: 28rpx;
  370. color: #222222;
  371. padding-top: 24rpx;
  372. border-top: 1rpx solid #F0F0F0;
  373. .num{
  374. }
  375. .price{
  376. margin-left: 20rpx;
  377. }
  378. }
  379. }
  380. .type-box{
  381. .type-btn-box{
  382. display: flex;
  383. align-items: center;
  384. justify-content: space-between;
  385. margin-top: 20rpx;
  386. .btn{
  387. width: 316rpx;
  388. height: 80rpx;
  389. line-height: 80rpx;
  390. text-align: center;
  391. background: #F6F6F6;
  392. border-radius: 40rpx 40rpx 40rpx 40rpx;
  393. font-weight: bold;
  394. font-size: 28rpx;
  395. color: #AAAAAA;
  396. }
  397. .btn.active{
  398. background: rgba(238,67,32,0.1);
  399. color: #EE4320;
  400. }
  401. }
  402. }
  403. .notice-box{
  404. .notice{
  405. font-size: 24rpx;
  406. color: #AAAAAA;
  407. margin-top: 20rpx;
  408. }
  409. }
  410. .btn-box {
  411. position: fixed;
  412. bottom: 0%;
  413. left: 0%;
  414. z-index: 2;
  415. width: 100%;
  416. display: flex;
  417. align-items: center;
  418. justify-content: space-between;
  419. box-sizing: border-box;
  420. padding: 10rpx 24rpx env(safe-area-inset-bottom);
  421. background: #fff;
  422. border-top: 1rpx solid #EEEEEE;
  423. .left{
  424. display: flex;
  425. align-items: flex-end;
  426. .total{
  427. font-weight: 300;
  428. font-size: 24rpx;
  429. color: #222222;
  430. display: flex;
  431. align-items: flex-end;
  432. margin-left: 6rpx;
  433. .price-box{
  434. display: flex;
  435. align-items: flex-end;
  436. font-weight: 400;
  437. font-size: 32rpx;
  438. color: #FF4D3A;
  439. .unit{
  440. font-size: 20rpx;
  441. }
  442. .price{
  443. font-weight: bold;
  444. }
  445. }
  446. }
  447. }
  448. .btn {
  449. width: 280rpx;
  450. height: 80rpx;
  451. line-height: 80rpx;
  452. text-align: center;
  453. background: $uni-color-primary;
  454. border-radius: 40rpx;
  455. font-weight: 600;
  456. font-size: 28rpx;
  457. color: #FFFFFF;
  458. margin: 0;
  459. }
  460. }
  461. .modal-box{
  462. .shop-name{
  463. font-weight: 600;
  464. font-size: 32rpx;
  465. color: #181818;
  466. width: 100%;
  467. }
  468. .address{
  469. font-weight: 300;
  470. font-size: 24rpx;
  471. color: #AAAAAA;
  472. margin-top: 4rpx;
  473. width: 100%;
  474. }
  475. .notice{
  476. margin-top: 20rpx;
  477. font-weight: 300;
  478. font-size: 24rpx;
  479. color: #AAAAAA;
  480. }
  481. }
  482. }
  483. </style>