index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <template>
  2. <view class="order-detail" :class="{ 'fixed-bottom-2': type == 2 }" @click="playGlobalSound">
  3. <scroll-view class="scroller" :scroll-into-view="toView" scroll-y="true" scroll-with-animation="true">
  4. <view class="flex flex-a-c flex-j-b bg-white bind-audit mb-16">
  5. <text>绑定审核员</text>
  6. <text class="text-center flex-1">{{
  7. orderDetail.auditUserName || selectedAuditor?.userName || ""
  8. }}</text>
  9. <text @click="showAuditorSelector = true" class="color-primary">绑定</text>
  10. </view>
  11. <OrderInfo :detail="orderDetail" @refresh="() => getOrderDetail(true)" />
  12. <UserInfoCard :detail="orderDetail" />
  13. <view class="mt-16" style="padding: 0 6rpx">
  14. <u-subsection :list="list" mode="subsection" :current="current"
  15. @change="handleSectionChange"></u-subsection>
  16. <BookInfo v-if="current == 0" :bookList="orderDetail.detailVoList" :detail="orderDetail"
  17. @get-all-firstLetter="onGetAllFirstLetter" />
  18. <LogisticsTimeline v-if="current == 1" :list="orderDetail.trackingVoList" />
  19. <FileInfo v-if="current == 2" :orderId="orderDetail.orderId" />
  20. </view>
  21. </scroll-view>
  22. <view class="fixed-left">
  23. <view class="bind-code common-bg" style="margin-bottom: 30px; padding: 20rpx" @click="handleBindCode">绑码
  24. </view>
  25. <view class="common-bg flex flex-a-c flex-j-c flex-d">
  26. <view class="book-status-item" @click="scrollToView('good')">良好</view>
  27. <view class="book-status-item item-center" @click="scrollToView('average')">一般</view>
  28. <view class="book-status-item" @click="scrollToView('poor')">极差</view>
  29. </view>
  30. </view>
  31. <view class="fixed-right">
  32. <view class="letter-bg flex flex-a-c flex-j-c flex-d">
  33. <view class="letter-item"><u-icon name="arrow-up-fill" size="20" color="#ffffff"
  34. @click="scrollToTop"></u-icon></view>
  35. <view class="letter-item" v-for="(item, index) in allLetters" :key="index" @click="scrollToView(item)">
  36. {{ item }}</view>
  37. </view>
  38. </view>
  39. <view class="common-bg fixed-bottom" v-if="type != 2">
  40. <u-button type="warning" size="large" v-if="orderDetail.status == 5"
  41. @click="handleLogisticsConfirm">物流签收</u-button>
  42. <u-button type="primary" size="large" v-if="orderDetail.status == 6" @click="handleConfirm">确认收货</u-button>
  43. <template v-if="orderDetail.status == 8 || orderDetail.status == 9 || orderDetail.status == 10">
  44. <u-button type="warning" size="large" @click="handleScanCode">扫码</u-button>
  45. <u-button type="primary" size="large" @click="handleComplete">完成</u-button>
  46. </template>
  47. </view>
  48. <AuditorSelector :show="showAuditorSelector" @update:show="showAuditorSelector = $event"
  49. @auditor-selected="handleAuditorSelected" />
  50. </view>
  51. </template>
  52. <script setup>
  53. import { ref, onUnmounted } from "vue";
  54. import { onLoad, onShow } from "@dcloudio/uni-app";
  55. import AuditorSelector from "./components/AuditorSelector.vue";
  56. import OrderInfo from "./components/OrderInfo.vue";
  57. import UserInfoCard from "./components/UserInfoCard.vue";
  58. import LogisticsTimeline from "../express/components/LogisticsTimeline.vue";
  59. import BookInfo from "./components/BookInfo.vue";
  60. import FileInfo from "./components/FileInfo.vue";
  61. const showAuditorSelector = ref(false);
  62. const selectedAuditor = ref({});
  63. const handleAuditorSelected = (auditor) => {
  64. selectedAuditor.value = auditor;
  65. orderDetail.value.auditUserId = auditor.userId;
  66. orderDetail.value.auditUserName = auditor.userName;
  67. uni.setStorageSync("checkUserInfo", {
  68. userName: auditor.userName,
  69. userId: auditor.userId,
  70. });
  71. };
  72. //点击全局音效
  73. function playGlobalSound() {
  74. uni.$u.playClickSound();
  75. }
  76. //点击滚动的位置
  77. const toView = ref("");
  78. function scrollToView(to) {
  79. toView.value = to;
  80. uni.pageScrollTo({
  81. selector: "#" + to,
  82. duration: 200,
  83. });
  84. }
  85. //回到顶部
  86. function scrollToTop() {
  87. uni.pageScrollTo({
  88. top: 0,
  89. duration: 200,
  90. });
  91. }
  92. //绑码
  93. function handleBindCode() {
  94. uni.$u.toast("暂无开发");
  95. }
  96. const list = ref(["图书清单", "物流信息", "上传附件"]);
  97. const current = ref(0);
  98. const handleSectionChange = (index) => {
  99. current.value = index;
  100. };
  101. //监听书籍的首字母
  102. const allLetters = ref([]);
  103. function onGetAllFirstLetter(data) {
  104. allLetters.value = data;
  105. }
  106. //物流签收 /app/orderinfo/signLogistics
  107. function handleLogisticsConfirm() {
  108. uni.showModal({
  109. title: "提示",
  110. content: "是否确认物流签收?",
  111. success: (res) => {
  112. if (res.confirm) {
  113. uni.showLoading({ title: "加载中...", mask: true });
  114. uni.$u.http
  115. .post("/app/orderinfo/signLogistics", {
  116. searchType: 1,
  117. search: orderDetail.value.orderId,
  118. })
  119. .then((res) => {
  120. if (res.code == 200) {
  121. uni.showToast({ title: "签收成功", icon: "none" });
  122. uni.$u.ttsModule.speak("签收成功");
  123. uni.navigateBack();
  124. }
  125. })
  126. .finally(() => {
  127. uni.hideLoading();
  128. });
  129. }
  130. },
  131. });
  132. }
  133. //确认收货 /app/orderinfo/confirmOrder
  134. function handleConfirm() {
  135. uni.showLoading({ title: "加载中...", mask: true });
  136. uni.$u.http
  137. .post("/app/orderinfo/confirmOrder", {
  138. searchType: 1,
  139. search: orderDetail.value.orderId,
  140. })
  141. .then((res) => {
  142. if (res.code == 200) {
  143. uni.showToast({ title: "确认收货成功", icon: "none" });
  144. uni.$u.ttsModule.speak("确认收货成功");
  145. getOrderDetail(true); // 强制刷新数据
  146. }
  147. })
  148. .finally(() => {
  149. uni.hideLoading();
  150. });
  151. }
  152. //完成
  153. function handleComplete() {
  154. let bookList = orderDetail.value.detailVoList;
  155. let bool = bookList.some((item) => item.auditCommentList?.length < item.num);
  156. if (bool) {
  157. let text = "还有未审核的书";
  158. uni.$u.toast(text);
  159. uni.$u.ttsModule.speak(text);
  160. return;
  161. } else {
  162. uni.$u.http
  163. .post("/app/orderinfo/checkOrderFinish", {
  164. checkUserId: orderDetail.value.auditUserId,
  165. orderId: orderDetail.value.orderId,
  166. })
  167. .then((res) => {
  168. if (res.code == 200) {
  169. uni.showToast({ title: "审核完成", icon: "none" });
  170. uni.$u.ttsModule.speak("审核完成");
  171. uni.navigateBack();
  172. }
  173. });
  174. }
  175. }
  176. const orderDetail = ref({ status: 0 });
  177. //获取订单详情
  178. function getOrderDetail(forceRefresh = false) {
  179. if (!orderId.value) return;
  180. // 如果是强制刷新,重置标志位
  181. if (forceRefresh) {
  182. hasLoadedOrderDetail.value = false;
  183. hasLoadedCheckUser.value = false;
  184. }
  185. uni.showLoading({
  186. title: "加载中...",
  187. mask: true,
  188. });
  189. uni.$u.http
  190. .get("/app/orderinfo/getOrderInfoForCheck", {
  191. params: {
  192. searchType: 1,
  193. search: orderId.value,
  194. },
  195. })
  196. .then((res) => {
  197. if (res.code == 200) {
  198. orderDetail.value = res.data;
  199. // 只有在首次加载且没有审核员信息时才调用getCheckUserInfo
  200. if (!hasLoadedCheckUser.value && !res.data.auditUserId) {
  201. getCheckUserInfo();
  202. }
  203. if (res.data.auditUserId) {
  204. let auditUserInfo = {
  205. userName: res.data.auditUserName,
  206. userId: res.data.auditUserId,
  207. };
  208. uni.setStorageSync("checkUserInfo", auditUserInfo);
  209. } else {
  210. let userInfo = uni.getStorageSync("checkUserInfo");
  211. if (userInfo && userInfo.userName) {
  212. orderDetail.value.auditUserName = userInfo.userName;
  213. orderDetail.value.auditUserId = userInfo.userId;
  214. }
  215. }
  216. if (isOnLoad.value) {
  217. if (res.data.manageRemark.length > 0 && res.data.status < 10) {
  218. uni.$u.ttsModule.speak("此订单有备注信息,请注意查看");
  219. }
  220. if (res.data.warnArea && res.data.warnArea.length > 0) {
  221. let text = `此订单来源于${res.data.warnArea}`;
  222. uni.$u.ttsModule.speak(text);
  223. }
  224. isOnLoad.value = false;
  225. }
  226. hasLoadedOrderDetail.value = true; // 标记订单详情已加载
  227. } else {
  228. uni.$u.toast(res.msg);
  229. }
  230. })
  231. .finally(() => {
  232. uni.hideLoading();
  233. });
  234. }
  235. //获取上一次绑定的审核员信息
  236. function getCheckUserInfo() {
  237. uni.$u.http.get("/app/orderinfo/getCheckUser").then((res) => {
  238. if (res.code == 200) {
  239. let userInfo = res.data || {};
  240. orderDetail.value.auditUserName = userInfo.userName || '';
  241. orderDetail.value.auditUserId = userInfo.userId || '';
  242. uni.setStorageSync("checkUserInfo", {
  243. userName: userInfo.userName,
  244. userId: userInfo.userId,
  245. });
  246. }
  247. hasLoadedCheckUser.value = true; // 标记审核员信息已加载
  248. });
  249. }
  250. //isbn正则校验是否符合
  251. function checkIsbn(isbn) {
  252. const isbn13Regex = /^(?:97[89]-?\d{1,5}-?\d{1,7}-?\d{1,6}-?\d)$/;
  253. if (isbn13Regex.test(isbn)) {
  254. return true;
  255. }
  256. return false;
  257. }
  258. //扫码之后的逻辑
  259. function handleScan(isbn) {
  260. if (!checkIsbn(isbn)) {
  261. let text = `不是正确的ISBN码`;
  262. uni.$u.ttsModule.speak(text);
  263. return;
  264. }
  265. if (orderDetail.value.status >= 10) {
  266. uni.$u.ttsModule.speak("订单已审核完成");
  267. return;
  268. }
  269. //取 isbn 的后四位字符串进行播报
  270. let isbnStr = `${isbn.slice(-4)}`;
  271. let isbnList = orderDetail.value.detailVoList.map((item) => item.isbn);
  272. if (isbnList.includes(isbn)) {
  273. let book = orderDetail.value.detailVoList.find((item) => item.isbn == isbn);
  274. //扫描到套装书
  275. if (book.suit == 1) {
  276. let text = `${isbnStr}请注意套装书是否齐全`;
  277. uni.$u.ttsModule.speak(text);
  278. }
  279. //扫描到需要取出的书
  280. if (book.bookWarn == 1) {
  281. let text = `请注意${isbnStr}需要取出`;
  282. uni.$u.ttsModule.speak(text);
  283. }
  284. uni.navigateTo({
  285. url: `/pages/index/detail/book-audit?isbn=${isbn}&orderId=${orderDetail.value.orderId}`,
  286. });
  287. uni.setStorageSync("auditBook", book);
  288. uni.setStorageSync("orderDetail", orderDetail.value);
  289. } else {
  290. let text = `此订单中不存在${isbnStr}这本书 `;
  291. uni.$u.ttsModule.speak(text);
  292. }
  293. }
  294. //扫码
  295. function handleScanCode() {
  296. uni.scanCode({
  297. success: (res) => {
  298. res.result && handleScan(res.result);
  299. },
  300. });
  301. }
  302. const orderId = ref("");
  303. const isOnLoad = ref(false);
  304. const hasLoadedOrderDetail = ref(false); // 添加标志位控制订单详情是否已加载
  305. const hasLoadedCheckUser = ref(false); // 添加标志位控制审核员信息是否已加载
  306. // 1 表示到货审核 2 表示查看订单
  307. const type = ref(1);
  308. onLoad((options) => {
  309. isOnLoad.value = true;
  310. orderId.value = options.id;
  311. orderDetail.value = uni.getStorageSync("orderDetail") || {};
  312. type.value = options.type || 1;
  313. uni.removeStorageSync("scannedBooks");
  314. });
  315. const { unregister, register } = uni.$u.useEventListener((e) => {
  316. handleScan(e.barcode);
  317. }, true);
  318. onShow(() => {
  319. register();
  320. // 只有在首次加载时才调用getOrderDetail,避免重复请求
  321. getOrderDetail();
  322. });
  323. onUnmounted(() => {
  324. // #ifdef APP-PLUS
  325. if (typeof unregister === 'function') {
  326. unregister();
  327. }
  328. // #endif
  329. });
  330. </script>
  331. <style>
  332. page {
  333. background-color: #f5f5f5;
  334. }
  335. </style>
  336. <style lang="scss" scoped>
  337. .order-detail {
  338. font-size: 30rpx;
  339. padding-bottom: 140rpx;
  340. position: relative;
  341. &.fixed-bottom-2 {
  342. padding-bottom: 30rpx;
  343. }
  344. .bind-audit {
  345. padding: 20rpx 30rpx;
  346. border-bottom: 1px solid #e5e5e5;
  347. }
  348. .fixed-left {
  349. position: fixed;
  350. left: 0;
  351. top: 11%;
  352. width: 100rpx;
  353. .common-bg {
  354. background-color: rgba(34, 172, 56, 0.7);
  355. border-radius: 0 30rpx 30rpx 0;
  356. font-weight: 500;
  357. color: #ffffff;
  358. }
  359. .book-status-item {
  360. padding: 20rpx;
  361. border-top: 1rpx solid #ffffff;
  362. border-bottom: 1rpx solid #ffffff;
  363. }
  364. }
  365. .fixed-right {
  366. position: fixed;
  367. right: 0;
  368. top: 12%;
  369. width: 70rpx;
  370. .letter-bg {
  371. background-color: rgba(34, 172, 56, 0.7);
  372. border-radius: 10rpx 0 0 10rpx;
  373. font-weight: 500;
  374. color: #ffffff;
  375. padding: 12rpx 0;
  376. padding-bottom: 6rpx;
  377. }
  378. .letter-item {
  379. padding-bottom: 12rpx;
  380. }
  381. }
  382. }
  383. </style>