<!--
  @description:申报记录列表
  @Modifier:qk
  @routerPath:supplierDeclaration/declaraTionrecord
  @date:2020/2/17-17:27
-->
<template>
  <div>
    <table-crud
      ref="tableCrud"
      :search-form="searchForm"
      :menu="true"
      @on-load="loadData"
    >
      <template v-slot:header>
        申报记录
      </template>
      <template v-slot:search>
        <el-form-item ref="departName" label="审核单位" prop="departName">
          <el-input v-model="searchForm.departName" placeholder="请输入审核单位" style="width:220px" />
        </el-form-item>
        <el-form-item ref="createTime" label="申报日期" prop="createTime">
          <el-date-picker
            v-model="searchForm.createBeginTime"
            :value-format="elValueSaveFormat"
            type="date"
            placeholder="开始日期"
          />
          至
          <el-date-picker
            v-model="searchForm.createEndTime"
            :value-format="elValueSaveFormat"
            type="date"
            placeholder="结束日期"
          />
        </el-form-item>
        <el-form-item
          ref="status"
          class="list_seach_select"
          label="申报状态"
          prop="status"
        >
          <el-select v-model="searchForm.auditStatus" placeholder="请选择" style="width:220px">
            <el-option
              v-for="(item,index) in auditStatusList"
              :key="index"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
      </template>
      <template v-slot:menuLeft>
        <div class="mb10">
          <el-button :loading="declareLading" type="primary" @click="addDeclare">
            申报
          </el-button>
        </div>
      </template>
      <template v-slot:GXTable>
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
        >
          <el-table-column
            type="index"
            label="序号"
            width="60px"
            align="center"
          />
          <el-table-column
            prop="departName"
            header-align="center"
            label="审核单位"
            min-width="200"
          />
          <el-table-column
            label="供应范围"
            prop="supplyScope"
            header-align="center"
            min-width="200"
          />
          <el-table-column
            align="center"
            prop="qualificationsType"
            label="入库方式"
            width="110"
          >
            <template slot-scope="scope">
              <span
                v-for="(item,index) in supplierQualificationsTypeGroup"
                v-if="scope.row.qualificationsType===item.typecode"
                :key="index"
              >{{ item.typename }}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="createTime"
            label="申报日期"
            width="160"
          />
          <el-table-column
            header-align="center"
            prop="auditStatus"
            label="申报状态"
            min-width="110"
            align="center"
          >
            <template slot-scope="scope">
              <span
                v-for="(item,index) in auditStatusList"
                v-if="scope.row.auditStatus===item.typecode"
                :key="index"
              >{{ item.typename }}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="操作"
            align="center"
            min-width="220"
          >
            <template slot-scope="scope">
              <!-- auditStatus 审核状态:02驳回,03暂存，04 撤销 -->
              <el-link
                v-if="scope.row.auditStatus ==='03'|| scope.row.auditStatus === '02'||scope.row.auditStatus==='04'"
                type="primary"
                @click.stop="editProject(scope.row)"
              >
                [编辑]
              </el-link>
              <!-- auditStatus 审核状态:01通过 00：待审核 -->
              <!--v-if="scope.row.auditStatus ==='01'||scope.row.auditStatus==='00'"-->
              <el-link
                type="primary"
                @click.stop="preview(scope.row)"
              >
                [查看]
              </el-link>
              <!-- auditStatus 审核状态:00：待审核 -->
              <el-link
                v-if="scope.row.auditStatus==='00'"
                type="primary"
                @click.stop="revokeProject(scope.row)"
              >
                [撤销申报]
              </el-link>
              <!-- auditStatus 审核状态:02驳回,03暂存，04撤销-->
              <el-link
                v-if="scope.row.auditStatus ==='03'|| scope.row.auditStatus === '02'||scope.row.auditStatus==='04'"
                type="primary"
                @click.stop="deleteProject(scope.row)"
              >
                [删除]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </table-crud>
    <declaraTionrecords v-if="declareDialog.dialog" :declare-dialog="declareDialog" @declartInfo="declartInfo" />
    <declaraTionrecordDetail v-if="declareDetailDialog.dialog" :declare-detail-data="declareDetailDialog" />
  </div>
