<template>
  <div class="" style="margin: 30px 0 10px 0;">
     <el-card class="box-card" shadow="nerver">
                    <div slot="header" class="clearfix">
                      <span class="topClass">基本信息</span>
                    </div>

                     <el-row type="flex" class="row-bg">
                       <!-- <el-col :span="8" class="flex_text">
                         招标规则 : <span class="flex_name">    <el-tag v-if="bidInfo.tenderRule == 1" type="success" effect="plain">价低者得</el-tag>
          <el-tag v-if="bidInfo.tenderRule == 2" effect="plain" >价高者得</el-tag></span>
                       </el-col> -->
                         <el-col :span="8" class="flex_text">
                         标的编码 : <span class="flex_name"> {{priceData.processingCode}} </span>
                       </el-col>
                         <el-col :span="8" class="flex_text">
                         产地 : <span class="flex_name"> {{priceData.comesFrom}} </span>
                       </el-col>
                         <el-col :span="8" class="flex_text">
                         生产年限：<span class="flex_name">{{priceData.produceAge}}</span>
                       </el-col>
                    </el-row>
                    <el-row type="flex" class="row-bg">
                      <el-col :span="8" class="flex_text">
                         仓号：<span class="flex_name">{{priceData.warehouseNumber}}</span>
                       </el-col>
                         <el-col :span="8" class="flex_text">
                         品种 :  <span class="flex_name">{{priceData.breeds}}
                                    </span>
                       </el-col>
                         <el-col :span="8" class="flex_text">
                        　　 等级：<span class="flex_name">{{priceData.level}}</span>
                       </el-col>
                    </el-row>
                    <el-row type="flex" class="row-bg">
                      <el-col :span="8" class="flex_text">
                         数量（吨） : <span class="flex_name"> {{priceData.quantity}} </span>
                       </el-col>
                         <el-col :span="8" class="flex_text">
                      
                       </el-col>
                         <el-col :span="8" class="flex_text">
                       </el-col>
                    </el-row>
                  </el-card>

      <el-card class="box-card" shadow="nerver">
                    <div slot="header" class="clearfix">
                      <span class="topClass">投标详情</span>
                    </div>
    <!-- 查询和其他操作 -->
    <div class="" style="margin: 10px 0 30px 0;">
      <span style="font-size:14px">客户名称：</span>
      <el-select v-model="goodsName" filterable style="width: 200px;" clearable size="small" placeholder="请选择" @clear="handleFind">
            <el-option v-for="item in userDataList" :key="item.customerId" :label="item.customerName" :value="item.customerId" />
          </el-select>
      <span style="font-size:14px;margin-left:20px">是否为历史记录：</span>
       <el-select v-model="historyValue" style="width: 200px;" @keyup.enter.native="handleFind" @clear="handleFind" size="small" clearable  value-key="areaId" filterable placeholder="请选择">
        <el-option
          v-for="item in history"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        />
      </el-select>


      <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="customerName" width="150" label="客户名称" :show-overflow-tooltip="true" align="center" />
              <el-table-column prop="appendix" label="凭证" align="center" width="100">
                <template slot-scope="scope">
                    <el-link :disabled="scope.row.voucherFile ? false : true" :href="scope.row.voucherFile" type="primary" target="_target"><i class="el-icon-view"></i> 下载</el-link>
                </template>
              </el-table-column>

            <el-table-column prop="level"   label="级别" :show-overflow-tooltip="true" align="center" >
              <template slot-scope="scope">
                 <span>{{scope.row.level}}</span>
                 <!-- <span v-if="scope.row.level ==2">二级</span>
                 <span v-if="scope.row.level ==3">三级</span>
                 <span v-if="scope.row.level ==4">四级</span> -->
            </template>
            </el-table-column> 
            <el-table-column label="状态" align="center" width="100">
              <template slot-scope="scope">
                <el-tag effect="plain" v-if="scope.row.biddingStatus == 5">已投递</el-tag>
                <el-tag effect="plain" v-if="scope.row.biddingStatus ==6" type="info">审核中</el-tag>
                <el-tag effect="plain" v-if="scope.row.biddingStatus ==7" type="warning">已中标</el-tag>
                <el-tag effect="plain" v-if="scope.row.biddingStatus ==8" type="danger">未中标</el-tag>
                <el-tag effect="plain" v-if="scope.row.biddingStatus ==9" type="danger">已作废</el-tag>
              </template>
          </el-table-column>
           <el-table-column label="历史记录(是/否)" align="center" width="90">
                <template slot-scope="scope">
                  <el-tag effect="plain" type="danger" v-if="scope.row.isHistory == 1">是</el-tag>
                  <el-tag effect="plain" v-if="scope.row.isHistory ==0" >否</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="stocksRealStation" width="152"  label="实际库存点" :show-overflow-tooltip="true" align="center" />
            <el-table-column prop="biddingNumber"   label="数量（吨）" :show-overflow-tooltip="true" align="center" />

       
            <el-table-column prop="brownRiceRate" width="100" label="加工厂出糙率（%）" :show-overflow-tooltip="true" align="center" />
            <el-table-column prop="realPremiumComplex"  label="实际贴水贴杂（个）" :show-overflow-tooltip="true" align="center" />
            <el-table-column prop="warehouseFactoryDistance"  label="库点至加工厂的运距（KM)" :show-overflow-tooltip="true" align="center" />
            <el-table-column prop="warehouseFactoryPrice" width="100" label="库点至加工厂的短运费(元/吨)" :show-overflow-tooltip="true" align="center" />
            <el-table-column prop="ricePickupPrice"  label="稻壳自提单价(元/吨)" :show-overflow-tooltip="true" align="center" />
            <el-table-column prop="cornProcurePrice" width="152" label="玉米采购价(元/吨)" :show-overflow-tooltip="true" align="center" />
            <el-table-column  label="至鱼圈运费(包价元/吨)" align="center" >
                  <el-table-column prop="stationPrice" width="102" label="上站费" :show-overflow-tooltip="true" align="center" />
                  <el-table-column prop="stationUsePrice" width="102" label="站台使用费" :show-overflow-tooltip="true" align="center" />
                  <el-table-column prop="freightPrice" width="102" label="运费" :show-overflow-tooltip="true" align="center" />
                  <el-table-column prop="sumBiddingPrice" width="102" label="总费用" :show-overflow-tooltip="true" align="center" />
                  <el-table-column prop="otherRemarks" width="152" label="其他" :show-overflow-tooltip="true" align="center" />
            </el-table-column>
            <el-table-column prop="phone" width="152" label="联系电话" :show-overflow-tooltip="true" align="center" />
            <el-table-column prop="processBiddingEnquiryTime" label="投标时间"  width="152" :show-overflow-tooltip="true" align="center" />
            <!-- <el-table-column prop="remark" 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  slot="reference"  :disabled="scope.row.biddingStatus !=6"  icon="el-icon-check" type="text" @click="dialogVisible=true;dataForm=scope.row">中标</el-button>
            <!-- <el-button  slot="reference"   icon="el-icon-check" type="text" @click="dialogVisible=true;dataForm=scope.row">中标</el-button> -->
            <!-- :disabled="scope.row.biddingStatus !=7" -->
             <el-upload
                     :disabled="scope.row.biddingStatus !=7"
                    class="upload-demo"
                    :on-change="handleChange"
                    :on-remove="handleRemove"
                    :show-file-list="false"
                    name="multipartFile"
                    style="display:inline-block"
                    :action="BASE_API+'/common/tender/contract/send/' + scope.row.customerId"
                    list-type="text"
                    :data="fileData"
                    :file-list="fileList"
                    multiple
                  >
                          <el-button @click="handleUpload" :disabled="scope.row.biddingStatus !=7"  class="el-icon-upload2" size="small" type="text" style="width:90px;font-size:14px ">发送合同</el-button>
                  </el-upload>
          </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>

      </el-card>

   <el-dialog
      title=""
      :visible.sync="dialogVisible"
      width="35%"
      top="35vh"
      append-to-body
     >
      <span style="font-size:16px">此操作将“{{dataForm.customerName}}”，置中标</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
            <el-upload
                    class="upload-demo"
                    :on-change="handleChange"
                    :on-remove="handleRemove"
                    :show-file-list="false"
                    name="multipartFile"
                    style="display:inline-block"
                    :action="BASE_API+'/common/tender/contract/send/' + dataForm.customerId"
                    list-type="text"
                    :data="fileData"
                    :file-list="fileList"
                    multiple
                  >
                          <el-button @click="changeBid"  type="primary"  >确定并发送合同</el-button>
                  </el-upload>
        <el-button type="primary" @click="changeBid">确 定</el-button>
        
      </span>
    </el-dialog>

  </div>
