<template>
  <div class="price">
    <div class="flex">
      <div>
        <div class="flex-item" style="margin-bottom: 0.2rem;">
          <span class="t1 left">行业类别</span>
          <el-select v-model="getData.industryId" placeholder="请选择">
            <el-option
              v-for="item in industryOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
          <span class="t1 left">所在地区</span>
          <citySelect @sendprovinceId="receiveP" @sendcityId="receiveC" @senddistrictId="receiveS" ref = "mychild"></citySelect>
        </div>
        <div class="flex-item t1">
          <span class="t1 left">发布日期</span>
          <el-date-picker
            v-model="interTimerPicker"
            :picker-options="pickerOptions"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="testChange"
            :beginDate="getData.beginDate"
            :endDate="getData.endDate"
            style="width:240px"
          ></el-date-picker>
          <span class="left">项目名称</span>
          <el-input v-model="getData.title" placeholder="请输入内容" style="width: 2.3rem;" ></el-input>
          <div style="width:0.6rem;" class="flex">
              <el-button style="margin-left:20px" @click="queryStr">查询</el-button>
              <el-button class="reset" @click="reset">重置</el-button>
          </div>
        </div>
      </div>
      <!-- <div style="width:0.6rem;">
        <el-button type="primary" style="margin-bottom: 0.1rem;" @click="queryStr">查询</el-button>
        <el-button class="reset" @click="reset">重置</el-button>
      </div> -->
    </div>
    <ul v-if="isshow1">
      <li v-if = "!isshow1">暂无数据</li>
      <li v-for="item in priceList" :key="item.id">
        <div @click="handleChageUrl(item.noticeId)">  
          <div class="time">{{getTimer(item.createTime)}}</div>
          <div class="price-item">
            <div class="t1" style="font-weight: bold;">
              <span class="state-red">{{noticeT}}</span>
              <span>{{item.title}}</span>
            </div>
            <div class="flex-between">
              <div>所属行业:{{item.industryName}}</div>
              <div>采购商:{{item.companyName}}</div>
            </div>
            <div class="flex-between">
              <div
              >所属地区:{{item.area}}</div>
              <div>
                招标状态:
                <span class="state-red">{{item.projectStatus}}</span>
              </div>
            </div>
          </div>
        </div>
      </li>
    </ul>
    <!-- <div v-show="isshow">
      <h2>参与报价供应商情况</h2>
      <dataTable :table-data="tabledata" :columns="columns" :isPageobj="false"></dataTable>
    </div> -->
    <div class="pagination flex-center">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="getData.currentPage"
        :pageSize="getData.size"
         :page-sizes="[10, 20, 30, 40]"
        layout="total,prev, pager, next, sizes,jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import dataTable from "@/components/dataTable.vue";
