index.vue 16 KB

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