building.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. <template>
  2. <div class="content-box">
  3. <div class="left">
  4. <!-- <el-icon :size="23" class="camera"><VideoCameraFilled /></el-icon> -->
  5. <span class="cameratxt">楼栋单元管理</span>
  6. </div>
  7. <div class="scroll">
  8. <div class="middle">
  9. <div class="filter">
  10. <div class="condition">
  11. <el-input
  12. clearable
  13. v-model.trim="searchInput.name"
  14. class="w-50 m-2"
  15. placeholder="请输入关键字"
  16. style="width: 180px"
  17. @clear="searchBtn"
  18. />
  19. </div>
  20. <el-button
  21. style="margin-left: 20px"
  22. color="rgba(0, 97, 255, 1)"
  23. type="primary"
  24. class="search"
  25. @click="searchBtn"
  26. ><el-icon><Search /></el-icon> <span>查询</span></el-button
  27. >
  28. </div>
  29. <!-- 按钮列表 -->
  30. <div class="gongneng">
  31. <el-button type="primary" v-if="flagBtn.tianjia==1" color="rgba(0, 97, 255, 1)" @click="addlist"
  32. ><img
  33. src="@/assets/add.png"
  34. style="width: 14px; height: 14px; margin-right: 4px"
  35. alt=""
  36. /><span>新增楼栋单元</span></el-button
  37. >
  38. </div>
  39. </div>
  40. <div class="footer" v-loading="loading">
  41. <el-table
  42. :row-class-name="tableRowClassName"
  43. :data="tableData.list"
  44. @selection-change="handleSelectionChange"
  45. style="width: 100%"
  46. :header-cell-style="{
  47. background: 'rgba(240, 243, 247, 1)',
  48. height: '50px',
  49. border: 0,
  50. }"
  51. >
  52. <!-- <el-table-column align="center" type="selection" width="80" /> -->
  53. <el-table-column
  54. width="120"
  55. align="center"
  56. label="序号"
  57. type="index"
  58. index="1"
  59. />
  60. <el-table-column align="center" prop="building" label="楼栋" />
  61. <el-table-column align="center" prop="element" label="单元">
  62. </el-table-column>
  63. <el-table-column align="center" prop="createTime" label="创建时间"/>
  64. <el-table-column align="center" label="操作" width="180">
  65. <template #default="scope">
  66. <div class="options">
  67. <div v-if="flagBtn.bianji==1" class="look" @click="edit(scope.row)">编辑</div>
  68. <el-popconfirm
  69. v-if="flagBtn.shanchu==1"
  70. width="220"
  71. confirm-button-text="确认"
  72. cancel-button-text="取消"
  73. :icon="InfoFilled"
  74. icon-color="#f89626"
  75. title="是否删除此楼栋单元?"
  76. @confirm="del(scope.row)"
  77. @cancel="cancelEvent"
  78. >
  79. <template #reference>
  80. <div class="del">删除</div>
  81. </template>
  82. </el-popconfirm>
  83. </div>
  84. </template>
  85. </el-table-column>
  86. </el-table>
  87. <!-- 分页组件 -->
  88. <div class="pageSize">
  89. <span></span>
  90. <el-pagination
  91. background
  92. :current-page="currentPage"
  93. :page-size="pageSize"
  94. layout="total, prev, pager, next, jumper, slot"
  95. :total="total"
  96. @update:current-page="handleCurrentChange"
  97. />
  98. </div>
  99. <!-- 添加账号弹窗 -->
  100. <el-dialog
  101. class="addStaff"
  102. v-model="addDialogVisible"
  103. :close-on-click-modal="false"
  104. :close-on-press-escape="false"
  105. :title="dialongTitle"
  106. align-center
  107. width="520"
  108. :before-close="cancelAdd"
  109. >
  110. <el-form
  111. ref="ruleFormRef"
  112. :model="ruleForm"
  113. :rules="rules"
  114. label-width="100px"
  115. class="demo-ruleForm"
  116. :size="formSize"
  117. label-position="left"
  118. status-icon
  119. >
  120. <el-form-item label="楼栋 :" prop="build">
  121. <el-input
  122. v-model.trim="ruleForm.build"
  123. placeholder="请输入楼栋"
  124. clearable
  125. />
  126. </el-form-item>
  127. <el-form-item label="单元 :" prop="unit">
  128. <el-input
  129. v-model.trim="ruleForm.unit"
  130. placeholder="请输入单元"
  131. clearable
  132. />
  133. </el-form-item>
  134. <el-form-item class="options">
  135. <el-button
  136. color="rgba(0, 97, 255, 1)"
  137. class="queding"
  138. type="primary"
  139. @click="submitAdd(ruleFormRef)"
  140. >
  141. 确定
  142. </el-button>
  143. <el-button @click="cancelAdd(ruleFormRef)">取消</el-button>
  144. </el-form-item>
  145. </el-form>
  146. </el-dialog>
  147. </div>
  148. </div>
  149. </div>
  150. </template>
  151. <script setup>
  152. import {
  153. ref,
  154. watch,
  155. reactive,
  156. nextTick,
  157. onBeforeMount,
  158. onUnmounted,
  159. } from "vue";
  160. import { useRouter } from "vue-router";
  161. import { ElMessage, ElMessageBox } from "element-plus";
  162. import { Calendar } from "@element-plus/icons-vue";
  163. import { dayjs } from "element-plus";
  164. import lodash, { reduce } from "lodash";
  165. import axios from "axios";
  166. import { useStore } from "vuex";
  167. const store = useStore();
  168. const router = useRouter();
  169. // 表格数据
  170. const loading = ref(false);
  171. const tableData = reactive({
  172. list: [],
  173. });
  174. const activeIndex = ref(); // 默认跳转路由
  175. const dialongTitle = ref("新增楼栋单元"); // 弹窗标题
  176. const searchInput = reactive({
  177. status: "",
  178. name: "",
  179. createTime: "",
  180. }); // 搜索按钮数据
  181. const flagBtn = ref(); // 按钮权限
  182. watch(
  183. () => searchInput.createTime,
  184. (newVal, oldVal) => {
  185. console.log("监听时间:", newVal);
  186. if (newVal == null) {
  187. getList();
  188. }
  189. }
  190. );
  191. const currentPage = ref(1); // 当前页
  192. const pageSize = ref(10);
  193. const total = ref(); // 当前总数
  194. const api = ref("");
  195. const schoolCardList = ref();
  196. const schoolCardSearch = ref(); // 微信卡号下拉框搜索词
  197. const schoolCardPage = ref(1);
  198. const schoolCardSize = ref(20);
  199. const schoolCardTotalPage = ref();
  200. const addDialogVisible = ref(false); // 控制添加账号弹窗
  201. const editMemberTree = ref(); // 角色ref
  202. const roleData = ref(); // 角色列表
  203. const defaultProps = ref({
  204. children: "children",
  205. label: "name",
  206. });
  207. // 表单数据
  208. const formSize = ref("default");
  209. const ruleFormRef = ref();
  210. const ruleForm = reactive({
  211. build: "",
  212. unit: "",
  213. id: "",
  214. });
  215. var buildNum = (rule, value, callback) => {
  216. // if (!value) {
  217. // return callback(new Error("请输入楼栋)"));
  218. // }
  219. var reg = /^\\d$/;
  220. if (!reg.test(value)) {
  221. callback(new Error("输入值必须为纯数字!"));
  222. } else {
  223. callback();
  224. }
  225. };
  226. // 表单验证
  227. const rules = reactive({
  228. build: [
  229. { required: true, message: "楼栋不能为空", trigger: "blur" },
  230. // { validator: buildNum, trigger: "blur" },
  231. ],
  232. unit: [
  233. { required: true, message: "单元不能为空", trigger: "blur" },
  234. // { validator: buildNum, trigger: "blur" },
  235. ],
  236. // desc: [{ required: true, message: "Please input activity form", trigger: "blur" }],
  237. });
  238. // 获取账户列表
  239. const getList = async () => {
  240. loading.value = true;
  241. let data = {
  242. page: currentPage.value, // 当前页
  243. size: pageSize.value, // 一页数据条数
  244. // permissionSettingId: sessionStorage.getItem("permissionSettingId"),
  245. keyWord: searchInput.name,
  246. };
  247. // if (searchInput.createTime) {
  248. // data.startTime = searchInput.createTime[0];
  249. // data.endTime = searchInput.createTime[1];
  250. // }
  251. let res = await axios({
  252. method: "get",
  253. url: api.value + "/building/list",
  254. headers: {
  255. token: sessionStorage.getItem("token"),
  256. user_head: sessionStorage.getItem("user_head"),
  257. },
  258. params: data,
  259. });
  260. console.log(res, "楼栋管理");
  261. if (res.data.code == 200) {
  262. tableData.list = res.data.data.records;
  263. total.value = res.data.data.total;
  264. loading.value = false;
  265. // ElMessage({
  266. // type: "success",
  267. // showClose: true,
  268. // message: res.data.message,
  269. // center: true,
  270. // });
  271. } else {
  272. loading.value = false;
  273. if (res.data.code == 500) {
  274. console.log(res.data);
  275. if (res.data.message == "无效token,请重新登入") {
  276. router.push({ path: "/login" });
  277. }
  278. }
  279. ElMessage({
  280. type: "error",
  281. showClose: true,
  282. message: res.data.message,
  283. center: true,
  284. });
  285. }
  286. };
  287. // 搜索功能
  288. const searchBtn = lodash.debounce(async () => {
  289. getList();
  290. }, 300);
  291. // 添加账号
  292. const addlist = () => {
  293. dialongTitle.value = "新增楼栋单元";
  294. addDialogVisible.value = true;
  295. ruleForm.build = "";
  296. ruleForm.unit = "";
  297. ruleForm.id = "";
  298. };
  299. // 取消添加员工
  300. const cancelAdd = () => {
  301. addDialogVisible.value = false;
  302. ruleFormRef.value.resetFields();
  303. };
  304. //编辑按钮
  305. const edit = (row) => {
  306. console.log(row);
  307. dialongTitle.value = "编辑楼栋单元";
  308. addDialogVisible.value = true;
  309. ruleForm.build = row.building;
  310. ruleForm.unit = row.element;
  311. ruleForm.id = row.id;
  312. };
  313. // 确认添加员工
  314. const submitAdd = lodash.debounce(async (formEl) => {
  315. if (!formEl) return;
  316. await formEl.validate(async (valid, fields) => {
  317. if (valid) {
  318. if (ruleForm.id) {
  319. let data = {
  320. id:ruleForm.id,
  321. "building": ruleForm.build,
  322. "element": ruleForm.unit
  323. };
  324. let res = await axios({
  325. method: "post",
  326. url: api.value + "/building/update",
  327. headers: {
  328. token: sessionStorage.getItem("token"),
  329. user_head: sessionStorage.getItem("user_head"),
  330. },
  331. data: data,
  332. });
  333. console.log(res, "编辑楼栋管理");
  334. if (res.data.code == 200) {
  335. getList();
  336. ElMessage({
  337. type: "success",
  338. showClose: true,
  339. message: res.data.message,
  340. center: true,
  341. });
  342. addDialogVisible.value = false;
  343. ruleFormRef.value.resetFields();
  344. } else {
  345. ElMessage({
  346. type: "error",
  347. showClose: true,
  348. message: res.data.message,
  349. center: true,
  350. });
  351. }
  352. } else {
  353. let data = {
  354. "building": ruleForm.build,
  355. "element": ruleForm.unit
  356. }
  357. let res = await axios({
  358. method: "post",
  359. url: api.value + "/building/save",
  360. headers: {
  361. token: sessionStorage.getItem("token"),
  362. user_head: sessionStorage.getItem("user_head"),
  363. },
  364. data: data,
  365. });
  366. console.log(res, "添加楼栋");
  367. if (res.data.code == 200) {
  368. getList();
  369. ElMessage({
  370. type: "success",
  371. showClose: true,
  372. message: res.data.message,
  373. center: true,
  374. });
  375. addDialogVisible.value = false;
  376. ruleFormRef.value.resetFields();
  377. } else {
  378. ElMessage({
  379. type: "error",
  380. showClose: true,
  381. message: res.data.message,
  382. center: true,
  383. });
  384. }
  385. }
  386. } else {
  387. console.log("error submit!", fields);
  388. }
  389. });
  390. }, 1000);
  391. //删除按钮
  392. const del = async (row) => {
  393. // console.log(row);
  394. let data = {
  395. buildingId: row.id,
  396. // permissionSettingId: sessionStorage.getItem("permissionSettingId"),
  397. };
  398. let res = await axios({
  399. method: "get",
  400. url: api.value + "/building/delete",
  401. headers: {
  402. token: sessionStorage.getItem("token"),
  403. user_head: sessionStorage.getItem("user_head"),
  404. },
  405. params: data,
  406. });
  407. if (res.data.code == 200) {
  408. if (tableData.list.length == 1 && currentPage.value != 1) {
  409. currentPage.value = currentPage.value - 1;
  410. }
  411. getList();
  412. ElMessage({
  413. type: "success",
  414. showClose: true,
  415. message: res.data.message,
  416. center: true,
  417. });
  418. } else {
  419. ElMessage({
  420. type: "error",
  421. showClose: true,
  422. message: res.data.message,
  423. center: true,
  424. });
  425. }
  426. // console.log(res);
  427. };
  428. // 取消删除
  429. const cancelEvent = () => {
  430. ElMessage({
  431. type: "info",
  432. showClose: true,
  433. message: "取消删除",
  434. center: true,
  435. });
  436. };
  437. // 多选框功能
  438. // const handleSelectionChange = (val) => {
  439. // console.log(val);
  440. // selectData.list = val;
  441. // };
  442. // 表格斑马纹颜色修改
  443. const tableRowClassName = ({ row, rowIndex }) => {
  444. if (rowIndex % 2 === 0) {
  445. return "even";
  446. } else if (rowIndex % 2 !== 0) {
  447. return "odd";
  448. }
  449. return "";
  450. };
  451. // 分页
  452. const handleCurrentChange = (value) => {
  453. // console.log(value);
  454. currentPage.value = value;
  455. getList();
  456. };
  457. onBeforeMount(() => {
  458. api.value = store.state.user.api;
  459. const btnflag = JSON.parse(sessionStorage.getItem("btnflag"));
  460. flagBtn.value = btnflag.account;
  461. console.log(flagBtn.value, "按钮权限");
  462. getList();
  463. });
  464. onUnmounted(() => {
  465. // document.removeEventListener("keyup", Enters);
  466. });
  467. </script>
  468. <style scoped lang="scss">
  469. .content-box {
  470. width: calc(100% - 40px);
  471. height: calc(100% - 105px);
  472. margin: 20px auto;
  473. background-color: #fff;
  474. color: #fff;
  475. display: flex;
  476. flex-direction: column;
  477. box-shadow: 0px 3px 10px rgba(0, 97, 255, 0.2);
  478. .left {
  479. // width: calc(100wh - 40px);
  480. display: flex;
  481. align-items: center;
  482. height: 60px;
  483. margin: 0 30px;
  484. border-bottom: 1px solid #ccc;
  485. color: #000;
  486. font-size: 18px;
  487. font-weight: 600;
  488. .camera {
  489. margin-right: 15px;
  490. color: #4392f7;
  491. }
  492. }
  493. .scroll{
  494. width:calc(100% );
  495. height: calc(100% - 61px);
  496. display:flex;
  497. flex-direction:column;
  498. }
  499. .middle {
  500. width: calc(100% - 60px);
  501. margin: 0 auto;
  502. color: #000;
  503. // border-bottom: 1px solid rgb(231, 231, 231);
  504. .filter {
  505. display: flex;
  506. flex-wrap: wrap;
  507. align-items: center;
  508. // margin: 10px 0 0 0;
  509. .search {
  510. margin-left: 0 !important;
  511. color: #fff;
  512. }
  513. .condition {
  514. display: flex;
  515. align-items: center;
  516. margin: 10px 30px 10px 0;
  517. :deep(.el-input .el-input__inner) {
  518. font-size: 14px;
  519. }
  520. span {
  521. margin: 0 10px 0 0;
  522. }
  523. }
  524. }
  525. .gongneng {
  526. margin: 10px 0;
  527. .el-button {
  528. color: #fff;
  529. margin-right: 15px;
  530. }
  531. }
  532. :deep(.cont) {
  533. width: 60%;
  534. margin: 20px auto;
  535. }
  536. :deep(.download) {
  537. display: flex;
  538. align-items: center;
  539. margin: 10px;
  540. }
  541. :deep(.download span) {
  542. font-size: 16px;
  543. margin-left: 20px;
  544. }
  545. :deep(.cont .el-button) {
  546. margin-left: 60px;
  547. margin-bottom: 30px;
  548. }
  549. :deep(.cont .accomplish) {
  550. width: 100%;
  551. display: flex;
  552. justify-content: center;
  553. }
  554. :deep(.cont .accomplish .el-button) {
  555. width: 50%;
  556. margin: 0;
  557. }
  558. }
  559. .footer {
  560. width: calc(100% - 60px);
  561. flex:1;
  562. margin: 0 auto;
  563. overflow:auto;
  564. .el-table--fit {
  565. height: calc(100% - 60px);
  566. :deep(.el-table__header-wrapper) {
  567. background-color: #000;
  568. font-size: 15px;
  569. color: #000;
  570. .cell {
  571. color: #000;
  572. }
  573. }
  574. :deep(.el-table__row) {
  575. height: 50px;
  576. font-size: 15px;
  577. color: #000;
  578. }
  579. :deep(.el-table__row td) {
  580. padding: 0;
  581. border: 0;
  582. }
  583. .el-button--primary {
  584. margin-left: 5px;
  585. }
  586. :deep(.el-table__body .even) {
  587. background-color: #fff;
  588. }
  589. :deep(.el-table__body .odd) {
  590. background-color: rgba(240, 243, 247, 1);
  591. }
  592. :deep(.options) {
  593. display: flex;
  594. justify-content: center;
  595. align-items: center;
  596. .reset {
  597. color: rgba(9, 101, 98, 1);
  598. cursor: pointer;
  599. }
  600. .look {
  601. margin: 0 15px;
  602. color: rgba(30, 125, 251, 1);
  603. cursor: pointer;
  604. }
  605. .del {
  606. color: rgba(212, 48, 48, 1);
  607. cursor: pointer;
  608. }
  609. }
  610. }
  611. // 添加员工弹窗样式
  612. :deep(.addStaff) {
  613. // height: 420px;
  614. border-radius: 11px;
  615. .el-dialog__header {
  616. border-radius: 11px 11px 0 0;
  617. background: rgba(237, 241, 245, 1);
  618. font-weight: 600;
  619. margin: 0;
  620. .el-dialog__headerbtn {
  621. outline: none;
  622. }
  623. }
  624. .el-dialog__body {
  625. padding: 20px 20px 10px 20px;
  626. .el-input {
  627. width: 200px;
  628. .el-input__suffix-inner {
  629. color: rgba(61, 81, 232, 1);
  630. }
  631. }
  632. .options {
  633. margin: 40px 20px 20px 0;
  634. width: 100%;
  635. .el-form-item__content {
  636. display: flex;
  637. flex-direction: row-reverse;
  638. }
  639. .queding {
  640. color: #fff;
  641. margin-left: 15px;
  642. }
  643. }
  644. }
  645. }
  646. }
  647. .pageSize {
  648. display: flex;
  649. align-items: center;
  650. justify-content: space-between;
  651. margin: 0 30px;
  652. height:60px;
  653. span {
  654. color: #000;
  655. }
  656. .el-pagination {
  657. // width: 1600px;
  658. :deep(.el-pagination__total) {
  659. color: #000;
  660. }
  661. :deep(.el-pagination__goto) {
  662. color: #000;
  663. }
  664. :deep(.el-pagination__classifier) {
  665. color: #000;
  666. }
  667. :deep(.el-input__wrapper) {
  668. border: 1px solid rgba(0, 0, 0, 1);
  669. border-radius: 5px;
  670. box-shadow: none;
  671. }
  672. :deep(.el-pager li) {
  673. margin: 0 5px;
  674. border: 1px solid rgba(0, 0, 0, 1);
  675. border-radius: 5px;
  676. background-color: transparent;
  677. }
  678. :deep(.el-pager li.is-active) {
  679. // background-color: rgba(0, 97, 255, 0.8);
  680. border: 1px solid rgba(0, 97, 255, 1);
  681. color: rgba(0, 97, 255, 1);
  682. }
  683. :deep(.btn-prev) {
  684. margin-right: 5px;
  685. border: 1px solid rgba(0, 0, 0, 1);
  686. border-radius: 5px;
  687. background-color: transparent;
  688. }
  689. :deep(.btn-next) {
  690. margin-left: 5px;
  691. border: 1px solid rgba(0, 0, 0, 1);
  692. border-radius: 5px;
  693. background-color: transparent;
  694. }
  695. }
  696. }
  697. }
  698. .el-input {
  699. width: 192px;
  700. }
  701. </style>
  702. <style lang="scss">
  703. //添加成员 联系人下拉框样式
  704. .more-tag-data {
  705. // border: 1px solid red;
  706. .el-select-dropdown__wrap {
  707. height: 200px;
  708. }
  709. }
  710. .el-popper {
  711. .addStudentMore {
  712. text-align: center;
  713. }
  714. }
  715. </style>