zengh
2022-09-14 273c9401106930d437fae33ae0228d6a5b4decf0
src/views/wel/openUp.vue
@@ -1,284 +1,236 @@
<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>
  </basic-container>
    <basic-container>
        <avue-crud
            :option="option"
            :table-loading="loading"
            :data="data"
            :page.sync="page"
            :permission="permissionList"
            ref="crud"
            v-model="form"
            @search-change="searchChange"
            @search-reset="searchReset"
            @selection-change="selectionChange"
            @current-change="currentChange"
            @size-change="sizeChange"
            @refresh-change="refreshChange"
            @on-load="onLoad"
        ></avue-crud>
    </basic-container>
</template>
<script>
import { getOpenup } from "@/api/home/home";
import { mapGetters } from "vuex";
import { mapGetters } from "vuex"
import { getTeamDetail } from "@/api/home/team"
export default {
  props: ["id"],
  watch: {
    id() {
      this.searchReset();
    props: ["id"],
    watch: {
        id () {
            this.searchReset()
        },
    },
  },
  data() {
    return {
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      option: {
        height: "525px",
        calcHeight: 54,
        tip: false,
        searchShow: true,
        searchMenuSpan: 4,
        border: true,
        index: true,
        viewBtn: true,
        menu: false,
        selection: true,
        headerAlign: "center",
        align: "center",
        dialogClickModal: false,
        column: [
          //   {
          //     label: "账号",
          //     search: true,
          //     searchSpan: 4,
          //     display: false,
          //     disabled: true,
          //     prop: "account",
          //   },
          {
            label: "姓名",
            display: false,
            searchSpan: 4,
            searchLabelWidth: 55,
            search: true,
            disabled: true,
            prop: "realName",
          },
          {
            label: "性别",
            display: false,
            searchSpan: 4,
            // search: true,
            disabled: true,
            prop: "sex",
            type: "select",
            dicData: [
              {
                label: "男",
                value: 1,
              },
              {
                label: "女",
                value: 2,
              },
            ],
          },
          {
            label: "身份证",
            disabled: true,
            display: false,
            searchLabelWidth: 70,
            search: true,
            prop: "cardid",
          },
          {
            label: "手机号码",
            disabled: true,
            display: false,
            prop: "phone",
          },
          {
            label: "辖区",
            prop: "jurisdiction",
            type: "tree",
            dicUrl: "/api/jurisdiction/lazy-tree",
            props: {
              label: "title",
              value: "value"
    data () {
        return {
            form: {},
            query: {},
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0
            },
          },
          // {
          //   label: "部门",
          //   prop: "deptName",
          //   // type: "tree",
          //   // dicUrl: "/api/blade-system/dept/selectInfo",
          //   // props: {
          //   //   label: "title",
          //   //   value: "value"
          //   // },
          // },
        ],
      },
      data: [],
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.zc_add, false),
        viewBtn: this.vaildData(this.permission.zc_view, true),
        delBtn: this.vaildData(this.permission.zc_delete, false),
        editBtn: this.vaildData(this.permission.zc_edit, false),
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
  },
  methods: {
    handleEdit(row, index) {
      this.$refs.crud.rowEdit(row, index);
    },
    rowSave(row, done, loading) {
      add(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        (error) => {
          loading();
          window.console.log(error);
            selectionList: [],
            option: {
                height: 'auto',
                calcHeight: 54,
                labelWidth: "100",
                dialogWidth: 950,
                tip: false,
                border: true,
                index: true,
                viewBtn: true,
                header: false,
                addBtn: false,
                excelBtn: false,
                selection: true,
                dialogClickModal: false,
                column: [
                    {
                        label: "队伍名称",
                        prop: "name",
                        rules: [{
                            required: true,
                            message: "请输入队伍名称",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: "所属派出所",
                        prop: "police",
                        overHidden: true,
                        parent: false,
                        type: "tree",
                        dicUrl: "/api/jurisdiction/lazy-tree",
                        props: {
                            label: "title",
                            value: "id",
                        },
                        checkStrictly: true,
                        rules: [
                            {
                                required: true,
                                message: "请选择所属派出所",
                                trigger: "click",
                            },
                        ],
                    },
                    {
                        label: "队标",
                        prop: "url",
                        // align:'center',
                        width: 80,
                        type: "upload",
                        listType: "picture-img",
                        action: "/api/blade-resource/oss/endpoint/put-file",
                        propsHttp: {
                            res: "data",
                            url: "link",
                        },
                        // hide: true,
                        span: 24,
                    },
                    {
                        label: "队伍人数",
                        prop: "number",
                        type: "number",
                        rules: [{
                            required: true,
                            message: "请输入队伍人数",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: "队伍口号",
                        prop: "slogan",
                    },
                    {
                        label: "品牌队伍",
                        prop: "isBrand",
                        type: "select",
                        value: "0",
                        rules: [
                            {
                                required: true,
                                message: "请选择是否品牌队伍",
                                trigger: "blur",
                            },
                        ],
                        dicData: [
                            {
                                label: "是",
                                value: "1",
                            },
                            {
                                label: "否",
                                value: "0",
                            },
                        ],
                    },
                    {
                        label: "创建人",
                        prop: "realName",
                        addDisplay: false,
                        editDisplay: false,
                        viewDisplay: false,
                    },
                    {
                        label: "创建时间",
                        prop: "createTime",
                        type: "date",
                        format: "yyyy-MM-dd",
                        valueFormat: "yyyy-MM-dd",
                        addDisplay: false,
                        editDisplay: false,
                        viewDisplay: false,
                    },
                ]
            },
            data: []
        }
      );
    },
    rowUpdate(row, index, done, loading) {
      update(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
    computed: {
        ...mapGetters(["permission"]),
        permissionList () {
            return {
                addBtn: this.vaildData(this.permission.zc_add, false),
                viewBtn: this.vaildData(this.permission.zc_view, true),
                delBtn: this.vaildData(this.permission.zc_delete, false),
                editBtn: this.vaildData(this.permission.zc_edit, false),
            }
        },
        (error) => {
          loading();
          console.log(error);
        ids () {
            let ids = []
            this.selectionList.forEach(ele => {
                ids.push(ele.id)
            })
            return ids.join(",")
        }
      );
    },
    rowDel(row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        });
    mounted () {
    },
    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)) {
        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;
      params["roleId"] = this.id;
      getOpenup(
        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();
      });
    },
  },
    methods: {
        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
            params["police"] = this.id
            getTeamDetail(
                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()
                this.$nextTick(() => {
                    this.$refs.crud.doLayout()
                    this.$refs.crud.refreshTable()
                })
            })
        }
    }
};
</script>