recordItem.vue 17 KB

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