pay.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  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. async order() {
  293. let params = {
  294. receiveId: this.shopId,
  295. payId: this.vuex_userId,
  296. takeType: this.takeType,
  297. goodsPreview: JSON.stringify(this.cart),
  298. goodsTotalNum: this.totalNum,
  299. totalPrice: this.total,
  300. extraInfo: this.remark,
  301. expireTime: this.$dateTime.getExpireTime(),
  302. userPhone: this.vuex_phone,
  303. appId: this.$global.wxParams.APPID,
  304. }
  305. if (this.$isNotEmpty(this.vuex_channel)) {
  306. params.channelId = this.vuex_channel.id
  307. }
  308. if (this.takeType == this.$global.takeType.dine_in) {
  309. //店内堂食
  310. params.seatNum = this.seatNum
  311. }
  312. if (this.takeType == this.$global.takeType.package) {
  313. //到店自取,包装费
  314. params.packingPrice = this.vuex_orderInfo.store.packingPrice
  315. if (this.$isEmpty(this.takeTime)) {
  316. this.$refs.toast.error('请选择取餐时间')
  317. return
  318. } else {
  319. params.takeTime = this.takeTime
  320. }
  321. }
  322. if (this.takeType == this.$global.takeType.delivery) {
  323. if (this.$isEmpty(this.address)) {
  324. this.$refs.toast.error('请选择配送地址')
  325. return
  326. }
  327. //商家配送,包装费,配送费
  328. params.packingPrice = this.vuex_orderInfo.store.packingPrice
  329. params.sendingPrice = this.vuex_orderInfo.store.sendingPrice
  330. params.userPhone = address.phone
  331. params.receiver = address.consignee
  332. params.addressDetail = this.address.provinceName + '-' + this.address.cityName + '-' + this.address
  333. .areaName + ' ' + this.address.address
  334. }
  335. let res = await this.$api.goods.order(params)
  336. this.payParams = res.data
  337. this.successParams = this.payParams.successParams
  338. this.bills = this.successParams.bills
  339. if (this.bills.discount == -1) {
  340. this.bills.discount = 0
  341. }
  342. if (this.successParams.status == '付款成功') {
  343. this.handelResult(true)
  344. } else if (this.successParams.status == '待付款') {
  345. if (this.bills.cost == this.bills.price) {
  346. this.doWxPay(this.bills.id)
  347. } else {
  348. this.info = {
  349. shop: this.vuex_orderInfo.shopDetail,
  350. bills: this.bills,
  351. }
  352. this.title = "支付确认"
  353. this.isBack = false
  354. this.payShow = true
  355. }
  356. } else {
  357. this.handelResult(false)
  358. }
  359. uni.hideLoading()
  360. },
  361. async doWxPay(orderId) {
  362. this.$dialog.showLoading('付款中...')
  363. let obj = {
  364. orderType: this.$global.orderType.USER_PAY,
  365. orderId,
  366. payStatus: this.$global.payStatus.IS_WAIT
  367. }
  368. let res = await this.$api.pay.payOrder(obj)
  369. let prePayTn = JSON.parse(res.data.prePayTn)
  370. this.$mpi.requestPayment(prePayTn).then(() => {
  371. this.handelResult(true)
  372. }).catch(err => {
  373. this.handelResult(false)
  374. })
  375. uni.hideLoading()
  376. },
  377. handelResult(flag) {
  378. if (flag) {
  379. //跳转到支付页再到订单页
  380. // this.payResult = {
  381. // goodsBillsId:this.payParams.goodsBills.id,
  382. // isSuccess: true,
  383. // msg: "交易成功",
  384. // totalPrice: this.successParams.totalPrice,
  385. // amountNum: this.successParams.bills.price,
  386. // pointsNum: this.$digital.floatSub(this.successParams.totalPrice, this.successParams.bills
  387. // .price),
  388. // }
  389. //本页显示支付结果+抵扣详情
  390. uni.removeStorageSync(this.cartKey)
  391. this.info = {
  392. shop: this.vuex_orderInfo.shopDetail,
  393. bills: this.bills,
  394. }
  395. this.payConfirmType = 'paySuccess'
  396. this.title = "支付结果"
  397. this.isBack = false
  398. this.payShow = true
  399. return
  400. }
  401. this.payResult.msg = '交易失败'
  402. this.payResult.isSuccess = false
  403. uni.navigateTo({
  404. url: "/pagesC/pages/checkstand/pay-result?payResult=" + JSON.stringify(this.payResult)
  405. })
  406. },
  407. viewOrder() {
  408. uni.reLaunch({
  409. url: "/pagesD/pages/take-order/take-order?id=" + this.payParams.goodsBills.id
  410. })
  411. },
  412. continueOrdre() {
  413. let params = {
  414. shopId: this.shopId,
  415. seatNum: this.seatNum
  416. }
  417. uni.redirectTo({
  418. url: "/pagesD/pages/menu/menu" + this.$u.queryParams(params)
  419. })
  420. },
  421. payCancel() {
  422. if (this.payConfirmType == 'paySuccess') {
  423. this.$back()
  424. return
  425. }
  426. this.title = "收银台"
  427. this.isBack = true
  428. this.payShow = false
  429. },
  430. payConfirm() {
  431. if (this.payConfirmType == 'paySuccess') {
  432. this.viewOrder()
  433. return
  434. }
  435. this.doWxPay(this.bills.id)
  436. }
  437. }
  438. };
  439. </script>
  440. <style lang="scss" scoped>
  441. .content {
  442. margin: 20rpx;
  443. }
  444. .card {
  445. padding: 30rpx;
  446. background-color: #FFFFFF;
  447. border-bottom: 1rpx solid #f1f1f1;
  448. display: flex;
  449. justify-content: space-between;
  450. }
  451. .cart {
  452. border-bottom: 1rpx solid #f1f1f1;
  453. display: flex;
  454. background-color: #FFFFFF;
  455. padding: 15rpx;
  456. image {
  457. width: 120rpx;
  458. height: 120rpx;
  459. }
  460. .item-content {
  461. width: calc(100% - 120rpx - 15rpx);
  462. display: flex;
  463. flex-direction: column;
  464. justify-content: space-between;
  465. margin-left: 15rpx;
  466. text:first-child {
  467. font-size: 32rpx;
  468. padding-top: 10rpx;
  469. }
  470. text:last-child {
  471. font-size: 26rpx;
  472. color: #999;
  473. font-weight: 400;
  474. padding-bottom: 10rpx;
  475. }
  476. }
  477. .item-data {
  478. display: flex;
  479. align-items: center;
  480. width: 30%;
  481. justify-content: space-between;
  482. margin-right: 20rpx;
  483. }
  484. }
  485. .cart:last-child {
  486. border: none;
  487. }
  488. .pay-bar {
  489. height: 110rpx;
  490. background-color: #FFFFFF;
  491. display: flex;
  492. justify-content: space-between;
  493. }
  494. .add-address-box {
  495. min-height: 100rpx;
  496. background: url('http://file.shopro.top/imgs/order/order_address_line.png') no-repeat;
  497. background-size: 100% auto;
  498. background-position: bottom center;
  499. .select-notice {
  500. font-weight: 400;
  501. color: rgba(153, 153, 153, 1);
  502. line-height: 40rpx;
  503. }
  504. .name,
  505. .phone {
  506. font-size: 30rpx;
  507. font-weight: 500;
  508. }
  509. .phone {
  510. margin: 0 20rpx;
  511. }
  512. .tag {
  513. background: rgba(233, 191, 113, 0.2);
  514. border-radius: 6rpx;
  515. padding: 0 16rpx;
  516. line-height: 38rpx;
  517. color: #a8700d;
  518. font-size: 22rpx;
  519. }
  520. .detail {
  521. .address {
  522. margin-top: 25rpx;
  523. width: 543rpx;
  524. font-size: 26rpx;
  525. font-weight: 400;
  526. color: rgba(153, 153, 153, 1);
  527. line-height: 40rpx;
  528. }
  529. }
  530. }
  531. </style>