From f02caef2e782b578b2a29b84b59b15e2f43648f2 Mon Sep 17 00:00:00 2001
From: zhongrj <646384940@qq.com>
Date: Mon, 20 Feb 2023 17:29:18 +0800
Subject: [PATCH] 警员,值班新增导入

---
 src/views/scheduling/scheduling.vue |  594 +++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 331 insertions(+), 263 deletions(-)

diff --git a/src/views/scheduling/scheduling.vue b/src/views/scheduling/scheduling.vue
index f1b820b..c0dd957 100644
--- a/src/views/scheduling/scheduling.vue
+++ b/src/views/scheduling/scheduling.vue
@@ -1,283 +1,351 @@
 <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
-                   size="small"
-                   icon="el-icon-delete"
-                   plain
-                   v-if="permission.scheduling_delete"
-                   @click="handleDelete">删 除
+        <el-button size="small" icon="el-icon-delete" plain v-if="permission.scheduling_delete" @click="handleDelete">删 除
+        </el-button>
+        <el-button type="success" size="small" plain icon="el-icon-upload2" @click="handleImport">导入
         </el-button>
       </template>
     </avue-crud>
+    <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 {getList, getDetail, add, update, remove, getPliceman} from "@/api/scheduling/scheduling";
-  import {mapGetters} from "vuex";
+import { getList, getDetail, add, update, remove, getPliceman } from "@/api/scheduling/scheduling";
+import { mapGetters } from "vuex";
+import { exportBlob } from "@/api/common";
+import { downloadXls } from "@/util/util";
+import { getToken } from "@/util/auth";
 
