index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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. <scroll-view :scroll-y="true" style="height: 650rpx;">
  150. <view class="coupon-list">
  151. <view class="coupon-item" v-for="(item, index) in order.couponList" :key="index">
  152. <view class="item-wrapper" :class="[ !item.state.value ? 'disable' : '' ]" @click="handleSelectCoupon(index)">
  153. <!-- 优惠券类型 (标签) -->
  154. <view class="coupon-tag">
  155. <text>{{ CouponTypeEnum[item.coupon_type].name }}</text>
  156. </view>
  157. <view class="coupon-left">
  158. <!-- 优惠额度/折扣 -->
  159. <view class="coupon-reduce">
  160. <view class="coupon-reduce-unit"><text>¥</text></view>
  161. <view class="coupon-reduce-amount">
  162. <text class="value">{{ item.reduce_price }}</text>
  163. </view>
  164. </view>
  165. <!-- 最低消费金额 -->
  166. <text class="coupon-hint">满{{ item.min_price }}元可用</text>
  167. </view>
  168. <view class="coupon-content">
  169. <view class="coupon-name">{{ item.name }}</view>
  170. <view class="coupon-middle">
  171. <view class="coupon-expire">
  172. <text v-if="item.expire_type == CouponTypeEnum.FULL_DISCOUNT.value">领取后{{ item.expire_day }}天内有效</text>
  173. <text v-if="item.expire_type == CouponTypeEnum.DISCOUNT.value">
  174. <block v-if="item.start_time === item.end_time">{{ item.start_time }} 当天有效</block>
  175. <block v-else>{{ item.start_time }}~{{ item.end_time }}</block>
  176. </text>
  177. </view>
  178. </view>
  179. <view v-if="item.describe" class="coupon-expand" @click.stop="handleDescribe(index)">
  180. <text>使用说明</text>
  181. <text class="coupon-expand-arrow iconfont icon-arrow-down" :class="[item.expand ? 'expand' : '']" />
  182. </view>
  183. </view>
  184. <view class="coupon-right">
  185. <u-radio-group v-model="selectCouponId">
  186. <u-radio :name="item.user_coupon_id" :active-color="appTheme.mainBg"></u-radio>
  187. </u-radio-group>
  188. </view>
  189. </view>
  190. <!-- 优惠券描述 -->
  191. <view :class="[item.expand ? 'expand' : '']" class="coupon-expand-rules">
  192. <view class="coupon-expand-rules-content">
  193. <view class="pre">{{ item.describe }}</view>
  194. </view>
  195. </view>
  196. </view>
  197. </view>
  198. </scroll-view>
  199. <!-- 不使用优惠券 -->
  200. <view class="coupon__do_not">
  201. <view class="control" @click="handleNotUseCoupon()">
  202. <text class="f-26">不使用优惠券</text>
  203. </view>
  204. </view>
  205. </view>
  206. </u-popup>
  207. </view>
  208. <u-toast ref="uToast" />
  209. </view>
  210. </template>
  211. <script>
  212. import * as Verify from '@/utils/verify'
  213. import * as CheckoutApi from '@/api/checkout'
  214. import { CouponTypeEnum } from '@/common/enum/coupon'
  215. import { OrderTypeEnum, DeliveryTypeEnum } from '@/common/enum/order'
  216. const CouponColors = ['red', 'blue', 'violet', 'yellow']
  217. // 根据指定mode获取对应的api类
  218. const getCheckoutApi = (mode) => {
  219. const apiEnum = {
  220. buyNow: CheckoutApi,
  221. cart: CheckoutApi
  222. }
  223. return apiEnum[mode]
  224. }
  225. // 根据指定mode获取param
  226. const getModeParam = (mode, options) => {
  227. const param = {}
  228. // 结算模式: 立即购买
  229. if (mode === 'buyNow') {
  230. param.goodsId = options.goodsId
  231. param.goodsNum = options.goodsNum
  232. param.goodsSkuId = options.goodsSkuId
  233. }
  234. // 结算模式: 购物车
  235. if (mode === 'cart') {
  236. param.cartIds = options.cartIds
  237. }
  238. return param
  239. }
  240. export default {
  241. data() {
  242. return {
  243. // 枚举类
  244. OrderTypeEnum,
  245. DeliveryTypeEnum,
  246. CouponTypeEnum,
  247. // 当前页面参数
  248. options: {},
  249. // 配送方式
  250. isShowTab: false,
  251. DeliveryTypeEnum,
  252. curDelivery: null,
  253. // 优惠券颜色组
  254. CouponColors,
  255. // 选择的优惠券
  256. selectCouponId: 0,
  257. // 是否使用积分抵扣
  258. isUsePoints: false,
  259. // 买家留言
  260. remark: '',
  261. // 禁用submit按钮
  262. disabled: false,
  263. // 是否显示积分说明
  264. showPoints: false,
  265. // 是否显示优惠券弹窗
  266. showPopup: false,
  267. // 订单信息 (从后端api中获取)
  268. order: {
  269. // 商品列表
  270. goodsList: [],
  271. // 优惠券列表
  272. couponList: [],
  273. // 是否存在收货地址
  274. existAddress: false,
  275. // 默认收货地址
  276. address: null,
  277. // 是否存在收货地址
  278. existAddress: false,
  279. // 当前用户收货城市是否存在配送规则中
  280. isIntraRegion: true,
  281. // 是否存在错误
  282. hasError: false,
  283. // 错误信息
  284. errorMsg: '',
  285. },
  286. // 个人信息
  287. personal: {},
  288. // 商城设置
  289. setting: {}
  290. }
  291. },
  292. /**
  293. * 生命周期函数--监听页面加载
  294. */
  295. onLoad(options) {
  296. this.options = options
  297. },
  298. /**
  299. * 生命周期函数--监听页面的卸载
  300. */
  301. onUnload() {
  302. },
  303. /**
  304. * 生命周期函数--监听页面显示
  305. */
  306. onShow() {
  307. // 获取当前订单信息
  308. this.getOrderData()
  309. },
  310. methods: {
  311. // 获取订单数据
  312. getOrderData() {
  313. const app = this
  314. const { options: { mode } } = app
  315. // 请求的参数
  316. const params = app.getRequestParam()
  317. // 请求api
  318. getCheckoutApi(mode)
  319. .order(mode, params)
  320. .then(result => app.initData(result.data))
  321. .catch(err => err)
  322. },
  323. // 初始化数据
  324. initData({ order, setting, personal }) {
  325. const app = this
  326. app.order = order
  327. app.personal = personal
  328. app.setting = setting
  329. // 显示错误信息
  330. if (order.hasError) {
  331. app.showToast(order.errorMsg, 3000)
  332. }
  333. // 当前选择的配送方式
  334. app.curDelivery = order.delivery
  335. // 如果只有一种配送方式则不显示选项卡
  336. app.isShowTab = setting.deliveryType.length > 1
  337. },
  338. // 获取api请求的参数
  339. getRequestParam() {
  340. const app = this
  341. const { options } = app
  342. // 结算模式的固定参数
  343. const modeParam = getModeParam(options.mode, options)
  344. // 订单结算参数(用户选择)
  345. const orderParam = {
  346. delivery: app.curDelivery || 0,
  347. couponId: app.selectCouponId || 0,
  348. isUsePoints: app.isUsePoints ? 1 : 0,
  349. }
  350. return { ...orderParam, ...modeParam }
  351. },
  352. // 切换配送方式
  353. handleSwichDelivery(key) {
  354. this.curDelivery = key
  355. this.getOrderData()
  356. },
  357. // 显示积分说明
  358. handleShowPoints() {
  359. this.showPoints = true
  360. },
  361. // 显示优惠券弹窗
  362. handleShowPopup() {
  363. this.showPopup = true
  364. },
  365. // 展开优惠券描述
  366. handleDescribe(index) {
  367. const { couponList } = this.order
  368. couponList[index].expand = !couponList[index].expand
  369. },
  370. // 选择优惠券
  371. handleSelectCoupon(index) {
  372. const app = this
  373. const { couponList } = app.order
  374. // 当前选择的优惠券
  375. const couponItem = couponList[index]
  376. // 判断是否在适用范围
  377. if (!couponItem.is_apply) {
  378. app.showToast(couponItem.not_apply_info)
  379. return
  380. }
  381. // 记录选中的优惠券id
  382. app.selectCouponId = couponItem.user_coupon_id
  383. // 重新获取订单信息
  384. app.getOrderData()
  385. // 隐藏优惠券弹层
  386. app.showPopup = false
  387. },
  388. // 不使用优惠券
  389. handleNotUseCoupon() {
  390. const app = this
  391. app.selectCouponId = 0
  392. // 重新获取订单信息
  393. app.getOrderData()
  394. // 隐藏优惠券弹层
  395. app.showPopup = false
  396. },
  397. // 快递配送:选择收货地址
  398. onSelectAddress() {
  399. this.$navTo('pages/address/index', { from: 'checkout' })
  400. },
  401. // 跳转到商品详情页
  402. onTargetGoods(goodsId) {
  403. this.$navTo('pages/goods/detail', { goodsId })
  404. },
  405. // 订单提交
  406. onSubmitOrder() {
  407. const app = this
  408. if (app.disabled) {
  409. return false
  410. }
  411. // 表单验证
  412. if (!app.onVerifyFrom()) {
  413. return false
  414. }
  415. // 按钮禁用
  416. app.disabled = true
  417. // 请求api
  418. getCheckoutApi(app.options.mode)
  419. .submit(app.options.mode, app.getFormData())
  420. .then(result => {
  421. // 订单创建成功: 跳转到订单支付页
  422. const orderId = result.data.orderId
  423. setTimeout(() => {
  424. this.$navTo('pages/checkout/cashier/index', { orderId }, 'redirectTo')
  425. }, 100)
  426. })
  427. .catch(res => app.showToast(res.errMsg, 3000))
  428. .finally(() => setTimeout(() => app.disabled = false, 800))
  429. },
  430. // 跳转到我的订单(等待1秒)
  431. navToMyOrder() {
  432. setTimeout(() => {
  433. this.$navTo('pages/order/index', {}, 'redirectTo')
  434. }, 1000)
  435. },
  436. // 表单提交的数据
  437. getFormData() {
  438. const app = this
  439. const { options } = app
  440. // 表单数据
  441. const form = {
  442. delivery: app.curDelivery,
  443. couponId: app.selectCouponId || 0,
  444. isUsePoints: app.isUsePoints ? 1 : 0,
  445. remark: app.remark || '',
  446. }
  447. // 获取不同模式的参数
  448. const modeParam = getModeParam(options.mode, options)
  449. return { ...form, ...modeParam }
  450. },
  451. // 表单验证
  452. onVerifyFrom() {
  453. const app = this
  454. if (app.hasError) {
  455. app.showToast(app.errorMsg, 3000)
  456. return false
  457. }
  458. return true
  459. },
  460. // 显示toast信息
  461. showToast(title, duration = 2000) {
  462. this.$refs.uToast.show({ title, duration })
  463. }
  464. }
  465. }
  466. </script>
  467. <style lang="scss" scoped>
  468. @import "./style.scss";
  469. </style>