<template>
  <div class="" style="margin: 30px 0 10px 0;">
    <!-- 查询和其他操作 -->
    <div>
      <span style="font-size:14px">产品名称：</span>
      <el-input
        v-model="productName"
        clearable
        placeholder="请输入产品"
        style="width: 200px;margin-bottom:20px"
        size="small"
         @keyup.enter.native="handleFind"
         @clear="handleFind"
        class="filter-item"
      />
          <!-- <span style="fontSize:13px;marginLeft:20px">投标时间</span>
            <el-date-picker
              v-model="applyDateStart"
              size="mini"
              type="datetimerange"
              style="width: 280px;"
              range-separator="-"
              clearable
              value-format="yyyy-MM-dd HH:mm:ss"
              :default-time="['00:00:00', '23:59:59']"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
             @change="onApplyDate"
             @clear="onApplyDate"
            />
 -->


      <el-button style=" width:90px;  " size="small" type="primary" icon="el-icon-search" @click="handleFind">查询
      </el-button>
    </div>

    <el-table  ref="multipleTable" v-loading="loading" :data="tableData"  :header-cell-style="{ background: '#f5f7fa', }" style="width: 100%" border  >

     <el-table-column prop="tenderCode" width="150" fixed="left" label="标的编号" :show-overflow-tooltip="true" align="center" />
                            <el-table-column prop="productName" fixed="left" label="产品名称" :show-overflow-tooltip="true" align="center" />
                            <el-table-column prop="productEncode" width="150" label="产品内部编码" :show-overflow-tooltip="true" align="center" />
                            <!-- <el-table-column prop="processingLocation"   label="加工地点（所在加工厂） " :show-overflow-tooltip="true" align="center" /> -->
                            <el-table-column prop="number"  label="数量（吨）" :show-overflow-tooltip="true" align="center" />
                            <el-table-column prop="lowestPrice"  width="90" label="最低价（元/吨）" :show-overflow-tooltip="true" align="center" />
                            <el-table-column prop="highestPrice" width="90" label="最高价（元/吨）" :show-overflow-tooltip="true" align="center" />
                            <el-table-column prop="biddingStartPrice" width="100" label="投标起价（元）" :show-overflow-tooltip="true" align="center" />
                            <el-table-column prop="deposit" width="100" label="履约保证金" :show-overflow-tooltip="true" align="center" />
                           <el-table-column label="状态" align="center" width="100">
                            <template slot-scope="scope">
                             <el-tag effect="plain" v-if="scope.row.status ==3">进行中</el-tag>
                              <el-tag effect="plain" v-if="scope.row.status ==1" type="info">已结束</el-tag>
                              <el-tag effect="plain" v-if="scope.row.status ==5" type="info">待处理</el-tag>
                              <el-tag effect="plain" v-if="scope.row.status ==2" type="danger">已作废</el-tag>
                              <el-tag effect="plain" v-if="scope.row.status ==4" type="warning">未开始</el-tag>
                            </template>
                          </el-table-column>
                          <!-- <el-table-column prop="tenderSaleRule" width="100" label="中标规则" :show-overflow-tooltip="true" align="center" >
                              <template slot-scope="scope">
                                  <el-tag v-if="scope.row.tenderSaleRule == 1" type="success" effect="plain">价低者得</el-tag>
                                  <el-tag v-if="scope.row.tenderSaleRule == 2" effect="plain" >价高者得</el-tag>
                              </template>
                            </el-table-column> -->
                            <el-table-column prop="startTime" width="152" label="起始时间" :show-overflow-tooltip="true" align="center" />
                            <el-table-column prop="endTime" width="152" label="结束时间" :show-overflow-tooltip="true" align="center" />
                            <!-- <el-table-column prop="createTime" label="创建时间"  width="152" :show-overflow-tooltip="true" align="center" /> -->
                            <el-table-column prop="saleRemark" label="备注" width="162" :show-overflow-tooltip="true" align="center" />
        <el-table-column label="操作" width="250" fixed="right" align="center">
        <template slot-scope="scope">
          <!-- <el-button type="text" icon="el-icon-edit" @click="handleAdd(scope.row)">投标</el-button>
          <el-button v-if="scope.row.tenderStatus == 1 && scope.row.status == null" slot="reference" type="text" icon="el-icon-edit" @click="handleAdd(scope.row)">投标</el-button>
          <el-button v-if="scope.row.tenderStatus == 1 && scope.row.status == 0" slot="reference" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">改标</el-button> -->
          <el-button  slot="reference" type="text" :disabled="scope.row.status !=3" icon="el-icon-plus" @click="handleAdd(scope.row)">投标</el-button>
          <el-button  slot="reference" icon="el-icon-view" type="text" @click="handleView(scope.row)">查看更多</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--分页-->
    <div class="pagination">
      <el-pagination
        :current-page="current"
        :page-sizes="[1,10, 20, 30, 50]"
        :page-size="size"
        layout="total, sizes, prev, pager, next, jumper"
        background
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />

    </div>




  </div>
