order-list.vue 15 KB

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