recordItem.vue 16 KB

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