<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item prop="projectId">
        <el-select v-model="queryType" style="width: 100px;">
          <el-option label="项目编号" value="1"></el-option>
          <el-option label="项目名称" value="2"></el-option>
        </el-select>
        <el-select v-model="queryParams.projectId" clearable filterable remote reserve-keyword placeholder="请输入关键字"
          :remote-method="remoteMethod" :loading="loading" style="width: 300px;">
          <el-option v-for="project in projectList" :key="project.projectId"
            :label="project.projectNumber + '-' + project.projectName" :value="project.projectId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="归档人" prop="archiver">
        <el-select v-model="queryParams.archiver" filterable clearable @change="handleQuery">
          <el-option v-for="item in $store.state.user.userList" :key="item.userId" :label="item.nickName"
            :value="item.userId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="成果提交日期" prop="submitTime" label-width="128px">
        <el-date-picker clearable v-model="queryParams.submitTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择成果提交日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="归档时间" prop="archiveTime">
        <el-date-picker clearable v-model="queryParams.archiveTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择归档时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['oa:archive:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="archiveList" @selection-change="handleSelectionChange">
      <el-table-column type="index" label="序号" width="55" align="center" />
      <el-table-column label="项目编号" align="center" prop="project.projectNumber" />
      <el-table-column label="项目名称" align="center" prop="project.projectName" />
      <el-table-column label="备注说明" align="center" :show-overflow-tooltip="true" width="150" prop="submitSituation" />
      <el-table-column label="发起人" align="center" prop="leaderUser.nickName" />
      <!-- <el-table-column label="生产部门检查员" align="center" prop="produceUser.nickName" /> -->
      <!-- <el-table-column label="质量检查员" align="center" prop="qualityUser.nickName" /> -->
      <el-table-column label="技术质量与安全部意见" align="center" :show-overflow-tooltip="true" width="150" prop="deptComment" />
      <el-table-column label="技术质量与安全部负责人" align="center" width="170" prop="deptUser.nickName" />
      <el-table-column label="归档人" align="center" prop="archiveUser.nickName" />
      <el-table-column label="成果提交日期" align="center" prop="submitTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.submitTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="资料接收时间" align="center" prop="receiveTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.receiveTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="质量检查时间" align="center" prop="qualityTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.qualityTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产部门检查时间" align="center" prop="produceTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.produceTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="技术质量与安全部审核时间" align="center" prop="deptTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deptTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="归档时间" align="center" prop="archiveTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.archiveTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="生产部门意见" align="center" prop="produceComment" />
      <el-table-column label="质量检查意见" align="center" prop="qualityComment" />
      <el-table-column label="技术质量与安全部审核意见" align="center" prop="deptComment" />
      <el-table-column label="归档审核意见" align="center" prop="archiveComment" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)"
            v-hasPermi="['oa:archive: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="infoOpen" width="70%" append-to-body>
      <archive-form :taskForm="taskForm" :taskName="''" :isFlow="false"></archive-form>
    </el-dialog>
  </div>
</template>

<script>
import { listArchive, getArchive, delArchive, addArchive, updateArchive } from "@/api/oa/archive/archive";
import { listProject } from '@/api/oa/project/project';
import archiveForm from '../../flowable/form/archiveForm.vue';

export default {
  components: { archiveForm },
  name: "Archive",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // cmc成果归档表格数据
      archiveList: [],
      projectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: null,
        submitTime: null,
        submitSituation: null,
        locationLng: null,
        locationLat: null,
        produceInspector: null,
        qualityInspector: null,
        deptLeader: null,
        archiver: null,
        receiveTime: null,
        qualityTime: null,
        produceTime: null,
        deptTime: null,
        archiveTime: null,
        produceComment: null,
        qualityComment: null,
        deptComment: null,
        archiveComment: null
      },
      // 表单参数
      form: {},
      taskForm: {
        formId: ''
      },
      // 表单校验
      rules: {
      },
      infoOpen: false,
      queryType: '1',
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询cmc成果归档列表 */
    getList() {
      this.loading = true;
      listArchive(this.queryParams).then(response => {
        this.archiveList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    remoteMethod(val) {
      let params1 = {
        pageNum: 1,
        pageSize: 20,
        projectNumber: val
      }
      let params2 = {
        pageNum: 1,
        pageSize: 20,
        projectName: val
      }
      let params = {};
      if (this.queryType == '1') {
        params = params1
      } else {
        params = params2
      }
      listProject(params).then(res => {
        this.projectList = res.rows;
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        archiveId: null,
        projectId: null,
        submitTime: null,
        submitSituation: null,
        locationLng: null,
        locationLat: null,
        produceInspector: null,
        qualityInspector: null,
        deptLeader: null,
        archiver: null,
        receiveTime: null,
        qualityTime: null,
        produceTime: null,
        deptTime: null,
        archiveTime: null,
        produceComment: null,
        qualityComment: null,
        deptComment: null,
        archiveComment: null
      };
      this.resetForm("form");
    },
    handleView(row) {
      this.taskForm.formId = row.archiveId;
      this.infoOpen = true;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.archiveId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加cmc成果归档";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const archiveId = row.archiveId || this.ids
      getArchive(archiveId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改cmc成果归档";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.archiveId != null) {
            updateArchive(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addArchive(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const archiveIds = row.archiveId || this.ids;
      this.$modal.confirm('是否确认删除cmc成果归档编号为"' + archiveIds + '"的数据项？').then(function () {
        return delArchive(archiveIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('oa/archive/export', {
        ...this.queryParams
      }, `archive_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
