index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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 in crops" :key="crop.id" class="crop-section">
  11. <div class="crop-header">
  12. <div class="crop-tag">{{ crop.name }}</div>
  13. <div class="add-btn" @click="addVariety(crop)">+ 新增品种</div>
  14. </div>
  15. <div v-for="variety in crop.varieties" :key="variety.id" class="variety-card">
  16. <div class="field-row">
  17. <div class="field-value">
  18. <el-select
  19. v-model="variety.variety"
  20. class="variety-input"
  21. placeholder="选择品种"
  22. >
  23. <el-option v-for="item in varietyOptions" :key="item.value" :label="item.label"
  24. :value="item.value" />
  25. <template #footer>
  26. <el-button text bg @click="onAddOption(variety)">
  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 v-model="variety.currentStage" class="select-input" placeholder="选择物候期"
  37. >
  38. <el-option v-for="item in stageOptions" :key="item.value" :label="item.label"
  39. :value="item.value" />
  40. </el-select>
  41. </div>
  42. </div>
  43. <div class="field-row">
  44. <div class="field-label">第一批花穗时间</div>
  45. <div class="field-value">
  46. <el-date-picker :editable="false" style="width: 100%" v-model="variety.firstFlowerDate" class="date-picker" type="date"
  47. placeholder="选择时间" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </div>
  53. <!-- 底部按钮 -->
  54. <div class="fixed-btn-wrap">
  55. <div class="fixed-btn" @click="handleConfirm">
  56. 确认信息
  57. </div>
  58. </div>
  59. </div>
  60. <qr-code-popup ref="qrCodePopupRef">
  61. <template #success>
  62. <div class="success-text">
  63. <img class="success-icon" src="@/assets/img/home/right.png" alt="">
  64. 您的作物信息已完善
  65. </div>
  66. </template>
  67. </qr-code-popup>
  68. <popup class="add-tag-popup" :z-index="2500" round v-model:show="showAddPopup" @update:show="handlePopupClose">
  69. <div class="tag-item">
  70. <div class="popup-title">新增品种名称</div>
  71. <el-input autofocus class="popup-input" v-model="newVarietyName" placeholder="请输入品种名称" size="large" />
  72. </div>
  73. <div class="popup-button">
  74. <div class="cancel" @click="handleCancelAdd">取消</div>
  75. <div @click="handleAddVariety">确认</div>
  76. </div>
  77. </popup>
  78. </template>
  79. <script setup>
  80. import { ref, nextTick } from "vue";
  81. import { Popup } from "vant";
  82. import customHeader from "@/components/customHeader.vue";
  83. import qrCodePopup from "@/components/popup/qrCodePopup.vue";
  84. // 简单示例数据,后续可替换为接口返回
  85. const crops = ref([
  86. {
  87. id: 1,
  88. name: "荔枝",
  89. varieties: [
  90. {
  91. id: 1,
  92. variety: "",
  93. currentStage: "花穗期",
  94. firstFlowerDate: "",
  95. },
  96. ],
  97. },
  98. {
  99. id: 2,
  100. name: "水稻",
  101. varieties: [
  102. {
  103. id: 1,
  104. variety: "",
  105. currentStage: "花穗期",
  106. firstFlowerDate: "",
  107. },
  108. ],
  109. },
  110. ]);
  111. const addVariety = (crop) => {
  112. const nextId = crop.varieties.length + 1;
  113. crop.varieties.push({
  114. id: nextId,
  115. variety: "",
  116. currentStage: "花穗期",
  117. firstFlowerDate: "",
  118. });
  119. };
  120. // 品种下拉选项(示例)
  121. const varietyOptions = ref([
  122. { label: "桂味", value: "桂味" },
  123. { label: "糯米糍", value: "糯米糍" },
  124. { label: "妃子笑", value: "妃子笑" },
  125. { label: "井岗红糯", value: "井岗红糯" },
  126. ]);
  127. // 物候期选项(示例)
  128. const stageOptions = ref([
  129. { label: "花穗期", value: "花穗期" },
  130. { label: "萌芽期", value: "萌芽期" },
  131. { label: "抽梢期", value: "抽梢期" },
  132. { label: "坐果期", value: "坐果期" },
  133. ]);
  134. const qrCodePopupRef = ref(null);
  135. const handleConfirm = () => {
  136. qrCodePopupRef.value.showPopup();
  137. }
  138. const showAddPopup = ref(false);
  139. const newVarietyName = ref("");
  140. const currentVariety = ref(null); // 记录当前正在添加品种的 variety 对象
  141. const handleAddVariety = () => {
  142. if (!newVarietyName.value.trim()) {
  143. return;
  144. }
  145. const newOption = { label: newVarietyName.value, value: newVarietyName.value };
  146. varietyOptions.value.push(newOption);
  147. // 如果当前有正在添加品种的 variety,则自动选中新增的品种
  148. if (currentVariety.value) {
  149. currentVariety.value.variety = newVarietyName.value;
  150. }
  151. newVarietyName.value = "";
  152. showAddPopup.value = false;
  153. currentVariety.value = null;
  154. }
  155. const onAddOption = async (variety) => {
  156. // 先关闭下拉菜单
  157. if (document.activeElement) {
  158. document.activeElement.blur();
  159. }
  160. // 等待下拉菜单关闭后再显示弹窗
  161. await nextTick();
  162. // 记录当前 variety
  163. currentVariety.value = variety;
  164. showAddPopup.value = true;
  165. }
  166. const handleCancelAdd = () => {
  167. newVarietyName.value = "";
  168. showAddPopup.value = false;
  169. currentVariety.value = null;
  170. }
  171. const handlePopupClose = (show) => {
  172. if (!show) {
  173. // 弹窗关闭时清空状态
  174. newVarietyName.value = "";
  175. currentVariety.value = null;
  176. }
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. .interaction-page {
  181. height: 100vh;
  182. box-sizing: border-box;
  183. background: #F2F4F5;
  184. font-size: 14px;
  185. color: #1d2129;
  186. }
  187. .interaction-content {
  188. height: calc(100% - 40px);
  189. overflow: auto;
  190. padding: 12px 10px 70px 10px;
  191. box-sizing: border-box;
  192. }
  193. .intro-card {
  194. padding: 10px;
  195. border-radius: 6px;
  196. background: #ffffff;
  197. color: #666666;
  198. box-shadow: 0 2px 8px rgba(15, 35, 52, 0.06);
  199. margin-bottom: 12px;
  200. line-height: 17px;
  201. }
  202. .crop-section {
  203. background: #ffffff;
  204. border-radius: 6px;
  205. padding: 10px;
  206. box-shadow: 0 2px 8px rgba(15, 35, 52, 0.04);
  207. margin-bottom: 10px;
  208. }
  209. .crop-header {
  210. display: flex;
  211. align-items: center;
  212. justify-content: space-between;
  213. margin-bottom: 10px;
  214. .crop-tag {
  215. padding: 0 16px;
  216. border-radius: 2px;
  217. background: #2199F8;
  218. color: #ffffff;
  219. font-size: 14px;
  220. height: 26px;
  221. line-height: 26px;
  222. }
  223. .add-btn {
  224. padding: 0 12px;
  225. border-radius: 4px;
  226. height: 26px;
  227. line-height: 26px;
  228. box-sizing: border-box;
  229. border: 0.5px solid rgba(33, 153, 248, 0.5);
  230. color: #0B84E4;
  231. }
  232. }
  233. .variety-card {
  234. margin-top: 8px;
  235. padding: 10px;
  236. border-radius: 5px;
  237. background: rgba(33, 153, 248, 0.05);
  238. border: 1px solid rgba(33, 153, 248, 0.2);
  239. }
  240. .field-row {
  241. display: flex;
  242. align-items: center;
  243. margin-bottom: 10px;
  244. &:last-child {
  245. margin-bottom: 0;
  246. }
  247. }
  248. .field-label {
  249. width: 118px;
  250. flex: none;
  251. font-size: 14px;
  252. color: #1D2129;
  253. }
  254. .field-value {
  255. flex: 1;
  256. }
  257. .select-input,
  258. .date-picker {
  259. width: 100%;
  260. }
  261. .variety-input {
  262. width: 110px;
  263. ::v-deep {
  264. .el-select__wrapper {
  265. box-shadow: none;
  266. background-color: rgba(33, 153, 248, 0.1);
  267. // box-shadow: 0 0 0 1px var(--el-border-color) inset;
  268. }
  269. .el-select__placeholder {
  270. color: #2199F8;
  271. }
  272. .el-select__caret {
  273. color: #2199F8;
  274. }
  275. }
  276. }
  277. .fake-select {
  278. height: 32px;
  279. border-radius: 4px;
  280. border: 1px solid rgba(0, 0, 0, 0.08);
  281. background: #ffffff;
  282. display: flex;
  283. align-items: center;
  284. justify-content: space-between;
  285. padding: 0 8px;
  286. box-sizing: border-box;
  287. .text {
  288. color: #1d2129;
  289. font-size: 14px;
  290. }
  291. .arrow {
  292. font-size: 10px;
  293. color: #c0c4cc;
  294. }
  295. &.fake-select--plain {
  296. background: #ffffff;
  297. }
  298. }
  299. .fixed-btn-wrap {
  300. display: flex;
  301. justify-content: center;
  302. position: fixed;
  303. bottom: 0px;
  304. left: 0;
  305. right: 0;
  306. background: #fff;
  307. padding: 10px 12px;
  308. box-sizing: border-box;
  309. // box-shadow: 0 -2px 8px rgba(15, 35, 52, 0.06);
  310. box-shadow: 2px 2px 4.5px 0px #00000066;
  311. .fixed-btn {
  312. min-width: 110px;
  313. height: 40px;
  314. line-height: 40px;
  315. text-align: center;
  316. border-radius: 20px;
  317. background: linear-gradient(180deg, #70bffe, #2199f8);
  318. color: #ffffff;
  319. font-size: 14px;
  320. }
  321. }
  322. .date-input {
  323. height: 32px;
  324. border-radius: 4px;
  325. border: 1px dashed rgba(33, 153, 248, 0.6);
  326. background: #ffffff;
  327. display: flex;
  328. align-items: center;
  329. padding: 0 8px;
  330. box-sizing: border-box;
  331. color: #c0c4cc;
  332. font-size: 14px;
  333. }
  334. .success-text {
  335. display: flex;
  336. align-items: center;
  337. justify-content: center;
  338. font-size: 24px;
  339. color: #000;
  340. .success-icon {
  341. width: 28px;
  342. height: 28px;
  343. margin-right: 5px;
  344. }
  345. }
  346. .add-tag-popup {
  347. width: 90%;
  348. padding: 24px 16px 20px 16px;
  349. background: linear-gradient(360deg, #FFFFFF 74.2%, #D1EBFF 100%);
  350. .popup-title {
  351. font-size: 16px;
  352. font-weight: 400;
  353. margin-bottom: 12px;
  354. color: #000000;
  355. .name-text{
  356. font-weight: 500;
  357. color: #2199F8;
  358. padding: 0 2px;
  359. }
  360. }
  361. .ml-2 {
  362. margin-left: 3px;
  363. }
  364. .popup-input {
  365. margin-bottom: 24px;
  366. }
  367. .popup-button {
  368. display: flex;
  369. div {
  370. flex: 1;
  371. font-size: 16px;
  372. padding: 9px;
  373. border-radius: 20px;
  374. background: #2199F8;
  375. color: #fff;
  376. text-align: center;
  377. cursor: pointer;
  378. }
  379. .cancel {
  380. margin-right: 13px;
  381. color: #000;
  382. background: #fff;
  383. border: 1px solid #999999;
  384. }
  385. .delete {
  386. margin-right: 13px;
  387. color: #FF3D3D;
  388. background: #fff;
  389. border: 1px solid rgba(255, 61, 61, 0.4);
  390. }
  391. }
  392. }
  393. </style>