pay.vue 13 KB

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