<template>
  <div class="" style="margin: 30px 0 10px 0;">
    <!-- 查询和其他操作 -->
    <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="processingCode" width="150" label="标的编码" :show-overflow-tooltip="true" align="center" />
            <el-table-column prop="comesFrom"   label="产地" :show-overflow-tooltip="true" align="center" />
            <el-table-column prop="breeds"   label="品种" :show-overflow-tooltip="true" align="center" />
            <el-table-column prop="level"   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 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 prop="storageAssistFee" width="100" label="出库辅助费" :show-overflow-tooltip="true" align="center" />
            <el-table-column prop="rentalFee"  label="租赁费" :show-overflow-tooltip="true" align="center" />
            <el-table-column prop="processFee"  label="加工费" :show-overflow-tooltip="true" align="center" />
            <el-table-column prop="biddingPrice" width="100" label="投标价格" :show-overflow-tooltip="true" align="center" />
            <el-table-column prop="quantity"  label="数量（吨）" :show-overflow-tooltip="true" align="center" />
            <el-table-column prop="phone" width="152" label="联系电话" :show-overflow-tooltip="true" align="center" />
            <el-table-column prop="biddingTime" 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-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 { getBiddingList,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:[],
      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('biddingProcessingId', this.priceData.tenderProcessingId)
      params.append('current', this.current)
      params.append('size', this.size)
      this.loading =true
      getBiddingList(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;
}
</style>

