上饶市警务平台后台管理前端
zhongrj
2024-12-13 937998f45a5c0b8772d3f9e2ed97063a4818e60f
小区管理新增默认小区设置
3 files modified
18913 ■■■■■ changed files
package-lock.json 18033 ●●●●● patch | view | raw | blame | history
src/api/villageInfo/villageInfo.js 7 ●●●●● patch | view | raw | blame | history
src/views/community/community.vue 873 ●●●●● patch | view | raw | blame | history
package-lock.json
Diff too large
src/api/villageInfo/villageInfo.js
@@ -77,3 +77,10 @@
  })
}
export const setWeight = (row) => {
  return request({
    url: '/api/villageInfo/villageInfo/setWeight',
    method: 'post',
    data: row
  })
}
src/views/community/community.vue
@@ -1,37 +1,57 @@
<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page.sync="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               v-model="form"
               ref="crud"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @row-del="rowDel"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot="menuLeft">
        <el-button type="success"
                   size="small"
                   plain
                   icon="el-icon-upload2"
                   @click="handleImport">导入
        <el-button
          type="success"
          size="small"
          plain
          icon="el-icon-upload2"
          @click="handleImport"
          >导入
        </el-button>
      </template>
      <template slot-scope="{ row }" slot="weight">
        <el-switch @change="isWeightInput($event, row,1)" v-model="row.weight" :active-value="1" :inactive-value="0"
          active-color="#13ce66" inactive-color="#ccc">
        </el-switch>
      </template>
      <template slot-scope="{ row }" slot="stationWeight">
        <el-switch @change="isWeightInput($event, row,2)" v-model="row.stationWeight" :active-value="1" :inactive-value="0"
          active-color="#13ce66" inactive-color="#ccc">
        </el-switch>
      </template>
    </avue-crud>
    <el-dialog title="小区数据导入"
               append-to-body
               :visible.sync="excelBox"
               width="555px">
      <avue-form :option="excelOption" v-model="excelForm" :upload-after="uploadAfter">
    <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>
@@ -43,365 +63,506 @@
</template>
<script>
  import {getPage, getDetails, add, update, remove} from "@/api/villageInfo/villageInfo";
  import {mapGetters} from "vuex";
  import {exportBlob} from "@/api/common";
  import {getToken} from "@/util/auth";
  import {downloadXls} from "@/util/util";
