<!--
  @description: 代理机构-项目管理-已制作候选人公示组件
  @Modifier: 肖文龙
  @Modifier: hfx联调 2020/2/19-09:54
  @routerPath:
  @date: 2020/2/6-10:55
  isCanOperate: true可以操作 false不可以查看只有查看权限 00:否 01:是
-->
<template>
  <div>
    <el-table
      ref="table"
      :data="is_show?tableData:tableData[0]?[tableData[0]]:[]"
    >
      <el-table-column
        type="index"
        label="序号"
        width="60"
        align="center"
      />
      <!--候选人公示名称-->
      <el-table-column

        label="候选人公示名称"
        header-align="center"
        prop="title"
      />
      <!--标段（包）名称-->
      <el-table-column

        label="标段（包）编号"
        header-align="center"
        prop="packNos"
      />
      <!--状态-->
      <el-table-column
        label="状态"
        prop="useStatus"
        width="140px"
        align="center"
      >
        <template slot-scope="scope">
          <!-- 00审核中,02驳回,01通过 -->
          <span v-if="scope.row.useStatus==='00' && scope.row.auditStatus!=='02'" class="status4">草稿</span>
          <span v-if="scope.row.auditStatus==='00'" class="status2">待审核</span>
          <span v-if="scope.row.auditStatus==='01'" class="status1">审核通过</span>
          <span v-if="scope.row.auditStatus==='02'" class="status3">审核不通过</span>
        </template>
      </el-table-column>
      <el-table-column

        align="center"
        prop="bulletinStartTime"
        width="130px"
        label="公示开始时间"
      >
        <template slot-scope="scope">
          {{ scope.row.bulletinStartTime && $Moment(scope.row.bulletinStartTime).format(momentDateTime) }}
        </template>
      </el-table-column>
      <el-table-column

        align="center"
        prop="bulletinEndTime"
        width="130px"
        label="公示结束时间"
      >
        <template slot-scope="scope">
          {{ scope.row.bulletinEndTime && $Moment(scope.row.bulletinEndTime).format(momentDateTime) }}
        </template>
      </el-table-column>
      <el-table-column

        align="center"
        prop="publishStatus"
        width="110px"
        label="公示发布状态"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.publishStatus && scope.row.publishStatus==='01'" class="status1">已发布</span>
          <span v-else class="status2">未发布</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="150px"
      >
        <!--auditStatus 00:待审核 01:审核通过 02:审核不通过-->
        <template slot-scope="scope">
          <!--useStatus 00 草稿-->
          <el-link
            v-if="scope.row.useStatus!=='00'"
            type="primary"
            @click="see(scope.row)"
          >
            [查看]
          </el-link>
          <!--登录用户有权限则显示-->
          <template v-if="tenderBase.isCanOperate">
            <!--平台修改-->
            <el-link
              v-if="scope.row.auditStatus==='02'&&systemSourceType==='00' ||!scope.row.auditStatus&&systemSourceType==='00'"
              type="primary"
              @click="revamped(scope.row)"
            >
              [修改]
            </el-link>
            <!--使用工具修改-->
            <!-- <el-link
              v-if="scope.row.auditStatus==='02'&& systemSourceType==='01'||!scope.row.auditStatus&&systemSourceType==='01'"
              type="primary"
              @click="toolRevamped(scope.row)"
            >
              [修改2]
            </el-link> -->
            <el-link
              v-if="scope.row.auditStatus==='02'&& systemSourceType==='01'||!scope.row.auditStatus&&systemSourceType==='01'"
              type="primary"
              @click="openDialog(scope.row)"
            >
              [修改]
            </el-link>
            <el-link
              v-if="scope.row.auditStatus!=='01'&&scope.row.auditStatus!=='00'"
              type="primary"
              @click="deleteRow(scope.row,scope.$index)"
            >
              [删除]
            </el-link>
          </template>
        </template>
      </el-table-column>
    </el-table>
    <div class="more">
      <span v-if="is_show" class="pointer" @click="is_show=false">
        收起更多（0）
        <i class="el-icon-arrow-up" />
      </span>
      <span v-else class="pointer" @click="is_show=true">
        展开更多（{{ tableData.length>0?tableData.length -1:0 }}）
        <i class="el-icon-arrow-down" />
      </span>
    </div>
    <candidateDialog v-if="dialogData.visible" :dialog-data="dialogData" @toolRevamped="toolRevamped" />
  </div>
</template>

<script>
/* api*/
import { getCandidateBulletinMadeList, removeCandidateBulletinAllById } from '@api/bidding/bidCalibration'
/* 公用方法*/
import { cloneObject } from '@assets/js/utils'// 常用方法
/* 组件 */
import candidateBulletinDetail from './candidateBulletin-detail'// 候选人公示查看
import candidateDialog from './candidate-dialog'
export default {
  name: 'HasCandidatePublicityPackComp',
  components: {
    candidateDialog,
    candidateBulletinDetail
  },
  data() {
    return {
      dialogData: {
        visible: false
      },
      tenderBase: this.$store.getters.tenderBase, // 项目信息
      systemSourceType: '', // 系统来源-是否使用工具制作公告
      is_show: true, // 标段展示状态
      timer: true, // 定时器是否可以刷新状态 布尔值
      searchData: {
        tenderId: this.$route.query.id
      },
      tableData: [] // 已制作候选人公示标段列表
    }
  },
  created() {
    // 获取系统来源
    this.$store.dispatch('getSystemSource', 'candidateBulletin').then(() => {
      // 系统来源-是否使用工具制作公告
      this.systemSourceType = this.$store.getters.systemSourceVo.systemSourceCode // 01 工具制作模式 00 平台制作模式
    }).catch(() => {
    })
    this.initData()// 初始化数据
  },
  beforeDestroy() {
    // 清除定时器状态
    this.timer = false
  },
  methods: {
    // 初始化数据
    initData(candidateBulletinId) {
      getCandidateBulletinMadeList(this.searchData).then(res => {
        let isType = false // 是否定时刷新 布尔值
        const tableData = cloneObject(res.data)
        tableData.forEach((item, index) => {
          /*
            * 判断状态是否开启定时刷 并且 和当前正在制作的文件是同一个 并且查找为草稿的公示信息
            * useStatus === 00 草稿
            * */
          if (item.id === candidateBulletinId && item.useStatus === '00') {
            isType = true
          }
        })
        this.tableData = tableData// 赋值渲染列表
        // 定时刷新
        if (isType && this.timer) {
          setTimeout(() => {
            this.initData(candidateBulletinId)// 数据组装
          }, 2000)
        }
      })
    },
    // 查看
    see(row) {
      this.$router.push({
        path: '/bidding/projectDrive/calibration/candidateBulletinDetail',
        query: {
          ... this.$route.query,
          candidateBulletinId: row.id // 候选人公示id
        }
      })
    },
    // 修改
    revamped(row) {
      this.$emit('revamped', '01', row)
    },
    // 工具修改
    toolRevamped(row) {
      this.$emit('revamped', '00', row)
      this.dialogData.visible = false
    },
    openDialog(row) {
      this.dialogData.visible = true
      this.dialogData.row = row
    },
    // 删除
    deleteRow(row, index) {
      this.$confirm('确定删除已选标段（包）吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        removeCandidateBulletinAllById(row.id).then(res => {
          this.tableData.splice(index, 1)
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.$emit('initData')// 调用未制作标段查询接口
        })
      }).catch(() => {
      })
    }
  }
}
</script>
<style lang="less" scoped>

</style>
