order-list.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <template>
  2. <view class="order-list">
  3. <tui-skeleton v-if="isRequest" loadingType="2"></tui-skeleton>
  4. <!-- 滑块 tabs -->
  5. <view class="tabs">
  6. <tui-tabs
  7. :tabs="tabs"
  8. :currentTab="currentTab"
  9. @change="tabChange"
  10. :sliderWidth="48"
  11. color="#333333"
  12. selectedColor="#FF457B"
  13. sliderBgColor="#FF457B"
  14. ></tui-tabs>
  15. </view>
  16. <!-- 协销筛选订单 -->
  17. <cm-order-filter-control
  18. @click="handleFilter"
  19. :buttonGroup="screenTabBar"
  20. v-if="isDealer"
  21. ></cm-order-filter-control>
  22. <swiper
  23. :indicator-dots="false"
  24. :autoplay="false"
  25. class="swiper"
  26. :class="!isDealer ? 'swiper-hegiht1' : 'swiper-hegiht2'"
  27. :current="currentTab"
  28. @change="swiperChange"
  29. >
  30. <swiper-item v-for="tab in tabs" :key="tab.state">
  31. <!-- tab.orderList.length === 0 -->
  32. <view class="order-empty" v-if="tab.orderList.length === 0">
  33. <cm-empty :image="emptyInfo.image" :message="emptyInfo.message" :offset="100"></cm-empty>
  34. </view>
  35. <scroll-view scroll-y="true" v-else class="scroll-box" @scrolltolower="scrollBottom">
  36. <template v-for="(orderInfo, orderIndex) in tab.orderList">
  37. <view class="grid" :key="orderIndex"></view>
  38. <view class="order-section" :key="orderIndex" @click="handleToDetail(orderInfo)">
  39. <!-- 订单信息 -->
  40. <view class="order-info">
  41. <view class="order-num">
  42. <text class="label">订单编号:</text> <text>{{ orderInfo.orderNo }}</text>
  43. </view>
  44. <view class="order-time">
  45. <text class="label">下单时间:</text> <text>{{ orderInfo.orderTime }}</text>
  46. </view>
  47. <view class="status">{{ stateExpFormat(orderInfo.status) }}</view>
  48. </view>
  49. <view class="line"></view>
  50. <view
  51. class="shop-order"
  52. v-for="(shopOrder, shopOrderIndex) in orderInfo.shopOrderList"
  53. :key="shopOrderIndex"
  54. >
  55. <!-- 供应商 -->
  56. <view class="origin">
  57. <image class="cover" :src="shopOrder.shopLogo"></image>
  58. <view class="name">{{ shopOrder.shopName }}</view>
  59. </view>
  60. <!-- 商品列表 -->
  61. <view class="goods-list">
  62. <!-- 商品信息 -->
  63. <view
  64. class="order-goods"
  65. v-for="goods in shopOrder.orderProductList"
  66. :key="goods.productId"
  67. >
  68. <cm-order-prodcut :goods-data="goods"></cm-order-prodcut>
  69. </view>
  70. </view>
  71. </view>
  72. <!-- 统计 -->
  73. <view class="total">
  74. <view class="count">共{{ orderInfo.productCount }}件商品</view>
  75. <view class="status">
  76. <template v-if="['31', '32', '33'].includes(orderInfo.status)">
  77. <text class="label">已支付:</text>
  78. <text>¥{{ orderInfo.receiptAmount | formatPrice }}</text>
  79. </template>
  80. <template v-else>
  81. <text class="label">待付总额:</text>
  82. <text>¥{{ orderInfo.pendingPayments | formatPrice }}</text>
  83. </template>
  84. </view>
  85. </view>
  86. <!-- 操作 -->
  87. <cm-order-control-nav
  88. v-if="orderInfo.userId == userId"
  89. :orderInfo="orderInfo"
  90. @confirm="handleConfirmClick"
  91. ></cm-order-control-nav>
  92. </view>
  93. </template>
  94. <!-- loading -->
  95. <view class="loading-more">
  96. <tui-loadmore :index="3" :visible="loadmore"></tui-loadmore>
  97. <tui-nomore :text="loadMoreText" :visible="!loadmore" backgroundColor="#f7f7f7"></tui-nomore>
  98. </view>
  99. </scroll-view>
  100. </swiper-item>
  101. </swiper>
  102. <!-- 操作弹窗 -->
  103. <tui-modal
  104. :show="modal"
  105. :content="modalText"
  106. :size="32"
  107. :maskClosable="false"
  108. color="#333"
  109. shape="circle"
  110. @click="handleModalConfirm"
  111. ></tui-modal>
  112. <!-- 加载框 -->
  113. <cm-loading :visible="isSubLoading" :text="loadingText"></cm-loading>
  114. <!-- 失效商品列表 -->
  115. <cm-order-invalid-modal
  116. :goodsList="invalidList"
  117. :visible="buyAgainModal"
  118. @confirm="buyAgainModalClick"
  119. @cancel="buyAgainModalHide"
  120. ></cm-order-invalid-modal>
  121. </view>
  122. </template>
  123. <script>
  124. import CmOrderProdcut from '@/components/cm-module/cm-order-prodcut/cm-order-prodcut.vue'
  125. import CmOrderControlNav from '@/components/cm-module/cm-order-control-nav/cm-order-control-nav.vue'
  126. import CmOrderInvalidModal from '@/components/cm-module/cm-order-invalid-modal/cm-order-invalid-modal.vue'
  127. import CmOrderFilterControl from '@/components/cm-module/cm-order-filter-control/cm-order-filter-control.vue'
  128. import CmLoading from '@/components/cm-module/cm-loading/cm-loading.vue'
  129. import CmEmpty from '@/components/cm-module/cm-empty/cm-empty.vue'
  130. import { debounce } from '@/common/common.js'
  131. import orderList from './mixins/orderList.js'
  132. import wechatPay from './mixins/wechatPay.js'
  133. import { mapGetters } from 'vuex'
  134. export default {
  135. mixins: [wechatPay, orderList],
  136. components: {
  137. CmOrderProdcut,
  138. CmOrderControlNav,
  139. CmOrderInvalidModal,
  140. CmOrderFilterControl,
  141. CmLoading,
  142. CmEmpty
  143. },
  144. data() {
  145. return {
  146. tabs: [
  147. {
  148. name: '全部',
  149. state: 0,
  150. pageNum: 1,
  151. orderList: []
  152. },
  153. {
  154. name: '待付款',
  155. state: 1,
  156. pageNum: 1,
  157. orderList: []
  158. },
  159. {
  160. name: '待发货',
  161. state: 2,
  162. pageNum: 1,
  163. orderList: []
  164. },
  165. {
  166. name: '已发货',
  167. state: 3,
  168. pageNum: 1,
  169. orderList: []
  170. },
  171. {
  172. name: '退货/款',
  173. state: 4,
  174. pageNum: 1,
  175. orderList: []
  176. }
  177. ],
  178. currentTab: 0,
  179. screenTabBar: [{ id: 0, name: '全部订单' }, { id: 1, name: '用户订单' }, { id: 2, name: '自身订单' }],
  180. screenTab: 0,
  181. refresh: false,
  182. loadmore: false, // 正在加载更多
  183. isRequest: true,
  184. }
  185. },
  186. filters: {
  187. formatPrice(price) {
  188. if (!price) return '0.00'
  189. return Number(price).toFixed(2)
  190. }
  191. },
  192. computed: {
  193. ...mapGetters(['userId', 'userIdentity']),
  194. // 当前用户是否为协销
  195. isDealer() {
  196. return this.userIdentity === 2
  197. },
  198. tabInfo() {
  199. return this.tabs[this.currentTab]
  200. },
  201. loadMoreText() {
  202. if (this.tabInfo.orderList.length === 0) return '没有更多了'
  203. return this.tabInfo.hasMore ? '上拉加载更多' : '没有更多了'
  204. },
  205. emptyInfo() {
  206. const info = {}
  207. info.image = `${this.$Static}icon-empty-address.png`
  208. if (this.tabInfo.state === 0) {
  209. info.message = '您还没有任何的订单哟~_~'
  210. } else {
  211. info.message = '您还没有相关的订单哟~_~'
  212. }
  213. return info
  214. }
  215. },
  216. onLoad(options) {
  217. this.currentTab = options.state
  218. this.fetchOrderData()
  219. },
  220. // 下拉刷新
  221. onPullDownRefresh() {
  222. this.resetOrderList()
  223. },
  224. methods: {
  225. // 重置订单列表
  226. resetOrderList() {
  227. this.refresh = true
  228. this.tabInfo.pageNum = 1
  229. this.fetchOrderData()
  230. },
  231. // 更新订单列表
  232. updateOrderList(response) {
  233. const { name, state, pageNum } = this.tabInfo
  234. this.$set(this.tabs, this.currentTab, {
  235. name,
  236. state,
  237. pageNum: pageNum + 1,
  238. orderList: this.tabInfo.orderList.concat(response.data.list),
  239. hasMore: response.data.hasNextPage
  240. })
  241. },
  242. // 获取订单列表 使用防抖函数封装
  243. fetchOrderData: debounce(function() {
  244. this.loadmore = true
  245. const params = {
  246. orderState: this.currentTab,
  247. userId: this.userId,
  248. orderType: this.screenTab,
  249. pageNum: this.tabInfo.pageNum,
  250. pageSize: 10
  251. }
  252. if (this.isDealer) {
  253. this.queryOrderDealerList(params)
  254. } else {
  255. this.queryOrderList(params)
  256. }
  257. }, 500),
  258. // 普通用户获取订单列表
  259. queryOrderList(params) {
  260. this.OrderService.QueryOrderList(params)
  261. .then(res => {
  262. if (this.refresh) this.tabInfo.orderList = []
  263. this.updateOrderList(res)
  264. })
  265. .catch(err => {
  266. console.log(err)
  267. })
  268. .finally(() => {
  269. uni.stopPullDownRefresh()
  270. this.refresh = false
  271. this.loadmore = false
  272. this.isRequest = false
  273. })
  274. },
  275. // 分销者获取订单列表
  276. queryOrderDealerList(params) {
  277. console.log(params)
  278. this.OrderService.QueryOrderDealerList(params)
  279. .then(res => {
  280. if (this.refresh) this.tabInfo.orderList = []
  281. this.updateOrderList(res)
  282. })
  283. .catch(err => {
  284. console.log(err)
  285. })
  286. .finally(() => {
  287. uni.stopPullDownRefresh()
  288. this.refresh = false
  289. this.loadmore = false
  290. this.isRequest = false
  291. })
  292. },
  293. // 筛选订单
  294. handleFilter(e) {
  295. console.log(e.index)
  296. this.screenTab = e.index
  297. this.resetOrderList()
  298. this.fetchOrderData()
  299. },
  300. // 跳转详情
  301. handleToDetail(orderInfo){
  302. this.$api.navigateTo('/pages/order/order-detail?orderId=' + orderInfo.orderId)
  303. },
  304. // 滚动到底部
  305. scrollBottom() {
  306. if (!this.tabInfo.hasMore) return
  307. this.fetchOrderData()
  308. },
  309. // tab切换
  310. tabChange(e) {
  311. this.currentTab = e.index
  312. },
  313. // 轮播切换
  314. swiperChange(e) {
  315. this.currentTab = e.detail.current
  316. if (this.tabInfo.pageNum !== 1) return
  317. this.isRequest = true
  318. this.fetchOrderData()
  319. }
  320. }
  321. }
  322. </script>
  323. <style lang="scss" scoped>
  324. .order-list {
  325. min-height: 100vh;
  326. background: #f7f7f7;
  327. .tabs{
  328. position: relative;
  329. z-index: 100000;
  330. }
  331. .swiper {
  332. &.swiper-hegiht1 {
  333. height: calc(100vh - 40px);
  334. }
  335. &.swiper-hegiht2 {
  336. height: calc(100vh - 80px);
  337. }
  338. .scroll-box {
  339. height: 100%;
  340. }
  341. }
  342. .grid {
  343. height: 20rpx;
  344. background: #f7f7f7;
  345. }
  346. .order-section {
  347. padding: 38rpx 0;
  348. background-color: #fff;
  349. .line {
  350. width: 702rpx;
  351. height: 1px;
  352. background: #f7f7f7;
  353. }
  354. .order-info {
  355. position: relative;
  356. padding: 0 24rpx;
  357. margin-bottom: 32rpx;
  358. line-height: 1.6;
  359. .order-num,
  360. .order-time {
  361. font-size: 26rpx;
  362. color: #333333;
  363. .label {
  364. color: #999999;
  365. }
  366. }
  367. .status {
  368. position: absolute;
  369. font-size: 26rpx;
  370. color: #ff457b;
  371. right: 24rpx;
  372. bottom: 0;
  373. }
  374. }
  375. .origin {
  376. padding: 0 24rpx;
  377. margin-top: 24rpx;
  378. margin-bottom: 16rpx;
  379. display: flex;
  380. justify-content: flex-start;
  381. align-items: center;
  382. .cover {
  383. width: 56rpx;
  384. height: 56rpx;
  385. border-radius: 4rpx;
  386. border: 1px solid #F7F7F7;
  387. box-sizing: border-box;
  388. }
  389. .name {
  390. margin-left: 16rpx;
  391. font-size: 30rpx;
  392. color: #333333;
  393. font-weight: bold;
  394. }
  395. }
  396. .goods-list {
  397. .order-goods {
  398. padding-top: 32rpx;
  399. &:first-child {
  400. padding-top: 0;
  401. }
  402. }
  403. }
  404. .total {
  405. display: flex;
  406. justify-content: space-between;
  407. align-items: center;
  408. padding: 0 24rpx;
  409. margin: 32rpx 0;
  410. font-size: 26rpx;
  411. color: #333333;
  412. .count {
  413. font-weight: bold;
  414. }
  415. .status {
  416. color: #ff457b;
  417. .label {
  418. color: #333333;
  419. }
  420. }
  421. }
  422. }
  423. }
  424. </style>