index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <view>
  3. <view class="logistics">
  4. <!-- <view class="header acea-row row-between row-top">
  5. <view class="pictrue">
  6. <image :src="product.image"></image>
  7. </view>
  8. <view class="text acea-row row-between">
  9. <view class="name line2">{{ product.storeName }}</view>
  10. <view class="money">
  11. <view>¥{{ product.storePrice }}</view>
  12. <view>x{{ product.cartNum }}</view>
  13. </view>
  14. </view>
  15. </view> -->
  16. <view class="logisticsCon">
  17. <view class="company acea-row row-between-wrapper">
  18. <view class="picTxt acea-row row-between-wrapper">
  19. <view class="iconfont icon-delivery-"></view>
  20. <view class="text">
  21. <view
  22. ><text class="name line1">物流公司:</text>
  23. {{ orderInfo.deliveryName }}</view
  24. >
  25. <view class="express line1"
  26. ><text class="name">快递单号:</text>
  27. {{ orderInfo.deliveryId }}</view
  28. >
  29. </view>
  30. </view>
  31. <view class="copy copy-data" @click="setOrderId">复制单号</view>
  32. </view>
  33. <!-- <view class="item" v-for="(item, index) in expressList" :key="index">
  34. <view class="circular" :class="index === 0 ? 'on' : ''"></view>
  35. <view class="text" :class="index === 0 ? 'on-font on' : ''">
  36. <view>{{ item.status }}</view>
  37. <view class="data" :class="index === 0 ? 'on-font on' : ''">{{
  38. item.time
  39. }}</view>
  40. </view>
  41. </view> -->
  42. <view class="express-status">
  43. <!-- <up-loading-icon v-if="expressLoading"></up-loading-icon> -->
  44. <up-steps current="0" activeColor="#EAC37A" direction="column">
  45. <up-steps-item
  46. v-for="item in expressList"
  47. :title="item.context"
  48. :desc="item.ftime"
  49. >
  50. </up-steps-item>
  51. </up-steps>
  52. </view>
  53. </view>
  54. <recommend
  55. :hostProduct="hostProduct"
  56. v-if="hostProduct.length"
  57. ></recommend>
  58. </view>
  59. </view>
  60. </template>
  61. <script setup>
  62. import { ref, reactive, watch } from "vue";
  63. import { useAppStore } from "@/stores/app.js";
  64. import { onLoad, onReachBottom, onShow } from "@dcloudio/uni-app";
  65. import { getProductHot } from "@/api/store.js";
  66. import { getOrderDetail, getExpressList, getExpressInfo } from "@/api/order.js";
  67. import { useToast } from "@/hooks/useToast";
  68. // import ClipboardJS from "@/plugin/clipboard/clipboard.js"
  69. import { toLogin } from "@/libs/login.js";
  70. import recommend from "@/components/recommend";
  71. const appStore = useAppStore();
  72. const { Toast } = useToast();
  73. const product = ref({ productInfo: {} });
  74. const orderInfo = ref({});
  75. const expressList = ref([]);
  76. const hostProduct = ref([]);
  77. const loading = ref(false);
  78. const expressLoading = ref(false);
  79. const goodScroll = ref(true);
  80. const orderId = ref("");
  81. const params = reactive({
  82. page: 1,
  83. limit: 10,
  84. });
  85. const expressNum = ref("");
  86. const expressCom = ref("");
  87. // 监听登录状态
  88. watch(
  89. () => appStore.isLogin,
  90. (newV) => {
  91. if (newV) {
  92. fetchExpressInfo();
  93. getHostProduct();
  94. }
  95. }
  96. );
  97. onShow(() => {
  98. // 页面显示时获取订单信息
  99. if (appStore.isLogin) {
  100. fetchExpressInfo();
  101. // getOrderInfo()
  102. } else {
  103. toLogin();
  104. }
  105. });
  106. async function fetchExpressInfo() {
  107. try {
  108. expressLoading.value = true;
  109. // 获取订单详情
  110. const res = await getOrderDetail(orderId.value);
  111. orderInfo.value = res.data;
  112. product.value = res.data.orderInfoList[0] || {};
  113. // 根据物流公司名称获取快递公司code编码
  114. const expressCode = await getExpressList({
  115. keywords: orderInfo.value.deliveryName,
  116. });
  117. if (expressCode.data.list?.[0].code) {
  118. expressCom.value = expressCode.data.list[0].code;
  119. const params = {
  120. com: expressCom.value,
  121. num: orderInfo.value.deliveryId,
  122. };
  123. // 获取物流信息
  124. const expressData = await getExpressInfo(params);
  125. const fmtExpressData = JSON.parse(expressData.data) || {};
  126. if (fmtExpressData.status === "200") {
  127. expressList.value = fmtExpressData.data;
  128. } else {
  129. expressList.value = [];
  130. Toast({ title: fmtExpressData.message || "获取物流信息失败" });
  131. }
  132. expressLoading.value = false;
  133. console.log("expressData", JSON.parse(expressData.data));
  134. }
  135. } catch (error) {
  136. expressLoading.value = false;
  137. console.error("Error fetching express info:", error);
  138. Toast({ title: "获取物流信息失败" });
  139. }
  140. // const params = {
  141. // com: 'yuantong',
  142. // num: 'YT7543172596536',
  143. // }
  144. // const express = express(params)
  145. }
  146. // function getOrderInfo() {
  147. // getOrderDetail(orderId.value).then(res => {
  148. // console.log('res', res.data)
  149. // product.value = res.data.order.info[0] || {}
  150. // orderInfo.value = res.data.order
  151. // expressList.value = res.data.express.list || []
  152. // })
  153. // }
  154. // 精品推荐
  155. function getHostProduct() {
  156. loading.value = true;
  157. if (!goodScroll.value) return;
  158. getProductHot(params.page, params.limit).then((res) => {
  159. loading.value = false;
  160. goodScroll.value = res.data.list.length >= params.limit;
  161. params.page++;
  162. hostProduct.value = hostProduct.value.concat(res.data.list);
  163. });
  164. }
  165. // 复制单号
  166. function copyOrderId() {
  167. uni.setClipboardData({ data: orderInfo.value.deliveryId });
  168. }
  169. // 授权回调
  170. function onLoadFun() {
  171. fetchExpressInfo();
  172. getHostProduct();
  173. }
  174. // 页面加载
  175. onLoad((options) => {
  176. console.log({ options });
  177. if (!options.orderId) return Toast({ title: "缺少订单号" });
  178. orderId.value = options.orderId;
  179. if (appStore.isLogin) {
  180. getHostProduct();
  181. fetchExpressInfo();
  182. } else {
  183. toLogin();
  184. }
  185. });
  186. // reach bottom
  187. onReachBottom(() => {
  188. if (params.page !== 1) {
  189. getHostProduct();
  190. }
  191. });
  192. const setOrderId = () => {
  193. uni.setClipboardData({
  194. data: orderInfo.value.deliveryId,
  195. success: function () {
  196. Toast({ title: "复制成功" });
  197. },
  198. });
  199. };
  200. </script>
  201. <style scoped lang="scss">
  202. .logistics .header {
  203. padding: 23rpx 30rpx;
  204. background-color: #fff;
  205. height: 166rpx;
  206. box-sizing: border-box;
  207. }
  208. .logistics .header .pictrue {
  209. width: 120rpx;
  210. height: 120rpx;
  211. }
  212. .logistics .header .pictrue image {
  213. width: 100%;
  214. height: 100%;
  215. border-radius: 6rpx;
  216. }
  217. .logistics .header .text {
  218. width: 540rpx;
  219. font-size: 28rpx;
  220. color: #999;
  221. margin-top: 6rpx;
  222. }
  223. .logistics .header .text .name {
  224. width: 365rpx;
  225. color: #282828;
  226. }
  227. .logistics .header .text .money {
  228. text-align: right;
  229. }
  230. .logistics .logisticsCon {
  231. background-color: #fff;
  232. margin: 12rpx 0;
  233. }
  234. .logistics .logisticsCon .company {
  235. height: 120rpx;
  236. margin: 0 0 45rpx 30rpx;
  237. padding-right: 30rpx;
  238. border-bottom: 1rpx solid #f5f5f5;
  239. }
  240. .logistics .logisticsCon .company .picTxt {
  241. width: 520rpx;
  242. }
  243. .logistics .logisticsCon .company .picTxt .iconfont {
  244. width: 50rpx;
  245. height: 50rpx;
  246. background-color: #666;
  247. text-align: center;
  248. line-height: 50rpx;
  249. color: #fff;
  250. font-size: 35rpx;
  251. }
  252. .logistics .logisticsCon .company .picTxt .text {
  253. width: 450rpx;
  254. font-size: 26rpx;
  255. color: #282828;
  256. }
  257. .logistics .logisticsCon .company .picTxt .text .name {
  258. color: #999;
  259. }
  260. .logistics .logisticsCon .company .picTxt .text .express {
  261. margin-top: 5rpx;
  262. }
  263. .logistics .logisticsCon .company .copy {
  264. font-size: 20rpx;
  265. width: 106rpx;
  266. height: 40rpx;
  267. text-align: center;
  268. line-height: 40rpx;
  269. border-radius: 20rpx;
  270. border: 1rpx solid #999;
  271. }
  272. .logistics .logisticsCon .express-status {
  273. padding: 0 30rpx 20rpx;
  274. margin-bottom: 30rpx;
  275. }
  276. .logistics .logisticsCon .item {
  277. padding: 0 40rpx;
  278. position: relative;
  279. }
  280. .logistics .logisticsCon .item .circular {
  281. width: 20rpx;
  282. height: 20rpx;
  283. border-radius: 50%;
  284. position: absolute;
  285. top: -1rpx;
  286. left: 31.5rpx;
  287. background-color: #ddd;
  288. }
  289. .logistics .logisticsCon .item .circular.on {
  290. background-color: $theme-color;
  291. }
  292. .logistics .logisticsCon .item .text.on-font {
  293. color: $theme-color;
  294. }
  295. .logistics .logisticsCon .item .text .data.on-font {
  296. color: $theme-color;
  297. }
  298. .logistics .logisticsCon .item .text {
  299. font-size: 26rpx;
  300. color: #666;
  301. width: 615rpx;
  302. border-left: 1rpx solid #e6e6e6;
  303. padding: 0 0 60rpx 38rpx;
  304. }
  305. .logistics .logisticsCon .item .text.on {
  306. border-left-color: #f8c1bd;
  307. }
  308. .logistics .logisticsCon .item .text .data {
  309. font-size: 24rpx;
  310. color: #999;
  311. margin-top: 10rpx;
  312. }
  313. .logistics .logisticsCon .item .text .data .time {
  314. margin-left: 15rpx;
  315. }
  316. </style>