recordItem.vue 16 KB

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