order.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <view class="list-page">
  3. <view class="tabs-box">
  4. <up-tabs :list="list" @click="tabsChange" lineColor="#f8c20f"></up-tabs>
  5. </view>
  6. <view v-if="orderList.length === 0" class="empty">
  7. <image
  8. style="width: 60%"
  9. src="https://mp-ad17e5cd-05c1-4df9-b060-556e25dac130.cdn.bspapp.com/mini/common/empty.png"
  10. mode="widthFix"
  11. ></image>
  12. <text>暂无订单~</text>
  13. </view>
  14. <view v-else class="inner">
  15. <view
  16. v-for="(item, index) in orderList"
  17. :key="index"
  18. class="block"
  19. @click="nativeTo(item)"
  20. >
  21. <view class="header">
  22. <view class="title">订单号:{{ item.orderNo }}</view>
  23. <view class="tag" :class="['status' + item.status]">
  24. {{ getOrderType(item.status) }}
  25. </view>
  26. </view>
  27. <view class="detail">
  28. <image
  29. style="width: 50px; height: 50px; border-radius: 6px"
  30. :src="item.images[0] || emptyImg"
  31. mode="scaleToFill"
  32. v-if="item.images"
  33. @click="previewImage(item.images)"
  34. ></image>
  35. </view>
  36. <view class="end">
  37. <view>
  38. <view class="desc">
  39. 订单自估重量:
  40. <span
  41. class="price"
  42. v-for="(i, index) in item.goldMaterials"
  43. :key="index"
  44. >{{ `${getCate(i.type)}${i.weight}g` }}</span
  45. >
  46. </view>
  47. </view>
  48. <view class="desc">
  49. <view class="">下单时间:{{ item.createTime }}</view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </template>
  56. <script setup>
  57. import { ref } from "vue";
  58. import {
  59. onLoad,
  60. onShow,
  61. onPullDownRefresh,
  62. onReachBottom,
  63. } from "@dcloudio/uni-app";
  64. import { depositPageAPI } from "@/api/functions";
  65. import { useAppStore } from "@/stores/app";
  66. const appStore = useAppStore();
  67. // 响应式变量(替代 Vue2 的 data)
  68. const list = ref([
  69. { name: "全部", status: "" },
  70. { name: "待签收", status: 0 },
  71. { name: "待检测", status: 1 },
  72. { name: "待确认", status: 2 },
  73. { name: "已完成", status: 4 },
  74. ]);
  75. const options = ref({ status: 0 });
  76. const orderList = ref([]);
  77. const emptyImg = ref(
  78. "https://mp-ad17e5cd-05c1-4df9-b060-556e25dac130.cdn.bspapp.com/mini/recycle/example/example1.png"
  79. );
  80. const params = ref({
  81. page: 1,
  82. limit: 20,
  83. status: "",
  84. // userId: appStorze.userInfo.userId,
  85. });
  86. const total = ref(0);
  87. const loading = ref(false); // 加载状态
  88. const hasMore = ref(true); // 是否还有更多数据
  89. onShow((options) => {
  90. console.log(1111);
  91. params.value.page = 1;
  92. getOrderList();
  93. });
  94. const getOrderList = async (isRefresh = false) => {
  95. if (loading.value) return;
  96. loading.value = true;
  97. uni.showLoading({
  98. title: "加载中",
  99. });
  100. try {
  101. const res = await depositPageAPI(params.value);
  102. console.log(res);
  103. const newList = res.data.list.map((v) => {
  104. return {
  105. ...v,
  106. images: JSON.parse(v.expressImage),
  107. };
  108. });
  109. if (isRefresh) {
  110. orderList.value = newList;
  111. } else {
  112. // 避免重复添加
  113. if (params.value.page === 1) {
  114. orderList.value = newList;
  115. } else {
  116. orderList.value = [...orderList.value, ...newList];
  117. }
  118. }
  119. total.value = res.data.total;
  120. // 判断是否还有更多数据
  121. hasMore.value = orderList.value.length < total.value;
  122. uni.hideLoading();
  123. } catch (error) {
  124. console.error("获取订单列表失败:", error);
  125. uni.showToast({
  126. title: "加载失败",
  127. icon: "none",
  128. });
  129. } finally {
  130. loading.value = false;
  131. // 停止下拉刷新动画
  132. if (isRefresh) {
  133. uni.stopPullDownRefresh();
  134. }
  135. }
  136. };
  137. // 其他生命周期
  138. onPullDownRefresh(() => {
  139. // 下拉刷新逻辑(保持原有空实现,可根据需求补充)
  140. });
  141. onReachBottom(() => {
  142. // 如果没有更多数据或正在加载中,则不执行
  143. if (!hasMore.value || loading.value) return;
  144. // 增加页码
  145. params.value.page++;
  146. // 加载下一页数据
  147. getOrderList();
  148. });
  149. onShow(() => {
  150. // 页面显示时逻辑(保持原有空实现,可根据需求补充)
  151. });
  152. // 标签页切换
  153. const tabsChange = (item) => {
  154. params.value.status = item.status;
  155. params.value.page = 1;
  156. getOrderList();
  157. };
  158. // 跳转详情页(原 methods 中的 nativeTo)
  159. const nativeTo = (item) => {
  160. if (item.status === 2 || item.status == 3 || item.status == 4) {
  161. uni.navigateTo({
  162. url: `/pages/users/vault/storeMetal/gmReport?orderInfo=${encodeURIComponent(
  163. JSON.stringify(item)
  164. )}`,
  165. });
  166. }
  167. };
  168. // 获取商品类别(原 methods 中的 getCate)
  169. const getCate = (cate) => {
  170. switch (cate) {
  171. case 1:
  172. return "黄金";
  173. case 3:
  174. return "白银";
  175. case 2:
  176. return "铂金";
  177. case 4:
  178. return "K金";
  179. default:
  180. return ""; // 增加默认值,避免 undefined
  181. }
  182. };
  183. // 获取订单状态文本(原 methods 中的 getOrderType)
  184. const getOrderType = (status) => {
  185. switch (status) {
  186. case 0:
  187. return "待签收";
  188. case 1:
  189. return "待检测";
  190. case 2:
  191. return "待确认";
  192. case 3:
  193. return "待充值";
  194. case 4:
  195. return "已完成";
  196. default:
  197. return "-"; // 增加默认值,避免 undefined
  198. }
  199. };
  200. const previewImage = (urls) => {
  201. uni.previewImage({
  202. current: urls[0],
  203. urls: urls, // 需要预览的图片URL列表
  204. success: () => {},
  205. fail: (err) => {
  206. console.error("预览图片失败:", err);
  207. },
  208. });
  209. };
  210. </script>
  211. <style scoped lang="scss">
  212. .list-page {
  213. // min-height: 100vh;
  214. background: $uni-bg-primary !important;
  215. }
  216. .tabs-box {
  217. width: 100%;
  218. height: 75rpx;
  219. // background: #ffffff;
  220. box-sizing: border-box;
  221. ::v-deep .u-tabs__wrapper__nav__item {
  222. padding: 0 37rpx;
  223. }
  224. }
  225. .empty {
  226. display: flex;
  227. flex-direction: column;
  228. align-items: center;
  229. color: #fff;
  230. }
  231. .tabs {
  232. z-index: 100;
  233. position: sticky;
  234. }
  235. .inner {
  236. padding: 10px;
  237. .footer {
  238. border-radius: 5px;
  239. border: 0 0 10px 20px;
  240. color: #707070;
  241. font-size: 12px;
  242. padding: 10px;
  243. background-color: rgb(252, 247, 230);
  244. }
  245. }
  246. .block {
  247. margin-bottom: 10px;
  248. padding-top: 10px;
  249. border-radius: 5px;
  250. background-color: #fff;
  251. border: 1px solid #cecece;
  252. .header {
  253. padding: 0 10px;
  254. position: relative;
  255. display: flex;
  256. align-items: center;
  257. justify-content: space-between;
  258. padding-bottom: 10px;
  259. border-bottom: 1px solid #eee;
  260. .tag {
  261. font-size: 12px;
  262. padding: 2px 5px;
  263. border-radius: 4px;
  264. color: #ff0800;
  265. background-color: #ffcece;
  266. &.status-1 {
  267. color: #555;
  268. background-color: #eeeeee;
  269. }
  270. &.status1 {
  271. color: #ff9900;
  272. background-color: #ffeccf;
  273. }
  274. &.status2 {
  275. color: #d6006b;
  276. background-color: #fdd3e9;
  277. }
  278. &.status3 {
  279. color: #9900ff;
  280. background-color: #e2b7ff;
  281. }
  282. &.status4 {
  283. color: rgb(48, 24, 136);
  284. background-color: #bbb0fa;
  285. }
  286. &.status5 {
  287. color: #0051ff;
  288. background-color: #b7d6ff;
  289. }
  290. &.status6 {
  291. color: #3dac27;
  292. background-color: #c8ffb7;
  293. }
  294. }
  295. .title {
  296. font-size: 14px;
  297. }
  298. }
  299. .info {
  300. flex: 1;
  301. width: 100%;
  302. font-size: 14px;
  303. margin-left: 10px;
  304. color: #999;
  305. .cartList {
  306. margin-bottom: 3px;
  307. display: flex;
  308. justify-content: space-between;
  309. .right {
  310. min-width: 120px;
  311. display: flex;
  312. justify-content: space-between;
  313. .weight {
  314. color: #daa520;
  315. }
  316. }
  317. }
  318. }
  319. .detail {
  320. display: flex;
  321. padding: 10px 13px;
  322. }
  323. .end {
  324. padding: 10px 10px;
  325. color: #999;
  326. font-size: 14px;
  327. .desc {
  328. margin-bottom: 6px;
  329. display: flex;
  330. align-items: center;
  331. // justify-content: space-between;
  332. .price {
  333. margin-right: 10rpx;
  334. }
  335. }
  336. }
  337. }
  338. </style>