</template>

<script>
import { Listarea } from '@/api/dataForm'
import { parseTime } from '@/utils/index'
import { getBiddingSaleList } from '@/api/tender'

export default {
  data() {
    return {
    //   size: 'small',
      tableData: [],
      priceData: [],
      SelectionList:[],
      productName: '',
      tenderParentId: '',
      applyDateStart:[],
      customerType: [
        { id: 1, name: '有限责任公司（自然人独资）' },
        { id: 2, name: '有限责任公司(自然人投资或控股)' },
        { id: 3, name: '股份有限公司' },
        { id: 4, name: '有限合伙企业' },
        { id: 5, name: '外商独资公司' },
        { id: 6, name: '个人独资企业' },
        { id: 7, name: '国有独资公司' },
        { id: 8, name: '其他' }

      ],
      areaList: [],
      query: {
        goodsName: '',
        tenderParentId:""
      },
      formLabelWidth: '90px',
      isEditForm: false,
      current: '1',
      size: 10,
      total: 0, // 总数量
      dataForm: {
      },

      loading: false,
      dialogVisible: false,
      batchVisible:false,
       BASE_API: process.env.BASE_API,
       fileList: [],
      roles:[],
      startTime:"",
      endTime:"",
        // dialogTableVisible:false
    }
  },
  created() {
    // this.getTenantList()
    console.log('res')
  },
  methods: {
        handleAdd(row){
      this.$emit("onAdd",row)
    },
      handleView(row){
          console.log("我被点击了")
            this.$emit('change',row)
        //   this.$parent.dialogTableVisible = true
      },
    parseTime,
    getTenantList: function() {
      this.loading = true
      const params = new URLSearchParams()
      params.append('tenderParentId', this.tenderParentId)
      params.append('productName', this.productName)
      // params.append('startTime', this.startTime)
      // params.append('endTime', this.endTime)
      params.append('current', this.current)
      params.append('size', this.size)
      getBiddingSaleList(params).then(response => {
        console.log(response)
        this.loading = false
          let data = response.data.data.records
        console.log(new Date().valueOf(),"当前时间")
        data.map((res)=>{
          // 开始时间
          let startTime = res.startTime
          // 结束时间
          let endTime = res.endTime

          const date = new Date(startTime)
          const modify = new Date(endTime)

          const start = date.valueOf()         //开始时间
          const end = modify.valueOf()        //结束时间
          const time = new Date().valueOf()   //当前时间
          console.log(start,"start")
          console.log(end,"end")
          if(res.tenderStatus == 1 || res.tenderStatus == 2){
             res.status = res.tenderStatus 
            console.log("我的状态是：" + res.tenderStatus)
          }else if(time < start){
            res.status = 4
            console.log("当前时间小于开始时间，未开始")
          }else if(time > start && time < end){
            res.status = 3
            console.log("当前时间大于开始时间并且小于结束时间，进行中")
          }else if(time > end){
            res.status = 5
            console.log("当前时间大于结束时间，待处理")
          }
          return res
        })
        this.tableData = data
        console.log('1' + response.data.data.records)
        this.total = response.data.data.total
      })
    },
   onApplyDate(){
      let startTime
      let endTime
            if(this.applyDateStart != null){
              this.startTime =this.applyDateStart[0]
              this.endTime = this.applyDateStart[1]
            }else{
              this.startTime =""
              this.endTime =""
            }

      this.getTenantList()
    },

    handleFind: function() {
      this.current = '1'
      this.getTenantList()
    },
    handleSizeChange: function(val) {
      this.size = val
      this.getTenantList()
    },
    // 换页
    handleCurrentChange: function(val) {
      const page = val.toString()
      this.current = page
      this.getTenantList()
    },
    // 查看
    // lookRecord:function(row){
    //     this.lookCord=row
    //     this.dialogVisible = true
    //     console.log(row)
    // },
   handleOneChange(row,i){
       console.log(row,i)
       this.$refs.multipleTable.toggleRowSelection(row);
   },
    handleSelectionChange(row){
        console.log(row)
        this.SelectionList = row
    }
  }
}
</script>

<style scoped lang="scss" >
    .ckTable{
        width: 100%;
        border: #eee;
        text-align: center;
        tr,td{
        border: 0.5px solid#dfe6ec;
        line-height: 23px;
        }
    }
   .el-dropdown-link {
    cursor: pointer;
    color: #1282f3;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
  .el-scrollbar__wrap {
   overflow-y: hidden;
}

.el-card {
  border: 0px solid #fff;
  .topClass{
    font-weight: 600;
    font-size: 17px;
  }
}
.el-icon-document{
  font-size: 70px;
  color:#409EFF;
  line-height: 130px;
}
/deep/.el-card__body {
  padding: 20px 10px 0 10px !important;
}
/deep/ .el-table__expanded-cell[class*=cell]{
    padding: 0;
}

</style>

