liuyg
2021-07-21 aedf54d825771471a208663bc8d627c71521864d
src/views/securityCompany/security.vue
@@ -6,275 +6,418 @@
 * menu-name 保安服务公司查询
 */
<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"
                   @row-click="handleRowClick"
                   @on-load="onLoad">
  <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"
      @row-click="handleRowClick"
      @on-load="onLoad"
    >
      <template slot-scope="{ type, size, row }" slot="menu">
        <el-button
          :size="size"
          :type="type"
          class="zhengJian-icon"
          @click.stop="punish(row)"
          >处罚</el-button
        >
      </template></avue-crud
    >
    <el-dialog
      title="处罚"
      :visible.sync="dialogVisible"
      width="60%"
      :before-close="handleClose"
      :modal-append-to-body="false"
      center
    >
      <!-- <span>这是一段信息</span> -->
      <avue-form
        :option="optionf"
        v-model="objf"
        @submit="submitf"
        @error="errorf"
      >
        <template slot-scope="{ type, size, row }" slot="menuForm">
          <el-button
            :size="size"
            icon="el-icon-error"
            :type="type"
            @click="close(row)"
            >关闭</el-button
          >
        </template>
      </avue-form>
      <!-- <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span> -->
    </el-dialog>
  </basic-container>
</template>
        </avue-crud>
    </basic-container>
