<template>
  <div class="edit-add-detail">
    <div class="crumbs">
      <Breadcrumb
        :breadcrumbOpt="breadcrumbOpt"
        svg-name="#icon-roleEdit"
        @breadcrumb-click="handleClose"
      />
    </div>
    <div class="common-page-shadow">
      <div class="common-search-container" ref="contentPanel">
        <el-form
          ref="form"
          :model="searchForm"
          label-width="auto"
          label-position="right "
          :inline="true"
          type="flex"
          justify="left"
        >
          <el-form-item label="路线编号">
            <el-input
              size="small"
              v-model="searchForm.code"
              clearable
              placeholder="请输入路线编号"
            ></el-input>
          </el-form-item>
        </el-form>
        <div>
          <el-button
            size="small"
            icon="el-icon-search"
            type="primary"
            class="btn btn-plus"
            @click="handleSearch"
          >
            搜索
          </el-button>
          <el-button
            size="small"
            icon="el-icon-refresh-right"
            class="btn btn-plus"
            @click="clearSearchForm"
          >
            重置
          </el-button>
        </div>
      </div>
      <el-row class="common-table-container flex searchPanel">
        <el-col :span="24" class="common-table-wrapper">
          <!-- LJ：表格高度自适应需配合样式  btn-pagenation 有按钮有分页  btngroup只有按钮  pagenation只有分页 -->
          <div class="common-table-content btn-pagenation">
            <el-table
              :border="true"
              stripe
              fit
              size="mini"
              v-loading="tableLoading"
              ref="multipleSelection"
              @row-click="handleTable"
              :data="tableData"
              height="100%"
            >
              <el-table-column
                type="index"
                width="55"
                align="center"
                label="序号"
              >
              </el-table-column>
              <el-table-column
                prop="date"
                min-width="10%"
                label="物料名称"
                align="center"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="name"
                show-overflow-tooltip
                min-width="10%"
                align="center"
                label="数量"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="companyName"
                show-overflow-tooltip
                min-width="10%"
                align="center"
                label="单位"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="upset"
                show-overflow-tooltip
                min-width="10%"
                align="center"
                label="拍卖底价"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="quote"
                show-overflow-tooltip
                min-width="10%"
                align="center"
                label="当前报价"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="companyName"
                show-overflow-tooltip
                min-width="10%"
                align="center"
                label="我的报价"
                resizable
              >
              </el-table-column>
              <el-table-column
                show-overflow-tooltip
                min-width="15%"
                align="center"
                label="开始倒计时"
                resizable
              >
                <template slot-scope="scope">
                  <div class="auction" v-if="scope.row.auctionStatus == 1">
                    <div id="box">
                      <div
                        id="time"
                        :class="scope.row.dateTime.days < 0 ? 'red' : ''"
                      >
                        <strong>
                          <span id="day">
                            {{ scope.row.dateTime.days }}天
                          </span>
                        </strong>
                        <strong>
                          <span id="hour">
                            {{ scope.row.dateTime.hours }}时
                          </span>
                        </strong>
                        <strong>
                          <span id="minute">
                            {{ scope.row.dateTime.minutes }}分
                          </span>
                        </strong>
                        <strong>
                          <span id="second">
                            {{ scope.row.dateTime.seconds }}秒
                          </span>
                        </strong>
                      </div>
                    </div>
                  </div>
                  <div v-if="scope.row.auctionStatus == 2">
                    {{ (scope.row.dateTime = '进行中') }}
                  </div>
                  <div v-if="scope.row.auctionStatus == 3">
                    {{ (scope.row.endDateTime = '已结束') }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column
                prop="companyName"
                show-overflow-tooltip
                min-width="15%"
                align="center"
                label="结束倒计时"
                resizable
              >
                <template slot-scope="scope">
                  <div class="auction" v-if="scope.row.endStatus == 1">
                    <div id="box">
                      <div
                        id="time"
                        :class="scope.row.endDateTime.days < 0 ? 'red' : ''"
                      >
                        <strong>
                          <span id="day">
                            {{ scope.row.endDateTime.days }}天
                          </span>
                        </strong>
                        <strong>
                          <span id="hour">
                            {{ scope.row.endDateTime.hours }}时
                          </span>
                        </strong>
                        <strong>
                          <span id="minute">
                            {{ scope.row.endDateTime.minutes }}分
                          </span>
                        </strong>
                        <strong>
                          <span id="second">
                            {{ scope.row.endDateTime.seconds }}秒
                          </span>
                        </strong>
                      </div>
                    </div>
                  </div>
                  <div v-if="scope.row.endStatus == 2">
                    {{ (scope.row.endDateTime = '进行中') }}
                  </div>
                  <div v-if="scope.row.endStatus == 3">
                    {{ (scope.row.endDateTime = '已结束') }}
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="common-pagenation">
            <el-pagination
              ref="paginationPanel"
              background
              :current-page="queryParam.pageBean.page"
              :page-sizes="[20, 30, 40, 50]"
              :page-size="queryParam.pageBean.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="queryParam.pageBean.total"
            >
            </el-pagination>
          </div>
        </el-col>
        <el-col :span="8" class="common-table-quote"
          ><div class="quote-content">
            <div class="content-img">
              <img src="../../../../../assets/img/logo.png" alt="" />
            </div>
            <el-form
              ref="form"
              :model="searchForm"
              label-width="auto"
              label-position="right "
              :inline="true"
              type="flex"
              justify="left"
            >
              <el-row :gutter="24">
                <el-col :span="24">
                  <el-form-item label="当前报价(元):">
                    <span>{{ quoteForm.quote }}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="24">
                <el-col :span="24">
                  <el-form-item label="拍卖底价(元):">
                    <span>{{ quoteForm.upset }}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="24">
                <el-col :span="24">
                  <el-form-item label="加价幅度(元):">
                    <span>{{ searchForm.projectName }}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="24">
                <el-col :span="24">
                  <el-form-item label="加价倍数:">
                    <el-input-number
                      v-model="searchForm.num"
                      :min="1"
                    ></el-input-number>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="24">
                <el-col :span="24">
                  <el-form-item label="我的报价(元):">
                    <el-input-number
                      v-model="searchForm.num1"
                      :min="1"
                    ></el-input-number>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <div class="button" v-if="quoteForm.auctionStatus === 2">
              <el-button
                size="small"
                type="primary"
                class="btn btn-plus"
                @click="handleSearch"
              >
                报价
              </el-button>
              <import-file
                :importData="importData"
                @load="load"
                
              ></import-file>
            </div>
            <div class="button" v-if="quoteForm.auctionStatus === 1">
              <el-button
                disabled
                size="small"
                type="primary"
                class="btn btn-plus"
                @click="handleSearch"
              >
                未开始
              </el-button>
            </div>
            <div class="button" v-if="quoteForm.auctionStatus === 3">
              <el-button
                disabled
                size="small"
                type="primary"
                class="btn btn-plus"
                @click="handleSearch"
              >
                已结束
              </el-button>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import Breadcrumb from '@/components/Breadcrumb/index.vue'
export default {
  name: 'domesticDialog',
  components: {Breadcrumb},
  props: {
    editData: Object
  },
  data() {
    return {
      importData: {
        title: '导入报价',
        templateName: '导入报价导入模板.xls',
        downloadUrl: '/../fvue/static/excel/material.xlsx',
        importUrl: window.context.portal + '/biz/Gs/v1/importExcelData',
        showProject: true
      },
      breadcrumbOpt: [{breadcrumbName: '询价采购'}, {breadcrumbName: '报价'}],
      tableData: [
        {
          id: 1,
          quote: 0,
          upset: 1000,
          date: '2016-05-02',
          auctionStatus: 1,
          endStatus: 1,
          auctionStartDate: '2030-01-01 16:00.00',
          endCountdown: '2024-01-01 16:00.00',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        },
        {
          id: 2,
          quote: 0,
          upset: 10000,
          date: '2016-05-04',
          auctionStatus: 1,
          endStatus: 2,
          auctionStartDate: '2030-01-01 16:00.00',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1517 弄'
        },
        {
          id: 3,
          quote: 0,
          upset: 100000,
          date: '2016-05-01',
          auctionStatus: 2,
          endStatus: 2,
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        },
        {
          id: 4,
          quote: 0,
          upset: 1000000,
          date: '2016-05-03',
          auctionStatus: 3,
          endStatus: 3,
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄'
        }
      ],
      quoteForm: {},
      tableLoading: false,
      searchForm: {
        num: 1,
        num1: 1
      }, // 顶部搜索对象
      params: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0
        }
      },
      pageResult: {
        page: 1,
        pageSize: 20,
        total: 0
      }
    }
  },
  created() {},
  mounted() {
    this.tableData.forEach(ele => {
      ele.dateTime = {
        dd: '**',
        hh: '**',
        mm: '**',
        ss: '**'
      }
      this.countDownMethod(ele)
    })
    this.quoteForm = this.tableData[1]
  },
  methods: {
    //行点击事件
    handleTable(row) {
      this.quoteForm = row
    },
    // 倒计时定时器
    countDownMethod(row) {
      row.countDown = setInterval(() => {
        const date = new Date(row.auctionStartDate) - new Date()
        if (date > 0) {
          row.dateTime = this.formatDate(date)
          this.tableData = [...this.tableData]
        } else {
          clearInterval(row.countDown)
        }
      }, 1000)
      row.endDown = setInterval(() => {
        const endDate = new Date(row.endCountdown) - new Date()
        if (endDate > 0) {
          row.endDateTime = this.formatDate(endDate)
          this.tableData = [...this.tableData]
        } else {
          clearInterval(row.endDown)
        }
      }, 1000)
    },
    formatDate(time) {
      const date = new Date(time)
      let days = this.addZero(Math.floor(time / 1000 / 60 / 60 / 24)) //天
      let hours = this.addZero(Math.floor((time / 1000 / 60 / 60) % 24)) //时
      let minutes = this.addZero(Math.floor((time / 1000 / 60) % 60)) //分
      let seconds = this.addZero(Math.floor((time / 1000) % 60)) //秒
      const dd = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
      const hh = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
      const mm =
        date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
      const ss =
        date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
      return {
        days,
        hours,
        minutes,
        seconds
      }
    },
    addZero(d) {
      return parseInt(d) < 10 ? '0' + d : d
    },
    load() {
      // this.loadData()
    },
    // 关闭//面包屑点击
    handleClose() {
      this.$router.push({
        name: 'quotesMy',
        params: {
          tabsActiveName: 'InquiryProcurement',
          pageBean: this.$route.query.pageBean
        }
      })
    },
    //重置
    clearSearchForm() {},
    // 顶部搜索
    handleSearch(searchForm) {
      debugger
      let obj = searchForm
      console.log(obj)
      let querys = []
      for (let i in obj) {
        if (obj[i]) {
          querys.push({
            group: 'main',
            operation:
              i == 'name' || i == 'code' || i == 'companyName'
                ? 'LIKE'
                : 'EQUAL',
            parentGroup: '',
            property: i,
            relation: 'AND',
            value: obj[i]
          })
        }
      }
      console.log(querys, 'querys')
      this.params.querys = querys
      console.log(this.params, 'params')
      this.loadData(this.params)
    }
  }
}
</script>

<style lang="scss" scoped>
.common-page-shadow {
  width: 100%;
  height: calc(100% - 40px);
  box-sizing: border-box;
  margin-top: 10px;
  .common-search-container {
    height: 80px;
    div {
      display: flex;
      align-items: center;
    }
  }
  .common-table-container {
    height: calc(100% - 80px);
    .common-table-quote {
      height: 100%;
      padding: 26px 20px 40px 20px;
      .quote-content {
        border: 1px solid #eee;
        border-radius: 10px;
        height: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        .content-img {
          display: flex;
          justify-content: center;
          img {
            width: 80%;
          }
        }
        .button {
          display: flex;
          justify-content: center;
        }
      }
    }
  }
}

.rows {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ebebeb;
  margin-bottom: 16px;
  padding: 10px 0;
  .rows-left {
    margin-right: 10px;
    .rows-hr {
      width: 3px;
      height: 18px;
      background-color: #0e6eff;
      border-radius: 2px;
    }
  }
  .rows-title {
    .text-overflow {
      width: 100%;
      font-size: 16px;
    }
  }
}
</style>
