index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <template>
  2. <view class="container p-bottom" v-if="order.goodsList.length">
  3. <!-- 快递配送:配送地址 -->
  4. <view v-if="curDelivery == DeliveryTypeEnum.EXPRESS.value" @click="onSelectAddress" class="flow-delivery">
  5. <view class="flow-delivery__detail dis-flex flex-y-center">
  6. <view class="detail-location dis-flex">
  7. <text class="iconfont icon-dingwei"></text>
  8. </view>
  9. <view class="detail-content flex-box">
  10. <block v-if="order.address">
  11. <view class="detail-content__title dis-flex">
  12. <text class="f-30">{{ order.address.name }}</text>
  13. <text class="detail-content__title-phone f-28">{{ order.address.phone }}</text>
  14. </view>
  15. <view class="address detail-content__describe">
  16. <text class="region" v-for="(region, idx) in order.address.region" :key="idx">{{ region }}</text>
  17. <text class="detail">{{ order.address.detail }}</text>
  18. </view>
  19. </block>
  20. <block v-else>
  21. <view class="detail-content__describe dis-flex">
  22. <text class="col-6">请选择配送地址</text>
  23. </view>
  24. </block>
  25. </view>
  26. <view class="detail-arrow dis-flex">
  27. <text class="iconfont icon-arrow-right"></text>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- 商品列表 -->
  32. <view class="m-top20">
  33. <view class="checkout_list" v-for="(item, index) in order.goodsList" :key="index">
  34. <view class="flow-shopList dis-flex" data-index="index" @click="onTargetGoods(item.goods_id)">
  35. <!-- 商品图片 -->
  36. <view class="flow-list-left">
  37. <image mode="scaleToFill" :src="item.goods_image"></image>
  38. </view>
  39. <view class="flow-list-right flex-box">
  40. <!-- 商品名称 -->
  41. <text class="goods-name twoline-hide">{{ item.goods_name }}</text>
  42. <!-- 商品规格 -->
  43. <view class="goods-props clearfix">
  44. <view class="goods-props-item" v-for="(props, idx) in item.skuInfo.goods_props" :key="idx">
  45. <text class="group-name">{{ props.group.name }}: </text>
  46. <text>{{ props.value.name }};</text>
  47. </view>
  48. </view>
  49. <!-- 商品数量和单价 -->
  50. <view class="flow-list-cont dis-flex flex-x-between flex-y-center">
  51. <text class="small">×{{ item.total_num }}</text>
  52. <text class="flow-cont" :class="[item.is_user_grade ? 'price-delete' : '']">¥{{ item.goods_price }}</text>
  53. </view>
  54. <!-- 会员折扣价 -->
  55. <view v-if="item.is_user_grade" class="grade-price">
  56. <text>会员折扣价:¥{{ item.grade_goods_price }}</text>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <view class="flow-num-box b-f">
  62. <text>共{{ order.orderTotalNum }}件商品,合计:</text>
  63. <text class="flow-money col-m">¥{{ order.orderTotalPrice }}</text>
  64. </view>
  65. </view>
  66. <!-- 商品金额 -->
  67. <view class="flow-all-money b-f m-top20">
  68. <view class="flow-all-list dis-flex">
  69. <text class="flex-five">订单总金额:</text>
  70. <view class="flex-five t-r">
  71. <text class="col-m">¥{{ order.orderTotalPrice }}</text>
  72. </view>
  73. </view>
  74. <!-- 优惠券 -->
  75. <view class="flow-all-list dis-flex">
  76. <text class="flex-five">优惠券:</text>
  77. <view class="flex-five t-r">
  78. <view v-if="order.couponList.length > 0" @click="handleShowPopup()">
  79. <text class="col-m" v-if="order.couponId > 0">-¥{{ order.couponMoney }}</text>
  80. <text class="col-m" v-else>有{{ order.couponList.length }}张优惠券</text>
  81. <text class="right-arrow iconfont icon-arrow-right"></text>
  82. </view>
  83. <text v-else class="">无优惠券可用</text>
  84. </view>
  85. </view>
  86. <!-- 积分抵扣 -->
  87. <view v-if="order.isAllowPoints" class="points flow-all-list dis-flex flex-y-center">
  88. <view class="block-left flex-five" @click="handleShowPoints()">
  89. <text class="title">可用{{ order.setting.points_name }}抵扣:</text>
  90. <text class="iconfont icon-help"></text>
  91. </view>
  92. <view class="flex-five dis-flex flex-x-end flex-y-center">
  93. <text class="points-money col-m">-¥{{ order.pointsMoney }}</text>
  94. <u-switch v-model="isUsePoints" size="48" active-color="#07c160" @change="getOrderData()"></u-switch>
  95. </view>
  96. </view>
  97. <!-- 配送费用 -->
  98. <view v-if="curDelivery == DeliveryTypeEnum.EXPRESS.value" class="dis-flex flow-all-list">
  99. <text class="flex-five">配送费用:</text>
  100. <view class="flex-five t-r">
  101. <view v-if="order.address">
  102. <text class="col-m" v-if="order.isIntraRegion">+¥{{ order.expressPrice }}</text>
  103. <text v-else>不在配送范围</text>
  104. </view>
  105. <view v-else>
  106. <text class="col-7">请先选择配送地址</text>
  107. </view>
  108. </view>
  109. </view>
  110. </view>
  111. <!-- 支付方式 -->
  112. <view class="pay-method flow-all-money b-f m-top20">
  113. <view class="flow-all-list dis-flex">
  114. <text class="flex-five">支付方式</text>
  115. </view>
  116. <!-- 微信支付 -->
  117. <!-- #ifdef MP-WEIXIN -->
  118. <view class="pay-item dis-flex flex-x-between" @click="handleSelectPayType(PayTypeEnum.WECHAT.value)">
  119. <view class="item-left dis-flex flex-y-center">
  120. <view class="item-left_icon wechat">
  121. <text class="iconfont icon-wxpay"></text>
  122. </view>
  123. <view class="item-left_text">
  124. <text>{{ PayTypeEnum.WECHAT.name }}</text>
  125. </view>
  126. </view>
  127. <view class="item-right col-m" v-if="curPayType == PayTypeEnum.WECHAT.value">
  128. <text class="iconfont icon-check"></text>
  129. </view>
  130. </view>
  131. <!-- #endif -->
  132. <!-- 余额支付 -->
  133. <view class="pay-item dis-flex flex-x-between" @click="handleSelectPayType(PayTypeEnum.BALANCE.value)">
  134. <view class="item-left dis-flex flex-y-center">
  135. <view class="item-left_icon balance">
  136. <text class="iconfont icon-qiandai"></text>
  137. </view>
  138. <view class="item-left_text">
  139. <text>{{ PayTypeEnum.BALANCE.name }}</text>
  140. </view>
  141. </view>
  142. <view class="item-right col-m" v-if="curPayType == PayTypeEnum.BALANCE.value">
  143. <text class="iconfont icon-check"></text>
  144. </view>
  145. </view>
  146. </view>
  147. <!-- 买家留言 -->
  148. <view class="flow-all-money b-f m-top20">
  149. <view class="ipt-wrapper dis-flex flow-all-list">
  150. <input v-model="remark" placeholder="选填:买家留言(50字以内)"></input>
  151. </view>
  152. </view>
  153. <!-- 提交订单 -->
  154. <view class="flow-fixed-footer b-f m-top10">
  155. <view class="dis-flex chackout-box">
  156. <view class="chackout-left pl-12">实付款:
  157. <text class="col-m">¥{{ order.orderPayPrice }}</text>
  158. </view>
  159. <view class="chackout-right" @click="onSubmitOrder()">
  160. <view class="flow-btn f-32" :class="{ disabled }">提交订单</view>
  161. </view>
  162. </view>
  163. </view>
  164. <!-- 积分说明弹窗 -->
  165. <u-modal v-model="showPoints" :title="`${setting.points_name}说明`">
  166. <scroll-view class="points-content" :scroll-y="true">
  167. <text>{{ order.setting.points_describe }}</text>
  168. </scroll-view>
  169. </u-modal>
  170. <!-- 优惠券弹出框 -->
  171. <u-popup v-model="showPopup" mode="bottom">
  172. <view class="popup__coupon">
  173. <view class="coupon__title f-30">选择优惠券</view>
  174. <!-- 优惠券列表 -->
  175. <view class="coupon-list">
  176. <scroll-view :scroll-y="true" style="height: 565rpx;">
  177. <view class="coupon-item" v-for="(item, index) in order.couponList" :key="index">
  178. <view class="item-wrapper"
  179. :class="[item.is_apply ? 'color-' + CouponColors[index % CouponColors.length] : 'color-gray']"
  180. @click="handleSelectCoupon(index)">
  181. <view class="coupon-type">{{ CouponTypeEnum[item.coupon_type].name }}</view>
  182. <view class="tip dis-flex flex-dir-column flex-x-center">
  183. <view v-if="item.coupon_type == CouponTypeEnum.FULL_DISCOUNT.value">
  184. <text class="f-30">¥</text>
  185. <text class="money">{{ item.reduce_price }}</text>
  186. </view>
  187. <text class="money"
  188. v-if="item.coupon_type == CouponTypeEnum.DISCOUNT.value">{{ item.discount }}折</text>
  189. <text class="pay-line">满{{ item.min_price }}元可用</text>
  190. </view>
  191. <view class="split-line"></view>
  192. <view class="content dis-flex flex-dir-column flex-x-between">
  193. <view class="title">{{ item.name }}</view>
  194. <view class="bottom dis-flex flex-y-center">
  195. <view class="time flex-box">
  196. <block v-if="item.start_time === item.end_time">{{ item.start_time }}</block>
  197. <block v-else>{{ item.start_time }}~{{ item.end_time }}</block>
  198. </view>
  199. </view>
  200. </view>
  201. </view>
  202. </view>
  203. </scroll-view>
  204. </view>
  205. <!-- 不使用优惠券 -->
  206. <view class="coupon__do_not dis-flex flex-y-center flex-x-center">
  207. <view class="control dis-flex flex-y-center flex-x-center" @click="handleNotUseCoupon()">
  208. <text class="f-26">不使用优惠券</text>
  209. </view>
  210. </view>
  211. </view>
  212. </u-popup>
  213. </view>
  214. </template>
  215. <script>
  216. import * as Verify from '@/utils/verify'
  217. import * as CheckoutApi from '@/api/checkout'
  218. import { CouponTypeEnum } from '@/common/enum/coupon'
  219. import DeliveryTypeEnum from '@/common/enum/order/DeliveryType'
  220. import PayTypeEnum from '@/common/enum/order/PayType'
  221. import { wxPayment } from '@/core/app'
  222. const CouponColors = ['red', 'blue', 'violet', 'yellow']
  223. export default {
  224. data() {
  225. return {
  226. // 枚举类
  227. DeliveryTypeEnum,
  228. PayTypeEnum,
  229. CouponTypeEnum,
  230. // 当前页面参数
  231. options: {},
  232. // 优惠券颜色组
  233. CouponColors,
  234. // 系统设置
  235. setting: {},
  236. // 当前选中的配送方式
  237. curDelivery: null,
  238. // 当前选中的支付方式
  239. curPayType: PayTypeEnum.BALANCE.value,
  240. // 选择的优惠券
  241. selectCouponId: 0,
  242. // 是否使用积分抵扣
  243. isUsePoints: false,
  244. // 买家留言
  245. remark: '',
  246. // 禁用submit按钮
  247. disabled: false,
  248. // 是否显示积分说明
  249. showPoints: false,
  250. // 是否显示优惠券弹窗
  251. showPopup: false,
  252. // 按钮禁用
  253. disabled: false,
  254. // 订单信息 (从后端api中获取)
  255. order: {
  256. // 商品列表
  257. goodsList: [],
  258. // 优惠券列表
  259. couponList: [],
  260. // 是否存在收货地址
  261. existAddress: false,
  262. // 默认收货地址
  263. address: null,
  264. // 是否存在收货地址
  265. existAddress: false,
  266. // 当前用户收货城市是否存在配送规则中
  267. isIntraRegion: true,
  268. // 是否存在错误
  269. hasError: false,
  270. // 错误信息
  271. errorMsg: '',
  272. }
  273. }
  274. },
  275. /**
  276. * 生命周期函数--监听页面加载
  277. */
  278. onLoad(options) {
  279. this.options = options
  280. },
  281. /**
  282. * 生命周期函数--监听页面显示
  283. */
  284. onShow() {
  285. // 获取当前订单信息
  286. this.getOrderData()
  287. },
  288. methods: {
  289. // 获取订单数据
  290. getOrderData() {
  291. const app = this
  292. // 请求的参数
  293. const params = {
  294. delivery: app.curDelivery || 0,
  295. couponId: app.selectCouponId || 0,
  296. isUsePoints: app.isUsePoints ? 1 : 0,
  297. }
  298. // 请求api
  299. CheckoutApi.order(app.options.mode, app.getRequestParam())
  300. .then(result => {
  301. app.initData(result.data)
  302. })
  303. .catch(err => err)
  304. },
  305. // 初始化数据
  306. initData({ order }) {
  307. const app = this
  308. app.order = order
  309. // 显示错误信息
  310. if (order.hasError) {
  311. app.$toast(order.errorMsg)
  312. }
  313. // 当前选择的配送方式
  314. app.curDelivery = order.delivery
  315. // 当前选择支付方式 (如果是微信小程序默认使用微信支付)
  316. if (app.$platform === 'MP-WEIXIN') {
  317. app.curPayType = PayTypeEnum.WECHAT.value
  318. }
  319. },
  320. // 获取api请求的参数
  321. getRequestParam() {
  322. const app = this
  323. const { options } = app
  324. // 结算模式的固定参数
  325. const modeParam = {}
  326. // 结算模式: 立即购买
  327. if (options.mode === 'buyNow') {
  328. modeParam.goodsId = options.goodsId
  329. modeParam.goodsNum = options.goodsNum
  330. modeParam.goodsSkuId = options.goodsSkuId
  331. }
  332. // 结算模式: 购物车
  333. if (options.mode === 'cart') {
  334. modeParam.cartIds = options.cartIds
  335. }
  336. // 订单结算参数(用户选择)
  337. const orderParam = {
  338. delivery: app.curDelivery || 0,
  339. couponId: app.selectCouponId || 0,
  340. isUsePoints: app.isUsePoints ? 1 : 0,
  341. }
  342. return { ...orderParam, ...modeParam }
  343. },
  344. // 显示积分说明
  345. handleShowPoints() {
  346. this.showPoints = true
  347. },
  348. // 显示优惠券弹窗
  349. handleShowPopup() {
  350. this.showPopup = true
  351. },
  352. // 选择优惠券
  353. handleSelectCoupon(index) {
  354. const app = this
  355. const { couponList } = app.order
  356. // 当前选择的优惠券
  357. const couponItem = couponList[index]
  358. // 判断是否在适用范围
  359. if (!couponItem.is_apply) {
  360. app.$toast(couponItem.not_apply_info)
  361. return
  362. }
  363. // 记录选中的优惠券id
  364. app.selectCouponId = couponItem.user_coupon_id
  365. // 重新获取订单信息
  366. app.getOrderData()
  367. // 隐藏优惠券弹层
  368. app.showPopup = false
  369. },
  370. // 不使用优惠券
  371. handleNotUseCoupon() {
  372. const app = this
  373. app.selectCouponId = 0
  374. // 重新获取订单信息
  375. app.getOrderData()
  376. // 隐藏优惠券弹层
  377. app.showPopup = false
  378. },
  379. // 选择支付方式
  380. handleSelectPayType(value) {
  381. this.curPayType = value
  382. },
  383. // 快递配送:选择收货地址
  384. onSelectAddress() {
  385. this.$navTo('pages/address/index', { from: 'checkout' })
  386. },
  387. // 跳转到商品详情页
  388. onTargetGoods(goodsId) {
  389. this.$navTo('pages/goods/detail', { goodsId })
  390. },
  391. // 订单提交
  392. onSubmitOrder() {
  393. const app = this
  394. if (app.disabled) {
  395. return false
  396. }
  397. // 表单验证
  398. if (!app.onVerifyFrom()) {
  399. return false
  400. }
  401. // 按钮禁用
  402. app.disabled = true
  403. // 请求api
  404. CheckoutApi.submit(app.options.mode, app.getFormData())
  405. .then(result => app.onSubmitCallback(result))
  406. .catch(err => {
  407. if (err.result) {
  408. const errData = err.result.data
  409. if (errData.is_created) {
  410. app.navToMyOrder()
  411. return false
  412. }
  413. }
  414. app.disabled = false
  415. })
  416. },
  417. // 订单提交成功后回调
  418. onSubmitCallback(result) {
  419. const app = this
  420. // 发起微信支付
  421. if (result.data.payType == PayTypeEnum.WECHAT.value) {
  422. wxPayment(result.data.payment)
  423. .then(() => app.$success('支付成功'))
  424. .catch(err => app.$error('订单未支付'))
  425. .finally(() => {
  426. app.disabled = false
  427. app.navToMyOrder()
  428. })
  429. }
  430. // 余额支付
  431. if (result.data.payType == PayTypeEnum.BALANCE.value) {
  432. app.$success('支付成功')
  433. app.disabled = false
  434. app.navToMyOrder()
  435. }
  436. },
  437. // 跳转到我的订单(等待1秒)
  438. navToMyOrder() {
  439. setTimeout(() => {
  440. this.$navTo('pages/order/index')
  441. }, 1000)
  442. },
  443. // 表单提交的数据
  444. getFormData() {
  445. const app = this
  446. const { options } = app
  447. // 表单数据
  448. const form = {
  449. delivery: app.curDelivery,
  450. payType: app.curPayType,
  451. couponId: app.selectCouponId || 0,
  452. isUsePoints: app.isUsePoints ? 1 : 0,
  453. remark: app.remark || '',
  454. }
  455. // 创建订单-立即购买
  456. if (options.mode === 'buyNow') {
  457. form.goodsId = options.goodsId
  458. form.goodsNum = options.goodsNum
  459. form.goodsSkuId = options.goodsSkuId
  460. }
  461. // 创建订单-购物车结算
  462. if (options.mode === 'cart') {
  463. form.cartIds = options.cartIds || null
  464. }
  465. return form
  466. },
  467. // 表单验证
  468. onVerifyFrom() {
  469. const app = this
  470. if (app.hasError) {
  471. app.$toast(app.errorMsg)
  472. return false
  473. }
  474. return true
  475. },
  476. }
  477. }
  478. </script>
  479. <style lang="scss" scoped>
  480. @import "./style.scss";
  481. </style>