import {
  getPage,
  getDetails,
  add,
  update,
  remove,
  setWeight
} from "@/api/villageInfo/villageInfo";
import { mapGetters } from "vuex";
import { exportBlob } from "@/api/common";
import { getToken } from "@/util/auth";
import { downloadXls } from "@/util/util";
  export default {
    data() {
      return {
        excelBox:false,
        form: {},
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        excelOption: {
          submitBtn: false,
          emptyBtn: false,
          column: [
            {
              label: '模板上传',
              prop: 'excelFile',
              type: 'upload',
              drag: true,
              loadText: '模板上传中,请稍等',
              span: 24,
              propsHttp: {
                res: 'data'
export default {
  data() {
    return {
      excelBox: false,
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      excelOption: {
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "模板上传",
            prop: "excelFile",
            type: "upload",
            drag: true,
            loadText: "模板上传中,请稍等",
            span: 24,
            propsHttp: {
              res: "data",
            },
            tip: "请上传 .xls,.xlsx 标准格式文件",
            action: "/api/villageInfo/villageInfo/import-village-info",
          },
          {
            label: "数据覆盖",
            prop: "isCovered",
            type: "switch",
            align: "center",
            width: 80,
            dicData: [
              {
                label: "否",
                value: 0,
              },
              tip: '请上传 .xls,.xlsx 标准格式文件',
              action: "/api/villageInfo/villageInfo/import-village-info"
            },
            {
              label: "数据覆盖",
              prop: "isCovered",
              type: "switch",
              align: "center",
              width: 80,
              dicData: [
                {
                  label: "否",
                  value: 0
                },
                {
                  label: "是",
                  value: 1
                }
              ],
              value: 0,
              slot: true,
              rules: [
                {
                  required: true,
                  message: "请选择是否覆盖",
                  trigger: "blur"
                }
              ]
            },
            {
              label: '模板下载',
              prop: 'excelTemplate',
              formslot: true,
              span: 24,
            }
          ]
        },
        selectionList: [],
        option: {
          height:'auto',
          calcHeight: 30,
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          index: true,
          viewBtn: true,
          addBtn: false,
          editBtn: false,
          delBtn: false,
          // selection: true,
          menu:false,
          dialogClickModal: false,
          column: [
            {
              label: "主键",
              prop: "id",
              type: "input",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              hide: true,
            },
            {
              label: "小区名",
              prop: "aoiName",
              type: "input",
              search: true,
              rules: [{
              {
                label: "是",
                value: 1,
              },
            ],
            value: 0,
            slot: true,
            rules: [
              {
                required: true,
                message: "请选择是否覆盖",
                trigger: "blur",
              },
            ],
          },
          {
            label: "模板下载",
            prop: "excelTemplate",
            formslot: true,
            span: 24,
          },
        ],
      },
      selectionList: [],
      option: {
        height: "auto",
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        viewBtn: true,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        // selection: true,
        menu: false,
        dialogClickModal: false,
        column: [
          {
            label: "主键",
            prop: "id",
            type: "input",
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            hide: true,
          },
          {
            label: "小区名",
            prop: "aoiName",
            type: "input",
            search: true,
            searchSpan:5,
            rules: [
              {
                required: true,
                message: "请输入小区名",
                trigger: "blur"
              }],
            },
            {
              label: "小区范围",
              prop: "position",
              type: "input",
              rules: [{
                trigger: "blur",
              },
            ],
          },
          {
            label: "小区范围",
            prop: "position",
            type: "input",
            rules: [
              {
                required: true,
                message: "请输入小区范围",
                trigger: "blur"
              }],
            },
            {
              label: "责任区",
              prop: "areaName",
              addDisplay:false,
              editDisplay:false,
              viewDisplay:false,
              rules: [{
                required: true,
                message: "请选择所属责任区",
                trigger: "blur"
              }]
            },
            {
              label: "责任区",
              prop: "areaId",
              type: "tree",
              emitPath:false,
              hide:true,
              dicUrl: "api/policeStationInfo/policeStationInfo/getPoliceStationTwoTrees",
              parent:false,
              props:{
                label:'name',
                value:'id'
                trigger: "blur",
              },
              rules: [{
            ],
          },
          {
            label: "责任区",
            prop: "areaName",
            align:"center",
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            rules: [
              {
                required: true,
                message: "请选择所属责任区",
                trigger: "blur"
              }]
                trigger: "blur",
              },
            ],
          },
          {
            label: "派出所",
            prop: "policeStationName",
            searchSpan:4,
            align:"center",
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            search:true,
            rules: [
              {
                required: true,
                message: "请输入派出所",
                trigger: "blur",
              },
            ],
          },
          {
            label: "责任区",
            prop: "areaId",
            type: "tree",
            emitPath: false,
            hide: true,
            dicUrl:
              "api/policeStationInfo/policeStationInfo/getPoliceStationTwoTrees",
            parent: false,
            props: {
              label: "name",
              value: "id",
            },
            {
              label: "创建人",
              prop: "createUser",
              type: "input",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              hide: true,
            },
            {
              label: "创建部门",
              prop: "createDept",
              type: "input",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              hide: true,
            },
            {
              label: "创建时间",
              prop: "createTime",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
            },
            {
              label: "修改人",
              prop: "updateUser",
              type: "input",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              hide: true,
            },
            {
              label: "修改时间",
              prop: "updateTime",
              type: "input",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              hide: true,
            },
            {
              label: "状态",
              prop: "status",
              type: "input",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              hide: true,
            },
            {
              label: "是否已删除",
              prop: "isDeleted",
              type: "input",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              hide: true,
            },
          ]
        }
        ,
        data: []
            rules: [
              {
                required: true,
                message: "请选择所属责任区",
                trigger: "blur",
              },
            ],
          },
          {
            label: "是否分局默认小区",
            prop: "weight",
            type: "select",
            search:true,
            slot:true,
            searchSpan:4,
            align:"center",
            searchLabelWidth:130,
            dicData: [
              {
                label: "全部",
                value: "",
              },
              {
                label: "是",
                value: "1",
              },
              {
                label: "否",
                value: "0",
              },
            ],
            rules: [
              {
                required: true,
                message: "请选择所属责任区",
                trigger: "blur",
              },
            ],
          },
          {
            label: "是否派出所默认小区",
            prop: "stationWeight",
            type: "select",
            slot:true,
            search:true,
            searchSpan:4,
            align:"center",
            searchLabelWidth:150,
            dicData: [
              {
                label: "全部",
                value: "",
              },
              {
                label: "是",
                value: "1",
              },
              {
                label: "否",
                value: "0",
              },
            ],
            rules: [
              {
                required: true,
                message: "请选择所属责任区",
                trigger: "blur",
              },
            ],
          },
          {
            label: "创建人",
            prop: "createUser",
            type: "input",
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            hide: true,
          },
          {
            label: "创建部门",
            prop: "createDept",
            type: "input",
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            hide: true,
          },
          {
            label: "创建时间",
            prop: "createTime",
            align:"center",
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
          },
          {
            label: "修改人",
            prop: "updateUser",
            type: "input",
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            hide: true,
          },
          {
            label: "修改时间",
            prop: "updateTime",
            type: "input",
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            hide: true,
          },
          {
            label: "状态",
            prop: "status",
            type: "input",
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            hide: true,
          },
          {
            label: "是否已删除",
            prop: "isDeleted",
            type: "input",
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            hide: true,
          },
        ],
      },
      data: [],
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.community_add, false),
        viewBtn: this.vaildData(this.permission.community_view, false),
        delBtn: this.vaildData(this.permission.community_delete, false),
        editBtn: this.vaildData(this.permission.community_edit, false),
      };
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.community_add, false),
          viewBtn: this.vaildData(this.permission.community_view, false),
          delBtn: this.vaildData(this.permission.community_delete, false),
          editBtn: this.vaildData(this.permission.community_edit, false)
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
    methods: {
      rowSave(row, done, loading) {
        add(row).then(() => {
  },
  methods: {
    // 是否默认小区设置 type: 1:分局权重设置  2:派出所权重设置
    isWeightInput(e,row,type){
      if(!row.policeStationId){
        this.$message({
            type: "error",
            message: "无法匹配分局派出所,无法分配!",
          });
        return
      }
      if(type===1){
        row.weight = e
      }
      if(type===2){
        row.stationWeight = e
      }
      // 更新
      setWeight(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
            message: "操作成功!",
          });
          done();
        }, error => {
        },
        (error) => {
          loading();
          window.console.log(error);
        });
      },
      rowUpdate(row, index, done, loading) {
        update(row).then(() => {
        }
      );
    },
    rowSave(row, done, loading) {
      add(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
            message: "操作成功!",
          });
          done();
        }, error => {
        },
        (error) => {
          loading();
          window.console.log(error);
        }
      );
    },
    rowUpdate(row, index, done, loading) {
      update(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        (error) => {
          loading();
          console.log(error);
        });
      },
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(row.id);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      },
      handleDelete() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
      );
    },
    rowDel(row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(row.id);
        })
          .then(() => {
            return remove(this.ids);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crud.toggleSelection();
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
      },
      beforeOpen(done, type) {
        if (["edit", "view"].includes(type)) {
          getDetails(this.form.id).then(res => {
              this.form = res.data.data;
          });
        }
        done();
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        this.loading = true;
        getPage(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
      },
      //下面为导入操作
      handleImport() {
        this.excelBox = true;
      },
      uploadAfter(res, done, loading, column) {
        window.console.log(column);
        this.excelBox = false;
        this.refreshChange();
        done();
      },
      handleTemplate() {
        exportBlob(`/api/villageInfo/villageInfo/export-template?${this.website.tokenHeader}=${getToken()}`).then(res => {
          downloadXls(res.data, "小区数据模板.xlsx");
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(this.ids);
        })
      },
    }
  };
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.$refs.crud.toggleSelection();
        });
    },
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        getDetails(this.form.id).then((res) => {
          this.form = res.data.data;
        });
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getPage(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      ).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },
    //下面为导入操作
    handleImport() {
      this.excelBox = true;
    },
    uploadAfter(res, done, loading, column) {
      window.console.log(column);
      this.excelBox = false;
      this.refreshChange();
      done();
    },
    handleTemplate() {
      exportBlob(
        `/api/villageInfo/villageInfo/export-template?${
          this.website.tokenHeader
        }=${getToken()}`
      ).then((res) => {
        downloadXls(res.data, "小区数据模板.xlsx");
      });
    },
  },
};
</script>
<style>
</style>
<style></style>