西藏巴青项目

order-panel.vue 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <view class="sp-order-page">
  3. <view class="sp-tabs">
  4. <view
  5. v-for="tab in tabs"
  6. :key="tab.key"
  7. class="sp-tab"
  8. :class="{ 'sp-tab--on': activeTab === tab.key }"
  9. @tap="switchTab(tab.key)"
  10. >
  11. <text class="sp-tab__txt">{{ tab.label }}</text>
  12. </view>
  13. </view>
  14. <scroll-view
  15. scroll-y
  16. class="sp-order-scroll"
  17. enable-back-to-top
  18. :show-scrollbar="false"
  19. @scrolltolower="loadMore"
  20. >
  21. <view v-if="loading && !rows.length" class="sp-empty">
  22. <text class="sp-empty__txt">加载中…</text>
  23. </view>
  24. <view v-else-if="!rows.length" class="sp-empty">
  25. <text class="sp-empty__txt">暂无订单</text>
  26. </view>
  27. <view v-else class="sp-order-list">
  28. <view
  29. v-for="item in rows"
  30. :key="item._key"
  31. class="sp-order-card"
  32. @tap="openDetail(item)"
  33. >
  34. <view class="sp-order-card__head">
  35. <text class="sp-order-card__no">订单编号 {{ item.displayNo }}</text>
  36. <text class="sp-order-card__status" :class="item.statusClass">{{ item.statusName }}</text>
  37. </view>
  38. <view class="sp-order-card__body">
  39. <view class="sp-order-card__thumb">
  40. <text class="sp-order-card__thumb-txt">牦</text>
  41. </view>
  42. <view class="sp-order-card__info">
  43. <text class="sp-order-card__line">供应商:{{ item.partnerName }}</text>
  44. <text class="sp-order-card__line">订单创建时间:{{ item.createTime }}</text>
  45. <text class="sp-order-card__line">订单支付时间:{{ item.payTime }}</text>
  46. </view>
  47. </view>
  48. <view class="sp-order-card__foot">
  49. <text class="sp-order-card__amount">订单合计:{{ item.amountText }}</text>
  50. <text class="sp-order-card__heads">共 {{ item.totalHeads || 0 }} 头牦牛</text>
  51. </view>
  52. </view>
  53. </view>
  54. <view v-if="rows.length && (loadingMore || noMore)" class="sp-list-foot">
  55. <text class="sp-list-foot__txt">{{ loadingMore ? '加载中…' : '没有更多了' }}</text>
  56. </view>
  57. <view class="sp-footer-spacer" />
  58. </scroll-view>
  59. </view>
  60. </template>
  61. <script>
  62. import { listDistributorOrders } from '@/api/distributor/order'
  63. import { DASH, formatCurrency, formatDateTime } from '@/utils/format'
  64. const TABS = [
  65. { key: 'ALL', label: '全部订单' },
  66. { key: 'PENDING', label: '待支付' },
  67. { key: 'COMPLETED', label: '已完成' }
  68. ]
  69. export default {
  70. data() {
  71. return {
  72. tabs: TABS,
  73. activeTab: 'ALL',
  74. rows: [],
  75. pageNum: 1,
  76. pageSize: 10,
  77. total: 0,
  78. loading: false,
  79. loadingMore: false
  80. }
  81. },
  82. computed: {
  83. noMore() {
  84. return this.rows.length > 0 && this.rows.length >= this.total
  85. }
  86. },
  87. methods: {
  88. reload() {
  89. this.reloadList()
  90. },
  91. switchTab(key) {
  92. if (this.activeTab === key) return
  93. this.activeTab = key
  94. this.reloadList()
  95. },
  96. reloadList() {
  97. this.pageNum = 1
  98. this.rows = []
  99. this.total = 0
  100. this.fetchList(true)
  101. },
  102. loadMore() {
  103. if (this.loading || this.loadingMore || this.noMore) return
  104. this.pageNum += 1
  105. this.fetchList(false)
  106. },
  107. fetchList(reset) {
  108. if (reset) {
  109. this.loading = true
  110. } else {
  111. this.loadingMore = true
  112. }
  113. listDistributorOrders({
  114. pageNum: this.pageNum,
  115. pageSize: this.pageSize,
  116. statusTab: this.activeTab
  117. })
  118. .then((res) => {
  119. const list = (res.rows || []).map((row) => this.mapRow(row))
  120. this.total = res.total != null ? Number(res.total) : 0
  121. this.rows = reset ? list : this.rows.concat(list)
  122. })
  123. .catch(() => {
  124. if (reset) {
  125. this.rows = []
  126. this.total = 0
  127. } else {
  128. this.pageNum -= 1
  129. }
  130. })
  131. .finally(() => {
  132. this.loading = false
  133. this.loadingMore = false
  134. })
  135. },
  136. mapRow(row) {
  137. const statusName = row.orderStatusName || DASH
  138. return {
  139. _key: `o-${row.id}`,
  140. id: row.id,
  141. displayNo: row.orderNo,
  142. statusName,
  143. statusClass: this.resolveStatusClass(statusName),
  144. partnerName: row.supplierName || DASH,
  145. createTime: formatDateTime(row.createTime),
  146. payTime: formatDateTime(row.finishTime),
  147. amountText: formatCurrency(row.totalAmount),
  148. totalHeads: row.totalHeads
  149. }
  150. },
  151. resolveStatusClass(name) {
  152. const text = String(name || '')
  153. if (text.includes('完成')) return 'sp-order-card__status--done'
  154. if (text.includes('待')) return 'sp-order-card__status--pending'
  155. return ''
  156. },
  157. openDetail(item) {
  158. uni.navigateTo({
  159. url: `/pages/distributor/order-detail/index?id=${item.id}`
  160. })
  161. }
  162. }
  163. }
  164. </script>
  165. <style lang="scss" scoped>
  166. @import '@/styles/morandi.scss';
  167. .sp-order-page {
  168. display: flex;
  169. flex-direction: column;
  170. flex: 1;
  171. min-height: 0;
  172. min-width: 0;
  173. background: $morandi-bg-page;
  174. }
  175. .sp-tabs {
  176. display: flex;
  177. flex-direction: row;
  178. background: #ffffff;
  179. border-bottom: 1rpx solid $morandi-border-soft;
  180. flex-shrink: 0;
  181. }
  182. .sp-tab {
  183. flex: 1;
  184. min-width: 0;
  185. padding: 24rpx 8rpx;
  186. display: flex;
  187. align-items: center;
  188. justify-content: center;
  189. border-bottom: 4rpx solid transparent;
  190. }
  191. .sp-tab--on {
  192. border-bottom-color: #3b82f6;
  193. }
  194. .sp-tab__txt {
  195. font-size: 26rpx;
  196. color: $morandi-text-secondary;
  197. }
  198. .sp-tab--on .sp-tab__txt {
  199. color: #2563eb;
  200. font-weight: 600;
  201. }
  202. .sp-order-scroll {
  203. flex: 1;
  204. min-height: 0;
  205. height: 0;
  206. min-width: 0;
  207. }
  208. .sp-order-list {
  209. padding: 16rpx 24rpx 0;
  210. display: flex;
  211. flex-direction: column;
  212. gap: 20rpx;
  213. }
  214. .sp-order-card {
  215. padding: 24rpx;
  216. border-radius: 16rpx;
  217. background: $morandi-bg-card;
  218. border: 1rpx solid $morandi-border-soft;
  219. box-sizing: border-box;
  220. }
  221. .sp-order-card__head {
  222. display: flex;
  223. flex-direction: row;
  224. align-items: center;
  225. justify-content: space-between;
  226. gap: 16rpx;
  227. margin-bottom: 20rpx;
  228. }
  229. .sp-order-card__no {
  230. flex: 1;
  231. min-width: 0;
  232. font-size: 26rpx;
  233. color: $morandi-text;
  234. word-break: break-all;
  235. }
  236. .sp-order-card__status {
  237. flex-shrink: 0;
  238. font-size: 26rpx;
  239. color: $morandi-text-secondary;
  240. }
  241. .sp-order-card__status--pending {
  242. color: #ea580c;
  243. }
  244. .sp-order-card__status--done {
  245. color: #16a34a;
  246. }
  247. .sp-order-card__body {
  248. display: flex;
  249. flex-direction: row;
  250. gap: 20rpx;
  251. margin-bottom: 20rpx;
  252. }
  253. .sp-order-card__thumb {
  254. width: 120rpx;
  255. height: 120rpx;
  256. border-radius: 12rpx;
  257. background: #e5e7eb;
  258. display: flex;
  259. align-items: center;
  260. justify-content: center;
  261. flex-shrink: 0;
  262. }
  263. .sp-order-card__thumb-txt {
  264. font-size: 40rpx;
  265. font-weight: 700;
  266. color: #6b7280;
  267. }
  268. .sp-order-card__info {
  269. flex: 1;
  270. min-width: 0;
  271. display: flex;
  272. flex-direction: column;
  273. gap: 10rpx;
  274. }
  275. .sp-order-card__line {
  276. font-size: 24rpx;
  277. color: $morandi-text-secondary;
  278. line-height: 1.45;
  279. }
  280. .sp-order-card__foot {
  281. display: flex;
  282. flex-direction: row;
  283. align-items: center;
  284. justify-content: space-between;
  285. gap: 16rpx;
  286. padding-top: 16rpx;
  287. border-top: 1rpx solid $morandi-border-soft;
  288. }
  289. .sp-order-card__amount {
  290. font-size: 28rpx;
  291. font-weight: 600;
  292. color: #dc2626;
  293. }
  294. .sp-order-card__heads {
  295. font-size: 24rpx;
  296. color: $morandi-text-muted;
  297. }
  298. .sp-empty,
  299. .sp-list-foot {
  300. padding: 48rpx 24rpx;
  301. text-align: center;
  302. }
  303. .sp-empty__txt,
  304. .sp-list-foot__txt {
  305. font-size: 26rpx;
  306. color: $morandi-text-muted;
  307. }
  308. .sp-footer-spacer {
  309. height: 40rpx;
  310. }
  311. </style>