<template>
  <div class="workbench-box">
    <header>
      <div class="workbench-serch">
        <div class="workbench-title">
          <div class="title-item">
            查企业
          </div>
          <div class="title-item">
            查项目
          </div>
          <div class="title-item">
            查荣誉
          </div>
        </div>
        <div class="workbench-btn">
          <el-input placeholder="请输入企业名称、项目名称、荣誉，查询" v-model="search" class="input-with-select">
            <template slot="append" class="work-btn">搜索</template>
          </el-input>
        </div>
      </div>
    </header>
    <main>
      <el-row class="main-row">
        <el-col :span="16" class="work-main-left">
          <div class="main-left">
            
          </div>
        </el-col>
        <el-col :span="8" class="work-main-right">
          <div class="main-right">
            <div class="right-header">
              <div class="title">【待办提醒】</div>
              <el-button @click="MoreRecords" type="text" v-if="backlogArray.length > 0">>> 更多记录</el-button>
            </div>
            <div class="right-main" v-if="backlogArray.length > 0">
              <div class="main-items" v-for="(item,index) in backlogArray" :key="index" :class="index % 2 == 0 ? '':'main-item'">
                <div>{{ item.projectName }}</div>
                <div>审批【知识产权】材料</div>
                <div @click="MoreRecords">去审批</div>
              </div>
            </div>
            <div class="right-main" v-else>
              <el-divider content-position="center">暂未待审核</el-divider>
            </div>
          </div>
        </el-col>
      </el-row>
    </main>
    <!-- 申报审核对话框 -->
    <!-- <el-dialog title="申报审核" :visible.sync="open" width="600px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" label-position="left">
        <el-row>
          <el-col :span="24">
            <el-form-item label="审批状态" prop="approvalStatus">
              <el-radio-group v-model="form.approvalStatus">
                <el-radio label="1">审批通过</el-radio>
                <el-radio label="2">审批驳回</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="审批意见" prop="approvalOpinions">
              <el-input v-model="form.approvalOpinions" type="textarea" placeholder="请输入审批意见" maxlength="200"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="审批附件" prop="fileList">
              <el-upload
                class="upload-demo"
                :show-file-list="false"
                action=""
                accept=".xlsx,.XLSX,.XSL,.doc,.xls,.ppt,.pdf,.png,.jpg,.jpeg,.rar,.zip,.docx"
                :http-request="handleFileUpload"
                :file-list="fileList"
                >
                <el-button slot="trigger" size="small" type="success">上传文件</el-button>
                <div slot="tip" class="el-upload__tip">请上传格式为<span style="color: red;">doc/xls/ppt/pdf/png/jpg/jpeg/rar/zip/docx/xlsx</span>的文件</div>
              </el-upload>
              <ul v-if="fileList.length >0" class="upload_ul">
                <li v-for="item in uploadList" :key="item.url" class="upload_li">
                  <img src="@/assets/images/uploadBgc.jpg" class="li_img" alt="">
                  <span class="icon_name">{{ item.name }}</span>
                  <el-button type="text" style="color: red;" @click="deleteUpload(item)">删除</el-button>
                </li>
              </ul>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>
<script>
import { approvalList, approvalEdit, uploadFile } from "@/api/onlineDeclartion/pendingReview"
export default {
  data() {
    return {
      search:"",
      backlogArray:[],
      pagination: {
        pageNum:1,
        pageSize:10,
        approvalStatusStr: 0,
      },
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {
        approvalOpinions: ''
      },
      // 表单校验
      rules: {
        approvalStatus: [
          { required: true, message: "请选择审批状态", trigger: "blur" }
        ],
        approvalOpinions: [
          { required: true, message: "名录维护方式不能为空", trigger: "blur" }
        ],
      },
      fileList: [],
      uploadList: [],
    }
  },
  mounted(){
    this.getList();
  },
  methods:{
    getList(){
      approvalList(this.pagination).then(res=>{
        // console.log(res);
        this.backlogArray = res.rows
      })
    },
    // 更多记录
    MoreRecords(){
      this.$router.push({
        name: 'PendingReview',
        params: { approvalStatusStr: "0" }
      })
    },
    // 审批弹框
    handleApproval(row) {
      this.reset();
      this.form.declarationRecordsId = row.declarationRecordsId
      this.open = true;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        approvalOpinions: '',
        approvalStatus: '1',
        approvalAttachment: '',
      };
      this.resetForm("form");
      this.uploadList = []
    },
    handleFileUpload(params) {
      const file = params.file
      let form = new FormData()
      form.append('file', file)
      uploadFile(form).then(response => {
        this.fileList = []
        this.fileList.push(file)
        this.form.fileList = this.fileList
        let data = {}
        data.name = response.originalFilename;
        data.url = response.fileName;
        this.uploadList.push(data)
        // console.log('this.fileList: ', this.fileList);
      })
    },
    deleteUpload(value) {
      this.uploadList =  this.uploadList.filter(item => {
        return item.url != value.url
      })
    },
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.uploadList.forEach((item,index) => {
            if(this.uploadList.length-1 == index){
              this.form.approvalAttachment+=`${item.url}`
            } else {
              this.form.approvalAttachment+=`${item.url},`
            }
          })
          // console.log("sdas", this.form);
          approvalEdit(this.form).then(response => {
            this.$modal.msgSuccess("审核完成");
            this.open = false;
            this.getList();
          });
        }
      });
    },
  },
}
</script>
<style lang="scss" scoped>

</style>
