index.vue 11.2 KB
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" @submit.native.prevent>
      <el-form-item label="标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入标题"
          size="small"
          type="text"
        />
        </el-form-item>
      <el-form-item>
        <el-button type="cyan" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['daily:report:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['daily:report:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['daily:report:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          size="mini"
          @click="handleExport"
          v-hasPermi="['daily:report:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="reportList" border @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键id" align="center" prop="id" />-->
      <el-table-column label="标题" align="center" prop="title" />
      <el-table-column label="填写人" align="center" prop="writer" />
      <el-table-column label="填写时间" align="center" prop="writeTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.writeTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleById(scope.row)"
            v-hasPermi="['daily:report:query']">
            查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改工作日报对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row type="flex" justify="center">
          <el-col>
            <el-form-item label="周期" prop="startTime">
              <el-input v-model="form.startTime" placeholder="周期" style="width: 300px"/>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="至" prop="endTime">
              <el-input v-model="form.endTime" placeholder="" style="width: 300px"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" justify="center">
          <el-col>
        <el-form-item label="填写时间" prop="writeTime">
          <el-date-picker  size="small" style="width: 300px"
            v-model="form.writeTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择填写时间">
          </el-date-picker>
        </el-form-item>
        </el-col>
        <el-col>
            <el-form-item label="填写人" prop="writer">
              <el-input v-model="form.writer" placeholder="请输入填写人" style="width: 300px"/>
            </el-form-item>
          </el-col>
       </el-row>
          <el-form-item label="标题" prop="title">
              <el-input v-model="form.title" placeholder="" />
            </el-form-item>
      <el-form-item label="报表内容">
        <editor v-model="form.reportContent" :min-height="192"/>
      </el-form-item>
      <a v-if="form.attachmentLink!='' " style="color: blue;margin-left: 10px;" @click="downloadFile(form.attachmentLink)">附件下载</a> <a style="color: red;" @click="form.attachmentLink='';" v-if="form.attachmentLink!=''">删除</a>
      <el-row>
        <el-col :span="6">
      <el-form-item label="附件" v-if="form.attachmentLink==''">
      <el-upload :headers="upload.headers" :action="upload.url" :file-list="fileList" :show-file-list="false"
        :on-success="uploadSuccess" >
        <el-button size="small" type="primary">选择附件</el-button>
        <el-input v-model="form.attachmentLink" disabled type="hidden"/>
      </el-upload>
      </el-form-item>
        </el-col>
      </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listReport, getReport, delReport, addReport, updateReport, exportReport } from "@/api/daily/report";
import Editor from '@/components/Editor';
import {getInformation_sharing} from "@/api/daily/information_sharing";
  import {
    getToken
  } from "@/utils/auth";

export default {
  name: "Report",
  props: {
    type: {
      type: Number
    }
  },
  components: { Editor },
  data() {
    return {
      // 遮罩层
      loading: true,
      border:true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工作日报表格数据
      reportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: null,
        type:0,
      },
      upload: {
        // 是否显示弹出层(用户导入)
        open: false,
        // 弹出层标题(用户导入)
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken()
        },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/business/threestep/upload",
      },
      titleType:"工作报表",
      // 表单参数
      form: {
          attachmentLink:'',
      },
      fileList:[],
      // 表单校验
      rules: {
        title: [
          { required: true, message: "标题不能为空", trigger: "blur" }
        ],
        writer: [
          { required: true, message: "填写人不能为空", trigger: "blur" }
        ],
        writeTime: [
          { required: true, message: "填写时间不能为空", trigger: "blur" }
        ],
        reportContent: [
          { required: true, message: "报表内容不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.queryParams.type = this.type;

    if(this.queryParams.type == 1){

      this.titleType = "日报";

    }else if(this.queryParams.type == 2){

      this.titleType = "周报";

    }else if(this.queryParams.type == 3){

      this.titleType = "月报";

    }
    this.getList();
  },
  methods: {

      downloadFile(path) {
        window.location.href = process.env.VUE_APP_BASE_API + "/business/threestep/download?path=" + encodeURI(path);
      },
    getList() {
      this.loading = true;
      listReport(this.queryParams).then(response => {
        this.reportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    uploadSuccess(res, file, fileList) {

      if(res.code){
        this.$message(res.message);
        return;
      }
      this.fileList = [];

      this.fileList.push(file);

      this.form.attachmentLink = res;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        title: null,
        writer: null,
        writeTime: null,
        reportContent: null,
        attachmentLink:'',
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加" + this.titleType;
      console.log(this.form.attachmentLink);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getReport(id).then(response => {
        this.form = response.data;
        if(this.form.attachmentLink == undefined){
          this.form.attachmentLink = '';
        }
        this.open = true;
        this.title = "修改" + this.titleType;
      });
    },
    /** 查看详情按钮操作*/
    handleById(row){
      this.reset();
      const  id = row.id ||this.ids
      getReport(id).then(response => {
        this.form = response.data;
        if(this.form.attachmentLink == undefined){
          this.form.attachmentLink = '';
        }
        this.open = true;
        this.title = "查看详情信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.type = this.queryParams.type;
          if (this.form.id != null) {
            updateReport(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addReport(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除' + this.titleType + '编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delReport(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有' + this.titleType + '数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportReport(queryParams);
        }).then(response => {
          this.download(response.message);
        })
    }
  }
};
</script>