</template>
<script>
import { getList, getDetail, add, update, remove } from "@/api/securityCompany/security";
import {
  getList,
  getDetail,
  add,
  update,
  remove,
} from "@/api/securityCompany/security";
import { mapGetters } from "vuex";
export default {
    data () {
        return {
            form: {},
            query: {},
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0
  data() {
    return {
      objf: {},
      optionf: {
        column: [
          {
            label: "公司名称",
            prop: "enterprisename",
            span: 24,
            labelWidth: 110,
            rules: [
              {
                required: true,
                message: "请输入身份证号码",
                trigger: "blur",
              },
            ],
          },
          {
            label: "处罚原因",
            prop: "sex",
            span: 24,
            labelWidth: 110,
            rules: [
              {
                required: true,
                message: "请输入荣誉名称",
                trigger: "blur",
              },
            ],
          },
          {
            label: "处罚内容",
            prop: "sex1",
            span: 24,
            type: "textarea",
            labelWidth: 110,
          },
          //   {
          //     label: "授予单位名称",
          //     prop: "sex2",
          //     span: 24,
          //     labelWidth: 110,
          //   },
        ],
      },
      dialogVisible: false,
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      option: {
        // 操作栏多余按钮去除
        delBtn: false,
        editBtn: false,
        addBtn: false,
        selection: false,
        searchShowBtn: false,
        // menu: false,
        align: "center",
        height: "auto",
        calcHeight: 30,
        tip: false,
        searchShow: true,
        menuWidth: 100,
        searchMenuSpan: 6,
        index: true,
        viewBtn: true,
        dialogClickModal: false,
        column: [
          {
            label: "公司名称",
            prop: "enterprisename",
            search: true,
            searchSpan: 4,
            width: 150,
            overHidden: true,
            display: false,
          },
          {
            label: "法定代表人",
            prop: "representative",
            display: false,
            width: 120,
          },
          {
            label: "成立日期",
            prop: "establishtime",
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            mock: {
              type: "datetime",
              format: "yyyy-MM-dd",
            },
            selectionList: [],
            option: {
                // 操作栏多余按钮去除
                delBtn: false,
                editBtn: false,
                addBtn: false,
                selection: false,
                menu: false,
                align: 'center',
                height: 'auto',
                calcHeight: 30,
                tip: false,
                searchShow: true,
                searchMenuSpan: 6,
                index: true,
                viewBtn: true,
                dialogClickModal: false,
                column: [
                    {
                        label: "公司名称",
                        prop: "enterprisename",
                        search: true,
                        searchSpan: 4,
                        display: false,
                    },
                    {
                        label: "法定代表人",
                        prop: "representative",
                        display: false,
                        width: 120
                    },
                    {
                        label: "成立日期",
                        prop: "establishtime",
                        type: "date",
                        format: 'yyyy-MM-dd',
                        valueFormat: 'yyyy-MM-dd',
                        mock: {
                            type: 'datetime',
                            format: 'yyyy-MM-dd'
                        },
                        search: true,
                        searchSpan: 4,
                        display: false,
                        width: 180
                    },
                    {
                        label: "注册资金",
                        prop: "registeredcapital",
                        display: false,
                        width: 200
                    },
                    {
                        label: "实缴资金",
                        prop: "capital",
                        display: false,
                        width: 200
                    },
                    {
                        label: "公司类型",
                        prop: "enterprises",
                        display: false,
                    },
                    {
                        label: "注册地址",
                        prop: "address",
                        display: false,
                        width: 200
                    }
                ]
                ,
                group: [
                    {
                        label: '详细信息',
                        prop: 'baseInfo',
                        icon: 'el-icon-user-solid',
                        column: [
                            {
                                label: "公司名称",
                                prop: "enterprisename",
                                display: false,
                            },
                        ]
                    },
                    {
                        label: '详细信息',
                        prop: 'detailInfo',
                        icon: 'el-icon-s-order',
                        column: [
                        ]
                    },
                    {
                        label: '职责信息',
                        prop: 'dutyInfo',
                        icon: 'el-icon-s-custom',
                        column: [
                        ]
                    },
                ]
            },
            data: []
        };
            search: true,
            searchSpan: 4,
            display: false,
            width: 180,
          },
          {
            label: "注册资金",
            prop: "registeredcapital",
            display: false,
            width: 200,
          },
          {
            label: "实缴资金",
            prop: "capital",
            display: false,
            width: 200,
          },
          {
            label: "公司类型",
            prop: "enterprises",
            display: false,
            overHidden: true,
          },
          {
            label: "注册地址",
            prop: "address",
            display: false,
            width: 200,
          },
        ],
        group: [
          {
            label: "详细信息",
            prop: "baseInfo",
            icon: "el-icon-user-solid",
            column: [
              {
                label: "公司名称",
                prop: "enterprisename",
                display: false,
              },
            ],
          },
          {
            label: "详细信息",
            prop: "detailInfo",
            icon: "el-icon-s-order",
            column: [],
          },
          {
            label: "职责信息",
            prop: "dutyInfo",
            icon: "el-icon-s-custom",
            column: [],
          },
        ],
      },
      data: [],
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.post_add, false),
        viewBtn: this.vaildData(this.permission.post_view, false),
        delBtn: this.vaildData(this.permission.post_delete, false),
        editBtn: this.vaildData(this.permission.post_edit, false),
      };
    },
    computed: {
        ...mapGetters(["permission"]),
        permissionList () {
            return {
                addBtn: this.vaildData(this.permission.post_add, false),
                viewBtn: this.vaildData(this.permission.post_view, false),
                delBtn: this.vaildData(this.permission.post_delete, false),
                editBtn: this.vaildData(this.permission.post_edit, false)
            };
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
  },
  methods: {
    close(row) {
      this.dialogVisible = false;
    },
    submit(form, done) {
      this.$message.success(JSON.stringify(form));
      done();
    },
    error(err) {
      this.$message.success("请查看控制台");
      console.log(err);
    },
    handleClose(done) {
      this.objf = {};
      done();
    },
    punish(row) {
      //打开处罚
      // console.log(row);
      this.objf = {
        enterprisename: row.enterprisename,
      };
      this.dialogVisible = true;
    },
    rowSave(row, done, loading) {
      add(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        ids () {
            let ids = [];
            this.selectionList.forEach(ele => {
                ids.push(ele.id);
            });
            return ids.join(",");
        (error) => {
          window.console.log(error);
          loading();
        }
      );
    },
    methods: {
        rowSave (row, done, loading) {
            add(row).then(() => {
                this.onLoad(this.page);
                this.$message({
                    type: "success",
                    message: "操作成功!"
                });
                done();
            }, error => {
                window.console.log(error);
                loading();
            });
    rowUpdate(row, index, done, loading) {
      update(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        rowUpdate (row, index, done, loading) {
            update(row).then(() => {
                this.onLoad(this.page);
                this.$message({
                    type: "success",
                    message: "操作成功!"
                });
                done();
            }, error => {
                window.console.log(error);
                loading();
            });
        },
        rowDel (row) {
            this.$confirm("确定将选择数据删除?", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(() => {
                    return remove(row.id);
                })
                .then(() => {
                    this.onLoad(this.page);
                    this.$message({
                        type: "success",
                        message: "操作成功!"
                    });
                });
        },
        beforeOpen (done, type) {
            if (["edit", "view"].includes(type)) {
                getDetail(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;
            getList(page.currentPage, page.pageSize, Object.assign(params, this.query), 2).then(res => {
                const data = res.data.data;
                this.page.total = data.total;
                this.data = data.records;
                this.loading = false;
                this.selectionClear();
            });
        },
        (error) => {
          window.console.log(error);
          loading();
        }
      );
    },
    rowDel(row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        });
    },
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        getDetail(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;
      getList(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query),
        2
      ).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },
    // 行单击
    handleRowClick(row) {
      // delete (row["name"]);
      var obj = row;
      obj["name"] = "保安公司详细信息";
      this.$router.push({
        path: `/securityCompany/index`,
        query: obj,
      });
        // 行单击
        handleRowClick (row) {
            // delete (row["name"]);
            var obj = row
            obj["name"] = "保安公司详细资料"
            this.$router.push({
                path: `/securityCompany/index`,
                query: obj,
            });
      var flag = false,
        i = 0,
        ind = null;
        },
    }
      this.$store.state.tags.tagList.forEach((item, index) => {
        if (item.label == "保安公司详细信息") {
          if (flag == false) {
            ind = index;
            flag = true;
          }
          i++;
        }
      });
      if (i > 1) {
        this.$store.state.tags.tagList.splice(ind, 1);
      }
    },
  },
};
</script>