index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. <template>
  2. <view class="container">
  3. <mescroll-body ref="mescrollRef" :sticky="true" @init="mescrollInit" :down="{ native: true }" @down="downCallback"
  4. :up="upOption" @up="upCallback">
  5. <!-- tab栏 -->
  6. <u-tabs :list="tabs" :is-scroll="false" :current="curTab" active-color="#FA2209" :duration="0.2"
  7. @change="onChangeTab" />
  8. <!-- 订单列表 -->
  9. <view class="order-list">
  10. <view class="order-item" v-for="(item, index) in list.data" :key="index">
  11. <view class="item-top">
  12. <view class="item-top-left">
  13. <text class="order-time">{{ item.create_time }}</text>
  14. </view>
  15. <view class="item-top-right">
  16. <text class="state-text">{{ item.state_text }}</text>
  17. </view>
  18. </view>
  19. <!-- 商品列表 -->
  20. <view class="goods-list" @click="handleTargetDetail(item.order_id)">
  21. <view class="goods-item" v-for="(goods, idx) in item.goods" :key="idx">
  22. <!-- 商品图片 -->
  23. <view class="goods-image">
  24. <image class="image" :src="goods.goods_image" mode="scaleToFill"></image>
  25. </view>
  26. <!-- 商品信息 -->
  27. <view class="goods-content">
  28. <view class="goods-title"><text class="twoline-hide">{{ goods.goods_name }}</text></view>
  29. <view class="goods-props clearfix">
  30. <view class="goods-props-item" v-for="(props, idx) in goods.goods_props" :key="idx">
  31. <text>{{ props.value.name }}</text>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 交易信息 -->
  36. <view class="goods-trade">
  37. <view class="goods-price">
  38. <text class="unit">¥</text>
  39. <text class="value">{{ goods.is_user_grade ? goods.grade_goods_price : goods.goods_price }}</text>
  40. </view>
  41. <view class="goods-num">
  42. <text>×{{ goods.total_num }}</text>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <!-- 订单合计 -->
  48. <view class="order-total">
  49. <text>共{{ item.total_num }}件商品,总金额</text>
  50. <text class="unit">¥</text>
  51. <text class="money">{{ item.pay_price }}</text>
  52. </view>
  53. <!-- 订单操作 -->
  54. <view v-if="item.order_status != OrderStatusEnum.CANCELLED.value" class="order-handle">
  55. <view class="btn-group clearfix">
  56. <!-- 未支付取消订单 -->
  57. <block v-if="item.pay_status == PayStatusEnum.PENDING.value">
  58. <view class="btn-item" @click="onCancel(item.order_id)">取消</view>
  59. </block>
  60. <!-- 已支付进行中的订单 -->
  61. <block v-if="item.order_status != OrderStatusEnum.APPLY_CANCEL.value">
  62. <block
  63. v-if="item.pay_status == PayStatusEnum.SUCCESS.value && item.delivery_status == DeliveryStatusEnum.NOT_DELIVERED.value">
  64. <view class="btn-item" @click="onCancel(item.order_id)">申请取消</view>
  65. </block>
  66. </block>
  67. <!-- 已申请取消 -->
  68. <view v-else class="f-28 col-8">取消申请中</view>
  69. <!-- 未支付的订单 -->
  70. <block v-if="item.pay_status == PayStatusEnum.PENDING.value">
  71. <view class="btn-item active" @click="onPay(item.order_id)">去支付</view>
  72. </block>
  73. <!-- 确认收货 -->
  74. <block
  75. v-if="item.delivery_status == DeliveryStatusEnum.DELIVERED.value && item.receipt_status == ReceiptStatusEnum.NOT_RECEIVED.value">
  76. <view class="btn-item active" @click="onReceipt(item.order_id)">确认收货</view>
  77. </block>
  78. <!-- 订单评价 -->
  79. <block v-if="item.order_status == OrderStatusEnum.COMPLETED.value && item.is_comment == 0">
  80. <view class="btn-item" @click="handleTargetComment(item.order_id)">评价</view>
  81. </block>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </mescroll-body>
  87. <!-- 支付方式弹窗 -->
  88. <u-popup v-model="showPayPopup" mode="bottom" border-radius="26" :closeable="true">
  89. <view class="pay-popup">
  90. <view class="title">请选择支付方式</view>
  91. <view class="pop-content">
  92. <!-- 微信支付 -->
  93. <!-- #ifdef MP-WEIXIN -->
  94. <view class="pay-item dis-flex flex-x-between" @click="onSelectPayType(PayTypeEnum.WECHAT.value)">
  95. <view class="item-left dis-flex flex-y-center">
  96. <view class="item-left_icon wechat">
  97. <text class="iconfont icon-wechat-pay"></text>
  98. </view>
  99. <view class="item-left_text">
  100. <text>{{ PayTypeEnum.WECHAT.name }}</text>
  101. </view>
  102. </view>
  103. </view>
  104. <!-- #endif -->
  105. <!-- 余额支付 -->
  106. <view class="pay-item dis-flex flex-x-between" @click="onSelectPayType(PayTypeEnum.BALANCE.value)">
  107. <view class="item-left dis-flex flex-y-center">
  108. <view class="item-left_icon balance">
  109. <text class="iconfont icon-balance-pay"></text>
  110. </view>
  111. <view class="item-left_text">
  112. <text>{{ PayTypeEnum.BALANCE.name }}</text>
  113. </view>
  114. </view>
  115. </view>
  116. </view>
  117. </view>
  118. </u-popup>
  119. </view>
  120. </template>
  121. <script>
  122. import {
  123. DeliveryStatusEnum,
  124. DeliveryTypeEnum,
  125. OrderStatusEnum,
  126. PayStatusEnum,
  127. PayTypeEnum,
  128. ReceiptStatusEnum
  129. } from '@/common/enum/order'
  130. import MescrollBody from '@/components/mescroll-uni/mescroll-body.vue'
  131. import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins'
  132. import { getEmptyPaginateObj, getMoreListData } from '@/core/app'
  133. import * as OrderApi from '@/api/order'
  134. import { wxPayment } from '@/core/app'
  135. // 每页记录数量
  136. const pageSize = 15
  137. // tab栏数据
  138. const tabs = [{
  139. name: `全部`,
  140. value: 'all'
  141. }, {
  142. name: `待支付`,
  143. value: 'payment'
  144. }, {
  145. name: `待发货`,
  146. value: 'delivery'
  147. }, {
  148. name: `待收货`,
  149. value: 'received'
  150. }, {
  151. name: `待评价`,
  152. value: 'comment'
  153. }]
  154. export default {
  155. components: {
  156. MescrollBody
  157. },
  158. mixins: [MescrollMixin],
  159. data() {
  160. return {
  161. // 枚举类
  162. DeliveryStatusEnum,
  163. DeliveryTypeEnum,
  164. OrderStatusEnum,
  165. PayStatusEnum,
  166. PayTypeEnum,
  167. ReceiptStatusEnum,
  168. // 当前页面参数
  169. options: { dataType: 'all' },
  170. // tab栏数据
  171. tabs,
  172. // 当前标签索引
  173. curTab: 0,
  174. // 订单列表数据
  175. list: getEmptyPaginateObj(),
  176. // 上拉加载配置
  177. upOption: {
  178. // 首次自动执行
  179. auto: true,
  180. // 每页数据的数量; 默认10
  181. page: { size: pageSize },
  182. // 数量要大于4条才显示无更多数据
  183. noMoreSize: 4,
  184. // 空布局
  185. empty: {
  186. tip: '亲,暂无订单记录'
  187. }
  188. },
  189. // 控制首次触发onShow事件时不刷新列表
  190. canReset: false,
  191. // 支付方式弹窗
  192. showPayPopup: false
  193. }
  194. },
  195. /**
  196. * 生命周期函数--监听页面加载
  197. */
  198. onLoad(options) {
  199. // 初始化当前选中的标签
  200. this.initCurTab(options)
  201. },
  202. /**
  203. * 生命周期函数--监听页面显示
  204. */
  205. onShow() {
  206. this.canReset && this.onRefreshList()
  207. this.canReset = true
  208. },
  209. methods: {
  210. // 初始化当前选中的标签
  211. initCurTab(options) {
  212. const app = this
  213. if (options.dataType) {
  214. const index = app.tabs.findIndex(item => item.value == options.dataType)
  215. app.curTab = index > -1 ? index : 0
  216. }
  217. },
  218. /**
  219. * 上拉加载的回调 (页面初始化时也会执行一次)
  220. * 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10
  221. * @param {Object} page
  222. */
  223. upCallback(page) {
  224. const app = this
  225. // 设置列表数据
  226. app.getOrderList(page.num)
  227. .then(list => {
  228. const curPageLen = list.data.length
  229. const totalSize = list.data.total
  230. app.mescroll.endBySize(curPageLen, totalSize)
  231. })
  232. .catch(() => app.mescroll.endErr())
  233. },
  234. // 获取订单列表
  235. getOrderList(pageNo = 1) {
  236. const app = this
  237. return new Promise((resolve, reject) => {
  238. OrderApi.list({ dataType: app.getTabValue(), page: pageNo }, { load: false })
  239. .then(result => {
  240. // 合并新数据
  241. const newList = app.initList(result.data.list)
  242. app.list.data = getMoreListData(newList, app.list, pageNo)
  243. resolve(newList)
  244. })
  245. })
  246. },
  247. // 初始化订单列表数据
  248. initList(newList) {
  249. newList.data.forEach(item => {
  250. item.total_num = 0
  251. item.goods.forEach(goods => {
  252. item.total_num += goods.total_num
  253. })
  254. })
  255. return newList
  256. },
  257. // 获取当前标签项的值
  258. getTabValue() {
  259. return this.tabs[this.curTab].value
  260. },
  261. // 切换标签项
  262. onChangeTab(index) {
  263. const app = this
  264. // 设置当前选中的标签
  265. app.curTab = index
  266. // 刷新订单列表
  267. app.onRefreshList()
  268. },
  269. // 刷新订单列表
  270. onRefreshList() {
  271. this.list = getEmptyPaginateObj()
  272. setTimeout(() => {
  273. this.mescroll.resetUpScroll()
  274. }, 120)
  275. },
  276. // 取消订单
  277. onCancel(orderId) {
  278. const app = this
  279. uni.showModal({
  280. title: '友情提示',
  281. content: '确认要取消该订单吗?',
  282. success(o) {
  283. if (o.confirm) {
  284. OrderApi.cancel(orderId)
  285. .then(result => {
  286. // 显示成功信息
  287. app.$toast(result.message)
  288. // 刷新订单列表
  289. app.onRefreshList()
  290. })
  291. }
  292. }
  293. });
  294. },
  295. // 确认收货
  296. onReceipt(orderId) {
  297. const app = this
  298. uni.showModal({
  299. title: '友情提示',
  300. content: '确认收到商品了吗?',
  301. success(o) {
  302. if (o.confirm) {
  303. OrderApi.receipt(orderId)
  304. .then(result => {
  305. // 显示成功信息
  306. app.$success(result.message)
  307. // 刷新订单列表
  308. app.onRefreshList()
  309. })
  310. }
  311. }
  312. });
  313. },
  314. // 点击去支付
  315. onPay(orderId) {
  316. // 记录订单id
  317. this.payOrderId = orderId
  318. // 显示支付方式弹窗
  319. this.showPayPopup = true
  320. },
  321. // 选择支付方式
  322. onSelectPayType(payType) {
  323. const app = this
  324. // 隐藏支付方式弹窗
  325. this.showPayPopup = false
  326. // 发起支付请求
  327. OrderApi.pay(app.payOrderId, payType)
  328. .then(result => app.onSubmitCallback(result))
  329. },
  330. // 订单提交成功后回调
  331. onSubmitCallback(result) {
  332. const app = this
  333. // 发起微信支付
  334. if (result.data.pay_type == PayTypeEnum.WECHAT.value) {
  335. wxPayment(result.data.payment)
  336. .then(() => {
  337. app.$success('支付成功')
  338. setTimeout(() => {
  339. app.onRefreshList()
  340. }, 1500)
  341. })
  342. .catch(err => {
  343. app.$error('订单未支付')
  344. })
  345. .finally(() => {
  346. app.disabled = false
  347. })
  348. }
  349. // 余额支付
  350. if (result.data.pay_type == PayTypeEnum.BALANCE.value) {
  351. app.$success('支付成功')
  352. app.disabled = false
  353. setTimeout(() => {
  354. app.onRefreshList()
  355. }, 1500)
  356. }
  357. },
  358. // 跳转到订单详情页
  359. handleTargetDetail(orderId) {
  360. this.$navTo('pages/order/detail', { orderId })
  361. },
  362. // 跳转到订单评价页
  363. handleTargetComment(orderId) {
  364. this.$navTo('pages/order/comment/index', { orderId })
  365. }
  366. },
  367. }
  368. </script>
  369. <style lang="scss" scoped>
  370. // 项目内容
  371. .order-item {
  372. margin: 20rpx auto 20rpx auto;
  373. padding: 30rpx 30rpx;
  374. width: 94%;
  375. box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
  376. border-radius: 16rpx;
  377. background: #fff;
  378. }
  379. // 项目顶部
  380. .item-top {
  381. display: flex;
  382. justify-content: space-between;
  383. font-size: 26rpx;
  384. margin-bottom: 40rpx;
  385. .order-time {
  386. color: #777;
  387. }
  388. .state-text {
  389. color: $uni-text-color-active;
  390. }
  391. }
  392. // 商品列表
  393. .goods-list {
  394. // 商品项
  395. .goods-item {
  396. display: flex;
  397. margin-bottom: 40rpx;
  398. // 商品图片
  399. .goods-image {
  400. width: 180rpx;
  401. height: 180rpx;
  402. .image {
  403. display: block;
  404. width: 100%;
  405. height: 100%;
  406. border-radius: 8rpx;
  407. }
  408. }
  409. // 商品内容
  410. .goods-content {
  411. flex: 1;
  412. padding-left: 16rpx;
  413. padding-top: 16rpx;
  414. .goods-title {
  415. font-size: 26rpx;
  416. max-height: 76rpx;
  417. }
  418. .goods-props {
  419. margin-top: 14rpx;
  420. height: 40rpx;
  421. color: #ababab;
  422. font-size: 24rpx;
  423. overflow: hidden;
  424. .goods-props-item {
  425. display: inline-block;
  426. margin-right: 14rpx;
  427. padding: 4rpx 16rpx;
  428. border-radius: 12rpx;
  429. background-color: #F5F5F5;
  430. width: auto;
  431. }
  432. }
  433. }
  434. // 交易信息
  435. .goods-trade {
  436. padding-top: 16rpx;
  437. width: 150rpx;
  438. text-align: right;
  439. color: $uni-text-color-grey;
  440. font-size: 26rpx;
  441. .goods-price {
  442. vertical-align: bottom;
  443. margin-bottom: 16rpx;
  444. .unit {
  445. margin-right: -2rpx;
  446. font-size: 24rpx;
  447. }
  448. }
  449. }
  450. }
  451. }
  452. // 订单合计
  453. .order-total {
  454. font-size: 26rpx;
  455. vertical-align: bottom;
  456. text-align: right;
  457. height: 40rpx;
  458. margin-bottom: 30rpx;
  459. .unit {
  460. margin-left: 8rpx;
  461. margin-right: -2rpx;
  462. font-size: 26rpx;
  463. }
  464. .money {
  465. font-size: 28rpx;
  466. }
  467. }
  468. // 订单操作
  469. .order-handle {
  470. .btn-group {
  471. .btn-item {
  472. border-radius: 10rpx;
  473. padding: 6rpx 20rpx;
  474. margin-left: 15rpx;
  475. font-size: 28rpx;
  476. float: right;
  477. color: #383838;
  478. border: 1rpx solid #a8a8a8;
  479. &:last-child {
  480. margin-left: 0;
  481. }
  482. &.active {
  483. color: $uni-text-color-active;
  484. border: 1rpx solid $uni-text-color-active;
  485. }
  486. }
  487. }
  488. }
  489. // 弹出层-支付方式
  490. .pay-popup {
  491. padding: 24rpx;
  492. .title {
  493. font-size: 30rpx;
  494. margin-bottom: 40rpx;
  495. font-weight: bold;
  496. text-align: center;
  497. }
  498. .pop-content {
  499. min-height: 260rpx;
  500. padding: 0 10rpx;
  501. .pay-item {
  502. padding: 24rpx 35rpx;
  503. font-size: 28rpx;
  504. border-bottom: 1rpx solid #f1f1f1;
  505. &:last-child {
  506. border-bottom: none;
  507. }
  508. .item-left_icon {
  509. margin-right: 20rpx;
  510. font-size: 32rpx;
  511. &.wechat {
  512. color: #00c800;
  513. }
  514. &.balance {
  515. color: #ff9700;
  516. }
  517. }
  518. }
  519. }
  520. }
  521. </style>