Administrator
2022-04-11 79d9fc857559982b00b68b2d709807bdc4cd286f
src/views/securityEquipment/car.vue
@@ -1,10 +1,19 @@
<template>
  <div class="equipments">
  <basic-container
    :class="[
      'equipments',
      $store.state.control.screenSize == 1366 ? 'smallSize' : 'normalSize',
      $store.state.control.windowWidth >= 1024 ? 'tooRowSearch1' : ''
    ]"
  >
    <avue-crud
      class="tablesss"
      v-if="visible"
      :option="option"
      :data="data"
      :page.sync="page"
      ref="crudrec"
      :permission="permissionList"
      @on-load="onLoad"
      :table-loading="loading"
      @row-save="rowSave"
@@ -21,53 +30,183 @@
          size="small"
          plain
          icon="el-icon-delete"
          v-if="permission.car_delete"
          @click="handleDelete"
          >删 除
        </el-button>
        <el-button
          type="success"
          size="small"
          plain
          icon="el-icon-upload2"
          v-if="permission.car_import"
          @click="handleImport"
          >批量导入
        </el-button>
      </template>
    </avue-crud>
  </div>
    <el-dialog
      title="车辆导入"
      append-to-body
      :visible.sync="excelBox"
      width="555px"
    >
      <avue-form
        :option="excelOption"
        v-model="excelForm"
        :upload-after="uploadAfter"
      >
        <template slot="excelTemplate">
          <el-button type="primary" @click="handleTemplate">
            点击下载<i class="el-icon-download el-icon--right"></i>
          </el-button>
        </template>
      </avue-form>
    </el-dialog>
  </basic-container>
</template>
<script>
import { data, column } from "./car";
import { getdata, adddata, update, remove } from "@/api/car/car";
import { mapGetters } from "vuex";
import { getToken } from "@/util/auth";
export default {
  props: ["fromDeptId", "windowHeight"],
  data() {
    return {
      visible: true,
      deptIds: "",
      excelBox: false,
      excelForm: {},
      excelOption: {
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "文件上传",
            prop: "excelFile",
            type: "upload",
            drag: true,
            loadText: "文件上传中,请稍等",
            span: 24,
            propsHttp: {
              res: "data"
            },
            tip: "请上传 .xls,.xlsx 标准格式文件",
            action: "/api/car/import-car?deptId=" + this.deptIds
          },
          {
            label: "模板下载",
            prop: "excelTemplate",
            formslot: true,
            span: 24
          }
        ]
      },
      loading: true,
      selectionList: [],
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
        total: 0
      },
      query: {},
      data: [],
      option: {
        // card: true,
        tip: false,
        index: true,
        searchSize: "mini",
        border: true,
        searchMenuSpan: 6,
        height: 627,
        height: "auto",
        menuWidth: 160,
        align: "center",
        selection: true,
        labelWidth: 110,
        column: column,
        ...this.$store.state.control.clearOtherBut
      },
      useifid: 266
    };
  },
  computed: {
    ...mapGetters(["permission", "userInfo"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.car_add, false),
        viewBtn: this.vaildData(this.permission.car_view, true),
        delBtn: this.vaildData(this.permission.car_delete, false),
        editBtn: this.vaildData(this.permission.car_edit, false)
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
    }
  },
  mounted() {
    this.$store.commit("setWindowSizeHeightAdd");
    this.deptIds = this.userInfo.dept_id;
  },
  created() {
    if (this.windowHeight) {
      this.option.height = this.windowHeight - 320;
    }
    var that = this;
    var roleName = this.userInfo.role_name;
    if (
      roleName == "装备管理员" ||
      roleName == "保安公司管理员" ||
      roleName == "保安" ||
      roleName == "分公司管理员"
    ) {
      //查询保安单位信息(包含子级)
      const column = this.findObject(this.option.column, "deptId");
      column.addDisplay = true;
      column.editDisplay = true;
      // column.search = false;
      //默认全部展开
      column.defaultExpandAll = true;
      column.dicUrl =
        "/api/blade-system/dept/security_lazy-tree?deptId=" +
        this.userInfo.dept_id;
      //赋值
      column.value = that.userInfo.dept_id;
      this.useifid = this.userInfo.dept_id;
    } else if (roleName == "公安管理员" || roleName == "administrator" || roleName == "民警") {
      var columnDept = that.findObject(that.option.column, "deptId");
      columnDept.dicUrl =
        "/api/blade-system/dept/security_lazy-tree?jurisdiction=" +
        that.userInfo.jurisdiction;
    } else {
      //查询保安单位信息(包含子级)
      const column = this.findObject(this.option.column, "deptId");
      // column.search = false;
      //默认全部展开
      column.dicUrl = "/api/blade-system/dept/security_lazy-tree";
    }
  },
  methods: {
    handleImport() {
      this.excelBox = true;
    },
    uploadAfter(res, done, loading, column) {
      window.console.log(column);
      this.excelBox = false;
      this.refreshChange();
      done();
    },
    handleTemplate() {
      window.open(
        `/api/car/export-template-car?${this.website.tokenHeader}=${getToken()}`
      );
    },
    sizeChange(val) {
      this.page1.currentPage = 1;
      this.page1.pageSize = val;
@@ -80,23 +219,22 @@
      //   this.$message.success("页码" + val);
    },
    rowSave(form, done, loading) {
      // var that = this;
      //   var form = this.data[0];
      //   delete form.id;
      //   for (var k = 0; k < 13; k++) {
      // console.log
      form["deptId"] = form.tenantName;
      delete form.tenantName;
      if (this.fromDeptId != undefined) {
        form["deptId"] = this.fromDeptId;
      }
      if (this.useifid != 266) {
        form["deptId"] = this.useifid;
      }
      adddata(form).then(
        (res) => {
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
            message: "操作成功!"
          });
          done();
        },
        (error) => {
        error => {
          window.console.log(error);
          loading();
        }
@@ -114,19 +252,25 @@
      this.onLoad(this.page);
    },
    rowUpdate(row, index, done, loading) {
      console.log(row);
      row["deptId"] = row.tenantName;
      delete row.tenantName;
      // console.log(row);
      // row["deptId"] = row.tenantName;
      // delete row.tenantName;
      if (this.fromDeptId != undefined) {
        row["deptId"] = this.fromDeptId;
      }
      if (this.useifid != 266) {
        row["deptId"] = this.useifid;
      }
      update(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
            message: "操作成功!"
          });
          done();
        },
        (error) => {
        error => {
          window.console.log(error);
          loading();
        }
@@ -136,7 +280,7 @@
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        type: "warning"
      })
        .then(() => {
          return remove(row.id);
@@ -145,7 +289,7 @@
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
            message: "操作成功!"
          });
        });
    },
