recordItem.vue 17 KB

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