index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <div class="base-container">
  3. <fnHeader :hideSwitch="true" :hideShadow="true" showDate></fnHeader>
  4. <div class="content">
  5. <div class="content-left">
  6. <div class="btn" @click="goBack">
  7. <img src="@/assets/images/common/back-icon.png" alt="" />
  8. 返回
  9. </div>
  10. <chart-box class="left-cont" name="品种列表" color="yellow">
  11. <div class="box">
  12. <div class="add-cont" v-if="baseData.length === 0">
  13. <div>暂无数据</div>
  14. <div class="tips-text">请先添加品种,再框选右侧区域,进行品种确权</div>
  15. <div class="button" @click="handleAdd">
  16. <el-icon class="icon"><Plus /></el-icon>
  17. 添加品种
  18. </div>
  19. </div>
  20. <template v-else>
  21. <div class="box-item" v-for="item in baseData" :key="item.speciesItemId">
  22. <div>
  23. <div class="circle" :style="{background:item.color}"></div>
  24. {{ item.speciesItemName }}
  25. </div>
  26. <span>{{ item.sampleCount||0 }}颗</span>
  27. </div>
  28. <div class="button" @click="handleAdd">
  29. <el-icon class="icon"><Plus /></el-icon>
  30. 添加品种
  31. </div>
  32. </template>
  33. </div>
  34. </chart-box>
  35. </div>
  36. <div class="content-right">
  37. <div class="map-header">
  38. <div class="title">
  39. <img src="@/assets/images/common/area-icon.png" alt="" />
  40. 品种确权
  41. </div>
  42. <div class="button-group">
  43. <div class="button" @click="handleClear">清除框选</div>
  44. <div class="button start" @click="handleStart">开始框选</div>
  45. <div class="button end" @click="handleEnd">结束框选</div>
  46. </div>
  47. </div>
  48. <div class="map">
  49. <my-map ref="mapRef"></my-map>
  50. <div class="checkbox-list">
  51. <span class="text">全部设置为</span>
  52. <el-checkbox-group
  53. class="checkbox"
  54. v-model="checkedCities"
  55. :min="1"
  56. @change="handleCheckedCitiesChange"
  57. >
  58. <el-checkbox v-for="item in baseData" :key="item.speciesItemId" :value="item.speciesItemId">
  59. {{ item.speciesItemName }}
  60. </el-checkbox>
  61. </el-checkbox-group>
  62. <div class="add" @click="handleAdd">
  63. <el-icon class="icon"><Plus /></el-icon>
  64. 添加品种
  65. </div>
  66. </div>
  67. <div class="footer-btn">
  68. <div class="cancel" @click="handleCancel">取消</div>
  69. <div @click="handleSave">保存</div>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. <!-- 添加品种弹窗 -->
  76. <el-dialog
  77. v-model="dialogVisible"
  78. body-class="custom-dialog"
  79. title="添加品种"
  80. width="500"
  81. align-center
  82. :before-close="handleClose"
  83. >
  84. <el-select v-model="input" size="large" placeholder="请选择品种名称">
  85. <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id" />
  86. </el-select>
  87. <template #footer>
  88. <div class="dialog-footer">
  89. <div class="btn" @click="handleClose">取消</div>
  90. <div @click="handleOk">确定</div>
  91. </div>
  92. </template>
  93. </el-dialog>
  94. </template>
  95. <script setup>
  96. import { onMounted, ref } from "vue";
  97. import { ElMessage } from "element-plus";
  98. import fnHeader from "@/components/fnHeader.vue";
  99. import myMap from "./map";
  100. import chartBox from "@/components/chartBox.vue";
  101. import { useRouter, useRoute } from "vue-router";
  102. import { useStore } from "vuex";
  103. import eventBus from "@/api/eventBus";
  104. const store = useStore();
  105. const router = useRouter();
  106. const route = useRoute();
  107. const farmId = sessionStorage.getItem("farmId");
  108. onMounted(() => {
  109. getList();
  110. getSpeciesData();
  111. });
  112. //清除框选
  113. const handleClear = () => {
  114. eventBus.emit("handle:clear");
  115. };
  116. //开始框选
  117. const handleStart = () => {
  118. eventBus.emit("handle:start");
  119. };
  120. //结束框选
  121. const handleEnd = () => {
  122. eventBus.emit("handle:end");
  123. };
  124. const baseData = ref([]);
  125. const getList = () => {
  126. const params = {
  127. farmId,
  128. regionId: sessionStorage.getItem("regionId"),
  129. };
  130. VE_API.variety.speciesItemList(params).then((res) => {
  131. baseData.value = res.data || []
  132. eventBus.emit('species:list',res.data)
  133. });
  134. };
  135. const checkedCities = ref([]);
  136. const handleCheckedCitiesChange = (e) => {
  137. if(e.length){
  138. checkedCities.value = [e[e.length -1]];
  139. }
  140. };
  141. const mapRef = ref(null)
  142. const handleSave = () =>{
  143. const selectPoint = mapRef.value.getSelectPoint()
  144. const params = selectPoint.map(item =>{
  145. return {
  146. id:item.id,
  147. speciesItemId:checkedCities.value[0]
  148. }
  149. })
  150. if(params.length===0) return ElMessage.warning('请选择最少一棵树')
  151. if(checkedCities.value.length===0) return ElMessage.warning('请选择品种')
  152. VE_API.variety.updateSpeciesItem(params).then(res =>{
  153. if(res.code===0){
  154. getList()
  155. checkedCities.value = []
  156. ElMessage.success('添加成功')
  157. }
  158. })
  159. }
  160. const handleCancel = () =>{
  161. checkedCities.value = []
  162. eventBus.emit('handle:clear')
  163. }
  164. const goBack = () => {
  165. router.go(-1);
  166. };
  167. //添加品种弹窗
  168. const dialogVisible = ref(false);
  169. const input = ref("");
  170. const options = ref([])
  171. const handleAdd = () => {
  172. dialogVisible.value = true;
  173. };
  174. // 获取品种列表----下拉框
  175. const getSpeciesData = () => {
  176. VE_API.variety.speciesData({ farmId }).then(res =>{
  177. options.value = res.data || []
  178. });
  179. };
  180. const handleClose = () => {
  181. dialogVisible.value = false;
  182. input.value = "";
  183. }
  184. const handleOk = () =>{
  185. const arr = options.value.filter(item =>item.id === input.value)
  186. baseData.value.push({
  187. ...arr[0],
  188. speciesItemId:arr[0].id,
  189. speciesItemName:arr[0].name,
  190. })
  191. handleClose()
  192. };
  193. </script>
  194. <style lang="scss" scoped>
  195. .base-container {
  196. width: 100%;
  197. height: 100vh;
  198. color: #fff;
  199. position: relative;
  200. box-sizing: border-box;
  201. z-index: 1;
  202. background: #000;
  203. .content {
  204. width: 100%;
  205. height: calc(100% - 74px);
  206. display: flex;
  207. justify-content: space-between;
  208. box-sizing: border-box;
  209. padding: 20px;
  210. .content-left {
  211. width: 473px;
  212. height: 100%;
  213. box-sizing: border-box;
  214. .btn {
  215. display: flex;
  216. align-items: center;
  217. justify-content: center;
  218. border: 1px solid rgba(255, 255, 255, 0.78);
  219. border-radius: 4px;
  220. padding: 9px;
  221. margin-bottom: 13px;
  222. width: 104px;
  223. cursor: pointer;
  224. img {
  225. width: 14px;
  226. margin-right: 5px;
  227. }
  228. }
  229. .left-cont {
  230. width: 100%;
  231. height: calc(100% - 48px - 4px);
  232. .box {
  233. width: 100%;
  234. height: calc(100% - 58px);
  235. padding: 16px 12px;
  236. box-sizing: border-box;
  237. overflow-y: auto;
  238. display: flex;
  239. flex-direction: column;
  240. align-items: center;
  241. .button {
  242. color: #ffd489;
  243. display: flex;
  244. align-items: center;
  245. justify-content: center;
  246. border-radius: 8px;
  247. border: 1px solid #ffd489;
  248. padding: 8px 16px;
  249. background: rgba(255, 212, 137, 0.1);
  250. margin-top: 24px;
  251. width: 120px;
  252. font-size: 16px;
  253. box-sizing: border-box;
  254. cursor: pointer;
  255. .icon {
  256. margin-right: 4px;
  257. }
  258. }
  259. .add-cont {
  260. display: flex;
  261. flex-direction: column;
  262. align-items: center;
  263. font-size: 16px;
  264. .tips-text {
  265. width: 220px;
  266. text-align: center;
  267. color: #9f9f9f;
  268. font-size: 15px;
  269. margin-top: 8px;
  270. }
  271. }
  272. .box-item {
  273. width: 94%;
  274. display: flex;
  275. align-items: center;
  276. justify-content: space-between;
  277. border-radius: 5px;
  278. border: 1px solid #666666;
  279. padding: 12px;
  280. .circle{
  281. border-radius: 50%;
  282. border: 1px solid #fff;
  283. width: 11px;
  284. height: 11px;
  285. margin-right: 7px;
  286. }
  287. div {
  288. font-size: 18px;
  289. display: flex;
  290. align-items: center;
  291. }
  292. span {
  293. color: #9f9f9f;
  294. }
  295. }
  296. .box-item + .box-item{
  297. margin-top: 12px;
  298. }
  299. }
  300. }
  301. }
  302. .content-right {
  303. width: calc(100% - 473px - 18px);
  304. margin-left: 18px;
  305. height: 100%;
  306. background: #191919;
  307. border: 0.6px solid #444444;
  308. padding: 20px;
  309. box-sizing: border-box;
  310. border-radius: 8px;
  311. .map-header {
  312. display: flex;
  313. align-items: flex-start;
  314. justify-content: space-between;
  315. .title {
  316. font-size: 22px;
  317. display: flex;
  318. align-items: flex-end;
  319. font-family: "PangMenZhengDao";
  320. margin-bottom: 16px;
  321. img {
  322. margin-right: 8px;
  323. }
  324. }
  325. .button {
  326. color: #fff;
  327. padding: 5px 15px;
  328. border-radius: 4px;
  329. font-size: 16px;
  330. border: 1px solid #fff;
  331. cursor: pointer;
  332. }
  333. }
  334. .button-group{
  335. display: flex;
  336. div + div{
  337. margin-left: 10px;
  338. }
  339. .start{
  340. background: #f7be5a;
  341. color: #000;
  342. }
  343. .end{
  344. color: #f7be5a;
  345. }
  346. }
  347. .map {
  348. width: 100%;
  349. clip-path: inset(0px round 4px);
  350. height: calc(100% - 31px - 16px);
  351. position: relative;
  352. .checkbox-list {
  353. position: absolute;
  354. z-index: 2;
  355. right: 42px;
  356. bottom: 150px;
  357. background: rgba(0, 0, 0, 0.8);
  358. border-radius: 8px;
  359. display: flex;
  360. flex-direction: column;
  361. padding: 20px;
  362. .text {
  363. color: #9f9f9f;
  364. margin-bottom: 12px;
  365. font-size: 16px;
  366. }
  367. .checkbox {
  368. display: flex;
  369. flex-direction: column;
  370. ::v-deep {
  371. .el-checkbox__label {
  372. color: #fff;
  373. font-size: 16px;
  374. }
  375. .el-checkbox__inner {
  376. width: 18px;
  377. height: 18px;
  378. }
  379. .el-checkbox__input.is-checked .el-checkbox__inner {
  380. background: #ffd489;
  381. border-color: #ffd489;
  382. &::after {
  383. border-color: #000;
  384. border-width: 2px;
  385. height: 10px;
  386. left: 4px;
  387. width: 5px;
  388. top: 0;
  389. }
  390. }
  391. }
  392. }
  393. .add {
  394. margin-top: 12px;
  395. border: 1px solid #fff;
  396. border-radius: 4px;
  397. background: rgba(255, 255, 255, 0.2);
  398. display: flex;
  399. align-items: center;
  400. justify-content: center;
  401. padding: 8px;
  402. cursor: pointer;
  403. .icon {
  404. margin-right: 4px;
  405. }
  406. }
  407. }
  408. .footer-btn {
  409. position: absolute;
  410. right: 42px;
  411. bottom: 28px;
  412. z-index: 2;
  413. display: flex;
  414. width: 520px;
  415. div {
  416. text-align: center;
  417. width: calc(100% - 20px - 200px);
  418. font-size: 20px;
  419. color: #1d1d1d;
  420. background: #f7be5a;
  421. border-radius: 8px;
  422. border: 2px solid #fff;
  423. padding: 13px;
  424. cursor: pointer;
  425. }
  426. .cancel {
  427. margin-right: 20px;
  428. width: 200px;
  429. background: rgba(0, 0, 0, 0.6);
  430. color: #fff;
  431. }
  432. }
  433. }
  434. }
  435. }
  436. }
  437. .custom-dialog {
  438. .el-dialog__body {
  439. margin-top: 10px;
  440. }
  441. .input {
  442. width: 100%;
  443. }
  444. }
  445. .dialog-footer {
  446. display: flex;
  447. width: 100%;
  448. margin-top: 25px;
  449. div {
  450. flex: 1;
  451. padding: 10px;
  452. background: #ffd489;
  453. border-radius: 5px;
  454. color: #1d1d1d;
  455. text-align: center;
  456. cursor: pointer;
  457. }
  458. .btn {
  459. border: 1px solid #9f9f9f;
  460. background: #fff;
  461. margin-right: 14px;
  462. }
  463. }
  464. </style>