<template>
  <div class="price">
    <div class="flex">
      <div>
        <div class="flex-item" style="margin-bottom: 0.1rem;">
          <span class="t1 left">行业类别</span>
          <el-select v-model="getData.industryId" placeholder="请选择">
            <el-option
              v-for="item in industryoptions"
              :key="item.value"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
          <span class="t1 left">所属地区</span>
          <citySelect @sendprovinceId="receiveP" @sendcityId="receiveC" @senddistrictId="receiveS"></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="结束日期"
            :beginDate="getData .beginDate"
            :endDate="getData.endDate"
            @change = "changeTime"
          ></el-date-picker>
          <span class="left">项目</span>
          <el-input v-model="getData.title" placeholder="请输入内容" style="width: 2.3rem;"></el-input>
        </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>
      <li v-for="item in priceList" :key="item.id">
        <!-- 绑定中标详情页 -->
        <nuxt-link :to="`/notice/windetails?id=${item.id}`">
          <div class="time">{{getTimer(item.createTime)}}</div>
          <div class="price-item">
            <div class="t1" style="font-weight: bold;">
              <span class="state-red">[中标公告]</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>
        </nuxt-link>
      </li>
    </ul>
    <div class="pagination flex-center">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="getData.currentPage"
        :page-size="getData.size"
        :total="total"
        layout="total, prev, pager, next, jumper"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { getWinList } from "@/common/list.js";
import { industryList } from "@/api/common/list.js";
import citySelect from "@/components/citySelect.vue";
export default {
  components: {
    citySelect,
  },
  created() {
    let message = {}
    message.size = 10
    message.currentPage = 1
    this.getWinList(message);
    this.industryList();
  },
  data() {
    return {
      getData: {
        industryId: "",
        beginDate: "",
        endDate: "",
        title: "",
        provinceId: "1",
        cityId: "1",
        districtId: "1",
        size: 10,
        currentPage: 1,
      },
      total: 0,
      priceList: [
        {
          id: "",
          time: "",
          title:"",
          industry: "",
          user: "",
          local: "",
          state: "",
        }
      ],
      interTimerPicker: "",
      pickerOptions: {
        disabledDate: (time) => {
          return this.dealDisabledDate(time);
        },
      },
      industryoptions: [
        {
          value: "选项1",
          label: "黄金糕",
        },
        {
          value: "选项2",
          label: "双皮奶",
        },
        {
          value: "选项3",
          label: "蚵仔煎",
        },
        {
          value: "选项4",
          label: "龙须面",
        },
        {
          value: "选项5",
          label: "北京烤鸭",
        },
      ],
      areaoptions: [
        {
          value: "选项1",
          label: "黄金糕",
        },
        {
          value: "选项2",
          label: "双皮奶",
        },
        {
          value: "选项3",
          label: "蚵仔煎",
        },
        {
          value: "选项4",
          label: "龙须面",
        },
        {
          value: "选项5",
          label: "北京烤鸭",
        },
      ],
      value: "",
      input: "",
    };
  },
  methods: {
    changeTime(e){
      this.getData.beginDate = e[0].getTime()
      this.getData.endDate = e[1].getTime()
    },
    //年月日
    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 + 1 < 10 ? '0' + Day : Day;
      return Y + M + D;
    },
    reset(){
      this.getData = ''
    },
    //查询按钮getLi
    async queryStr() {
      console.log(this.getData);
      const { data } = await getWinList(this.getData);
      this.priceList = data;
    },
    async industryList() {
      const res = await industryList();
      this.industryoptions = res;
    },
    async getWinList(params) {
      const { data, total } = await getWinList(params);
      for (var i = 0; i < data.length; i++) {
        if (data[i].auditStatus === 0) {
          data[i].auditStatus = "待审核";
        }
        if (data[i].auditStatus === 1) {
          data[i].auditStatus = "审核通过";
        }
        if (data[i].auditStatus === 2) {
          data[i].auditStatus = "未通过";
        }
      }
      this.total = total;
      this.priceList = data;
    },
    receiveP(data) {
      this.getData.provinceId = data;
    },
    receiveC(data) {
      this.getData.cityId = data;
    },
    receiveS(data) {
      this.getData.districtId = data;
    },
    handleSizeChange(val) {
      this.getWinList(val, this.currentPage);
    },
    handleCurrentChange(val) {
      this.getWinList(this.size, val);
    },
    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;
    },
  },
};
</script>
<style scoped>
.price {
  width: 9.2rem;
}

.left {
  margin-left: 0.3rem;
  margin-right: 0.15rem;
}

.reset {
  color: rgba(4, 134, 254, 1);
  background: rgba(230, 241, 252, 1);
  border: 1px solid rgba(163, 208, 253, 1);
}

.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: rgba(255, 24, 24, 1);
}
</style>

