pay.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <template>
  2. <view class="content">
  3. <view class="">
  4. <u-navbar :isBack="isBack" :title="title"></u-navbar>
  5. </view>
  6. <view class="" v-show="!payShow">
  7. <view class="">
  8. <view>
  9. <!-- 地址栏 -->
  10. <view v-if="takeType==tykeTypeGloabl.delivery" class="bg-white"
  11. @click="$jump('/pagesD/pages/address/address')">
  12. <view class="add-address-box u-flex u-flex-1" v-if="$isEmpty(address)">
  13. <view class="box-bg u-p-30 u-flex-1 u-flex u-row-between">
  14. <text class="select-notice">请选择收货地址</text>
  15. <text class="cuIcon-right" style="color: #bfbfbf;"></text>
  16. </view>
  17. </view>
  18. <view class="add-address-box u-p-20" v-else>
  19. <view class="flex">
  20. <view class="center margin-right-20">
  21. <view class="cuIcon cu-btn round bg-base xl " style="width: 80rpx;height: 80rpx;">
  22. <text>{{ address.consignee.substring(0,1)}}</text>
  23. </view>
  24. </view>
  25. <view class="" style="width: 90%;">
  26. <view class="top u-flex">
  27. <text class="name">{{ address.consignee }}</text>
  28. <text class="phone">{{ address.phone }}</text>
  29. <text class="tag" v-show="address.isDefault == 1">默认</text>
  30. </view>
  31. <view class="detail u-flex u-row-between" style="width: 100%;">
  32. <view class="address text-cut-1" style="width: 90%;">
  33. {{ address.provinceName }}{{ address.cityName }}{{ address.areaName }}{{ address.address }}
  34. </view>
  35. <text class="cuIcon-right margin-left-20" style="color: #bfbfbf;"></text>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. <view class="card" style="justify-content: flex-start;">
  42. <text class="cuIcon-shop center text-base" style="font-size: 34rpx;"></text>
  43. <text class="text-lg margin-left-10">{{vuex_orderInfo.store.shopName}}</text>
  44. </view>
  45. <view class="card text-df" @click="takeTypeShow=true">
  46. <text class="text-gray">取餐方式</text>
  47. <view class="">
  48. <text>{{takeType}}</text>
  49. <text class="cuIcon-right"></text>
  50. </view>
  51. </view>
  52. <view v-if="takeType==tykeTypeGloabl.dine_in" class="card text-df">
  53. <text class="text-gray">取餐时间</text>
  54. <view class="">
  55. <text>立即用餐</text>
  56. <text class="cuIcon-right"></text>
  57. </view>
  58. </view>
  59. <view v-if="takeType==tykeTypeGloabl.package" class="card text-df" @click="timeShow=true">
  60. <view class="">
  61. <text class="text-gray">自取时间</text>
  62. <view class='cu-tag light sm round margin-left-10 bg-orange'>可预约</view>
  63. </view>
  64. <view class="">
  65. <text>{{takeTime?takeTime:'请选择自取时间'}}</text>
  66. <text class="cuIcon-right"></text>
  67. </view>
  68. </view>
  69. <view v-if="takeType==tykeTypeGloabl.dine_in" class="card text-df center"
  70. style="padding-top: 15rpx;padding-bottom: 15rpx;">
  71. <text class="text-gray">取餐座位</text>
  72. <view class="flex justify-end" style="width: 50%;">
  73. <text>{{seatNum}}</text>
  74. <text class="cuIcon-right center"></text>
  75. </view>
  76. </view>
  77. <view v-if="takeType==tykeTypeGloabl.package" class="card text-df" style="border: none;">
  78. <text class="text-gray">联系电话</text>
  79. <view class="">
  80. <text>{{vuex_phone}}</text>
  81. <text class="cuIcon-right"></text>
  82. </view>
  83. </view>
  84. </view>
  85. <view style="margin-top: 20rpx;">
  86. <u-read-more ref="uReadMore" close-text="展开更多" show-height="500" color="#999">
  87. <view v-for="(item,index) in cart" :key="index" class="cart">
  88. <view class="flex" style="width: 70%;">
  89. <image :src="item.image" mode=""></image>
  90. <view class="item-content">
  91. <text class="text-cut-1">{{item.name}}</text>
  92. <text class="text-cut-1">{{item.propertyStr ? item.propertyStr : item.name}}</text>
  93. </view>
  94. </view>
  95. <view class="item-data">
  96. <view class="">
  97. <text class="text-sm">x</text>
  98. <text class="text-lg" style="margin-left: 6rpx;">{{item.number}}</text>
  99. </view>
  100. <text class="text-price text-lg">{{item.realPrice / 100}}</text>
  101. </view>
  102. </view>
  103. </u-read-more>
  104. <!-- 商家配送 -->
  105. <block v-if="takeType==tykeTypeGloabl.delivery">
  106. <view class="card text-df">
  107. <text class="text-gray">包装费</text>
  108. <text class="text-price">{{vuex_orderInfo.store.packingPrice / 100}}</text>
  109. </view>
  110. <view class="card text-df">
  111. <text class="text-gray">配送费</text>
  112. <text class="text-price">{{vuex_orderInfo.store.sendingPrice / 100}}</text>
  113. </view>
  114. </block>
  115. <!-- 到店自取 -->
  116. <block v-if="takeType==tykeTypeGloabl.package">
  117. <view class="card text-df">
  118. <text class="text-gray">包装费</text>
  119. <text class="text-price">{{vuex_orderInfo.store.packingPrice / 100}}</text>
  120. </view>
  121. </block>
  122. <view class="card" style="justify-content: flex-end;flex-direction: column;text-align: right;">
  123. <view class="">
  124. <text>总计:</text>
  125. <text class="text-price text-bold text-xl">{{total / 100}}</text>
  126. </view>
  127. <view class="text-base text-sm margin-top-20">
  128. * 以实际付款为准
  129. </view>
  130. </view>
  131. </view>
  132. <view class="card margin-top-20">
  133. <text>备注</text>
  134. <view style="width: 80%;" class="flex justify-end" @click="goRemark">
  135. <text class="text-gray" v-if="!remark">点击填写备注</text>
  136. <text v-else class="text-cut-1 text-gray">{{remark}}</text>
  137. <text class="cuIcon-right margin-left-10 center"></text>
  138. </view>
  139. </view>
  140. <!-- #ifdef MP-WEIXIN-->
  141. <view class="margin-top-20">
  142. <channel-list></channel-list>
  143. </view>
  144. <!-- #endif -->
  145. </view>
  146. <!-- 付款栏 begin -->
  147. <view class="" style="height: 140rpx;"></view>
  148. <view class="footer-fixed pay-bar" style="z-index: 99;">
  149. <view class="center" style="justify-content: flex-start;margin-left: 40rpx;">
  150. <text>总计:</text>
  151. <text class="text-price text-bold text-xl">{{total / 100}}</text>
  152. </view>
  153. <view @click="order" class="bg-base center text-lg" style="width: 25%;">
  154. 付款
  155. </view>
  156. </view>
  157. <!-- 付款栏 end -->
  158. </view>
  159. <pay-confirm confirmText="查看订单" cancelText="继续点餐" :type="payConfirmType" v-show="payShow" :info="info"
  160. @confirm="payConfirm" @cancel="payCancel"></pay-confirm>
  161. <toast ref="toast"></toast>
  162. <!-- 取餐方式 -->
  163. <u-picker @confirm="pickConfirm" confirm-color="#FF9447" :default-selector="defaultSelector" mode="selector" v-model="takeTypeShow"
  164. :range="takeTypeList"></u-picker>
  165. <!-- 自取时间 -->
  166. <h-time-alert title="自取时间" :rangeStartTime="vuex_orderInfo.store.businessStartTime"
  167. :rangeEndTime="vuex_orderInfo.store.businessEndTime" intervalTime="30" dayStartIntTime="15" rangeDay="1"
  168. :isNow="true" :isShow="timeShow" @closeAlert="handelClose">
  169. </h-time-alert>
  170. </view>
  171. </template>
  172. <script>
  173. import payConfirm from '@/components/pay-confirm.vue'
  174. import channelList from '@/components/channel-list.vue'
  175. import global from "@/assets/http/global.js"
  176. import hTimeAlert from "../../comps/h-time-alert.vue"
  177. export default {
  178. components: {
  179. payConfirm,
  180. channelList,
  181. hTimeAlert
  182. },
  183. data() {
  184. return {
  185. //navbar
  186. title: "付款",
  187. isBack: true,
  188. shopId: '',
  189. //购物车
  190. cartKey: '',
  191. cart: [],
  192. //商品备注
  193. remark: '',
  194. //商品总数
  195. totalNum: 0,
  196. // 座位号
  197. seatNum: '',
  198. //取餐方式
  199. takeType: '',
  200. tykeTypeGloabl: global.takeType,
  201. takeTypeList: ['店内堂食', '到店自取'],
  202. takeTypeShow: false,
  203. //自取时间
  204. timeShow: false,
  205. takeTime: '',
  206. //配送地址
  207. address: {},
  208. //支付参数
  209. payParams: {},
  210. successParams: {},
  211. //支付结果
  212. payConfirmType: "",
  213. payResult: {
  214. isSuccess: false,
  215. msg: "交易失败",
  216. //总价
  217. totalPrice: 0,
  218. //消耗积分值
  219. pointsNum: 0,
  220. //消耗现金值
  221. amountNum: 0,
  222. },
  223. //支付确认
  224. bills: {},
  225. payShow: false,
  226. info: {},
  227. };
  228. },
  229. onLoad() {
  230. this.init()
  231. uni.$on('REMARK', (remark) => {
  232. this.remark = remark
  233. })
  234. uni.$on('ADDRESS', (address) => {
  235. console.log(address);
  236. this.address = address
  237. })
  238. },
  239. computed: {
  240. total() {
  241. this.totalNum = 0
  242. const sum = this.cart.reduce((pre, item) => {
  243. this.totalNum += item.number
  244. return pre + item.number * item.realPrice
  245. }, 0)
  246. //商家配送
  247. if (this.takeType == this.$global.takeType.delivery) {
  248. return sum + (this.vuex_orderInfo.store.packingPrice) +
  249. (this.vuex_orderInfo.store.sendingPrice)
  250. }
  251. //到店自取
  252. if (this.takeType == this.$global.takeType.package) {
  253. return sum + (this.vuex_orderInfo.store.packingPrice)
  254. }
  255. return sum
  256. },
  257. defaultSelector(){
  258. return [this.takeTypeList.indexOf(this.takeType)]
  259. }
  260. },
  261. methods: {
  262. init() {
  263. this.seatNum = this.vuex_orderInfo.seatNum
  264. this.address = this.vuex_orderInfo.address
  265. this.takeType = this.vuex_orderInfo.takeType
  266. this.cart = this.vuex_orderInfo.cart
  267. this.shopId = this.vuex_orderInfo.shopId
  268. this.cartKey = this.$global.cart_prefix + this.vuex_orderInfo.shopId
  269. },
  270. goRemark() {
  271. uni.navigateTo({
  272. url: "remark?data=" + this.remark
  273. })
  274. },
  275. pickConfirm(e) {
  276. let index = e[0]
  277. let takeType = this.takeTypeList[index]
  278. if (takeType == this.$global.takeType.delivery && this.total < this.vuex_orderInfo.store
  279. .sendingNeedLeastPrice) {
  280. //商家配送,总价格低于配送费
  281. this.modalShow = true
  282. return
  283. }
  284. this.takeType = takeType
  285. },
  286. handelClose(data) {
  287. this.timeShow = false;
  288. if (this.$isNotEmpty(data)) {
  289. this.takeTime = this.$dateTime.format(new Date(data.date))
  290. }
  291. },
  292. getGoodsPreview(){
  293. let goodsPreview=[]
  294. this.cart.forEach(item=>{
  295. let obj={
  296. image:item.image,
  297. name:item.name,
  298. propertyStr:item.propertyStr,
  299. number:item.number,
  300. realPrice:item.realPrice,
  301. defaultPrice:item.defaultPrice
  302. }
  303. goodsPreview.push(obj)
  304. })
  305. return JSON.stringify(goodsPreview)
  306. },
  307. async order() {
  308. let goodsPreview=this.getGoodsPreview()
  309. let params = {
  310. receiveId: this.shopId,
  311. payId: this.vuex_userId,
  312. takeType: this.takeType,
  313. goodsPreview,
  314. goodsTotalNum: this.totalNum,
  315. totalPrice: this.total,
  316. extraInfo: this.remark,
  317. expireTime: this.$dateTime.getExpireTime(),
  318. userPhone: this.vuex_phone,
  319. appId: this.$global.wxParams.APPID,
  320. }
  321. if (this.$isNotEmpty(this.vuex_channel)) {
  322. params.channelId = this.vuex_channel.id
  323. }
  324. if (this.takeType == this.$global.takeType.dine_in) {
  325. //店内堂食
  326. params.seatNum = this.seatNum
  327. }
  328. if (this.takeType == this.$global.takeType.package) {
  329. //到店自取,包装费
  330. params.packingPrice = this.vuex_orderInfo.store.packingPrice
  331. if (this.$isEmpty(this.takeTime)) {
  332. this.$refs.toast.error('请选择取餐时间')
  333. return
  334. } else {
  335. params.takeTime = this.takeTime
  336. }
  337. }
  338. if (this.takeType == this.$global.takeType.delivery) {
  339. if (this.$isEmpty(this.address)) {
  340. this.$refs.toast.error('请选择配送地址')
  341. return
  342. }
  343. //商家配送,包装费,配送费
  344. params.packingPrice = this.vuex_orderInfo.store.packingPrice
  345. params.sendingPrice = this.vuex_orderInfo.store.sendingPrice
  346. params.userPhone = address.phone
  347. params.receiver = address.consignee
  348. params.addressDetail = this.address.provinceName + '-' + this.address.cityName + '-' + this.address
  349. .areaName + ' ' + this.address.address
  350. }
  351. let res = await this.$api.goods.order(params)
  352. this.payParams = res.data
  353. this.successParams = this.payParams.successParams
  354. this.bills = this.successParams.bills
  355. if (this.bills.discount == -1) {
  356. this.bills.discount = 0
  357. }
  358. if (this.successParams.status == '付款成功') {
  359. this.handelResult(true)
  360. } else if (this.successParams.status == '待付款') {
  361. if (this.bills.cost == this.bills.price) {
  362. this.doWxPay(this.bills.id)
  363. } else {
  364. this.info = {
  365. shop: this.vuex_orderInfo.shopDetail,
  366. bills: this.bills,
  367. }
  368. this.title = "支付确认"
  369. this.isBack = false
  370. this.payShow = true
  371. }
  372. } else {
  373. this.handelResult(false)
  374. }
  375. uni.hideLoading()
  376. },
  377. async doWxPay(orderId) {
  378. this.$dialog.showLoading('付款中...')
  379. let obj = {
  380. orderType: this.$global.orderType.USER_PAY,
  381. orderId,
  382. payStatus: this.$global.payStatus.IS_WAIT
  383. }
  384. let res = await this.$api.pay.payOrder(obj)
  385. if (this.$isEmpty(res.data.prePayTn)) {
  386. this.$refs.toast.error(res.data.message)
  387. return
  388. }
  389. let prePayTn = JSON.parse(res.data.prePayTn)
  390. this.$mpi.requestPayment(prePayTn).then(() => {
  391. this.handelResult(true)
  392. }).catch(err => {
  393. this.handelResult(false)
  394. })
  395. uni.hideLoading()
  396. },
  397. handelResult(flag) {
  398. if (flag) {
  399. //跳转到支付页再到订单页
  400. // this.payResult = {
  401. // goodsBillsId:this.payParams.goodsBills.id,
  402. // isSuccess: true,
  403. // msg: "交易成功",
  404. // totalPrice: this.successParams.totalPrice,
  405. // amountNum: this.successParams.bills.price,
  406. // pointsNum: this.$digital.floatSub(this.successParams.totalPrice, this.successParams.bills
  407. // .price),
  408. // }
  409. //本页显示支付结果+抵扣详情
  410. uni.removeStorageSync(this.cartKey)
  411. this.info = {
  412. shop: this.vuex_orderInfo.shopDetail,
  413. bills: this.bills,
  414. }
  415. this.payConfirmType = 'paySuccess'
  416. this.title = "支付结果"
  417. this.isBack = false
  418. this.payShow = true
  419. return
  420. }
  421. this.payResult.msg = '交易失败'
  422. this.payResult.isSuccess = false
  423. uni.navigateTo({
  424. url: "/pagesC/pages/checkstand/pay-result?payResult=" + JSON.stringify(this.payResult)
  425. })
  426. },
  427. viewOrder() {
  428. uni.reLaunch({
  429. url: "/pagesD/pages/take-order/take-order?id=" + this.payParams.goodsBills.id
  430. })
  431. },
  432. continueOrdre() {
  433. let params = {
  434. shopId: this.shopId,
  435. seatNum: this.seatNum
  436. }
  437. uni.redirectTo({
  438. url: "/pagesD/pages/menu/menu" + this.$u.queryParams(params)
  439. })
  440. },
  441. payCancel() {
  442. if (this.payConfirmType == 'paySuccess') {
  443. this.$back()
  444. return
  445. }
  446. this.title = "收银台"
  447. this.isBack = true
  448. this.payShow = false
  449. },
  450. payConfirm() {
  451. if (this.payConfirmType == 'paySuccess') {
  452. this.viewOrder()
  453. return
  454. }
  455. this.doWxPay(this.bills.id)
  456. }
  457. }
  458. };
  459. </script>
  460. <style lang="scss" scoped>
  461. .content {
  462. margin: 20rpx;
  463. }
  464. .card {
  465. padding: 30rpx;
  466. background-color: #FFFFFF;
  467. border-bottom: 1rpx solid #f1f1f1;
  468. display: flex;
  469. justify-content: space-between;
  470. }
  471. .cart {
  472. border-bottom: 1rpx solid #f1f1f1;
  473. display: flex;
  474. background-color: #FFFFFF;
  475. padding: 15rpx;
  476. image {
  477. width: 120rpx;
  478. height: 120rpx;
  479. }
  480. .item-content {
  481. width: calc(100% - 120rpx - 15rpx);
  482. display: flex;
  483. flex-direction: column;
  484. justify-content: space-between;
  485. margin-left: 15rpx;
  486. text:first-child {
  487. font-size: 32rpx;
  488. padding-top: 10rpx;
  489. }
  490. text:last-child {
  491. font-size: 26rpx;
  492. color: #999;
  493. font-weight: 400;
  494. padding-bottom: 10rpx;
  495. }
  496. }
  497. .item-data {
  498. display: flex;
  499. align-items: center;
  500. width: 30%;
  501. justify-content: space-between;
  502. margin-right: 20rpx;
  503. }
  504. }
  505. .cart:last-child {
  506. border: none;
  507. }
  508. .pay-bar {
  509. height: 110rpx;
  510. background-color: #FFFFFF;
  511. display: flex;
  512. justify-content: space-between;
  513. }
  514. .add-address-box {
  515. min-height: 100rpx;
  516. background: url('http://file.shopro.top/imgs/order/order_address_line.png') no-repeat;
  517. background-size: 100% auto;
  518. background-position: bottom center;
  519. .select-notice {
  520. font-weight: 400;
  521. color: rgba(153, 153, 153, 1);
  522. line-height: 40rpx;
  523. }
  524. .name,
  525. .phone {
  526. font-size: 30rpx;
  527. font-weight: 500;
  528. }
  529. .phone {
  530. margin: 0 20rpx;
  531. }
  532. .tag {
  533. background: rgba(233, 191, 113, 0.2);
  534. border-radius: 6rpx;
  535. padding: 0 16rpx;
  536. line-height: 38rpx;
  537. color: #a8700d;
  538. font-size: 22rpx;
  539. }
  540. .detail {
  541. .address {
  542. margin-top: 25rpx;
  543. width: 543rpx;
  544. font-size: 26rpx;
  545. font-weight: 400;
  546. color: rgba(153, 153, 153, 1);
  547. line-height: 40rpx;
  548. }
  549. }
  550. }
  551. </style>