index.vue 12 KB

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