import { getInquiryList} from "@/common/list.js";
import { industryList} from "@/api/common/list.js";
import citySelect from "@/components/citySelect.vue"
import Cookies from 'js-cookie'
export default {
  components: {
    citySelect,
    dataTable
  },
  async asyncData({query}){
       let mes ={
        currentPage:1,
        size:10,
        noticeType:"ENQUIRY"
      }  
        const res = await industryList();
        const {data,total} = await getInquiryList(mes)
        return {
          priceList : data,
          total : total,
          industryOptions:res
        }
  },
  mounted(){
      console.log(11111111111)
      if(Cookies.get("details")){
        let mes = {}
        mes.currentPage = Cookies.get("currentPage")
        mes.size = Cookies.get("size")
        mes.noticeType = "ENQUIRY"
        this. getInquiryList(mes)
      }
      this. industryList();
      Cookies.remove("details")
      Cookies.remove("currentPage")
      Cookies.remove("size")
    },
  data() {
    return {
      cacheCurrentPage:'',
      noticeT:'[询价公告]',
      isshow1:true,
      isshow: false,
      tabledata: [
        {
          num: 1111,
          price: 6666,
          timer: "2016-03-02",
        },
      ],
      columns: [
        {
          label: "序号",
          prop: "num",
        },
        {
          label: "报价",
          prop: "price",
        },
        {
          label: "供应时间",
          prop: "timer",
        },
      ],
      total: 1,
      getData: {
        industryId: "",
        beginDate: "",
        endDate: "",
        title: "",
        provinceId: "",
        cityId: "",
        districtId: "",
        size: 10,
        currentPage: 1,
        noticeType:'ENQUIRY'
      },
      priceList: [
        {
          id: "",
          time: "",
          title: "",
          industry: "",
          user: "",
          local: "",
          state: "",
        }
      ],
      interTimerPicker: "",
      industry: "",
      pickerOptions: {
        disabledDate: (time) => {
          return this.dealDisabledDate(time);
        },
      },

      industryOptions: [
        
      ],
      value: "",
    };
  },
  /* destroyed(){
    Cookies.remove("details");
  }, */
  methods: {
    //年月日
    getTimer(dateStr){
      var date = new Date(dateStr);
      var Month = date.getMonth() + 1;
      var Day = date.getDate();
      var Y = date.getFullYear() + '-';
      var M = Month < 10 ? '0' + Month + '-' : Month + '-';
      var D = Day  < 10 ? '0' + Day : Day;
      return Y + M + D 
    },
    
    testChange(e) {
      //将标准时间转换为时间戳
      this.getData.beginDate = e[0].getTime();
      this.getData.endDate = e[1].getTime();
      console.log(e[0].getTime());
    },
    //查询按钮getLi
    async queryStr() {
      console.log(this.getData);
      const { data,total,code } = await getInquiryList(this.getData);
      this.priceList = data;
      this.total = total
      if(code==200){
        if(total==0){
          this.$message.error("当前查询无内容!")
          this.reset()
        }else{
          this.$message.success("查询成功!")
        }
      }
    },
    async industryList() {
      const res = await industryList();
      this.industryOptions = res;
    },
    async reset() {
      this.getData.industryId = ''
      this.interTimerPicker = '' 
      this.$refs.mychild.clear()  
      this.getData.title = ''
      this.getInquiryList(this.getData)
    },
    async getInquiryList(params) {
      const { data, total} = await getInquiryList(params);
      console.log(data+'-------------------');
      this.priceList = data;
      if(total===null||0){
        this.isshow1 = false
      }
      this.total = total
    },
    receiveP(value) {
      this.getData.provinceId = value;
    },
    receiveC(value) {
      this.getData.cityId = value;
    },
    receiveS(value) {
      this.getData.districtId = value;
    },
    handleSizeChange(val) {
      let mess = {}
      mess.size = val
      this.getData.size = val
      mess.currentPage = this.getData.currentPage
      mess.noticeType = "ENQUIRY"
      Cookies.set("size",val)
      this.getInquiryList(mess)
    },
    handleCurrentChange(val) {
      let mess = {}
      mess.noticeType = "ENQUIRY"
      mess.currentPage = val
      this.getData.currentPage = val
      mess.size = this.getData.size
      Cookies.set("currentPage",val)
      this.getInquiryList(mess);
    },
    dealDisabledDate(time) {
      // 一天的毫秒数 = 8.64e7  判断时在return处可进行加减
      let curDate = new Date().getTime();
      let day = 12 * 30 * 24 * 3600 * 1000;
      let dateRegion = curDate - day;
      return time.getTime() > Date.now() || time.getTime() < dateRegion;
    },
    handleChageUrl(id){
      Cookies.set("details",true)
      /* let path = this.$router.path
      if(path=="/notice/inquiry/"){
        return this.$router.go(`notice/enquirydetails?id=${id}`)
      } */
      return this.$router.push(`/notice/enquirydetails?id=${id}`)
    }
  },
};
</script>
<style scoped>
.pagination{
  position: absolute;
  left: 50%;
  transform:translateX(-50%);
  margin-top:20px
}
.price {
  width: 9.2rem;
  position: relative;
}

.left {
  margin-left: 0.3rem;
  margin-right: 0.15rem;
  width:70px;
}
  .el-button{
    color: #fff;
    background-color: #FF5203;
  }
  .el-button:hover{
    background-color: #FF5203;
    color: #FFFFFF
  }
  .el-button:focus{
    background-color: #FF5203;
    color: #FFFFFF
  } 

.reset {
  color:#FF5203;
  background: #FFFFFF;
  border: 1px solid #FF5203
}

.price > ul {
  width: 9.3rem;
  box-sizing: border-box;
  padding-top: 0.2rem;
}

.price > ul > li {
  height: 1.87rem;
  border: 1px solid rgba(219, 219, 219, 1);
  margin-bottom: 0.2rem;
}

.price > ul > li .time {
  height: 0.41rem;
  line-height: 0.41rem;
  box-sizing: border-box;
  padding-left: 0.2rem;
  border-bottom: 1px solid rgba(219, 219, 219, 1);
  font-size: 0.16rem;
  color: rgba(153, 153, 153, 1);
}

.price > ul > li .price-item {
  margin: 0.13rem 0 0 0.2rem;
}

.price > ul > li .price-item > div {
  font-size: 0.14rem;
  color: rgba(76, 76, 76, 1);
}

.price-item > div:first-child {
  font-size: 0.16rem;
}

.price-item > div:nth-child(2) {
  margin-top: 0.24rem;
  margin-bottom: 0.19rem;
  width: 4.5rem;
}

.price-item > div:last-child {
  width: 4.5rem;
}

.state-red {
  color:#FF5203
}
   /* 更改element-UI按钮样式 */
</style>