</template>
<script>
/* 接口*/
import { listSupplierSelfDeclarationPages, checkDeclaration, removeDeclaration, repealDeclaration } from '@/api/supplier/declaraTionrecord'
/* 混合开发*/
import { declareHegSupperGroupMixin } from '@/views/supplier/editorDeclaration/mixins/declareHegSupperGroupMixin'// 供应商-字典
import { declareHegSupperMixins } from '@/views/supplier/editorDeclaration/mixins/declareHegSupperMixins'// 供应商-公用方法参数
import { supplierGroupMixin } from '@/views/supplier/mixins/supplierGroupMixin'
/* 公用方法*/
// import { filterObj } from '@/assets/js/utils'// 常用方法
/* 组件*/
import declaraTionrecords from './declaraTionrecord-dialog' // 新增申报
import declaraTionrecordDetail from './declaraTionrecordDetail-dialog' // 查看申报

export default {
  name: 'ProjectManagerTenderList',
  components: {
    declaraTionrecords, // 新增申报
    declaraTionrecordDetail// 查看申报
  },
  mixins: [declareHegSupperMixins, declareHegSupperGroupMixin, supplierGroupMixin],
  data() {
    return {
      loading: true, // 列表
      declareLading: false, // 申报按钮Loading
      // 新增申报弹框
      declareDialog: {
        dialog: false,
        id: '', // 申报id
        departId: '', // 供应商主键id
        lengthNumber: 0 // 还可以选几条数据
      },
      // 查看申报弹框
      declareDetailDialog: {
        dialog: false,
        id: '', // 申报id
        departId: ''// 供应商主键id
      },
      // 搜索
      searchForm: {
        departName: '', // 审核单位
        // createTime: [], // 申报时间
        createTimeBegin: '', // 申报创建日期
        createTimeEnd: '', // 申报结束日期
        auditStatus: '' // 申报状态
      },
      tableData: []// 列表信息
    }
  },
  created() {
    // 获取字典
    this.getDeclarationDictionariesGroup()
  },
  methods: {
    // 申报弹框
    addDeclare() {
      this.declareLading = true
      // 检查申报条件
      checkDeclaration().then((res) => {
        const data = res.data.split(':')
        this.submitList.forEach(item => {
          if (item.typecode === data[0]) {
            this.declareDialog.lengthNumber = Number(data[2])// 还可以申报几家单位
            if (Number(data[2]) <= 0) {
              const message = '等待其他单位审核同，才可申报'
              // 判断是否为空
              if (message) {
                this.$message({
                  message: message,
                  type: 'warning'
                })
                this.declareLading = false
              }
            } else {
              this.declareLading = false
              this.declareDialog = {
                dialog: true,
                id: '', // 申报id
                departId: ''// 供应商主键id
              }
            }
          }
        })
      }).catch(() => {
      })
    },
    // 获取数据
    loadData(params, callback) {
      listSupplierSelfDeclarationPages(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        callback(response.data.total)
      }).catch(() => {
      })
    },
    // 编辑
    editProject(row) {
      this.declareDialog = {
        dialog: true,
        id: row.id, // 申报id
        departId: row.departId// 供应商主键id
      }
    },
    // 删除申报
    deleteProject(row) {
      this.$confirm('确认删除本条申报记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        const data = [{
          id: row.id, // 申报id,
          departId: row.departId// 供应商主键id
        }]
        removeDeclaration(data).then(res => {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          // 获取列表信息
          this.$refs.tableCrud.onSearchChange()
        })
      }).catch(() => {
      })
    },
    declartInfo() {
      this.$refs.tableCrud.onSearchChange()
    },
    // 撤销
    revokeProject(row) {
      this.$confirm('确认撤销申报?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        const id = row.id // 审报
        repealDeclaration(id).then(res => {
          this.$message({
            message: '撤销成功',
            type: 'success'
          })
          this.$refs.tableCrud.onSearchChange()
        })
      }).catch(() => {
      })
    },
    // 查看
    preview(row) {
      this.declareDetailDialog = {
        dialog: true,
        id: row.id, // 申报id
        departId: row.departId// 供应商主键id
      }
    }
    // // 处理搜索时间格式
    // handleCreateTime(val) {
    //   if (val) {
    //     this.searchForm.createTimeBegin = this.searchForm.createTime[0] // 注册开始时间
    //     this.searchForm.createTimeEnd = this.searchForm.createTime[1] // 注册结束时间
    //   }
    // }
  }
}
</script>
<style lang="less" scoped>
</style>
