order.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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://my-go-easy-im.oss-cn-shenzhen.aliyuncs.com/goeasy-im-%E6%B0%B4%E8%B4%9D%E5%95%86%E5%9F%8E/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. params.value.page = 1;
  141. getOrderList();
  142. uni.stopPullDownRefresh();
  143. });
  144. onReachBottom(() => {
  145. // 如果没有更多数据或正在加载中,则不执行
  146. if (!hasMore.value || loading.value) return;
  147. // 增加页码
  148. params.value.page++;
  149. // 加载下一页数据
  150. getOrderList();
  151. });
  152. onShow(() => {
  153. // 页面显示时逻辑(保持原有空实现,可根据需求补充)
  154. });
  155. // 标签页切换
  156. const tabsChange = (item) => {
  157. params.value.status = item.status;
  158. params.value.page = 1;
  159. getOrderList();
  160. };
  161. // 跳转详情页(原 methods 中的 nativeTo)
  162. const nativeTo = (item) => {
  163. if (item.status === 2 || item.status == 3 || item.status == 4) {
  164. uni.navigateTo({
  165. url: `/pages/users/vault/storeMetal/gmReport?orderInfo=${encodeURIComponent(
  166. JSON.stringify(item)
  167. )}`,
  168. });
  169. }
  170. };
  171. // 获取商品类别(原 methods 中的 getCate)
  172. const getCate = (cate) => {
  173. switch (cate) {
  174. case 1:
  175. return "黄金";
  176. case 3:
  177. return "白银";
  178. case 2:
  179. return "铂金";
  180. case 4:
  181. return "K金";
  182. default:
  183. return ""; // 增加默认值,避免 undefined
  184. }
  185. };
  186. // 获取订单状态文本(原 methods 中的 getOrderType)
  187. const getOrderType = (status) => {
  188. switch (status) {
  189. case 0:
  190. return "待签收";
  191. case 1:
  192. return "待检测";
  193. case 2:
  194. return "待确认";
  195. case 3:
  196. return "待充值";
  197. case 4:
  198. return "已完成";
  199. default:
  200. return "-"; // 增加默认值,避免 undefined
  201. }
  202. };
  203. const previewImage = (urls) => {
  204. uni.previewImage({
  205. current: urls[0],
  206. urls: urls, // 需要预览的图片URL列表
  207. success: () => {},
  208. fail: (err) => {
  209. console.error("预览图片失败:", err);
  210. },
  211. });
  212. };
  213. </script>
  214. <style scoped lang="scss">
  215. .list-page {
  216. // min-height: 100vh;
  217. background: $uni-bg-primary !important;
  218. }
  219. .tabs-box {
  220. width: 100%;
  221. height: 75rpx;
  222. // background: #ffffff;
  223. box-sizing: border-box;
  224. ::v-deep .u-tabs__wrapper__nav__item {
  225. padding: 0 37rpx;
  226. }
  227. }
  228. .empty {
  229. display: flex;
  230. flex-direction: column;
  231. align-items: center;
  232. color: #fff;
  233. }
  234. .tabs {
  235. z-index: 100;
  236. position: sticky;
  237. }
  238. .inner {
  239. padding: 10px;
  240. .footer {
  241. border-radius: 5px;
  242. border: 0 0 10px 20px;
  243. color: #707070;
  244. font-size: 12px;
  245. padding: 10px;
  246. background-color: rgb(252, 247, 230);
  247. }
  248. }
  249. .block {
  250. margin-bottom: 10px;
  251. padding-top: 10px;
  252. border-radius: 5px;
  253. background-color: #fff;
  254. border: 2px solid #eee;
  255. box-shadow: 0 10rpx 8rpx rgba(100, 88, 88, 0.05);
  256. .header {
  257. padding: 0 10px;
  258. position: relative;
  259. display: flex;
  260. align-items: center;
  261. justify-content: space-between;
  262. padding-bottom: 10px;
  263. border-bottom: 1px solid #eee;
  264. .tag {
  265. font-size: 12px;
  266. padding: 2px 5px;
  267. border-radius: 4px;
  268. color: #ff0800;
  269. background-color: #ffcece;
  270. &.status-1 {
  271. color: #555;
  272. background-color: #eeeeee;
  273. }
  274. &.status1 {
  275. color: #ff9900;
  276. background-color: #ffeccf;
  277. }
  278. &.status2 {
  279. color: #d6006b;
  280. background-color: #fdd3e9;
  281. }
  282. &.status3 {
  283. color: #9900ff;
  284. background-color: #e2b7ff;
  285. }
  286. &.status4 {
  287. color: rgb(48, 24, 136);
  288. background-color: #bbb0fa;
  289. }
  290. &.status5 {
  291. color: #0051ff;
  292. background-color: #b7d6ff;
  293. }
  294. &.status6 {
  295. color: #3dac27;
  296. background-color: #c8ffb7;
  297. }
  298. }
  299. .title {
  300. font-size: 14px;
  301. }
  302. }
  303. .info {
  304. flex: 1;
  305. width: 100%;
  306. font-size: 14px;
  307. margin-left: 10px;
  308. color: #999;
  309. .cartList {
  310. margin-bottom: 3px;
  311. display: flex;
  312. justify-content: space-between;
  313. .right {
  314. min-width: 120px;
  315. display: flex;
  316. justify-content: space-between;
  317. .weight {
  318. color: #daa520;
  319. }
  320. }
  321. }
  322. }
  323. .detail {
  324. display: flex;
  325. padding: 10px 13px;
  326. }
  327. .end {
  328. padding: 10px 10px;
  329. color: #999;
  330. font-size: 14px;
  331. .desc {
  332. margin-bottom: 6px;
  333. display: flex;
  334. align-items: center;
  335. // justify-content: space-between;
  336. .price {
  337. margin-right: 10rpx;
  338. }
  339. }
  340. }
  341. }
  342. </style>