<!--
  @description:采购人-保证金管理-线下收取
  @Modifier:gmy
  @routerPath:
  @date:2020/5/12-16:55
-->
<template>
  <div style="padding: 0 15px;">
    <!--    响应内容-->
    <section class="main">
      <el-table
        ref="smallTable"
        v-loading="loading"
        :data="tableData"
      >
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          header-align="center"
          prop="tenderName"
          label="采购项目名称"
          min-width="110"
        />
        <el-table-column
          header-align="center"
          label="保证金额(元)"
          min-width="75"
          align="right"
        >
          <template slot-scope="scope">
            <p v-for="(item,index) in optionTend" v-if="item.typecode===scope.row.tenderMethod" :key="index">
              {{ item.typename }}
            </p>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          label="提交时间"
          prop="createTime"
          align="left"
          min-width="110"
        />
        <el-table-column
          label="审核状态"
          align="center"
        >
          <template slot-scope="scope">
            <p v-for="(item,index) in options" v-if="item.typecode===scope.row.purchaseProjectStatus" :key="index">
              {{ item.typename }}
            </p>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          label="操作"
          align="center"
        >
          <template slot-scope="scope">
            <el-link
              v-show="scope.row.useStatus==='01'"
              :underline="false"
              type="primary"
              size="mini"
              plain
              @click.stop="intoProject(scope.row)"
            >
              [进入项目]
            </el-link>
            <el-link
              v-show="scope.row.useStatus==='00'"
              :underline="false"
              type="primary"
              size="mini"
              plain
              @click.stop="redactProject(scope.row)"
            >
              [编辑]
            </el-link>
            <el-link
              v-show="scope.row.useStatus==='00'"
              :underline="false"
              type="primary"
              size="mini"
              plain
              @click.stop="delProject(scope.row)"
            >
              [删除]
            </el-link>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </section>
  </div>
</template>

<script>
/* 接口*/
import { listProjectManagementPages, DeleteProject } from '@/api/procurement/procurementProject'// 项目列表 项目删除
/* 公用方法*/
import { filterObj } from '@/assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { initGroupMixin } from '@/mixins/initGroupMixin'// 字典信息
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
export default {
  components: {
    pagination // 分页
  },
  mixins: [ListMixin, initGroupMixin],
  data() {
    return {
      optionTend: [], // 采购方式
      options: [], // 采购目前的状态
      childenData: {
        dialog: false
      },
      paginationData: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      },
      loading: true,
      date: [],
      // 弹窗-展示/隐藏状态 true 展示/false 隐藏
      dialogData: {
        consignContractVisible: false // 供货范围
      },
      value: '',
      // 搜索
      searchForm: {
        tenderNo: '', // 采购项目编号
        tenderName: '', // 采购项目名称
        purchaseProjectStatus: '', // 采购项目状态
        status: '00',
        tenderMethod: '', // 采购方式
        createTimeBegin: '', // 创建开始时间
        createTimeEnd: '' // 创建结束时间
      },
      tableData: []
    }
  },
  watch: {
    date(val) {
      this.searchForm.createTimeBegin = val[0]
      this.searchForm.createTimeEnd = val[1]
    }
  },
  created() {
    // 字典信息
    this.initTypeGroup('bidType')// 招标方式
    // 获取列表信息
    this.loadData()
  },
  methods: {
    // 获取数据
    loadData() {
      const params = this.getQueryParams()// 查询条件
      listProjectManagementPages(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {

      })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 编辑项目信息
    redactProject(row) {
      // 判断项目id
      if (row.id) {
        this.$router.push({ path: '/procurement/procurementProject/projectContent', query: { id: row.id }})
      }
    },
    // 删除项目
    delProject(row) {
      if (row.id) {
        this.$confirm('确定删除吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(() => {
          this.removeProject(row.id)
        }).catch(() => {
        })
      }
    },
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 获取列表信息
      this.loadData()
    },
    // 重置
    resetForm(formName) {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.searchForm.createTimeBegin = ''
      this.searchForm.createTimeEnd = ''
      this.date = []
      this.$refs[formName].resetFields()
      // 获取列表信息
      this.loadData()
    },
    // 删除项目方法
    async removeProject(bizId) {
      const res = await DeleteProject(bizId)
      // 判断是否删除成功
      if (res.header.msg === '删除成功') {
        this.$message({
          type: 'success',
          message: '删除成功!',
          onClose: () => {
            this.loadData()
          }
        })
      } else {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      }
    },
    // 进入项目
    intoProject(row) {
      this.$router.push({
        path: '/procurement/procurementDrive/procurementView',
        query: {
          id: row.id,
          tenderName: row.tenderName
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>

  /deep/.show-word-limit-padding{
    .el-input__inner{
      padding-right: 70px;
    }
  }
  .title{
    font-weight: 600;
  }
</style>
