<!--
  @description:招标-招标-邀请函列表
  @Modifier:haoFx/肖文龙
  @routerPath:/bidding/projectDrive/invitation/invitationList
  @date:2019/11/14-10:36
  isCanOperate: true可以操作 false不可以查看只有查看权限
-->
<template>
  <div class="main">
    <template v-if="tenderBase.isCanOperate">
      <!-- display==='00' 02 邀请招标的资审阶段展示-->
      <div v-if="display==='00'" class="mb10 clearfix">
        <div class="fl">
          <el-button type="primary" icon="iconfont icon-tianjia1" @click="addNotice">
            新增
          </el-button>
        </div>
      </div>
    </template>
    <div>
      <el-table
        ref="table"
        :data="tableData"
      >
        <el-table-column
          type="index"
          label="序号"
          width="60"
          align="center"
        />
        <el-table-column

          header-align="center"
          label="邀请函"
          prop="title"
          min-width="200"
        >
          <template slot-scope="scope">
            <div>{{ scope.row.title }}</div>
          </template>
        </el-table-column>
        <el-table-column

          header-align="center"
          prop="packNos"
          label="关联标段"
        />
        <el-table-column
          prop="auditStatus"
          label="审核状态"
          align="center"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.auditStatus!=='02' && scope.row.useStatus==='00'" 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 label="操作" header-align="center" width="160px">
          <template slot-scope="scope">
            <el-link
              v-if="scope.row.auditStatus==='00'||scope.row.auditStatus==='01'"
              type="primary"
              @click="examine(scope.row)"
            >
              [查看]
            </el-link>
            <el-link
              v-if="scope.row.auditStatus==='02'||!scope.row.auditStatus"
              type="primary"
              @click="edit(scope.row)"
            >
              [编辑]
            </el-link>
            <el-link
              v-if="scope.row.auditStatus==='02'||!scope.row.auditStatus"
              type="primary"
              @click="deleteRow(scope.$index,scope.row)"
            >
              [删除]
            </el-link>
            <!--searchForm.invitationType!=='02'"不是资审邀请函则显示-->
            <template v-if="scope.row.useStatus==='01' && searchForm.invitationType!=='02'">
              <!--是否超过邀请截止时间 00否 01是-->
              <el-link
                v-if="scope.row.isBeyondConfirmEndTime==='00'"
                type="primary"
                @click="addSupplier(scope.row)"
              >
                [追加邀请人]
              </el-link>
            </template>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </div>
  </div>
</template>

<script>
/* api*/
import { listTenderInvitationByTenderIdPages, removeInvitationIByInvitationId } from '@/api/bidding/bidInvitation'
import { getSystemConfigValueByConfigType } from '@/api/common/systemConfigCenter'
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
export default {
  components: {
    pagination
  },
  mixins: [ListMixin],
  props: {
    display: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      tenderBase: this.$store.getters.tenderBase, // 项目信息
      tableData: [], // 已制作邀请函
      searchForm: {
        invitationType: '', // 邀请函类型
        tenderId: '' // 项目Id
      },
      isSimpleInvitation: '' // 系统配置 00老版招标公告 01新版招标公告
    }
  },
  created() {
    this.searchForm.invitationType = this.tenderBase.invitationType
    this.searchForm.tenderId = this.$route.query.id
    this.loadData()// 获取邀请函列表
    this.getSystemConfigValueByConfigType() // 获取邀请函公告显示版本控制 01启用简易版招标公告
  },
  methods: {
    // 获取邀请函公告显示版本控制 01启用简易版招标公告
    getSystemConfigValueByConfigType() {
      getSystemConfigValueByConfigType('tenderInvitation-isSimpleInvitation').then((res) => {
        this.isSimpleInvitation = res.data
      })
    },
    // 获取邀请函列表
    loadData() {
      this.searchForm.pageNo = this.paginationData.pageNo
      this.searchForm.pageSize = this.paginationData.pageSize
      listTenderInvitationByTenderIdPages(this.searchForm).then(response => {
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {

      })
    },
    // 新增邀请函
    addNotice() {
      // 携带参数
      const data = {
        ...this.$route.query,
        invitationId: ''// 邀请函Id
      }
      if (this.isSimpleInvitation === '01') {
        //  新版招标邀请函新增页 isSimpleBulletin=01使用简易版招标公告 00使用老版
        this.$router.push({ path: '/bidding/projectDrive/invitation/newTenderInvitation-add', query: data })
      } else {
        this.$router.push({
          path: '/bidding/projectDrive/invitation/tabs/tenderInvitationInfo-add',
          query: data
        })
      }
    },
    // 查看
    examine(row) {
      // 携带参数
      const query = {
        ...this.$route.query,
        invitationId: row.invitationId// 邀请函Id
      }
      if (this.isSimpleInvitation === '01') {
        //  新版招标邀请函新增页 isSimpleBulletin=01使用简易版招标公告 00使用老版
        this.$router.push({ path: '/bidding/projectDrive/invitation/newTenderInvitation-detail', query: query })
      } else {
        this.$router.push({
          path: '/bidding/projectDrive/invitation/tenderInvitationDetail',
          query: query
        })
      }
      // this.$router.push({
      //   path: '/bidding/projectDrive/invitation/tenderInvitationDetail',
      //   query: query
      // })
    },
    // 编辑
    edit(row) {
      // 携带参数
      const data = {
        ...this.$route.query,
        invitationId: row.invitationId// 邀请函Id
      }
      if (this.isSimpleInvitation === '01') {
        //  新版招标邀请函新增页 isSimpleBulletin=01使用简易版招标公告 00使用老版
        this.$router.push({ path: '/bidding/projectDrive/invitation/newTenderInvitation-add', query: data })
      } else {
        this.$router.push({
          path: '/bidding/projectDrive/invitation/tabs/tenderInvitationInfo-add',
          query: data
        })
      }
      // this.$router.push({
      //   path: '/bidding/projectDrive/invitation/tabs/tenderInvitationInfo-add',
      //   query: data
      // })
    },
    // 追加邀请函
    addSupplier(row) {
      this.$router.push({
        path: '/bidding/projectDrive/invitation/packageAppendSupplierInvitation',
        query: {
          ...this.$route.query,
          invitationId: row.invitationId
        }
      })
    },
    //  删除
    deleteRow(index, row) {
      this.$confirm('此操作将永久删除该邀请函, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        removeInvitationIByInvitationId(row.invitationId).then(res => {
          this.tableData.splice(index, 1)
          this.$message({
            type: 'success',
            message: '删除成功'
          })
        }).catch(() => {

        })
      }).catch(() => {
      })
    }
  }

}
</script>

<style lang="less" scoped>

</style>