@@ -160,7 +304,7 @@
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        type: "warning"
      })
        .then(() => {
          return remove(this.ids);
@@ -169,7 +313,7 @@
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
            message: "操作成功!"
          });
          this.$refs.crudrec.toggleSelection();
        });
@@ -177,30 +321,80 @@
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    closeDep(name) {
      for (let k in this.option.column) {
        if (this.option.column[k].prop == name) {
          this.option.column[k].search = false;
          this.option.column[k].hide = true;
          this.option.column[k].addDisplay = false;
          this.option.column[k].editDisplay = false;
        }
      }
    },
    openDep(name) {
      for (let k in this.option.column) {
        if (this.option.column[k].prop == name) {
          this.option.column[k].search = true;
          this.option.column[k].hide = false;
          this.option.column[k].addDisplay = true;
          this.option.column[k].editDisplay = true;
        }
      }
    },
    onLoad(page, params = {}) {
      this.loading = true;
      var that = this;
      // console.log(params.deptId);
      if (this.fromDeptId != undefined) {
        params["deptId"] = this.fromDeptId;
        // this.closeDep("deptId");
      } else if (this.useifid != 266) {
        params["deptId"] = this.useifid;
      } else {
        this.openDep("deptId");
      }
      //公安局进入
      if (this.userInfo.role_name == "公安管理员" || this.userInfo.role_name == "民警") {
        params["jurisdiction"] = that.userInfo.jurisdiction;
      }
      //保安公司进入
      if (
        this.userInfo.role_name == "保安公司管理员" ||
        this.userInfo.role_name == "分公司管理员"
      ) {
        params["deptId"] = that.userInfo.dept_id;
        //导入action 修改
        const importColumn = that.findObject(
          that.excelOption.column,
          "excelFile"
        );
        importColumn.action =
          "/api/car/import-car?deptId=" + that.userInfo.dept_id;
      }
      getdata(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      ).then((res) => {
        // console.log(res);
      ).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
        data.records.forEach(item => {
          if (item.numberType == -1) {
            item.numberType = null;
          }
          if (item.carType == -1) {
            item.carType = null;
          }
        });
        this.data = data.records;
        console.log(this.data);
        this.$store.commit("setWindowSizeHeightAdd");
        // console.log(this.data);
        this.loading = false;
      });
    },
  },
  mounted() {
    // this.Ourdata = data;
    // this.getData();
    // this.onLoad(this.page);
    // var dept_id = JSON.parse(
    //   window.localStorage.getItem("saber-userInfo")
    // ).content.dept_id;
  },
    }
  }
};
</script>
@@ -219,4 +413,4 @@
// .el-tag--light {
//   padding: 0 !important;
// }
</style>
</style>