index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <template>
  2. <div class="interaction-page">
  3. <custom-header name="农情互动" bgColor="#f2f4f5" :isClose="true" :showClose="false" />
  4. <div class="interaction-content">
  5. <!-- 顶部说明 -->
  6. <div class="intro-card">
  7. 完善作物品种以及物候信息,精准匹配种植方案,实现精细化管理
  8. </div>
  9. <!-- 作物块(每个农场一块) -->
  10. <div v-for="(crop, cropIndex) in farmData" :key="cropIndex" class="crop-section">
  11. <div class="crop-header">
  12. <div class="crop-tag">{{ crop.speciesName }}</div>
  13. <div class="add-btn" @click="addVariety(crop)">+ 新增品种</div>
  14. </div>
  15. <div v-for="(region, regionIndex) in crop.regions" :key="regionIndex" class="variety-card">
  16. <div class="field-row">
  17. <div class="field-value">
  18. <el-select
  19. v-model="region.regionId"
  20. class="variety-input"
  21. placeholder="选择品种"
  22. >
  23. <el-option v-for="(item, index) in crop.typeIdItems" :key="index" :label="item.name"
  24. :value="item.id" />
  25. <template #footer>
  26. <el-button text bg @click="onAddOption(region)">
  27. + 增加品种
  28. </el-button>
  29. </template>
  30. </el-select>
  31. </div>
  32. </div>
  33. <div class="field-row">
  34. <div class="field-label">当下物候期</div>
  35. <div class="field-value">
  36. <el-select
  37. v-model="region.phenologyId"
  38. class="select-input"
  39. placeholder="选择物候期"
  40. >
  41. <el-option v-for="(item, index) in crop.phenologyOptions" :key="index" :label="item.phenologyName"
  42. :value="item.phenologyId" />
  43. </el-select>
  44. </div>
  45. </div>
  46. <div class="field-row" v-if="region.phenologyId">
  47. <div class="field-label">{{ getPhenologyLabel(crop, region.phenologyId) }}</div>
  48. <div class="field-value">
  49. <el-date-picker
  50. :editable="false"
  51. style="width: 100%"
  52. v-model="region.phenologyStartDate"
  53. class="date-picker"
  54. type="date"
  55. placeholder="选择时间" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. <!-- 底部按钮 -->
  62. <div class="fixed-btn-wrap">
  63. <div class="fixed-btn" @click="handleConfirm">
  64. 确认信息
  65. </div>
  66. </div>
  67. </div>
  68. <tip-popup v-model:show="showTipPopup" type="success" text="您的作物信息已完善" />
  69. <popup class="add-tag-popup" :z-index="2500" round v-model:show="showAddPopup" @update:show="handlePopupClose">
  70. <div class="tag-item">
  71. <div class="popup-title">新增品种名称</div>
  72. <el-input autofocus class="popup-input" v-model="newVarietyName" placeholder="请输入品种名称" size="large" />
  73. </div>
  74. <div class="popup-button">
  75. <div class="cancel" @click="handleCancelAdd">取消</div>
  76. <div @click="handleAddVariety">确认</div>
  77. </div>
  78. </popup>
  79. </template>
  80. <script setup>
  81. import { ref, nextTick, onActivated } from "vue";
  82. import { ElMessage } from "element-plus";
  83. import { Popup } from "vant";
  84. import customHeader from "@/components/customHeader.vue";
  85. import { useRoute } from "vue-router";
  86. import tipPopup from "@/components/popup/tipPopup.vue";
  87. const route = useRoute();
  88. onActivated(() => {
  89. const subjectId = route.query.subjectId;
  90. getPhenologyInitOrConfirmStatus(subjectId);
  91. });
  92. const farmData = ref([])
  93. const getPhenologyInitOrConfirmStatus = async (subjectId) => {
  94. const {data} = await VE_API.farm_v3.phenologyInitOrConfirmStatus({subjectId});
  95. farmData.value = data.farms;
  96. farmData.value.forEach(item => {
  97. addVariety(item);
  98. });
  99. }
  100. const addVariety = (crop) => {
  101. if (!Array.isArray(crop.regions)) {
  102. crop.regions = [];
  103. }
  104. crop.regions.push({
  105. regionId: null,
  106. phenologyId: null,
  107. phenologyStartDate: "",
  108. });
  109. };
  110. // 获取物候期对应的时间标签
  111. const getPhenologyLabel = (farm, phenologyId) => {
  112. if (!farm?.phenologyOptions) return "选择时间";
  113. const found = farm.phenologyOptions.find(
  114. (item) => item.id === phenologyId || item.phenologyId === phenologyId
  115. );
  116. return found?.startDateLabel || "选择时间";
  117. };
  118. const showTipPopup = ref(false);
  119. const handleConfirm = async () => {
  120. // 组装为 initFarmData 接口所需的 farmDataList 结构
  121. const farmDataList = farmData.value
  122. .map((farm) => {
  123. const typeIdItems = (farm.regions || [])
  124. .filter(
  125. (r) => r.regionId && r.phenologyId && r.phenologyStartDate
  126. )
  127. .map((r) => {
  128. const origin =
  129. (farm.typeIdItems || []).find(
  130. (t) => String(t.id) === String(r.regionId)
  131. ) || {};
  132. return {
  133. id: r.regionId,
  134. name: origin.name || "",
  135. phenologyId: r.phenologyId,
  136. phenologyStartDate: r.phenologyStartDate,
  137. };
  138. })
  139. .filter((item) => item.id);
  140. return {
  141. farmId: farm.farmId,
  142. speciesId: farm.speciesId,
  143. typeIdItems,
  144. };
  145. })
  146. .filter((item) => item.typeIdItems.length > 0);
  147. if (!farmDataList.length) {
  148. ElMessage.warning("请先选择品种、物候期和时间");
  149. return;
  150. }
  151. const params = {
  152. expertMiniUserId: 81881,
  153. farmDataList,
  154. };
  155. console.log("params", params);
  156. const { code, msg } = await VE_API.farm_v3.initFarmData(params);
  157. if (code === 0) {
  158. showTipPopup.value = true;
  159. } else {
  160. ElMessage.error(msg || "提交失败");
  161. }
  162. // 大物候期转换所需参数// 组装为后端所需的 farmDataList 结构
  163. // const farmDataList = farmData.value
  164. // .map((farm) => {
  165. // const regionPhenologyItems = (farm.regions || [])
  166. // .filter(
  167. // (r) => r.regionId && r.phenologyId && r.phenologyStartDate
  168. // )
  169. // .map((r) => ({
  170. // regionId: r.regionId,
  171. // phenologyId: r.phenologyId,
  172. // phenologyStartDate: r.phenologyStartDate,
  173. // }));
  174. // return {
  175. // farmId: farm.farmId,
  176. // regionPhenologyItems,
  177. // };
  178. // })
  179. // .filter((item) => item.regionPhenologyItems.length > 0);
  180. // console.log("farmDataList", farmDataList);
  181. // const params = {
  182. // farmDataList,
  183. // expertMiniUserId: 81881,
  184. // }
  185. // const {code, msg} = await VE_API.farm_v3.confirmReproductivePhenology(params);
  186. // if(code === 0) {
  187. // qrCodePopupRef.value.showPopup();
  188. // } else {
  189. // ElMessage.error(msg);
  190. // }
  191. };
  192. const showAddPopup = ref(false);
  193. const newVarietyName = ref("");
  194. const currentVariety = ref(null); // 记录当前正在添加品种的 variety 对象
  195. const handleAddVariety = () => {
  196. if (!newVarietyName.value.trim()) {
  197. return;
  198. }
  199. // 如果当前有正在添加品种的 variety,则自动选中新增的品种
  200. if (currentVariety.value) {
  201. currentVariety.value.variety = newVarietyName.value;
  202. }
  203. newVarietyName.value = "";
  204. showAddPopup.value = false;
  205. currentVariety.value = null;
  206. }
  207. const onAddOption = async (region) => {
  208. // 先关闭下拉菜单
  209. if (document.activeElement) {
  210. document.activeElement.blur();
  211. }
  212. // 等待下拉菜单关闭后再显示弹窗
  213. await nextTick();
  214. // 记录当前 region
  215. currentVariety.value = region;
  216. showAddPopup.value = true;
  217. }
  218. const handleCancelAdd = () => {
  219. newVarietyName.value = "";
  220. showAddPopup.value = false;
  221. currentVariety.value = null;
  222. }
  223. const handlePopupClose = (show) => {
  224. if (!show) {
  225. // 弹窗关闭时清空状态
  226. newVarietyName.value = "";
  227. currentVariety.value = null;
  228. }
  229. }
  230. </script>
  231. <style lang="scss" scoped>
  232. .interaction-page {
  233. height: 100vh;
  234. box-sizing: border-box;
  235. background: #F2F4F5;
  236. font-size: 14px;
  237. color: #1d2129;
  238. }
  239. .interaction-content {
  240. height: calc(100% - 40px);
  241. overflow: auto;
  242. padding: 12px 10px 70px 10px;
  243. box-sizing: border-box;
  244. }
  245. .intro-card {
  246. padding: 10px;
  247. border-radius: 6px;
  248. background: #ffffff;
  249. color: #666666;
  250. box-shadow: 0 2px 8px rgba(15, 35, 52, 0.06);
  251. margin-bottom: 12px;
  252. line-height: 17px;
  253. }
  254. .crop-section {
  255. background: #ffffff;
  256. border-radius: 6px;
  257. padding: 10px;
  258. box-shadow: 0 2px 8px rgba(15, 35, 52, 0.04);
  259. margin-bottom: 10px;
  260. }
  261. .crop-header {
  262. display: flex;
  263. align-items: center;
  264. justify-content: space-between;
  265. margin-bottom: 10px;
  266. .crop-tag {
  267. padding: 0 16px;
  268. border-radius: 2px;
  269. background: #2199F8;
  270. color: #ffffff;
  271. font-size: 14px;
  272. height: 26px;
  273. line-height: 26px;
  274. }
  275. .add-btn {
  276. padding: 0 12px;
  277. border-radius: 4px;
  278. height: 26px;
  279. line-height: 26px;
  280. box-sizing: border-box;
  281. border: 0.5px solid rgba(33, 153, 248, 0.5);
  282. color: #0B84E4;
  283. }
  284. }
  285. .variety-card {
  286. margin-top: 8px;
  287. padding: 10px;
  288. border-radius: 5px;
  289. background: rgba(33, 153, 248, 0.05);
  290. border: 1px solid rgba(33, 153, 248, 0.2);
  291. }
  292. .field-row {
  293. display: flex;
  294. align-items: center;
  295. margin-bottom: 10px;
  296. &:last-child {
  297. margin-bottom: 0;
  298. }
  299. }
  300. .field-label {
  301. width: 118px;
  302. flex: none;
  303. font-size: 14px;
  304. color: #1D2129;
  305. }
  306. .field-value {
  307. flex: 1;
  308. }
  309. .select-input,
  310. .date-picker {
  311. width: 100%;
  312. }
  313. .variety-input {
  314. width: 110px;
  315. ::v-deep {
  316. .el-select__wrapper {
  317. box-shadow: none;
  318. background-color: rgba(33, 153, 248, 0.1);
  319. // box-shadow: 0 0 0 1px var(--el-border-color) inset;
  320. }
  321. .el-select__placeholder {
  322. color: #2199F8;
  323. }
  324. .el-select__caret {
  325. color: #2199F8;
  326. }
  327. }
  328. }
  329. .fake-select {
  330. height: 32px;
  331. border-radius: 4px;
  332. border: 1px solid rgba(0, 0, 0, 0.08);
  333. background: #ffffff;
  334. display: flex;
  335. align-items: center;
  336. justify-content: space-between;
  337. padding: 0 8px;
  338. box-sizing: border-box;
  339. .text {
  340. color: #1d2129;
  341. font-size: 14px;
  342. }
  343. .arrow {
  344. font-size: 10px;
  345. color: #c0c4cc;
  346. }
  347. &.fake-select--plain {
  348. background: #ffffff;
  349. }
  350. }
  351. .fixed-btn-wrap {
  352. display: flex;
  353. justify-content: center;
  354. position: fixed;
  355. bottom: 0px;
  356. left: 0;
  357. right: 0;
  358. background: #fff;
  359. padding: 10px 12px;
  360. box-sizing: border-box;
  361. // box-shadow: 0 -2px 8px rgba(15, 35, 52, 0.06);
  362. box-shadow: 2px 2px 4.5px 0px #00000066;
  363. .fixed-btn {
  364. min-width: 110px;
  365. height: 40px;
  366. line-height: 40px;
  367. text-align: center;
  368. border-radius: 20px;
  369. background: linear-gradient(180deg, #70bffe, #2199f8);
  370. color: #ffffff;
  371. font-size: 14px;
  372. }
  373. }
  374. .date-input {
  375. height: 32px;
  376. border-radius: 4px;
  377. border: 1px dashed rgba(33, 153, 248, 0.6);
  378. background: #ffffff;
  379. display: flex;
  380. align-items: center;
  381. padding: 0 8px;
  382. box-sizing: border-box;
  383. color: #c0c4cc;
  384. font-size: 14px;
  385. }
  386. .success-text {
  387. display: flex;
  388. align-items: center;
  389. justify-content: center;
  390. font-size: 24px;
  391. color: #000;
  392. .success-icon {
  393. width: 28px;
  394. height: 28px;
  395. margin-right: 5px;
  396. }
  397. }
  398. .add-tag-popup {
  399. width: 90%;
  400. padding: 24px 16px 20px 16px;
  401. background: linear-gradient(360deg, #FFFFFF 74.2%, #D1EBFF 100%);
  402. .popup-title {
  403. font-size: 16px;
  404. font-weight: 400;
  405. margin-bottom: 12px;
  406. color: #000000;
  407. .name-text{
  408. font-weight: 500;
  409. color: #2199F8;
  410. padding: 0 2px;
  411. }
  412. }
  413. .ml-2 {
  414. margin-left: 3px;
  415. }
  416. .popup-input {
  417. margin-bottom: 24px;
  418. }
  419. .popup-button {
  420. display: flex;
  421. div {
  422. flex: 1;
  423. font-size: 16px;
  424. padding: 9px;
  425. border-radius: 20px;
  426. background: #2199F8;
  427. color: #fff;
  428. text-align: center;
  429. cursor: pointer;
  430. }
  431. .cancel {
  432. margin-right: 13px;
  433. color: #000;
  434. background: #fff;
  435. border: 1px solid #999999;
  436. }
  437. .delete {
  438. margin-right: 13px;
  439. color: #FF3D3D;
  440. background: #fff;
  441. border: 1px solid rgba(255, 61, 61, 0.4);
  442. }
  443. }
  444. }
  445. </style>