index.vue 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666
  1. <template>
  2. <Water></Water>
  3. <view class="detail-page" :style="{ minHeight: pageHeight }" v-if="!!data && !loading">
  4. <view id="detailPageTopAnchor"></view>
  5. <view class="detail-card detail-bg" :style="{ backgroundImage: 'url(' + bg + ')' }">
  6. <view class="detail-drug-title">{{ data.physicName }}</view>
  7. <view class="detail-row detail-traceability">
  8. <view class="detail-label">追溯码:</view>
  9. <view class="detail-value detail-wrap">{{ formatTraceCode(traceCode) }}</view>
  10. <view class="detail-copy-btn" @click="copy(traceCode)">
  11. <image src="../../../static/images/copy.png" mode="scaleToFill" :style="{ width: '30rpx', height: '30rpx' }" />
  12. </view>
  13. </view>
  14. <view class="detail-row">
  15. <view class="detail-label">生产企业:</view>
  16. <view
  17. class="detail-value detail-wrap detail-company-value"
  18. :class="{ 'detail-clamp': !companyExpanded }"
  19. :style="{ marginBottom: needCompanyToggle ? '40rpx' : undefined }"
  20. id="companyValue">
  21. <text>{{ data.produceEntName }}</text>
  22. </view>
  23. <text v-if="needCompanyToggle" class="detail-expand-tag" @click="toggleCompanyExpand">{{ companyExpanded ? "收起" : "展开" }}</text>
  24. </view>
  25. <view class="detail-row">
  26. <view class="detail-label">批准文号:</view>
  27. <view class="detail-value">{{ data.approveNo }}</view>
  28. </view>
  29. <view class="detail-row">
  30. <view class="detail-label">生产日期:</view>
  31. <view class="detail-value">{{ data.produceDate }}</view>
  32. </view>
  33. <view class="detail-row" v-show="cardExpanded">
  34. <view class="detail-label">产品批号:</view>
  35. <view class="detail-value">{{ data.produceBatchNo }}</view>
  36. </view>
  37. <view class="detail-row" v-show="cardExpanded">
  38. <view class="detail-label"> 剂<text :style="{ opacity: 0 }">剂型</text>型:</view>
  39. <view class="detail-value">{{ data.prepnDesc }}</view>
  40. </view>
  41. <view class="detail-row" v-show="cardExpanded">
  42. <view class="detail-label">包装规格:</view>
  43. <view class="detail-value">{{ data.prepnSpec }}</view>
  44. </view>
  45. <view class="detail-row" v-show="cardExpanded">
  46. <view class="detail-label">有效期至:</view>
  47. <view class="detail-value">{{ data.validEndDate }}</view>
  48. </view>
  49. <view class="detail-card-toggle" @click="toggleCardExpand">
  50. <uni-icons :type="cardExpanded ? 'up' : 'down'" size="18" color="#9aa4b2"></uni-icons>
  51. </view>
  52. </view>
  53. <view class="detail-timeline detail-bg" :style="{ backgroundImage: 'url(' + bg + ')' }">
  54. <view class="detail-section-header">
  55. <view class="detail-section-title">扫码跟踪</view>
  56. <view class="detail-section-actions">
  57. <view class="detail-section-action" @tap="toggleTimelineView">
  58. <uni-icons :type="timelineView === 'text' ? 'image' : 'list'" size="20" color="#59a8f2"></uni-icons>
  59. <text>{{ timelineView === "text" ? "查看图形" : "查看文字" }}</text>
  60. </view>
  61. <view class="detail-section-action" @tap="onSetDefaultView">
  62. <uni-icons type="gear" size="20" color="#59a8f2"></uni-icons>
  63. <text>设置默认</text>
  64. </view>
  65. </view>
  66. </view>
  67. <view class="detail-graph-panel" v-if="timelineView === 'graph'">
  68. <view class="graph-mode-row">
  69. <view class="graph-mode-left">
  70. <view class="graph-mode-title">货权流向模式</view>
  71. <view class="graph-mode-desc">开启后则会按照码的实际实物货权关系,将委托企业(若有)还原到收发货企业上并绘制流向图。</view>
  72. </view>
  73. <switch :checked="ownershipFlowMode" color="#2c69ff" @change="onOwnershipModeChange" />
  74. </view>
  75. <view
  76. :style="{
  77. width: graphViewWidth + 'px',
  78. height: graphViewHeight + 'px',
  79. }"
  80. v-if="isShowGraph">
  81. <l-echart ref="chartRef" :beforeDelay="180" :lStyle="`width:${graphViewWidth}px;height:${graphViewHeight}px;`" @finished="initChart"></l-echart>
  82. </view>
  83. <view
  84. :style="{
  85. width: graphViewWidth + 'px',
  86. height: graphViewHeight + 'px',
  87. display: 'flex',
  88. alignItems: 'center',
  89. justifyContent: 'center',
  90. }"
  91. v-else>
  92. 链路过长无法展示
  93. </view>
  94. </view>
  95. <view class="detail-timeline-toolbar" v-if="timelineView === 'text'">
  96. <view class="detail-toolbar-btn" @tap.stop="setAllTimelineDetail(!allTimelineDetail)">{{ !allTimelineDetail ? "全部展示详情" : "全部展示概要" }}</view>
  97. <!-- <view class="detail-toolbar-btn" @tap.stop="setAllTimelineDetail(false)">全部展示概要</view> -->
  98. </view>
  99. <view
  100. v-if="timelineView === 'text'"
  101. class="detail-timeline-item"
  102. :class="{ 'detail-timeline-item-first': i === 0 }"
  103. v-for="(value, i) in visibleBillDetailList"
  104. :key="i">
  105. <view class="detail-left">
  106. <view class="detail-dot" :class="{ 'detail-fill': false }"></view>
  107. <view class="detail-line" v-if="i < visibleBillDetailList.length - 1 || hasMoreTimelineItems"></view>
  108. </view>
  109. <view class="detail-right">
  110. <view class="detail-title-row">
  111. <view class="detail-title" :class="{ 'detail-bold': true }"> {{ value.billTypeName || "--" }} {{ value.billCode || "" }} </view>
  112. <view class="detail-item-toggle" @tap.stop="toggleTimelineItem(i)">
  113. {{ value._showDetail ? "概要" : "详情" }}
  114. <uni-icons :type="value._showDetail ? 'up' : 'down'" size="14" color="#888"></uni-icons>
  115. </view>
  116. </view>
  117. <view class="detail-info-row">
  118. <text class="detail-info-label">发货企业:</text>
  119. <text class="detail-info-value">{{ value.fromEntName || "--" }}</text>
  120. </view>
  121. <view class="detail-tag-row" v-if="value._showDetail && value.fromEntType !== '1'">
  122. <text class="detail-tag" v-if="value.fromCustomerNature">{{ value.fromCustomerNature }}</text>
  123. <text class="detail-tag" v-if="value.fromCustomerLevel">{{ value.fromCustomerLevel }}</text>
  124. <text class="detail-tag" v-if="value.fromResponsibleManager">{{ value.fromResponsibleManager }}</text>
  125. </view>
  126. <view class="detail-tag-row" v-if="value._showDetail">
  127. <text class="detail-tag" :style="getTagColorStyle(value.fromEntTypeName)" v-if="value.fromEntTypeName">{{ value.fromEntTypeName }}</text>
  128. <text class="detail-tag detail-tag-region" v-if="getRegionByPrefix(value, 'from')">{{ getRegionByPrefix(value, "from") }}</text>
  129. </view>
  130. <view class="detail-info-row">
  131. <text class="detail-info-label">收货企业:</text>
  132. <text class="detail-info-value">{{ value.toEntName || "--" }}</text>
  133. </view>
  134. <view class="detail-tag-row" v-if="value._showDetail && value.toEntType !== '1'">
  135. <text class="detail-tag" v-if="value.toCustomerNature">{{ value.toCustomerNature }}</text>
  136. <text class="detail-tag" v-if="value.toCustomerLevel">{{ value.toCustomerLevel }}</text>
  137. <text class="detail-tag" v-if="value.toResponsibleManager">{{ value.toResponsibleManager }}</text>
  138. </view>
  139. <view class="detail-tag-row" v-if="value._showDetail">
  140. <text class="detail-tag" :style="getTagColorStyle(value.toEntTypeName)" v-if="value.toEntTypeName">{{ value.toEntTypeName }}</text>
  141. <text class="detail-tag detail-tag-region" v-if="getRegionByPrefix(value, 'to')">{{ getRegionByPrefix(value, "to") }}</text>
  142. </view>
  143. <view class="detail-info-row">
  144. <text class="detail-info-label">入出库时间:</text>
  145. <text class="detail-info-value">{{ value.billTime || "--" }}</text>
  146. </view>
  147. <view class="detail-info-row" v-if="value._showDetail && value.uploadEntName">
  148. <text class="detail-info-label">上传企业:</text>
  149. <text class="detail-info-value">{{ value.uploadEntName }}</text>
  150. </view>
  151. <view class="detail-tag-row" v-if="value._showDetail && value.uploadEntName && value.uploadEntType !== '1'">
  152. <text class="detail-tag" v-if="value.uploadCustomerNature">{{ value.uploadCustomerNature }}</text>
  153. <text class="detail-tag" v-if="value.uploadCustomerLevel">{{ value.uploadCustomerLevel }}</text>
  154. <text class="detail-tag" v-if="value.uploadResponsibleManager">{{ value.uploadResponsibleManager }}</text>
  155. </view>
  156. <view class="detail-tag-row" v-if="value._showDetail && value.uploadEntName">
  157. <text class="detail-tag" :style="getTagColorStyle(value.uploadEntTypeName)" v-if="value.uploadEntTypeName">{{ value.uploadEntTypeName }}</text>
  158. <text class="detail-tag detail-tag-region" v-if="getRegionByPrefix(value, 'upload')">{{ getRegionByPrefix(value, "upload") }}</text>
  159. </view>
  160. <view class="detail-info-row" v-if="value._showDetail && value.uploadEntName">
  161. <text class="detail-info-label">上传时间:</text>
  162. <text class="detail-info-value">{{ value.uploadTime || "--" }}</text>
  163. </view>
  164. <view class="detail-info-row" v-if="value._showDetail && value.disEntName">
  165. <text class="detail-info-label">配送企业:</text>
  166. <text class="detail-info-value">{{ value.disEntName }}</text>
  167. </view>
  168. <view class="detail-tag-row" v-if="value._showDetail && value.disEntName && !value.disEntName.includes(',') && value.disEntType !== '1'">
  169. <text class="detail-tag" v-if="value.disCustomerNature">{{ value.disCustomerNature }}</text>
  170. <text class="detail-tag" v-if="value.disCustomerLevel">{{ value.disCustomerLevel }}</text>
  171. <text class="detail-tag" v-if="value.disResponsibleManager">{{ value.disResponsibleManager }}</text>
  172. </view>
  173. <view class="detail-tag-row" v-if="value._showDetail && value.disEntName && !value.disEntName.includes(',')">
  174. <text class="detail-tag" :style="getTagColorStyle(value.disEntTypeName)" v-if="value.disEntTypeName">{{ value.disEntTypeName }}</text>
  175. <text class="detail-tag detail-tag-region" v-if="getRegionByPrefix(value, 'dis')">{{ getRegionByPrefix(value, "dis") }}</text>
  176. </view>
  177. <view class="detail-info-row" v-if="value._showDetail && value.assEntName">
  178. <text class="detail-info-label">委托企业:</text>
  179. <text class="detail-info-value">{{ value.assEntName }}</text>
  180. </view>
  181. <view class="detail-tag-row" v-if="value._showDetail && value.assEntName && value.assEntType !== '1'">
  182. <text class="detail-tag" v-if="value.assCustomerNature">{{ value.assCustomerNature }}</text>
  183. <text class="detail-tag" v-if="value.assCustomerLevel">{{ value.assCustomerLevel }}</text>
  184. <text class="detail-tag" v-if="value.assResponsibleManager">{{ value.assResponsibleManager }}</text>
  185. </view>
  186. <view class="detail-tag-row" v-if="value._showDetail && value.assEntName">
  187. <text class="detail-tag" :style="getTagColorStyle(value.assEntTypeName)" v-if="value.assEntTypeName">{{ value.assEntTypeName }}</text>
  188. <text class="detail-tag detail-tag-region" v-if="getRegionByPrefix(value, 'ass')">{{ getRegionByPrefix(value, "ass") }}</text>
  189. </view>
  190. </view>
  191. </view>
  192. <view v-if="timelineView === 'text' && hasMoreTimelineItems" class="detail-timeline-loadmore">
  193. 上拉加载更多({{ visibleBillDetailList.length }}/{{ timelineTotalCount }})
  194. </view>
  195. </view>
  196. </view>
  197. <transition name="back-top-fade">
  198. <view v-if="!!data && !loading && showBackTopButton" class="detail-back-top-btn" @tap="backToTop">
  199. <view class="detail-back-top-arrow"></view>
  200. </view>
  201. </transition>
  202. <view class="detail-page-empty" :style="{ height: pageHeight }" v-if="!data && !loading">
  203. <image src="../../../static/images/empty.png" mode="scaleToFill" :style="{ width: '264rpx', height: '200rpx' }" />
  204. <text
  205. :style="{
  206. fontSize: '24rpx',
  207. color: '#99a1ad',
  208. marginTop: '60rpx',
  209. textAlign: 'center',
  210. }"
  211. >所查询药品所在生产企业尚未纳入扫码范围,后续将进一步扩大,敬请期待</text
  212. >
  213. </view>
  214. <view class="detail-page-empty" :style="{ height: pageHeight }" v-if="loading">
  215. <image src="../../../static/images/loading.png" mode="scaleToFill" :style="{ width: '50rpx', height: '50rpx' }" class="detail-loading" />
  216. </view>
  217. </template>
  218. <script>
  219. import bg from "../../../static/images/bg.png";
  220. import { formatDate } from "../../../utils/utils.js";
  221. import request from "../../../request/index.js";
  222. import Water from "@/components/water/water.vue";
  223. import lEchart from "../../../uni_modules/lime-echart/components/l-echart/l-echart.vue";
  224. import { markRaw } from "vue";
  225. const echarts = require("../../../static/js/echarts.min.js");
  226. export default {
  227. components: {
  228. Water,
  229. lEchart,
  230. },
  231. data() {
  232. return {
  233. data: null,
  234. loading: true,
  235. statusBarHeight: 20,
  236. traceCode: "",
  237. pageHeight: 0,
  238. bg,
  239. companyExpanded: true,
  240. needCompanyToggle: false,
  241. cardExpanded: false,
  242. allTimelineDetail: false,
  243. timelineView: "text",
  244. defaultTimelineViewKey: "traceabilityCodeQuery.detail.timelineDefaultView",
  245. imageData: [],
  246. graphViewWidth: 300,
  247. graphViewHeight: 480,
  248. chartInstance: null,
  249. chartOption: {},
  250. ownershipFlowMode: false,
  251. timelinePageSize: 20,
  252. timelineVisibleCount: 20,
  253. scrollTopValue: 0,
  254. scrollIntoViewId: "",
  255. backTopThreshold: 0,
  256. showBackTopButton: false,
  257. backTopHideTimer: null,
  258. };
  259. },
  260. onLoad(options) {
  261. const info = uni.getSystemInfoSync();
  262. this.statusBarHeight = info.statusBarHeight || 20;
  263. this.pageHeight = (info.windowHeight && info.windowHeight + "px") || "100%";
  264. this.backTopThreshold = info.windowHeight || 667;
  265. this.graphViewWidth = Math.max((info.windowWidth || 375) - 36, 280);
  266. this.graphViewHeight = Math.max((info.windowHeight || 667) - 200, 420);
  267. if (options.traceCode) {
  268. this.traceCode = options.traceCode;
  269. }
  270. const defaultView = uni.getStorageSync(this.defaultTimelineViewKey);
  271. if (defaultView === "graph" || defaultView === "text") {
  272. this.timelineView = defaultView;
  273. }
  274. // this.getData(options.traceCode);
  275. this.getData2(options.traceCode);
  276. },
  277. onReady() {
  278. this.$nextTick(() => {
  279. const info = uni.getSystemInfoSync();
  280. const lineHeightPx = (info.windowWidth / 750) * 40;
  281. this.companyExpanded = true; // 展开测量高度
  282. uni
  283. .createSelectorQuery()
  284. .in(this)
  285. .select("#companyValue")
  286. .boundingClientRect((rect) => {
  287. if (!rect || !lineHeightPx) return;
  288. const lines = Math.round(rect.height / lineHeightPx);
  289. this.needCompanyToggle = lines > 2;
  290. this.companyExpanded = !this.needCompanyToggle;
  291. })
  292. .exec();
  293. });
  294. },
  295. onReachBottom() {
  296. if (this.timelineView !== "text") return;
  297. this.loadMoreTimelineItems();
  298. },
  299. onPageScroll(e) {
  300. this.handlePageScroll(e);
  301. },
  302. // 页面卸载时销毁图表实例
  303. beforeUnmount() {
  304. if (this.backTopHideTimer) {
  305. clearTimeout(this.backTopHideTimer);
  306. this.backTopHideTimer = null;
  307. }
  308. if (this.$refs.chartRef) {
  309. this.$refs.chartRef.dispose();
  310. }
  311. },
  312. computed: {
  313. isShowGraph() {
  314. return this.data.billDetailList.length < 30;
  315. },
  316. timelineTotalCount() {
  317. if (!this.data || !Array.isArray(this.data.billDetailList)) return 0;
  318. return this.data.billDetailList.length;
  319. },
  320. visibleBillDetailList() {
  321. if (!this.data || !Array.isArray(this.data.billDetailList)) return [];
  322. const maxCount = Math.min(this.timelineVisibleCount, this.timelineTotalCount);
  323. return this.data.billDetailList.slice(0, maxCount);
  324. },
  325. hasMoreTimelineItems() {
  326. return this.visibleBillDetailList.length < this.timelineTotalCount;
  327. },
  328. },
  329. methods: {
  330. getTagColorStyle(tag) {
  331. let color = "#57bfe1";
  332. if (tag.includes("生产")) color = "#f5c269";
  333. if (tag.includes("零售")) color = "#91c76d";
  334. return {
  335. color,
  336. borderColor: color + "80",
  337. };
  338. },
  339. // 判断 imageData 中是否存在一条 source -> target 的有向连接线
  340. hasDirectedEdge(sourceName, targetName, list = this.imageData) {
  341. const sourceNode = (list || []).find((n) => n && n.name === sourceName);
  342. if (!sourceNode || !Array.isArray(sourceNode.to)) return false;
  343. return sourceNode.to.some((t) => t && t.name === targetName);
  344. },
  345. // 1) 当前节点与相邻节点是否被同一节点指向,返回数量与当前位置(1-based)
  346. getInboundAdjacentGroupInfo(currentIndex, list = this.imageData) {
  347. const nodes = Array.isArray(list) ? list : [];
  348. if (currentIndex < 0 || currentIndex >= nodes.length) return null;
  349. const currentName = nodes[currentIndex]?.name;
  350. if (!currentName) return null;
  351. const sourceNames = nodes
  352. .filter((node) => Array.isArray(node?.to) && node.to.some((toItem) => toItem && toItem.name === currentName))
  353. .map((node) => node.name);
  354. let best = null;
  355. sourceNames.forEach((sourceName) => {
  356. let start = currentIndex;
  357. let end = currentIndex;
  358. while (start - 1 >= 0 && this.hasDirectedEdge(sourceName, nodes[start - 1]?.name, nodes)) {
  359. start--;
  360. }
  361. while (end + 1 < nodes.length && this.hasDirectedEdge(sourceName, nodes[end + 1]?.name, nodes)) {
  362. end++;
  363. }
  364. const count = end - start + 1;
  365. const position = currentIndex - start + 1;
  366. if (!best || count > best.count) {
  367. best = { sourceName, count, position, start, end };
  368. }
  369. });
  370. return (
  371. best || {
  372. sourceName: null,
  373. count: 1,
  374. position: 1,
  375. start: currentIndex,
  376. end: currentIndex,
  377. }
  378. );
  379. },
  380. // 2) 当前节点与相邻节点是否共同指向同一节点,返回数量与当前位置(1-based)
  381. getOutboundAdjacentGroupInfo(currentIndex, list = this.imageData) {
  382. const nodes = Array.isArray(list) ? list : [];
  383. if (currentIndex < 0 || currentIndex >= nodes.length) return null;
  384. const currentNode = nodes[currentIndex] || {};
  385. const targetNames = Array.isArray(currentNode.to) ? currentNode.to.map((t) => t && t.name).filter(Boolean) : [];
  386. let best = null;
  387. targetNames.forEach((targetName) => {
  388. let start = currentIndex;
  389. let end = currentIndex;
  390. while (start - 1 >= 0 && this.hasDirectedEdge(nodes[start - 1]?.name, targetName, nodes)) {
  391. start--;
  392. }
  393. while (end + 1 < nodes.length && this.hasDirectedEdge(nodes[end + 1]?.name, targetName, nodes)) {
  394. end++;
  395. }
  396. const count = end - start + 1;
  397. const position = currentIndex - start + 1;
  398. if (!best || count > best.count) {
  399. best = { targetName, count, position, start, end };
  400. }
  401. });
  402. return (
  403. best || {
  404. targetName: null,
  405. count: 1,
  406. position: 1,
  407. start: currentIndex,
  408. end: currentIndex,
  409. }
  410. );
  411. },
  412. // 3) 当前节点与目标节点之间是否只有一条连接线(双向算多条)
  413. // 3) 判断当前节点与目标节点之间是否只有一条连接线
  414. // 说明:当前节点可能有多条连线指向目标节点(to 中出现多次),目标节点也可能反向指向当前节点,均计入总数
  415. getConnectionLineInfo(currentName, targetName, list = this.imageData) {
  416. const nodes = Array.isArray(list) ? list : [];
  417. const countEdges = (fromName, toName) => {
  418. const fromNode = nodes.find((n) => n && n.name === fromName);
  419. if (!fromNode || !Array.isArray(fromNode.to)) return 0;
  420. return fromNode.to.filter((t) => t && t.name === toName).length;
  421. };
  422. const forward = countEdges(currentName, targetName);
  423. const backward = countEdges(targetName, currentName);
  424. const edgeCount = forward + backward;
  425. return {
  426. edgeCount,
  427. isSingleLine: edgeCount === 1,
  428. forwardCount: forward,
  429. backwardCount: backward,
  430. hasForward: forward > 0,
  431. hasBackward: backward > 0,
  432. };
  433. },
  434. // 4) 当前节点与上一个/下一个节点之间是否存在连接线(任一方向都算)
  435. getAdjacentConnectionInfo(currentIndex, list = this.imageData) {
  436. const nodes = Array.isArray(list) ? list : [];
  437. if (currentIndex < 0 || currentIndex >= nodes.length) return null;
  438. const currentName = nodes[currentIndex]?.name;
  439. const prevName = nodes[currentIndex - 1]?.name || null;
  440. const nextName = nodes[currentIndex + 1]?.name || null;
  441. const hasPrevConnection = prevName ? this.getConnectionLineInfo(currentName, prevName, nodes).edgeCount > 0 : false;
  442. const hasNextConnection = nextName ? this.getConnectionLineInfo(currentName, nextName, nodes).edgeCount > 0 : false;
  443. return { hasPrevConnection, hasNextConnection, prevName, nextName };
  444. },
  445. buildGraphLayout(nodes = []) {
  446. const chartWidth = Number(this.graphViewWidth) || 320;
  447. const nodeSize = 86;
  448. const sidePadding = nodeSize / 2 + 10;
  449. const centerX = chartWidth / 2;
  450. const hGap = Math.max(140, Math.min(210, chartWidth - sidePadding * 2));
  451. const vGap = 150;
  452. const componentGap = 15;
  453. const edgeRecords = [];
  454. const nameIndexMap = {};
  455. nodes.forEach((node, index) => {
  456. if (node && node.name) nameIndexMap[node.name] = index;
  457. });
  458. nodes.forEach((node, sourceIndex) => {
  459. const tos = Array.isArray(node && node.to) ? node.to : [];
  460. tos.forEach((to, targetIndex) => {
  461. const targetNodeIndex = nameIndexMap[to && to.name];
  462. if (!to || !to.name || to.name === node.name || typeof targetNodeIndex !== "number") return;
  463. edgeRecords.push({
  464. sourceIndex,
  465. targetIndex,
  466. targetNodeIndex,
  467. sourceName: node.name,
  468. targetName: to.name,
  469. uniqId: `${sourceIndex}_${targetIndex}`,
  470. });
  471. });
  472. });
  473. const parent = nodes.map((_, index) => index);
  474. const find = (index) => {
  475. if (parent[index] !== index) parent[index] = find(parent[index]);
  476. return parent[index];
  477. };
  478. const union = (a, b) => {
  479. const rootA = find(a);
  480. const rootB = find(b);
  481. if (rootA !== rootB) parent[rootB] = rootA;
  482. };
  483. edgeRecords.forEach((edge) => union(edge.sourceIndex, edge.targetNodeIndex));
  484. const componentMap = {};
  485. nodes.forEach((_, index) => {
  486. const root = find(index);
  487. if (!componentMap[root]) componentMap[root] = [];
  488. componentMap[root].push(index);
  489. });
  490. const components = Object.values(componentMap).sort((a, b) => Math.min(...a) - Math.min(...b));
  491. const positions = new Array(nodes.length);
  492. let baseY = 100;
  493. components.forEach((component) => {
  494. const componentSet = new Set(component);
  495. const layers = {};
  496. component.forEach((index) => {
  497. layers[index] = 0;
  498. });
  499. for (let i = 0; i < component.length; i++) {
  500. let changed = false;
  501. edgeRecords.forEach((edge) => {
  502. if (!componentSet.has(edge.sourceIndex) || !componentSet.has(edge.targetNodeIndex)) return;
  503. const nextLayer = layers[edge.sourceIndex] + 1;
  504. if (nextLayer > layers[edge.targetNodeIndex]) {
  505. layers[edge.targetNodeIndex] = nextLayer;
  506. changed = true;
  507. }
  508. });
  509. if (!changed) break;
  510. }
  511. const grouped = {};
  512. component.forEach((index) => {
  513. const layer = layers[index] || 0;
  514. if (!grouped[layer]) grouped[layer] = [];
  515. grouped[layer].push(index);
  516. });
  517. const layerKeys = Object.keys(grouped)
  518. .map(Number)
  519. .sort((a, b) => a - b);
  520. layerKeys.forEach((layer) => {
  521. const group = grouped[layer].sort((a, b) => a - b);
  522. group.forEach((nodeIndex, positionIndex) => {
  523. positions[nodeIndex] = {
  524. x: centerX + (positionIndex - (group.length - 1) / 2) * hGap,
  525. y: baseY + layer * vGap,
  526. };
  527. });
  528. });
  529. const maxLayer = layerKeys.length ? Math.max(...layerKeys) : 0;
  530. baseY += (maxLayer + 1) * vGap + componentGap;
  531. });
  532. const pairMembers = {};
  533. edgeRecords.forEach((edge) => {
  534. const pairKey = [edge.sourceName, edge.targetName].sort().join("__");
  535. if (!pairMembers[pairKey]) pairMembers[pairKey] = [];
  536. pairMembers[pairKey].push(edge);
  537. });
  538. const curvenessMap = {};
  539. const edgeMetaMap = {};
  540. Object.keys(pairMembers).forEach((pairKey) => {
  541. const list = pairMembers[pairKey];
  542. const step = this.ownershipFlowMode ? (list.length === 2 ? 0.86 : 0.68) : list.length === 2 ? 0.72 : 0.56;
  543. list.forEach((edge, index) => {
  544. curvenessMap[edge.uniqId] = list.length > 1 ? (index - (list.length - 1) / 2) * step : 0;
  545. edgeMetaMap[edge.uniqId] = {
  546. count: list.length,
  547. index,
  548. offset: index - (list.length - 1) / 2,
  549. };
  550. });
  551. });
  552. return { positions, curvenessMap, edgeMetaMap, height: Math.max(520, baseY - componentGap + 70) };
  553. },
  554. // 初始化图表
  555. async initChart() {
  556. if (!this.$refs.chartRef || !this.isShowGraph || this.timelineView !== "graph") return;
  557. if (this._initChartLock) return;
  558. this._initChartLock = true;
  559. try {
  560. await this._doInitChart();
  561. } finally {
  562. this._initChartLock = false;
  563. }
  564. },
  565. async _doInitChart() {
  566. let option = {};
  567. const data = [];
  568. const links = [];
  569. const lineWidth = 2;
  570. const _nodes = this.imageData || [];
  571. const { positions: _positions, curvenessMap: _curvenessMap, edgeMetaMap: _edgeMetaMap } = this.buildGraphLayout(_nodes);
  572. const nameIndexMap = {};
  573. _nodes.forEach((node, nodeIndex) => {
  574. if (node && node.name) nameIndexMap[node.name] = nodeIndex;
  575. });
  576. this.imageData.forEach((item, index) => {
  577. const { name, to } = item;
  578. const toLen = to.length;
  579. const { x, y } = _positions[index] || { x: 350, y: index * 250 + 100 };
  580. const color = name.includes("生产") ? "#fde58f" : name.includes("零售") ? "#b5ea8e" : name.includes("消费者") ? "#e0d3fe" : "#a3e6ff";
  581. data.push({
  582. name,
  583. x,
  584. y,
  585. itemStyle: {
  586. color,
  587. },
  588. });
  589. to.forEach((toItem, toIndex) => {
  590. const { name: toName, text: toText } = toItem;
  591. if (name === toName) {
  592. const loopLabelName = `${name}__self_loop_${toIndex}`;
  593. data.push({
  594. name: loopLabelName,
  595. x: x + 88,
  596. y,
  597. itemStyle: {
  598. color: "rgba(0,0,0,0)",
  599. },
  600. label: {
  601. show: true,
  602. color: "#c6c6c6",
  603. formatter: toText,
  604. },
  605. tooltip: {
  606. show: false,
  607. },
  608. });
  609. links.push(
  610. {
  611. source: name,
  612. target: loopLabelName,
  613. label: {
  614. show: false,
  615. },
  616. lineStyle: {
  617. color: "#c6c6c6",
  618. width: lineWidth,
  619. curveness: 0.34,
  620. },
  621. },
  622. {
  623. source: loopLabelName,
  624. target: name,
  625. label: {
  626. show: false,
  627. },
  628. lineStyle: {
  629. color: "#c6c6c6",
  630. width: lineWidth,
  631. curveness: 0.34,
  632. },
  633. },
  634. );
  635. } else {
  636. const isOut = toText.includes("出库");
  637. const isReturn = toText.includes("退货");
  638. // 文案包含"退货"时整条线统一橙色;其余按出/入库区分蓝/灰
  639. const linkColor = isReturn ? "#ff9500" : isOut ? "#80a6fd" : "#aaaaaa";
  640. // 从预计算的曲率表中取值:同一对节点间多条线已均匀分配,单条线为 0(直线)
  641. const assignedCurveness = _curvenessMap[`${index}_${toIndex}`] || 0;
  642. const edgeMeta = _edgeMetaMap[`${index}_${toIndex}`] || { count: 1, offset: 0 };
  643. const targetPosition = _positions[nameIndexMap[toName]] || { x, y: y + 120 };
  644. const midX = (x + targetPosition.x) / 2;
  645. const midY = (y + targetPosition.y) / 2;
  646. const dx = targetPosition.x - x;
  647. const dy = targetPosition.y - y;
  648. const length = Math.sqrt(dx * dx + dy * dy) || 1;
  649. const perpX = -dy / length;
  650. const perpY = dx / length;
  651. const labelName = `${name}__edge_label_${toIndex}`;
  652. const labelText = toText.split(/\s+/).filter(Boolean).join("\n");
  653. const stagger = edgeMeta.count > 1 ? edgeMeta.offset : 0;
  654. const labelGap = this.ownershipFlowMode ? 68 : 54;
  655. const labelPerpGap = this.ownershipFlowMode ? 32 : 24;
  656. data.push({
  657. name: labelName,
  658. x: midX + perpX * stagger * labelGap,
  659. y: midY + stagger * labelGap + perpY * stagger * labelPerpGap,
  660. symbolSize: 1,
  661. itemStyle: {
  662. color: "rgba(0,0,0,0)",
  663. },
  664. label: {
  665. show: true,
  666. formatter: () => labelText,
  667. color: linkColor,
  668. fontSize: 12,
  669. lineHeight: 14,
  670. width: 120,
  671. overflow: "breakAll",
  672. },
  673. tooltip: {
  674. show: false,
  675. },
  676. });
  677. links.push({
  678. source: name,
  679. target: toName,
  680. label: {
  681. show: false,
  682. },
  683. lineStyle: {
  684. color: linkColor,
  685. width: lineWidth,
  686. curveness: assignedCurveness,
  687. },
  688. });
  689. }
  690. });
  691. });
  692. // console.log("this.imageData", this.imageData);
  693. // console.log("data", data);
  694. // console.log("links", links);
  695. option = {
  696. tooltip: {},
  697. animationDurationUpdate: 1500,
  698. animationEasingUpdate: "quinticInOut",
  699. series: [
  700. {
  701. type: "graph",
  702. layout: "none",
  703. symbolSize: 86,
  704. roam: true,
  705. label: {
  706. show: true,
  707. fontSize: 8,
  708. lineHeight: 10,
  709. formatter: (params) => {
  710. const text = String((params && params.name) || "");
  711. if (!text) return "";
  712. return text.split(/\s+/).filter(Boolean).join("\n");
  713. },
  714. },
  715. edgeSymbol: ["circle", "arrow"],
  716. edgeSymbolSize: [4, 10],
  717. data,
  718. links,
  719. lineStyle: {
  720. opacity: 0.9,
  721. width: 2,
  722. curveness: 0,
  723. },
  724. },
  725. ],
  726. };
  727. try {
  728. await this.$nextTick();
  729. // if (this.chartInstance) {
  730. // this.chartInstance.setOption(option, true);
  731. // return;
  732. // }
  733. this.chartInstance = markRaw(await this.$refs.chartRef.init(echarts));
  734. this.chartInstance.setOption(option, true);
  735. } catch (error) {
  736. console.error("图表初始化失败:", error);
  737. }
  738. },
  739. // 更新图表数据
  740. updateChart(newOption) {
  741. if (this.chartInstance) {
  742. this.chartInstance.setOption(newOption);
  743. } else if (this.$refs.chartRef) {
  744. this.$refs.chartRef.setOption(newOption);
  745. }
  746. },
  747. // 调整图表大小
  748. resizeChart() {
  749. if (this.$refs.chartRef) {
  750. this.$refs.chartRef.resize();
  751. }
  752. },
  753. formatDate(date) {
  754. return formatDate({ date }, "YYYY-MM-DD");
  755. },
  756. getRegion(value = {}) {
  757. const { provinceDesc, cityDesc, areaDesc } = value;
  758. return [provinceDesc, cityDesc, areaDesc].filter(Boolean).join(",") || "";
  759. },
  760. getRegionByPrefix(value = {}, prefix = "from") {
  761. const province = value[`${prefix}ProvinceDesc`];
  762. const city = value[`${prefix}CityDesc`];
  763. const area = value[`${prefix}AreaDesc`];
  764. return [province, city, area].filter(Boolean).join("-") || "";
  765. },
  766. initTimelineVisibleCount() {
  767. this.timelineVisibleCount = this.timelinePageSize;
  768. },
  769. handlePageScroll(e) {
  770. const top = Number((e && (e.scrollTop || (e.detail && e.detail.scrollTop))) || 0);
  771. if (top < this.backTopThreshold) {
  772. this.showBackTopButton = false;
  773. if (this.backTopHideTimer) {
  774. clearTimeout(this.backTopHideTimer);
  775. this.backTopHideTimer = null;
  776. }
  777. return;
  778. }
  779. this.showBackTopButton = true;
  780. if (this.backTopHideTimer) {
  781. clearTimeout(this.backTopHideTimer);
  782. }
  783. this.backTopHideTimer = setTimeout(() => {
  784. this.showBackTopButton = false;
  785. this.backTopHideTimer = null;
  786. }, 3000);
  787. },
  788. backToTop() {
  789. this.scrollTopValue = 0;
  790. this.scrollIntoViewId = "detailPageTopAnchor";
  791. this.showBackTopButton = false;
  792. if (this.backTopHideTimer) {
  793. clearTimeout(this.backTopHideTimer);
  794. this.backTopHideTimer = null;
  795. }
  796. this.$nextTick(() => {
  797. this.scrollIntoViewId = "";
  798. });
  799. uni.pageScrollTo({
  800. scrollTop: 0,
  801. duration: 300,
  802. });
  803. },
  804. onTimelineScrollToLower() {
  805. if (this.timelineView !== "text") return;
  806. this.loadMoreTimelineItems();
  807. },
  808. loadMoreTimelineItems() {
  809. if (!this.hasMoreTimelineItems) return;
  810. this.timelineVisibleCount = Math.min(this.timelineVisibleCount + this.timelinePageSize, this.timelineTotalCount);
  811. },
  812. toggleTimelineItem(index) {
  813. if (!this.data || !Array.isArray(this.data.billDetailList)) return;
  814. const item = this.data.billDetailList[index];
  815. if (!item) return;
  816. this.$set(item, "_showDetail", !item._showDetail);
  817. },
  818. setAllTimelineDetail(showDetail) {
  819. this.allTimelineDetail = !!showDetail;
  820. if (!this.data || !Array.isArray(this.data.billDetailList)) return;
  821. this.data.billDetailList.forEach((item) => {
  822. if (item) this.$set(item, "_showDetail", !!showDetail);
  823. });
  824. },
  825. toggleTimelineView() {
  826. this.timelineView = this.timelineView === "text" ? "graph" : "text";
  827. if (this.timelineView === "text") {
  828. this.initTimelineVisibleCount();
  829. }
  830. if (this.timelineView === "graph" && this.data && Array.isArray(this.data.billDetailList)) {
  831. this.imageData = this.ownershipFlowMode ? this.buildImageData2(this.data.billDetailList) : this.buildImageData(this.data.billDetailList);
  832. this.updateGraphCanvasSize();
  833. this.$nextTick(() => this.initChart());
  834. }
  835. },
  836. onOwnershipModeChange(e) {
  837. this.ownershipFlowMode = !!(e && e.detail && e.detail.value);
  838. if (!this.data || !Array.isArray(this.data.billDetailList)) return;
  839. this.imageData = this.ownershipFlowMode ? this.buildImageData2(this.data.billDetailList) : this.buildImageData(this.data.billDetailList);
  840. this.updateGraphCanvasSize();
  841. if (this.timelineView === "graph") {
  842. this.$nextTick(() => this.initChart());
  843. }
  844. },
  845. onSetDefaultView() {
  846. uni.setStorageSync(this.defaultTimelineViewKey, this.timelineView);
  847. uni.showToast({
  848. title: "已设为默认",
  849. icon: "none",
  850. });
  851. },
  852. buildImageData2(data) {
  853. if (!data || !Array.isArray(data)) return [];
  854. let list = [];
  855. const buildTime = (time) => {
  856. return time.split(" ")[0];
  857. };
  858. const buildTo = (to, item) => {
  859. const hasAss = !!item.assEntName;
  860. const isWarehousing = item.billTypeName.includes("入库");
  861. const hasType = item.billTypeName && item.billTypeName !== "****";
  862. if (item.billTypeName === "使用出库") {
  863. to.push({
  864. name: "消费者",
  865. text: !hasType ? "****" : buildTime(item.billTime) + " " + item.billTypeName,
  866. });
  867. } else if (item.toEntName) {
  868. const address = [item.toProvinceDesc, item.toCityDesc, item.toAreaDesc].filter(Boolean).join(",");
  869. const assAddress = [item.assProvinceDesc, item.assCityDesc, item.assAreaDesc].filter(Boolean).join(",");
  870. const name = item.toEntTypeName + " " + item.toEntName + " " + address;
  871. const assName = item.assEntTypeName + " " + item.assEntName + " " + assAddress;
  872. to.push({
  873. name: hasAss && isWarehousing ? assName : name,
  874. text: !hasType ? "****" : buildTime(item.billTime) + " " + item.billTypeName,
  875. });
  876. if (hasAss && hasType) {
  877. to[to.length - 1].text += " 被委托:" + (isWarehousing ? item.toEntName : item.fromEntName);
  878. }
  879. }
  880. return to;
  881. };
  882. data.forEach((item, i) => {
  883. const hasAss = !!item.assEntName;
  884. const isWarehousing = item.billTypeName.includes("入库");
  885. const index = list.findIndex((i) => i.name.includes(hasAss && !isWarehousing ? item.assEntName : item.fromEntName));
  886. let to = [];
  887. if (index !== -1) {
  888. to = list[index].to;
  889. }
  890. to = buildTo(to, item);
  891. const address = [item.fromProvinceDesc, item.fromCityDesc, item.fromAreaDesc].filter(Boolean).join(",");
  892. const assAddress = [item.assProvinceDesc, item.assCityDesc, item.assAreaDesc].filter(Boolean).join(",");
  893. const name = item.fromEntTypeName + " " + item.fromEntName + " " + address;
  894. const assName = item.assEntTypeName + " " + item.assEntName + " " + assAddress;
  895. if (index === -1) {
  896. list.push({
  897. num: i,
  898. name: hasAss && !isWarehousing ? assName : name,
  899. to,
  900. });
  901. } else {
  902. list[index].to = to;
  903. }
  904. if (item.toEntName && list.findIndex((i) => i.name.includes(item.toEntName)) === -1) {
  905. const address = [item.toProvinceDesc, item.toCityDesc, item.toAreaDesc].filter(Boolean).join(",");
  906. list.push({
  907. num: i + 9999,
  908. name: item.toEntTypeName + " " + item.toEntName + " " + address,
  909. to: [],
  910. });
  911. }
  912. });
  913. list = list.filter((i) => Array.isArray(i.to) && i.to.length !== 0);
  914. const lastItem = list[list.length - 1];
  915. if (lastItem?.to?.[0]?.name === "消费者") {
  916. list.push({
  917. num: 99999,
  918. name: "消费者",
  919. to: [],
  920. });
  921. }
  922. list.sort((a, b) => a.num - b.num);
  923. return list;
  924. },
  925. buildImageData(data) {
  926. if (!data || !Array.isArray(data)) return [];
  927. const list = [];
  928. const buildTime = (time) => {
  929. return time.split(" ")[0];
  930. };
  931. const buildTo = (to, item) => {
  932. const hasType = item.billTypeName && item.billTypeName !== "****";
  933. if (item.billTypeName === "使用出库") {
  934. to.push({
  935. name: "消费者",
  936. text: !hasType ? "****" : buildTime(item.billTime) + " " + item.billTypeName,
  937. });
  938. } else if (item.toEntName) {
  939. const address = [item.toProvinceDesc, item.toCityDesc, item.toAreaDesc].filter(Boolean).join(",");
  940. to.push({
  941. name: item.toEntTypeName + " " + item.toEntName + " " + address,
  942. text: !hasType ? "****" : buildTime(item.billTime) + " " + item.billTypeName,
  943. });
  944. if (item.assEntName && hasType) {
  945. to[to.length - 1].text += " 委托:" + item.assEntName;
  946. }
  947. }
  948. return to;
  949. };
  950. data.forEach((item, i) => {
  951. const index = list.findIndex((i) => i.name.includes(item.fromEntName));
  952. let to = [];
  953. if (index !== -1) {
  954. to = list[index].to;
  955. }
  956. to = buildTo(to, item);
  957. if (index === -1) {
  958. const address = [item.fromProvinceDesc, item.fromCityDesc, item.fromAreaDesc].filter(Boolean).join(",");
  959. list.push({
  960. num: i,
  961. name: item.fromEntTypeName + " " + item.fromEntName + " " + address,
  962. to,
  963. });
  964. } else {
  965. list[index].to = to;
  966. }
  967. if (item.toEntName && list.findIndex((i) => i.name.includes(item.toEntName)) === -1) {
  968. const address = [item.toProvinceDesc, item.toCityDesc, item.toAreaDesc].filter(Boolean).join(",");
  969. list.push({
  970. num: i + 9999,
  971. name: item.toEntTypeName + " " + item.toEntName + " " + address,
  972. to: [],
  973. });
  974. }
  975. });
  976. const lastItem = list[list.length - 1];
  977. if (lastItem?.to?.[0]?.name === "消费者") {
  978. list.push({
  979. num: 99999,
  980. name: "消费者",
  981. to: [],
  982. });
  983. }
  984. list.sort((a, b) => a.num - b.num);
  985. return list;
  986. },
  987. updateGraphCanvasSize() {
  988. if (!this.isShowGraph) {
  989. this.graphViewHeight = 50;
  990. return;
  991. }
  992. const list = this.imageData || [];
  993. this.graphViewHeight = this.buildGraphLayout(list).height;
  994. },
  995. getData2(traceCode) {
  996. request("/bills/scanCode2", {
  997. tracCode: traceCode,
  998. path: "/traceabilityCodeQuery/pages/detail/index.vue",
  999. }).then((res) => {
  1000. if (res.code == 200) {
  1001. const _data = res.data;
  1002. this.data = _data || null;
  1003. if (this.data && Array.isArray(this.data.billDetailList)) {
  1004. this.data.billDetailList = this.data.billDetailList.map((item) => ({
  1005. ...item,
  1006. _showDetail: !!this.allTimelineDetail,
  1007. }));
  1008. this.initTimelineVisibleCount();
  1009. if (this.isShowGraph) {
  1010. this.imageData = this.ownershipFlowMode ? this.buildImageData2(this.data.billDetailList) : this.buildImageData(this.data.billDetailList);
  1011. }
  1012. this.updateGraphCanvasSize();
  1013. this.initChart();
  1014. }
  1015. if (typeof _data === "object" && Object.values(_data).filter((i) => !!i).length == 0) {
  1016. this.data = null;
  1017. }
  1018. this.loading = false;
  1019. } else {
  1020. uni.showToast({ title: "查询失败", icon: "none" });
  1021. }
  1022. });
  1023. },
  1024. getData(traceCode) {
  1025. request("/bills/scanCode", {
  1026. tracCode: traceCode,
  1027. path: "/traceabilityCodeQuery/pages/detail/index.vue",
  1028. }).then((res) => {
  1029. if (res.code == 200) {
  1030. // const _data = res.data;
  1031. // this.data = _data || null;
  1032. // const defaultData = [
  1033. // {
  1034. // billTypeName: "生产入库",
  1035. // billCode: "SYS_IN_2025041410194699357",
  1036. // fromEntId: "00000000000000959808",
  1037. // fromEntName: "惠州市九惠制药股份有限公司",
  1038. // fromEntType: "1",
  1039. // fromEntTypeName: "生产企业",
  1040. // fromProvinceDesc: "广东省",
  1041. // fromCityDesc: "惠州市",
  1042. // fromAreaDesc: "惠城区",
  1043. // toEntId: "00000000000000959808",
  1044. // toEntName: "惠州市九惠制药股份有限公司",
  1045. // toEntType: "1",
  1046. // toEntTypeName: "生产企业",
  1047. // toProvinceDesc: "广东省",
  1048. // toCityDesc: "惠州市",
  1049. // toAreaDesc: "惠城区",
  1050. // billTime: "2025-04-12 00:00:00",
  1051. // uploadEntId: "00000000000000959808",
  1052. // uploadEntName: "惠州市九惠制药股份有限公司",
  1053. // uploadEntType: "1",
  1054. // uploadEntTypeName: "生产企业",
  1055. // uploadProvinceDesc: "广东省",
  1056. // uploadCityDesc: "惠州市",
  1057. // uploadAreaDesc: "惠城区",
  1058. // uploadTime: "2025-04-14 10:19:47",
  1059. // },
  1060. // {
  1061. // billTypeName: "销售出库",
  1062. // billCode: "20250414093811017995",
  1063. // fromEntId: "00000000000000959808",
  1064. // fromEntName: "惠州市九惠制药股份有限公司",
  1065. // fromEntType: "1",
  1066. // fromEntTypeName: "生产企业",
  1067. // fromProvinceDesc: "广东省",
  1068. // fromCityDesc: "惠州市",
  1069. // fromAreaDesc: "惠城区",
  1070. // toEntId: "00000000000012618117",
  1071. // toEntName: "深圳华润三九医药贸易有限公司",
  1072. // toEntType: "2",
  1073. // toEntTypeName: "批发企业",
  1074. // toProvinceDesc: "广东省",
  1075. // toCityDesc: "深圳市",
  1076. // toAreaDesc: "龙华区",
  1077. // billTime: "2025-04-14 09:38:11",
  1078. // uploadEntId: "00000000000000592642",
  1079. // uploadEntName: "华润三九医药股份有限公司",
  1080. // uploadEntType: "1",
  1081. // uploadEntTypeName: "生产企业",
  1082. // uploadProvinceDesc: "广东省",
  1083. // uploadCityDesc: "深圳市",
  1084. // uploadAreaDesc: "龙华区",
  1085. // uploadTime: "2025-10-31 17:29:36",
  1086. // },
  1087. // {
  1088. // billTypeName: "销售出库",
  1089. // billCode: "2504032G-2",
  1090. // fromEntId: "00000000000012618117",
  1091. // fromEntName: "深圳华润三九医药贸易有限公司",
  1092. // fromEntType: "2",
  1093. // fromEntTypeName: "批发企业",
  1094. // fromProvinceDesc: "广东省",
  1095. // fromCityDesc: "深圳市",
  1096. // fromAreaDesc: "龙华区",
  1097. // toEntId: "8b63aa19a9a94cb6aa472ee69d309bb5",
  1098. // toEntName: "国药控股福建有限公司",
  1099. // toEntType: "5",
  1100. // toEntTypeName: "物流企业",
  1101. // toProvinceDesc: "福建省",
  1102. // toCityDesc: "厦门市",
  1103. // toAreaDesc: "思明区",
  1104. // billTime: "2025-09-27 00:00:00",
  1105. // uploadEntId: "00000000000012618117",
  1106. // uploadEntName: "深圳华润三九医药贸易有限公司",
  1107. // uploadEntType: "2",
  1108. // uploadEntTypeName: "批发企业",
  1109. // uploadProvinceDesc: "广东省",
  1110. // uploadCityDesc: "深圳市",
  1111. // uploadAreaDesc: "龙华区",
  1112. // uploadTime: "2025-09-28 10:04:12",
  1113. // },
  1114. // {
  1115. // billTypeName: "采购入库",
  1116. // billCode: "2504032G-1",
  1117. // fromEntId: "00000000000000592642",
  1118. // fromEntName: "华润三九医药股份有限公司",
  1119. // fromEntType: "1",
  1120. // fromEntTypeName: "生产企业",
  1121. // fromProvinceDesc: "广东省",
  1122. // fromCityDesc: "深圳市",
  1123. // fromAreaDesc: "龙华区",
  1124. // toEntId: "00000000000012618117",
  1125. // toEntName: "深圳华润三九医药贸易有限公司",
  1126. // toEntType: "2",
  1127. // toEntTypeName: "批发企业",
  1128. // toProvinceDesc: "广东省",
  1129. // toCityDesc: "深圳市",
  1130. // toAreaDesc: "龙华区",
  1131. // billTime: "2025-09-27 00:00:00",
  1132. // uploadEntId: "00000000000000592642",
  1133. // uploadEntName: "华润三九医药股份有限公司",
  1134. // uploadEntType: "1",
  1135. // uploadEntTypeName: "生产企业",
  1136. // uploadProvinceDesc: "广东省",
  1137. // uploadCityDesc: "深圳市",
  1138. // uploadAreaDesc: "龙华区",
  1139. // uploadTime: "2025-09-28 10:04:06",
  1140. // },
  1141. // {
  1142. // billTypeName: "采购入库",
  1143. // billCode: "FJASNP2509280580393",
  1144. // fromEntId: "00000000000012618117",
  1145. // fromEntName: "深圳华润三九医药贸易有限公司",
  1146. // fromEntType: "2",
  1147. // fromEntTypeName: "批发企业",
  1148. // fromProvinceDesc: "广东省",
  1149. // fromCityDesc: "深圳市",
  1150. // fromAreaDesc: "龙华区",
  1151. // toEntId: "8b63aa19a9a94cb6aa472ee69d309bb5",
  1152. // toEntName: "国药控股福建有限公司",
  1153. // toEntType: "5",
  1154. // toEntTypeName: "物流企业",
  1155. // toProvinceDesc: "福建省",
  1156. // toCityDesc: "厦门市",
  1157. // toAreaDesc: "思明区",
  1158. // billTime: "2025-10-30 00:00:00",
  1159. // uploadEntId: "00000000000012618117",
  1160. // uploadEntName: "深圳华润三九医药贸易有限公司",
  1161. // uploadEntType: "2",
  1162. // uploadEntTypeName: "批发企业",
  1163. // uploadProvinceDesc: "广东省",
  1164. // uploadCityDesc: "深圳市",
  1165. // uploadAreaDesc: "龙华区",
  1166. // uploadTime: "2025-10-30 17:05:35",
  1167. // },
  1168. // {
  1169. // billTypeName: "销售出库",
  1170. // billCode: "FJS0CFFPHL",
  1171. // fromEntId: "8b63aa19a9a94cb6aa472ee69d309bb5",
  1172. // fromEntName: "国药控股福建有限公司",
  1173. // fromEntType: "5",
  1174. // fromEntTypeName: "物流企业",
  1175. // fromProvinceDesc: "福建省",
  1176. // fromCityDesc: "厦门市",
  1177. // fromAreaDesc: "思明区",
  1178. // toEntId: "00000000000001312166",
  1179. // toEntName: "国药控股厦门有限公司",
  1180. // toEntType: "2",
  1181. // toEntTypeName: "批发企业",
  1182. // toProvinceDesc: "福建省",
  1183. // toCityDesc: "厦门市",
  1184. // toAreaDesc: "同安区",
  1185. // billTime: "2025-10-31 00:00:00",
  1186. // uploadEntId: "8b63aa19a9a94cb6aa472ee69d309bb5",
  1187. // uploadEntName: "国药控股福建有限公司",
  1188. // uploadEntType: "5",
  1189. // uploadEntTypeName: "物流企业",
  1190. // uploadProvinceDesc: "福建省",
  1191. // uploadCityDesc: "厦门市",
  1192. // uploadAreaDesc: "思明区",
  1193. // uploadTime: "2025-11-01 00:03:29",
  1194. // },
  1195. // {
  1196. // billTypeName: "采购入库",
  1197. // billCode: "XMASNP2510310469890",
  1198. // fromEntId: "8b63aa19a9a94cb6aa472ee69d309bb5",
  1199. // fromEntName: "国药控股福建有限公司",
  1200. // fromEntType: "5",
  1201. // fromEntTypeName: "物流企业",
  1202. // fromProvinceDesc: "福建省",
  1203. // fromCityDesc: "厦门市",
  1204. // fromAreaDesc: "思明区",
  1205. // toEntId: "00000000000001312166",
  1206. // toEntName: "国药控股厦门有限公司",
  1207. // toEntType: "2",
  1208. // toEntTypeName: "批发企业",
  1209. // toProvinceDesc: "福建省",
  1210. // toCityDesc: "厦门市",
  1211. // toAreaDesc: "同安区",
  1212. // billTime: "2025-11-03 00:00:00",
  1213. // uploadEntId: "8b63aa19a9a94cb6aa472ee69d309bb5",
  1214. // uploadEntName: "国药控股福建有限公司",
  1215. // uploadEntType: "5",
  1216. // uploadEntTypeName: "物流企业",
  1217. // uploadProvinceDesc: "福建省",
  1218. // uploadCityDesc: "厦门市",
  1219. // uploadAreaDesc: "思明区",
  1220. // uploadTime: "2025-11-03 17:14:48",
  1221. // },
  1222. // ];
  1223. // this.imageData = this.buildImageData(defaultData);
  1224. // this.updateGraphCanvasSize();
  1225. // this.initChart();
  1226. // if (
  1227. // typeof _data === "object" &&
  1228. // Object.values(_data).filter((i) => !!i).length == 0
  1229. // ) {
  1230. // this.data = null;
  1231. // }
  1232. // this.loading = false;
  1233. // } else {
  1234. // uni.showToast({ title: "查询失败", icon: "none" });
  1235. // }
  1236. }
  1237. });
  1238. },
  1239. copy(text) {
  1240. const data = String(text || this.traceCode);
  1241. uni.setClipboardData({
  1242. data,
  1243. success: () => {
  1244. console.log("packages/traceabilityCodeQuery/pages/detail/index.vue" + "storage" + "clipboardData");
  1245. uni.showToast({
  1246. title: "已复制追溯码",
  1247. icon: "none",
  1248. duration: 2000,
  1249. });
  1250. },
  1251. });
  1252. },
  1253. toggleCompanyExpand() {
  1254. if (!this.needCompanyToggle) return;
  1255. this.companyExpanded = !this.companyExpanded;
  1256. },
  1257. toggleCardExpand() {
  1258. this.cardExpanded = !this.cardExpanded;
  1259. },
  1260. formatTraceCode(traceCode) {
  1261. return String(traceCode || "")
  1262. .replace(/(.{5})/g, "$1 ")
  1263. .trim();
  1264. },
  1265. },
  1266. };
  1267. </script>
  1268. <style>
  1269. .detail-bg {
  1270. background-position: center top;
  1271. background-size: 100% auto;
  1272. }
  1273. .detail-page {
  1274. box-sizing: border-box;
  1275. background: rgb(226 226 226);
  1276. padding-bottom: 50rpx;
  1277. }
  1278. .detail-page-empty {
  1279. box-sizing: border-box;
  1280. display: flex;
  1281. flex-direction: column;
  1282. align-items: center;
  1283. justify-content: center;
  1284. padding: 0 136rpx 280rpx;
  1285. }
  1286. .detail-back-top-btn {
  1287. position: fixed;
  1288. right: 28rpx;
  1289. bottom: 110rpx;
  1290. width: 84rpx;
  1291. height: 84rpx;
  1292. border-radius: 50%;
  1293. background: #fff;
  1294. display: flex;
  1295. align-items: center;
  1296. justify-content: center;
  1297. box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.18);
  1298. z-index: 999;
  1299. }
  1300. .back-top-fade-enter-active,
  1301. .back-top-fade-leave-active {
  1302. transition:
  1303. opacity 0.28s ease,
  1304. transform 0.28s ease;
  1305. }
  1306. .back-top-fade-enter-from,
  1307. .back-top-fade-leave-to {
  1308. opacity: 0;
  1309. transform: translateY(16rpx) scale(0.92);
  1310. }
  1311. .detail-back-top-arrow {
  1312. width: 20rpx;
  1313. height: 20rpx;
  1314. border-top: 4rpx solid #5f6773;
  1315. border-left: 4rpx solid #5f6773;
  1316. transform: rotate(45deg);
  1317. margin-top: 8rpx;
  1318. }
  1319. .detail-card {
  1320. padding: 40rpx;
  1321. }
  1322. .detail-drug-title {
  1323. font-size: 45rpx;
  1324. font-weight: 800;
  1325. color: #000;
  1326. margin-bottom: 16rpx;
  1327. }
  1328. .detail-row {
  1329. position: relative;
  1330. display: flex;
  1331. margin-top: 12rpx;
  1332. align-items: baseline;
  1333. }
  1334. .detail-label {
  1335. flex-shrink: 0;
  1336. display: inline-block;
  1337. vertical-align: baseline;
  1338. width: 150rpx;
  1339. font-size: 28rpx;
  1340. }
  1341. .detail-value {
  1342. display: inline-block;
  1343. vertical-align: baseline;
  1344. font-size: 28rpx;
  1345. }
  1346. .detail-company-value {
  1347. line-height: 40rpx;
  1348. }
  1349. .detail-company-value.detail-clamp {
  1350. display: -webkit-box;
  1351. -webkit-box-orient: vertical;
  1352. -webkit-line-clamp: 2;
  1353. overflow: hidden;
  1354. }
  1355. .detail-expand-tag {
  1356. position: absolute;
  1357. left: 150rpx;
  1358. bottom: 0;
  1359. color: #2c69ff;
  1360. font-size: 28rpx;
  1361. }
  1362. .detail-value.detail-wrap {
  1363. word-break: break-all;
  1364. white-space: normal;
  1365. }
  1366. .detail-copy-btn {
  1367. margin-left: 16rpx;
  1368. display: flex;
  1369. align-items: center;
  1370. color: #2c69ff;
  1371. }
  1372. .detail-copy-text {
  1373. margin-left: 6rpx;
  1374. font-size: 26rpx;
  1375. }
  1376. .detail-traceability {
  1377. font-size: 24rpx;
  1378. margin: -10rpx 0 45rpx;
  1379. }
  1380. .detail-card-toggle {
  1381. display: flex;
  1382. justify-content: center;
  1383. align-items: center;
  1384. padding-top: 18rpx;
  1385. }
  1386. .detail-traceability .detail-label {
  1387. width: auto;
  1388. }
  1389. .detail-section-header {
  1390. padding: 30rpx 24rpx 20rpx 46rpx;
  1391. border-bottom: 1rpx solid #55555526;
  1392. display: flex;
  1393. justify-content: space-between;
  1394. align-items: center;
  1395. }
  1396. .detail-section-title {
  1397. font-size: 35rpx;
  1398. font-weight: 900;
  1399. }
  1400. .detail-section-actions {
  1401. display: flex;
  1402. align-items: center;
  1403. gap: 12rpx;
  1404. }
  1405. .detail-section-action {
  1406. font-size: 26rpx;
  1407. color: #59a8f2;
  1408. padding: 4rpx 6rpx;
  1409. display: flex;
  1410. align-items: center;
  1411. gap: 6rpx;
  1412. }
  1413. .detail-section-action.active {
  1414. color: #2c69ff;
  1415. font-weight: 600;
  1416. }
  1417. .detail-timeline {
  1418. margin-top: 20rpx;
  1419. padding-bottom: 50rpx;
  1420. }
  1421. .detail-graph-placeholder {
  1422. margin: 16rpx 20rpx 0;
  1423. background: #fff;
  1424. border-radius: 14rpx;
  1425. font-size: 24rpx;
  1426. text-align: center;
  1427. color: #97a0ae;
  1428. padding: 120rpx 20rpx;
  1429. }
  1430. .detail-graph-panel {
  1431. margin: 16rpx 20rpx 0;
  1432. background: #fff;
  1433. border-radius: 14rpx;
  1434. padding: 16rpx;
  1435. }
  1436. .graph-mode-row {
  1437. display: flex;
  1438. align-items: flex-start;
  1439. justify-content: space-between;
  1440. gap: 18rpx;
  1441. margin-bottom: 18rpx;
  1442. padding: 4rpx 6rpx 0;
  1443. }
  1444. .graph-mode-left {
  1445. flex: 1;
  1446. }
  1447. .graph-mode-title {
  1448. font-size: 30rpx;
  1449. color: #333;
  1450. font-weight: 600;
  1451. }
  1452. .graph-mode-desc {
  1453. margin-top: 8rpx;
  1454. font-size: 24rpx;
  1455. color: #8d96a0;
  1456. line-height: 1.45;
  1457. }
  1458. .detail-graph-canvas {
  1459. width: 100%;
  1460. height: 920rpx;
  1461. background: #f8fafc;
  1462. border-radius: 10rpx;
  1463. }
  1464. .detail-timeline-toolbar {
  1465. display: flex;
  1466. gap: 16rpx;
  1467. padding: 20rpx 32rpx 10rpx;
  1468. }
  1469. .detail-toolbar-btn {
  1470. padding: 8rpx 18rpx;
  1471. border: 1rpx solid #d8dbe0;
  1472. border-radius: 999rpx;
  1473. color: #666;
  1474. font-size: 24rpx;
  1475. background: #fff;
  1476. }
  1477. .detail-timeline-item {
  1478. position: relative;
  1479. display: flex;
  1480. margin-left: 36rpx;
  1481. }
  1482. .detail-timeline-item-first {
  1483. margin-top: 20rpx;
  1484. }
  1485. .detail-timeline-loadmore {
  1486. text-align: center;
  1487. color: #8f98a3;
  1488. font-size: 24rpx;
  1489. padding: 18rpx 0 8rpx;
  1490. }
  1491. .detail-left {
  1492. position: absolute;
  1493. top: 34rpx;
  1494. left: 0;
  1495. height: 100%;
  1496. display: flex;
  1497. align-items: center;
  1498. flex-direction: column;
  1499. }
  1500. .detail-dot {
  1501. width: 16rpx;
  1502. height: 16rpx;
  1503. border-radius: 50%;
  1504. border: 2rpx solid #2c69ff;
  1505. }
  1506. .detail-dot.detail-fill {
  1507. background: #2c69ff;
  1508. border-color: #2c69ff;
  1509. }
  1510. .detail-line {
  1511. width: 2rpx;
  1512. flex: 1;
  1513. background: #8face68f;
  1514. margin-right: 2rpx;
  1515. }
  1516. .detail-right {
  1517. flex: 1;
  1518. padding: 20rpx 0;
  1519. margin-left: 45rpx;
  1520. border-bottom: 1rpx solid #55555526;
  1521. }
  1522. .detail-title-row {
  1523. display: flex;
  1524. justify-content: space-between;
  1525. align-items: flex-start;
  1526. gap: 16rpx;
  1527. }
  1528. .detail-title {
  1529. font-size: 32rpx;
  1530. color: #333;
  1531. }
  1532. .detail-title.detail-bold {
  1533. font-weight: 800;
  1534. }
  1535. .detail-item-toggle {
  1536. flex-shrink: 0;
  1537. padding: 6rpx 12rpx;
  1538. border: 1rpx solid #d8dbe0;
  1539. border-radius: 999rpx;
  1540. font-size: 22rpx;
  1541. color: #666;
  1542. display: flex;
  1543. align-items: center;
  1544. gap: 6rpx;
  1545. margin-right: 16rpx;
  1546. }
  1547. .detail-info-row {
  1548. display: flex;
  1549. margin-top: 10rpx;
  1550. font-size: 28rpx;
  1551. color: #444;
  1552. }
  1553. .detail-info-label {
  1554. color: #666;
  1555. flex-shrink: 0;
  1556. }
  1557. .detail-info-value {
  1558. color: #333;
  1559. word-break: break-all;
  1560. }
  1561. .detail-tag-row {
  1562. display: flex;
  1563. flex-wrap: wrap;
  1564. gap: 10rpx;
  1565. margin-top: 8rpx;
  1566. padding-left: 130rpx;
  1567. }
  1568. .detail-tag {
  1569. color: #57bfe1;
  1570. border-radius: 8rpx;
  1571. padding: 5rpx 14rpx;
  1572. font-size: 22rpx;
  1573. border: 1rpx solid #57bfe180;
  1574. }
  1575. .detail-tag-region {
  1576. color: #999;
  1577. border: 1rpx solid #d8dbe0;
  1578. }
  1579. .detail-text-red {
  1580. color: red;
  1581. }
  1582. .detail-loading {
  1583. animation: spin 1s linear infinite;
  1584. }
  1585. @keyframes spin {
  1586. from {
  1587. transform: rotate(0deg);
  1588. }
  1589. to {
  1590. transform: rotate(360deg);
  1591. }
  1592. }
  1593. </style>