</template>

<script>
import { Listarea } from '@/api/dataForm'
import { parseTime } from '@/utils/index'
import { getBiddingList1,getCustomerName,getContract } from '@/api/bid'
import { Notification, MessageBox } from 'element-ui'

export default {
  data() {
    return {
    //   size: 'small',
      tableData: [],
      priceData: {},
      SelectionList:[],
      goodsName: '',
      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: '其他' }

      ],
      history:[
        {id:0,name:"否"},
        {id:1,name:"是"}
      ],
      historyValue:"",
      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:[],
      fileData:{},
      userDataList:[],
      startTime:"",
      endTime:"",
        isShow:true
    }
  },
  created() {
    this.onCustmerName()
    console.log('res')
  },
  methods: {
          // 置中标
    changeBid(){
      console.log(this.dataForm)
      console.log(this.priceData,"priceData")
      getContract(this.dataForm.tenderProcessingId,this.dataForm.biddingProcessingId,this.priceData.tenderType).then((res)=>{
        if(res.data.code == 200){
           this.$message({
              message: '操作成功',
              type: 'success'
            });
            this.dialogVisible = false
            this.getTenantList()
        }
      })
    },
    // 点击时候
    handleUpload(){
      console.log(this.SelectionList,"我被固定了")
      // if(this.SelectionList.length == 0){
      //  this.$message({
      //     message: '请先选择已中标的客户',
      //     type: 'warning'
      //   });
      // }
      // return false
    },
    // 文件移除的时候
    handleRemove(file, fileList) {
      this.form.fileUrl = ''
      console.log(file, fileList, this.fileList, '移出')
    },
    // 文件状态改变时的钩子，添加文件、上传成功和上传失败时都会被调用
    handleChange(file, fileList) {
      console.log(file, fileList, '上传')
      if (file.response) {
        console.log(file.response, 'file')
        if (file.response.code == '200') {
           this.$message({
              message: '合同发送成功',
              type: 'success'
            });
          // this.form.fileUrl = file.response.data.filePath
          // this.form.tenderParentId = file.response.data.tenderParentId
        } else {
          Notification.error({
            title: file.response.msg,
            duration: 1000
          })
        }
      }
    },
    onCustmerName(){
        getCustomerName().then((res)=>{
            console.log(res)
            this.userDataList = res.data.data
        })
    },
      onshow(){
          this.isShow = !this.isShow
      },
    parseTime,
    getTenantList: function() {
        console.log(this.priceData)
      const params = new URLSearchParams()
      params.append('tenderParentId', this.priceData.tenderParentId)
      params.append('customerId', this.goodsName)
      params.append('isHistory', this.historyValue)
      params.append('tenderProcessingId', this.priceData.tenderProcessingId)
      params.append('target', this.priceData.target)
      params.append('current', this.current)
      params.append('size', this.size)
      this.loading =true
      getBiddingList1(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 = this.priceData.endTime

          const date = new Date(startTime)
          const start = date.valueOf()         //开始时间
          const time = new Date().valueOf()   //当前时间
          console.log(start,"start")
          if(res.biddingStatus < 7){
              console.log("我不满足")
                if(time < start){
                    res.biddingStatus = 5
                    console.log("当前时间小于投标时间，已投递")
                }else if(time > start){
                    res.biddingStatus = 6
                    console.log("当前时间小于投标时间，审核中")
                }
          }
          return res
        })
        console.log(data)
        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;
}
.pagination{
  padding-bottom: 30px;
}
.clearfix {
    line-height: 20px;
    font-size: 18px;
    font-weight: 600;
    color: #409EFF;
}
.box-card{
  margin-bottom: 20px;
  .row-bg{
  padding: 15px 40px 0 40px;
  .flex_text{
    line-height: 50px;
    color: #8C8C8C;
    font-size: 14px;
    // border:1px solid red;
    // font-weight: 600;
  }
  .flex_name{
    font-size: 14px;
    padding-left: 25px;
    color: #575757;
    font-weight: 550;
  }
}
}
</style>

