recordItem.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <template>
  2. <div class="record-item">
  3. <div class="record-title">
  4. <!-- 内置标题模板 -->
  5. <div v-if="titleMode === 'default'" class="box-title">
  6. <div class="title-l">
  7. {{ recordItemData.farmWorkName }}
  8. <span class="parent-text"> {{ getFarmTypeText(recordItemData.type || recordItemData.farmWorkType) }} </span>
  9. </div>
  10. <!-- 按钮样式 -->
  11. <div v-if="titleRightText && titleRightType !== 'dot'" class="title-r title-r-button">
  12. {{ titleRightText }}
  13. </div>
  14. <!-- 点样式 -->
  15. <div v-if="titleRightDotText && titleRightType === 'dot'" class="title-r title-r-dot">
  16. <span class="r-dot"></span>
  17. {{ titleRightDotText }}
  18. </div>
  19. </div>
  20. <!-- 自定义标题插槽 -->
  21. <slot v-else name="title"></slot>
  22. </div>
  23. <!-- 服务详情模式的内容 -->
  24. <div v-if="contentMode === 'serviceDetail'" class="record-content service-detail-content">
  25. <div class="content-info">
  26. <div class="info-line">
  27. 药物处方:<span class="info-val">{{ getPrescriptionInfo(recordItemData) }}</span>
  28. </div>
  29. <div class="review-title info-line">
  30. 复核成效
  31. <div class="info-val">
  32. {{ recordItemData.reCheckText || '暂无复核成效' }}
  33. </div>
  34. </div>
  35. <div class="review-image">
  36. <div class="image-wrapper" v-if="currentImageUrl">
  37. <span class="image-label">农事前</span>
  38. <img :src="currentImageUrl" alt="" />
  39. </div>
  40. <div class="image-wrapper" v-if="recordItemData.reviewImage.length">
  41. <span class="image-label">农事后</span>
  42. <img :src="base_img_url2 + recordItemData.reviewImage[recordItemData.reviewImage.length - 1]" alt="" />
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. <!-- 自定义内容插槽 -->
  48. <slot name="content" v-else-if="showContent"></slot>
  49. <!-- 默认内容 -->
  50. <div class="record-content" v-else>
  51. <div class="info-item">
  52. 推荐时间:
  53. <span class="info-val">{{ recordItemData?.executeDate || '--' }}</span>
  54. </div>
  55. <div
  56. class="info-item recipe-name"
  57. v-if="onlyRecipeName && recordItemData?.prescriptionList && recordItemData?.prescriptionList.length"
  58. >
  59. <span class="name-text">药物处方:</span>
  60. <div class="rescription info-val">
  61. <span v-for="(fertilizer, fertilizerI) in recordItemData.prescriptionList" :key="fertilizerI">
  62. <span v-for="(pest, pestI) in fertilizer.pesticideFertilizerList" :key="'sub' + pestI">
  63. {{ pest.defaultName }}
  64. <span
  65. v-if="
  66. pestI !== fertilizer.pesticideFertilizerList.length - 1 ||
  67. fertilizerI !== recordItemData.prescriptionList.length - 1
  68. "
  69. >
  70. +
  71. </span>
  72. </span>
  73. </span>
  74. </div>
  75. </div>
  76. <div
  77. class="info-item"
  78. v-if="
  79. !onlyRecipeName &&
  80. recordItemData?.farmWorkDetail?.prescription &&
  81. recordItemData?.farmWorkDetail?.prescription
  82. "
  83. >
  84. 药物处方
  85. <div class="info-table">
  86. <div class="table">
  87. <div class="th">
  88. <div class="td">功效</div>
  89. <div class="td width">名称</div>
  90. <div class="td">配比</div>
  91. <div class="td">方式</div>
  92. </div>
  93. <!-- <div v-for="(prescriptionItem, prescriptionI) in recordItemData.farmWorkDetail.prescription" :key="prescriptionI">
  94. <div class="tr" v-for="(subP, subI) in prescriptionItem.pesticideFertilizerList" :key="subI">
  95. <div class="td">{{ subP.typeName }}</div>
  96. <div class="td width">{{ subP.name }}</div>
  97. <div class="td">{{ subP.ratio }}</div>
  98. <div class="td">人工</div>
  99. </div>
  100. </div> -->
  101. <div>
  102. <div
  103. class="tr"
  104. v-for="(subP, subI) in recordItemData.farmWorkDetail.prescription
  105. .pesticideFertilizerList"
  106. :key="subI"
  107. >
  108. <div class="td">{{ subP.typeName }}</div>
  109. <div class="td width">{{ subP.name }}</div>
  110. <div class="td">{{ subP.ratio }}</div>
  111. <div class="td">人工</div>
  112. </div>
  113. </div>
  114. <!-- <div class="tr">
  115. <div class="td width">80%代森锰锌</div>
  116. <div class="td">山德生</div>
  117. <div class="td">1:2000</div>
  118. <div class="td">人工</div>
  119. </div> -->
  120. </div>
  121. </div>
  122. </div>
  123. <div class="info-item">
  124. 触发条件:
  125. <span class="info-val">{{ recordItemData?.farmWorkDetail?.condition || recordItemData?.condition || '暂无触发条件' }}</span>
  126. </div>
  127. <div class="info-item one-text">
  128. 农事编号:
  129. <span class="info-val">{{ recordItemData?.farmWorkDetail?.code ||recordItemData.farmWorkCode || recordItemData.code }}</span>
  130. </div>
  131. <div class="info-item">
  132. 巡园提醒:
  133. <span class="info-val">{{ recordItemData?.attention || '暂无巡园提醒' }}</span>
  134. </div>
  135. </div>
  136. <slot name="footer"></slot>
  137. </div>
  138. </template>
  139. <script setup>
  140. import { ref, computed, watch } from 'vue';
  141. import { base_img_url2 } from '@/api/config';
  142. const props = defineProps({
  143. onlyRecipeName: {
  144. type: Boolean,
  145. default: false,
  146. },
  147. recordItemData: {
  148. type: Object,
  149. default: () => ({}),
  150. },
  151. showContent: {
  152. type: Boolean,
  153. default: false,
  154. },
  155. contentMode: {
  156. type: String,
  157. default: "",
  158. validator: (value) => ["", "serviceDetail"].includes(value),
  159. },
  160. titleMode: {
  161. type: String,
  162. default: "",
  163. validator: (value) => ["", "default"].includes(value),
  164. },
  165. titleRightText: {
  166. type: String,
  167. default: "",
  168. },
  169. titleRightType: {
  170. type: String,
  171. default: "button",
  172. validator: (value) => ["button", "dot"].includes(value),
  173. },
  174. titleRightDotText: {
  175. type: String,
  176. default: "",
  177. },
  178. });
  179. const getPrescriptionInfo = (section) => {
  180. // 将 prescriptionList 中所有 pesticideFertilizerName 用 + 连接
  181. if (section && Array.isArray(section.prescriptionList)) {
  182. const names = section.prescriptionList
  183. .flatMap((item) => Array.isArray(item?.pesticideFertilizerList) ? item.pesticideFertilizerList : [])
  184. .map((sub) => sub?.pesticideFertilizerName)
  185. .filter((name) => typeof name === "string" && name.trim().length > 0);
  186. if (names.length > 0) {
  187. return names.join("+");
  188. }
  189. }
  190. return "";
  191. };
  192. const getFarmTypeText = (type) => {
  193. const value = typeof type === "string" ? type.trim() : type;
  194. if (value === 0 || value === "0") return "预警农事";
  195. if (value === 1 || value === "1") return "标准农事";
  196. if (value === 2 || value === "2") return "建议农事";
  197. return "";
  198. };
  199. // 使用响应式对象存储图片 URL
  200. const imageUrlMap = ref({});
  201. // 存储正在加载的 ID,避免重复请求
  202. const loadingIds = ref(new Set());
  203. // 获取图片 URL 的函数
  204. const fetchImageUrl = (id) => {
  205. // 如果 id 不存在或已经在加载中,直接返回
  206. if (!id || loadingIds.value.has(id)) {
  207. return;
  208. }
  209. // 如果已经有缓存的 URL,直接返回
  210. if (imageUrlMap.value[id]) {
  211. return;
  212. }
  213. // 标记为加载中
  214. loadingIds.value.add(id);
  215. // 发起异步请求获取图片 URL
  216. VE_API.z_farm_work_record.getTriggerImg({ farmWorkRecordId: id }).then(({ data }) => {
  217. if(data && data.length > 0){
  218. const url = base_img_url2 + data[data.length - 1].cloudFilename;
  219. // 更新响应式数据,这样模板会自动更新
  220. imageUrlMap.value[id] = url;
  221. } else {
  222. imageUrlMap.value[id] = '';
  223. }
  224. }).catch(() => {
  225. // 请求失败时,设置为空字符串避免重复请求
  226. imageUrlMap.value[id] = '';
  227. }).finally(() => {
  228. // 清除加载标记
  229. loadingIds.value.delete(id);
  230. });
  231. }
  232. // 计算属性:根据 recordItemData.id 获取图片 URL(响应式)
  233. const currentImageUrl = computed(() => {
  234. const id = props.recordItemData?.id;
  235. if (id) {
  236. // 触发获取图片 URL(如果还没有获取过)
  237. fetchImageUrl(id);
  238. // 直接返回响应式数据,Vue 会自动追踪变化
  239. return imageUrlMap.value[id] || '';
  240. }
  241. return '';
  242. });
  243. // 监听 recordItemData.id 的变化,确保 ID 变化时重新获取
  244. watch(() => props.recordItemData?.id, (newId) => {
  245. if (newId && !imageUrlMap.value[newId] && !loadingIds.value.has(newId)) {
  246. fetchImageUrl(newId);
  247. }
  248. }, { immediate: true });
  249. </script>
  250. <style lang="scss" scoped>
  251. .record-item {
  252. background: #ffffff;
  253. border-radius: 8px;
  254. padding: 12px;
  255. margin-bottom: 10px;
  256. .record-title {
  257. font-size: 16px;
  258. color: #333333;
  259. .box-title {
  260. display: flex;
  261. align-items: center;
  262. justify-content: space-between;
  263. padding-bottom: 8px;
  264. .title-l {
  265. font-size: 16px;
  266. font-weight: 600;
  267. color: #000;
  268. display: flex;
  269. align-items: center;
  270. .parent-text {
  271. margin-left: 5px;
  272. font-size: 12px;
  273. font-weight: normal;
  274. padding: 4px 6px;
  275. border-radius: 14px;
  276. background: rgba(119, 119, 119, 0.1);
  277. }
  278. }
  279. .title-btn {
  280. width: 24px;
  281. height: 24px;
  282. border-radius: 50%;
  283. background: #2199f8;
  284. display: flex;
  285. align-items: center;
  286. justify-content: center;
  287. }
  288. .title-r {
  289. font-size: 12px;
  290. &.title-r-button {
  291. padding: 5px 10px;
  292. border-radius: 20px;
  293. border: 1px solid #ff953d;
  294. color: #ff953d;
  295. }
  296. &.title-r-dot {
  297. display: flex;
  298. align-items: center;
  299. color: #393939;
  300. .r-dot {
  301. width: 6px;
  302. height: 6px;
  303. border-radius: 50%;
  304. background: #393939;
  305. margin-right: 5px;
  306. }
  307. }
  308. }
  309. }
  310. }
  311. .record-content {
  312. font-size: 12px;
  313. .info-item {
  314. color: #bbbbbb;
  315. margin-bottom: 4px;
  316. .info-val {
  317. color: #666666;
  318. }
  319. &.one-text {
  320. width: 100%;
  321. white-space: nowrap;
  322. overflow: hidden;
  323. text-overflow: ellipsis;
  324. }
  325. }
  326. .recipe-name {
  327. display: flex;
  328. .name-text {
  329. flex: none;
  330. }
  331. .rescription {
  332. max-width: 100%;
  333. white-space: nowrap;
  334. overflow: hidden;
  335. text-overflow: ellipsis;
  336. }
  337. }
  338. .info-table {
  339. margin-top: 8px;
  340. .table {
  341. border: 1px solid rgba(196, 196, 196, 0.8);
  342. border-radius: 4px;
  343. font-size: 13px;
  344. .th {
  345. background: #f6f6f6;
  346. color: #999999;
  347. display: flex;
  348. justify-content: space-between;
  349. border-radius: 4px 4px 0 0;
  350. padding: 4px 0;
  351. }
  352. .tr {
  353. display: flex;
  354. justify-content: space-between;
  355. align-items: center;
  356. color: #333333;
  357. padding: 10px 0;
  358. }
  359. .tr + .tr {
  360. border-top: 1px solid rgba(0, 0, 0, 0.08);
  361. }
  362. .td {
  363. width: 25%;
  364. padding: 0 2px;
  365. text-align: center;
  366. }
  367. .width {
  368. width: 55%;
  369. }
  370. }
  371. }
  372. }
  373. // 服务详情模式样式
  374. .service-detail-content {
  375. .content-info {
  376. padding-top: 8px;
  377. .info-line {
  378. font-size: 12px;
  379. color: #bbbbbb;
  380. margin-bottom: 8px;
  381. line-height: 1.4;
  382. .info-val {
  383. color: #666666;
  384. }
  385. }
  386. .review-title {
  387. .info-val {
  388. margin-top: 5px;
  389. }
  390. }
  391. .review-image {
  392. display: flex;
  393. align-items: center;
  394. gap: 8px;
  395. .image-wrapper {
  396. position: relative;
  397. flex: 1;
  398. img {
  399. width: 100%;
  400. height: 105px;
  401. object-fit: cover;
  402. border-radius: 8px;
  403. }
  404. .image-label {
  405. position: absolute;
  406. top: 0;
  407. left: 0;
  408. padding: 4px 10px;
  409. background: rgba(54, 52, 52, 0.6);
  410. color: #fff;
  411. font-size: 12px;
  412. border-radius: 8px 0 8px 0;
  413. z-index: 1;
  414. backdrop-filter: blur(4px);
  415. }
  416. }
  417. }
  418. }
  419. }
  420. }
  421. </style>