-  export default {
-    data() {
-      return {
-        form: {},
-        query: {},
-        loading: true,
-        page: {
-          pageSize: 10,
-          currentPage: 1,
-          total: 0
-        },
-        selectionList: [],
-        option: {
-          height: 'auto',
-          calcHeight: 30,
-          dialogWidth: 950,
-          tip: false,
-          searchShow: true,
-          searchMenuSpan: 6,
-          border: true,
-          index: true,
-          viewBtn: true,
-          selection: true,
-          excelBtn: true,
-          dialogClickModal: false,
-          column: [
-            {
-              label: "值班员",
-              prop: "person",
-              search:true,
-              type: "select",
-              dicUrl: "/api/policeman/policeman/all",
-              props: {
-                label: "name",
-                value: "id"
+export default {
+  data() {
+    return {
+      form: {},
+      query: {},
+      loading: true,
+      page: {
+        pageSize: 10,
+        currentPage: 1,
+        total: 0
+      },
+      selectionList: [],
+      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/scheduling/scheduling/import-scheduling"
+          },
+          {
+            label: "数据覆盖",
+            prop: "isCovered",
+            type: "switch",
+            align: "center",
+            width: 80,
+            dicData: [
+              {
+                label: "否",
+                value: 0
+              },
+              {
+                label: "是",
+                value: 1
               }
-            },
-            {
-              label: "联系方式",
-              prop: "contact",
-            },
-            {
-              label: "值班岗位",
-              prop: "station",
-              row: true,
-              span: 24
-            },
-            {
-              label: "值班时间",
-              prop: "startTime",
-              type: "datetime",
-              defaultTime: '00:00:00',
-              format: "yyyy-MM-dd",
-              valueFormat: "yyyy-MM-dd HH:mm:ss",
-              rules: [{
+            ],
+            value: 0,
+            slot: true,
+            rules: [
+              {
                 required: true,
-                message: "请选择值班时间",
+                message: "请选择是否覆盖",
                 trigger: "blur"
-              }],
-            },
-            {
-              label: "带班领导",
-              prop: "leads",
-              type: "select",
-              dicUrl: "/api/policeman/policeman/all",
-              props: {
-                label: "name",
-                value: "id"
               }
-            },
-            {
-              label: "联系方式",
-              prop: "leadContact",
-            },
-          ]
-        },
-        data: [],
-        policemanList: []
+            ]
+          },
+          {
+            label: '模板下载',
+            prop: 'excelTemplate',
+            formslot: true,
+            span: 24,
+          }
+        ]
+      },
+      option: {
+        height: 'auto',
+        calcHeight: 30,
+        dialogWidth: 950,
+        tip: false,
+        searchShow: true,
+        searchMenuSpan: 6,
+        border: true,
+        index: true,
+        viewBtn: true,
+        addBtn: false,
+        editBtn: false,
+        selection: true,
+        excelBtn: true,
+        dialogClickModal: false,
+        column: [
+          {
+            label: "值班单位",
+            prop: "dept",
+            row: true,
+            span: 24
+          },
+          {
+            label: "值班日期",
+            prop: "day",
+            type: "date",
+            format: "yyyy-MM-dd",
+            valueFormat: "yyyy-MM-dd",
+            rules: [{
+              required: true,
+              message: "请选择值班日期",
+              trigger: "blur"
+            }],
+          },
+          {
+            label: "值班员",
+            prop: "person",
+            search: true,
+          },
+          {
+            label: "联系方式",
+            prop: "contact",
+          },
+          {
+            label: "值班类型",
+            prop: "type",
+          },
+          {
+            label: "带班领导",
+            prop: "leads",
+            type: "select",
+            dicUrl: "/api/policeman/policeman/all",
+            props: {
+              label: "name",
+              value: "id"
+            }
+          },
+          {
+            label: "联系方式",
+            prop: "leadContact",
+          },
+
+        ]
+      },
+      data: [],
+      policemanList: []
+    };
+  },
+  computed: {
+    ...mapGetters(["permission"]),
+    permissionList() {
+      return {
+        addBtn: this.vaildData(this.permission.scheduling_add, false),
+        viewBtn: this.vaildData(this.permission.scheduling_view, false),
+        delBtn: this.vaildData(this.permission.scheduling_delete, false),
+        editBtn: this.vaildData(this.permission.scheduling_edit, false)
       };
     },
-    computed: {
-      ...mapGetters(["permission"]),
-      permissionList() {
-        return {
-          addBtn: this.vaildData(this.permission.scheduling_add, false),
-          viewBtn: this.vaildData(this.permission.scheduling_view, false),
-          delBtn: this.vaildData(this.permission.scheduling_delete, false),
-          editBtn: this.vaildData(this.permission.scheduling_edit, false)
-        };
-      },
-      ids() {
-        let ids = [];
-        this.selectionList.forEach(ele => {
-          ids.push(ele.id);
-        });
-        return ids.join(",");
-      }
-    },
-    watch: {
-      'form.person': {
-        handler(res) {
-          this.policemanList.forEach(e => {
-            if (res == e.id) {
-              this.form.contact = e.contact
-            }
-          })
-        }
-      },
-      'form.leads': {
-        handler(res) {
-          this.policemanList.forEach(e => {
-            if (res == e.id) {
-              this.form.leadContact = e.contact
-            }
-          })
-        }
-      },
-    },
-    created() {
-      this.getPolicemanAll();
-    },
-    methods: {
-      rowSave(row, done, loading) {
-        add(row).then(() => {
-          this.onLoad(this.page);
-          this.$message({
-            type: "success",
-            message: "操作成功!"
-          });
-          done();
-        }, 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"
-        })
-          .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;
-        getList(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();
-        });
-      },
-      getPolicemanAll() {
-        getPliceman().then(res => {
-          this.policemanList = res.data.data
-          const securityIdColumn = this.findObject(this.option.column, "person")
-          securityIdColumn.dicData = this.policemanList
-          const securityIdColumns = this.findObject(this.option.column, "leads")
-          securityIdColumns.dicData = this.policemanList
-        })
-      }
+    ids() {
+      let ids = [];
+      this.selectionList.forEach(ele => {
+        ids.push(ele.id);
+      });
+      return ids.join(",");
     }
-  };
+  },
+  watch: {
+    'form.person': {
+      handler(res) {
+        this.policemanList.forEach(e => {
+          if (res == e.id) {
+            this.form.contact = e.contact
+          }
+        })
+      }
+    },
+    'form.leads': {
+      handler(res) {
+        this.policemanList.forEach(e => {
+          if (res == e.id) {
+            this.form.leadContact = e.contact
+          }
+        })
+      }
+    },
+    'excelForm.isCovered'() {
+      if (this.excelForm.isCovered !== '') {
+        const column = this.findObject(this.excelOption.column, "excelFile");
+        column.action = `/api/scheduling/scheduling/import-scheduling?isCovered=${this.excelForm.isCovered}`;
+      }
+    },
+  },
+  created() {
+    this.getPolicemanAll();
+  },
+  methods: {
+    rowSave(row, done, loading) {
+      add(row).then(() => {
+        this.onLoad(this.page);
+        this.$message({
+          type: "success",
+          message: "操作成功!"
+        });
+        done();
+      }, 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"
+      })
+        .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;
+      getList(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();
+      });
+    },
+    getPolicemanAll() {
+      getPliceman().then(res => {
+        this.policemanList = res.data.data
+        const securityIdColumn = this.findObject(this.option.column, "person")
+        securityIdColumn.dicData = this.policemanList
+        const securityIdColumns = this.findObject(this.option.column, "leads")
+        securityIdColumns.dicData = this.policemanList
+      })
+    },
+    //下面为导入操作
+    handleImport() {
+      this.excelBox = true;
+    },
+    uploadAfter(res, done, loading, column) {
+      window.console.log(column);
+      this.excelBox = false;
+      this.refreshChange();
+      done();
+    },
+    handleTemplate() {
+      exportBlob(`/api/scheduling/scheduling/export-template?${this.website.tokenHeader}=${getToken()}`).then(res => {
+        downloadXls(res.data, "值班信息数据模板.xlsx");
+      })
+    },
+  }
+};
 </script>
 
-<style>
-</style>
+<style></style>

--
Gitblit v1.9.3