index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. <template>
  2. <div class="device-page">
  3. <div class="device-panel">
  4. <!-- 筛选 -->
  5. <div class="filter-bar">
  6. <div class="filter-l">
  7. <span class="filter-bar__label">搜索设备名称</span>
  8. <el-select
  9. v-model="deviceName"
  10. class="filter-bar__select"
  11. clearable
  12. filterable
  13. placeholder="请选择设备名称"
  14. >
  15. <el-option
  16. v-for="item in deviceNameOptions"
  17. :key="item"
  18. :label="item"
  19. :value="item"
  20. />
  21. </el-select>
  22. </div>
  23. <div class="filter-r">
  24. <el-button class="btn-reset" @click="handleReset">重置</el-button>
  25. <el-button class="btn-search" type="warning" @click="handleSearch">搜索</el-button>
  26. </div>
  27. </div>
  28. <div class="device-content">
  29. <div class="toolbar">
  30. <div class="tabs">
  31. <div v-for="tab in tabs" :key="tab.key" class="tabs__item" :class="{ 'is-active': activeTab === tab.key }"
  32. @click="handleTabChange(tab.key)">
  33. {{ tab.label }}({{ tab.count }})
  34. </div>
  35. </div>
  36. <el-button class="btn-add" type="warning" @click="handleAdd">新增设备</el-button>
  37. </div>
  38. <el-table :data="pagedList" class="device-table" row-key="id" header-cell-class-name="device-table__header"
  39. @selection-change="handleSelectionChange">
  40. <el-table-column type="selection" width="48" align="center" />
  41. <el-table-column prop="code" label="农机代码" min-width="140" show-overflow-tooltip>
  42. <template #default="{ row }">
  43. <span class="code-tag">{{ row.code }}</span>
  44. </template>
  45. </el-table-column>
  46. <el-table-column prop="name" label="农机名称" min-width="120" show-overflow-tooltip />
  47. <el-table-column label="农机类型" min-width="110">
  48. <template #default="{ row }">
  49. <span class="type-tag">{{ row.type }}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="农事类别" min-width="160">
  53. <template #default="{ row }">
  54. <div class="category-grid">
  55. <span v-for="(item, idx) in row.categories" :key="idx" class="category-grid__item">
  56. {{ item }}
  57. </span>
  58. </div>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="存放点位" min-width="170">
  62. <template #default="{ row }">
  63. <div class="location-cell">
  64. <div class="location-cell__row">
  65. <el-icon class="location-cell__icon">
  66. <Location />
  67. </el-icon>
  68. <span class="location-cell__text" :title="row.location">{{ row.location }}</span>
  69. </div>
  70. <el-button link type="warning" class="link-btn" @click="handleViewLocation(row)">
  71. 查看点位
  72. </el-button>
  73. </div>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="执行区域" width="120" align="center">
  77. <template #default="{ row }">
  78. <div class="area-thumb">
  79. 一区,二区
  80. <el-button link type="warning" class="link-btn" @click="handleViewArea(row)">查看区域</el-button>
  81. </div>
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="负责人" min-width="150">
  85. <template #default="{ row }">
  86. <div class="owner-cell">
  87. <div>{{ row.ownerName }}</div>
  88. <div class="owner-cell__phone">{{ row.ownerPhone }}</div>
  89. </div>
  90. </template>
  91. </el-table-column>
  92. <!-- <el-table-column label="服务记录" min-width="260">
  93. <template #default="{ row }">
  94. <div class="service-cell">
  95. <div v-for="(record, idx) in row.serviceRecords.slice(0, 3)" :key="idx" class="service-cell__line">
  96. {{ record.date }} | {{ record.name }} | 作业区域: {{ record.area }}
  97. </div>
  98. <el-button link type="warning" class="link-btn" @click="handleViewMore(row)">
  99. 查看更多
  100. </el-button>
  101. </div>
  102. </template>
  103. </el-table-column> -->
  104. <el-table-column label="操作" width="150" fixed="right" align="center">
  105. <template #default="{ row }">
  106. <div class="ops">
  107. <el-button class="ops__btn" @click="handleEdit(row)">编辑</el-button>
  108. <el-button class="ops__btn" @click="handleDetail(row)">详情</el-button>
  109. <el-button class="ops__btn ops__btn--danger" type="danger" @click="handleDelete(row)">
  110. 删除
  111. </el-button>
  112. </div>
  113. </template>
  114. </el-table-column>
  115. </el-table>
  116. <div class="pager">
  117. <span class="pager__total">共 {{ total }} 项数据</span>
  118. <el-pagination v-model:current-page="page" v-model:page-size="pageSize" background
  119. layout="sizes, prev, pager, next, jumper" :page-sizes="[10, 20, 50]" :total="total" :pager-count="7" />
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. <DeviceFormDialog
  125. v-model="dialogVisible"
  126. :mode="dialogMode"
  127. :data="editingRow"
  128. @submit="handleDialogSubmit"
  129. />
  130. <DeviceDetailDialog
  131. v-model="detailVisible"
  132. :data="detailRow"
  133. @edit="handleDetailEdit"
  134. />
  135. </template>
  136. <script setup>
  137. import { computed, ref } from "vue";
  138. import { ElMessage, ElMessageBox } from "element-plus";
  139. import { Location } from "@element-plus/icons-vue";
  140. import DeviceFormDialog from "./DeviceFormDialog.vue";
  141. import DeviceDetailDialog from "./DeviceDetailDialog.vue";
  142. const tabs = ref([
  143. { key: "all", label: "全部设备", count: 158 },
  144. { key: "type-a", label: "某某类", count: 152 },
  145. { key: "type-b", label: "某某类", count: 158 },
  146. { key: "type-c", label: "某某类", count: 158 },
  147. ]);
  148. const activeTab = ref("type-a");
  149. const page = ref(1);
  150. const pageSize = ref(20);
  151. const selectedRows = ref([]);
  152. const deviceName = ref("");
  153. const appliedDeviceName = ref("");
  154. const DEVICE_NAMES = ["水肥一体机", "植保无人机", "收割机", "播种机"];
  155. const buildMockRows = (count = 101) => {
  156. const list = [];
  157. for (let i = 1; i <= count; i++) {
  158. list.push({
  159. id: i,
  160. code: "农场-类型-ID",
  161. name: DEVICE_NAMES[i % DEVICE_NAMES.length],
  162. type: "水肥一体",
  163. categories: ["类别一", "类别二", "类别三", "类别四", "类别五", "类别六"],
  164. location: "位置位置位置位置",
  165. areaLabel: "一区,二区",
  166. ownerName: "张扬",
  167. ownerPhone: "19871513658",
  168. serviceRecords: [
  169. { date: "2024-08-20", name: "农事名称", area: "3区" },
  170. { date: "2024-08-20", name: "农事名称", area: "3区" },
  171. { date: "2024-08-20", name: "农事名称", area: "3区" },
  172. { date: "2024-08-19", name: "农事名称", area: "2区" },
  173. ],
  174. categoryKey: i % 3 === 0 ? "type-b" : i % 2 === 0 ? "type-c" : "type-a",
  175. });
  176. }
  177. return list;
  178. };
  179. const allList = ref(buildMockRows());
  180. const deviceNameOptions = computed(() => {
  181. return [...new Set(allList.value.map((item) => item.name))];
  182. });
  183. const filteredList = computed(() => {
  184. let list = allList.value;
  185. if (activeTab.value !== "all") {
  186. list = list.filter((item) => item.categoryKey === activeTab.value);
  187. }
  188. if (appliedDeviceName.value) {
  189. list = list.filter((item) => item.name === appliedDeviceName.value);
  190. }
  191. return list;
  192. });
  193. const total = computed(() => filteredList.value.length);
  194. const pagedList = computed(() => {
  195. const start = (page.value - 1) * pageSize.value;
  196. return filteredList.value.slice(start, start + pageSize.value);
  197. });
  198. const handleTabChange = (key) => {
  199. activeTab.value = key;
  200. page.value = 1;
  201. };
  202. const handleSearch = () => {
  203. appliedDeviceName.value = deviceName.value || "";
  204. page.value = 1;
  205. };
  206. const handleReset = () => {
  207. deviceName.value = "";
  208. appliedDeviceName.value = "";
  209. page.value = 1;
  210. };
  211. const handleSelectionChange = (rows) => {
  212. selectedRows.value = rows;
  213. };
  214. const dialogVisible = ref(false);
  215. const dialogMode = ref("add");
  216. const editingRow = ref(null);
  217. const detailVisible = ref(false);
  218. const detailRow = ref(null);
  219. const handleAdd = () => {
  220. dialogMode.value = "add";
  221. editingRow.value = null;
  222. dialogVisible.value = true;
  223. };
  224. const handleEdit = (row) => {
  225. dialogMode.value = "edit";
  226. editingRow.value = { ...row };
  227. dialogVisible.value = true;
  228. };
  229. const handleDetail = (row) => {
  230. detailRow.value = { ...row };
  231. detailVisible.value = true;
  232. };
  233. const handleDetailEdit = () => {
  234. if (!detailRow.value) return;
  235. detailVisible.value = false;
  236. handleEdit(detailRow.value);
  237. };
  238. const handleDialogSubmit = ({ mode, data }) => {
  239. if (mode === "edit" && data.id != null) {
  240. const idx = allList.value.findIndex((item) => item.id === data.id);
  241. if (idx > -1) {
  242. allList.value[idx] = {
  243. ...allList.value[idx],
  244. ...data,
  245. };
  246. // 同步详情缓存
  247. if (detailRow.value?.id === data.id) {
  248. detailRow.value = { ...allList.value[idx] };
  249. }
  250. }
  251. return;
  252. }
  253. const nextId = allList.value.reduce((max, item) => Math.max(max, item.id), 0) + 1;
  254. allList.value.unshift({
  255. ...data,
  256. id: nextId,
  257. code: "农场-类型-ID",
  258. categoryKey: activeTab.value === "all" ? "type-a" : activeTab.value,
  259. serviceRecords: [],
  260. });
  261. };
  262. const handleViewLocation = () => ElMessage.info("查看存放点位");
  263. const handleViewArea = () => ElMessage.info("查看执行区域");
  264. const handleDelete = (row) => {
  265. ElMessageBox.confirm(`确认删除设备「${row.name}」吗?`, "提示", {
  266. type: "warning",
  267. confirmButtonText: "删除",
  268. cancelButtonText: "取消",
  269. })
  270. .then(() => {
  271. allList.value = allList.value.filter((item) => item.id !== row.id);
  272. ElMessage.success("已删除");
  273. })
  274. .catch(() => { });
  275. };
  276. </script>
  277. <style lang="scss" scoped>
  278. .device-page {
  279. box-sizing: border-box;
  280. min-height: 100%;
  281. padding: 25px;
  282. }
  283. .device-panel {
  284. min-height: calc(100% - 0px);
  285. display: flex;
  286. flex-direction: column;
  287. }
  288. .device-content {
  289. background: #fff;
  290. border-radius: 5px;
  291. padding: 0 10px;
  292. }
  293. .filter-bar {
  294. display: flex;
  295. align-items: center;
  296. gap: 30px;
  297. padding: 0 12px;
  298. border-radius: 5px;
  299. height: 72px;
  300. background: #fff;
  301. margin-bottom: 20px;
  302. }
  303. .filter-r {
  304. display: flex;
  305. align-items: center;
  306. gap: 12px;
  307. }
  308. .filter-bar__label {
  309. flex-shrink: 0;
  310. font-size: 14px;
  311. color: #333;
  312. padding-right: 8px;
  313. }
  314. .filter-bar__select {
  315. width: 220px;
  316. }
  317. .btn-reset {
  318. height: 32px;
  319. padding: 0 18px;
  320. color: $warning-color;
  321. background: #fff;
  322. border-color: $warning-color;
  323. border-radius: 4px;
  324. &:hover,
  325. &:focus {
  326. color: #fff;
  327. background: $warning-color;
  328. border-color: $warning-color;
  329. }
  330. }
  331. .btn-search {
  332. // --el-button-bg-color: #{$warning-color};
  333. // --el-button-border-color: #{$warning-color};
  334. // --el-button-hover-bg-color: #{mix(#fff, $warning-color, 12%)};
  335. // --el-button-hover-border-color: #{mix(#fff, $warning-color, 12%)};
  336. // --el-button-active-bg-color: #{mix(#000, $warning-color, 8%)};
  337. // --el-button-active-border-color: #{mix(#000, $warning-color, 8%)};
  338. height: 32px;
  339. padding: 0 18px;
  340. border-radius: 4px;
  341. }
  342. .toolbar {
  343. display: flex;
  344. align-items: center;
  345. justify-content: space-between;
  346. height: 56px;
  347. border-bottom: 1px solid #f0f0f0;
  348. }
  349. .tabs {
  350. display: flex;
  351. align-items: stretch;
  352. height: 100%;
  353. gap: 28px;
  354. }
  355. .tabs__item {
  356. position: relative;
  357. display: flex;
  358. align-items: center;
  359. height: 100%;
  360. font-size: 14px;
  361. color: #666;
  362. cursor: pointer;
  363. user-select: none;
  364. padding: 0 16px;
  365. &:hover {
  366. color: $warning-color;
  367. }
  368. &.is-active {
  369. color: $warning-color;
  370. font-weight: 500;
  371. &::after {
  372. content: "";
  373. position: absolute;
  374. left: 0;
  375. right: 0;
  376. bottom: 0;
  377. height: 2px;
  378. background: $warning-color;
  379. }
  380. }
  381. }
  382. .btn-add {
  383. // --el-button-bg-color: #{$warning-color};
  384. // --el-button-border-color: #{$warning-color};
  385. // --el-button-hover-bg-color: #{mix(#fff, $warning-color, 12%)};
  386. // --el-button-hover-border-color: #{mix(#fff, $warning-color, 12%)};
  387. // --el-button-active-bg-color: #{mix(#000, $warning-color, 8%)};
  388. // --el-button-active-border-color: #{mix(#000, $warning-color, 8%)};
  389. height: 36px;
  390. padding: 0 18px;
  391. border-radius: 4px;
  392. }
  393. .device-table {
  394. flex: 1;
  395. width: 100%;
  396. margin-top: 20px;
  397. :deep(.device-table__header) {
  398. &:nth-child(2) {
  399. color: #818080;
  400. }
  401. background: #F5F5F5 !important;
  402. color: #535353;
  403. font-weight: 500;
  404. }
  405. :deep(.el-table__cell) {
  406. padding: 12px 0;
  407. vertical-align: middle;
  408. }
  409. :deep(.el-checkbox__input.is-checked .el-checkbox__inner),
  410. :deep(.el-checkbox__input.is-indeterminate .el-checkbox__inner) {
  411. background-color: $warning-color;
  412. border-color: $warning-color;
  413. }
  414. }
  415. .type-tag {
  416. display: inline-block;
  417. padding: 2px 10px;
  418. border-radius: 4px;
  419. background: rgba($warning-color, 0.12);
  420. color: $warning-color;
  421. font-size: 12px;
  422. line-height: 22px;
  423. }
  424. .category-grid {
  425. display: flex;
  426. flex-wrap: wrap;
  427. gap: 4px;
  428. color: #666;
  429. font-size: 14px;
  430. line-height: 20px;
  431. .category-grid__item {
  432. width: fit-content;
  433. background: #F2F2F2;
  434. border-radius: 2px;
  435. padding: 1px 6px;
  436. }
  437. }
  438. .code-tag {
  439. color: #818080;
  440. }
  441. .location-cell {
  442. display: flex;
  443. flex-direction: column;
  444. align-items: flex-start;
  445. gap: 2px;
  446. }
  447. .location-cell__row {
  448. display: flex;
  449. align-items: center;
  450. gap: 4px;
  451. max-width: 100%;
  452. }
  453. .location-cell__icon {
  454. color: #999;
  455. flex-shrink: 0;
  456. }
  457. .location-cell__text {
  458. overflow: hidden;
  459. text-overflow: ellipsis;
  460. white-space: nowrap;
  461. color: #535353;
  462. font-size: 14px;
  463. }
  464. .link-btn {
  465. padding: 0;
  466. height: auto;
  467. font-size: 14px;
  468. }
  469. .area-thumb {
  470. width: 88px;
  471. height: 56px;
  472. margin: 0 auto;
  473. border-radius: 2px;
  474. overflow: hidden;
  475. cursor: pointer;
  476. }
  477. .owner-cell {
  478. color: #535353;
  479. display: flex;
  480. align-items: center;
  481. gap: 4px;
  482. color: #666;
  483. font-size: 14px;
  484. line-height: 20px;
  485. }
  486. .owner-cell__phone {
  487. // color: #999;
  488. font-weight: 500;
  489. }
  490. .service-cell {
  491. display: flex;
  492. flex-direction: column;
  493. align-items: flex-start;
  494. gap: 2px;
  495. }
  496. .service-cell__line {
  497. color: #666;
  498. font-size: 12px;
  499. line-height: 18px;
  500. white-space: nowrap;
  501. }
  502. .ops {
  503. display: flex;
  504. align-items: center;
  505. justify-content: center;
  506. gap: 4px;
  507. }
  508. .ops__btn {
  509. margin: 0 !important;
  510. height: 28px;
  511. padding: 0 6px;
  512. font-size: 14px;
  513. color: #4C4C4C;
  514. background: #F2F2F2;
  515. border: 1px solid #D2D2D2;
  516. border-radius: 2px;
  517. &:hover {
  518. color: $warning-color;
  519. border-color: rgba($warning-color, 0.45);
  520. background: rgba($warning-color, 0.06);
  521. }
  522. }
  523. .ops__btn--danger {
  524. color: #fff !important;
  525. background: #F56B6B !important;
  526. border-color: #F56B6B !important;
  527. &:hover {
  528. color: #fff !important;
  529. // background: mix(#fff, #F56B6B, 12%) !important;
  530. // border-color: mix(#fff, #F56B6B, 12%) !important;
  531. }
  532. }
  533. .pager {
  534. display: flex;
  535. align-items: center;
  536. justify-content: space-between;
  537. padding: 16px 34px;
  538. }
  539. .pager__total {
  540. color: rgba(0, 0, 0, 0.6);
  541. font-size: 14px;
  542. }
  543. :deep(.el-pagination.is-background .el-pager li.is-active) {
  544. background-color: $warning-color !important;
  545. }
  546. :deep(.el-pagination.is-background .el-pager li:hover) {
  547. color: $warning-color;
  548. }
  549. :deep(.el-pagination__jump) {
  550. margin-left: 12px;
  551. }
  552. </style>