<template>
  <div id="xmcg">
    <el-row style="min-width: 1200px;">
      <el-col :span="24" class="main">
        <el-col :span="24" class="one">
          <div class="w_1200">
            <el-col :span="20" class="left">
              <el-col :span="24" class="leftone">
                <span>科技成果展洽会</span>
                <span>欢迎您</span>
              </el-col>
              <el-col :span="24" class="lefttwo">
                SCIENTIFIC AND TECHNOLOGICAL ACHIEVEEMENTS EXHIBITION
              </el-col>
            </el-col>
            <el-col :span="4" class="right">
              <el-link :underline="false">帮助中心</el-link>
            </el-col>
          </div>
        </el-col>
        <el-col :span="24" class="two">
          <div class="w_1200">
            <el-col :span="24" class="twotop">
              <el-col :span="18" class="left">
                <p>{{ dockInfo.title }}</p>
                <el-image :src="two1"></el-image>
              </el-col>
              <el-col :span="6" class="right">
                <el-image :src="two2"></el-image>
                <p>{{ dockInfo.start_time }}</p>
                <p>距离展会开始还有</p>
                <p>{{ djs }}</p>
              </el-col>
            </el-col>
            <el-col :span="24" class="twocen">
              <el-col :span="15" class="left"> <span>主办单位：</span>{{ dockInfo.sponsor }} </el-col>
              <el-col :span="8" class="right">
                <el-button class="btn1" @click="$router.push({ path: '/halltwo/directTwo', query: { id: dockInfo.id } })">返回展会进行页</el-button>
                <el-button class="btn2" @click="$router.push({ path: '/halltwo/detail', query: { dock_id: dockInfo.id } })">进入展会总结页</el-button>
              </el-col>
            </el-col>
          </div>
        </el-col>
        <el-col :span="24" class="three">
          <div class="w_1200">
            <el-col :span="24" class="threeinfo">
              <p>项目成果</p>
              <el-col :span="24" class="all">
                <span class="field" v-for="(item, index) in fieldList" :key="index" @click="change(item, index)" :class="{ active: num == index }">{{
                  item.name
                }}</span>
              </el-col>
              <el-col :span="24" class="list">
                <el-table :data="list1" stripe style="width: 100%" fit :show-header="false">
                  <el-table-column prop="field" width="300">
                    <template slot-scope="scope">
                      <span style="margin-left: 20px">{{ scope.row.field || '暂无' }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column prop="name" width="700">
                    <template slot-scope="scope">
                      <span class="name">{{ scope.row.name }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column>
                    <template slot-scope="scope">
                      <el-button size="mini" type="primary" @click="handleEdit(scope.$index, scope.row)">对接</el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <el-col class="page1" :span="24">
                  <el-pagination
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    layout="total, prev, pager, next, jumper"
                    :total="total"
                    :page-size="pageSize"
                  >
                  </el-pagination>
                </el-col>
              </el-col>
            </el-col>
          </div>
        </el-col>
        <el-col :span="24" class="four">
          <div class="w_1200">
            <ywlx></ywlx>
          </div>
        </el-col>
      </el-col>
      <div class="pz_down">
        <live-foot></live-foot>
      </div>
    </el-row>
  </div>
</template>

<script>
import ywlx from './parts/ywlx.vue';
import liveFoot from '@/layout/live/foot.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: dock } = createNamespacedHelpers('dock');
const { mapActions: markettype } = createNamespacedHelpers('markettype');
var moment = require('moment');
export default {
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  name: 'xmcg',
  props: {},
  components: {
    liveFoot,
    ywlx,
  },
  data: function() {
    return {
      two1: require('@a/sy_04.png'),
      two2: require('@a/dock2.png'),
      // 展會詳情
      dockInfo: {},
      // 指导单位
      erweima: require('@a/二维码.jpg'),
      //领域列表
      fieldList: [],
      //全部列表
      list: [],
      //列表头部
      // showHead: false,
      pageSize: 10,
      total: 0,
      currentPage: 1,
      origin: [],
      list1: [],
      num: '0',
      // 倒计时
      djs: '',
    };
  },
  async created() {
    await this.searchType();
    await this.searchInfo();
  },
  methods: {
    ...dock({ dockQuery: 'query', dockFetch: 'fetch', goodsquery: 'goodsquery' }),
    ...markettype({ markettypeList: 'query' }),
    async searchInfo() {
      // 查询展会详情
      if (this.dock_id) {
        let res = await this.dockFetch(this.dock_id);
        if (this.$checkRes(res)) {
          this.$set(this, `dockInfo`, res.data);
          let czxm = res.data.apply.map(item => item.goodsList);
          czxm = _.flattenDeep(czxm);
          let czxmNew = czxm.filter(item => item.dockStatus == '1');
          // 技术成果
          let achieve = czxmNew.filter(i => i.type == '1');
          this.$set(this, `list`, achieve);
          this.$set(this, `total`, achieve.length);
        }
      }
    },
    seachtime() {
      // 倒计时
      this.timer = setInterval(() => {
        this.setTime(this.dockInfo.start_time);
      }, 1000);
    },
    // 倒计时
    setTime(end) {
      let now = moment().format('YYYY-MM-DD HH:mm:ss');
      // let now = moment().format('2020-11-20 08:00:00');
      if (end == now) {
        clearInterval(this.timer);
        this.$set(this, `djs`, '展会开始');
      } else {
        let sec = moment(end).diff(now, 'seconds');
        let day = _.floor(sec / 60 / 60 / 24);
        let hour = _.floor(Math.abs(day * 24 - sec / 60 / 60));
        let dayhour = day * 24;
        let minute = _.floor(Math.abs(day * 24 * 60 + hour * 60 - sec / 60));
        let second = _.floor(Math.abs(day * 24 * 60 * 60 + hour * 60 * 60 + minute * 60 - sec));
        let str = `${hour + dayhour}小时${minute}分${second}秒`;
        this.$set(this, `djs`, str);
      }
    },
    async searchType() {
      //查领域
      const res1 = await this.markettypeList({ category: '01' });
      if (res1) {
        res1.data.unshift({ name: '全部' });
        this.$set(this, `fieldList`, res1.data);
      }
    },
    searchPage(page = 1) {
      this.$set(this, `list1`, this.origin[page - 1]);
    },
    handleCurrentChange(currentPage) {
      this.searchPage(currentPage);
    },
    // 项目对接
    handleEdit(index, row) {
      this.$router.push({ path: '/halltwo/xmdj', query: { dock_id: this.dock_id, id: row._id, type: row.type } });
    },
    change(item, index) {
      let val = this.list;
      if (item.name == '全部') {
        this.searchInfo();
      } else {
        let techol = val.filter(i => i.field == item.name);
        this.$set(this, `list1`, techol);
        this.$set(this, `total`, techol.length);
      }
      this.num = index;
    },
  },
  computed: {
    ...mapState(['user']),
    dock_id() {
      return this.$route.query.dock_id;
    },
  },
  watch: {
    list: {
      immediate: true,
      deep: true,
      handler(val) {
        if (val && val.length > 0) this.$set(this, `origin`, _.chunk(val, this.pageSize));
        this.searchPage();
      },
    },
    dockInfo: {
      immediate: true,
      deep: true,
      handler(val) {
        this.seachtime();
      },
    },
  },
};
</script>

<style lang="less" scoped>
.active {
  background-color: #2152cb;
  color: #fff;
}
.main {
  .one {
    height: 100px;
    .left {
      height: 100px;
      .leftone {
        margin: 15px 0 0 0;
        span:nth-child(1) {
          font-size: 35px;
          color: #535353;
          font-weight: bold;
          font-family: cursive;
        }
        span:nth-child(2) {
          font-size: 15px;
          padding: 0 10px;
          color: #535353;
        }
      }
      .lefttwo {
        font-size: 12px;
        color: #535353;
      }
    }
    .right {
      height: 100px;
      line-height: 100px;
      text-align: right;
    }
  }
  .two {
    height: 610px;
    background: url('~@/assets/bj1.jpg');
    padding: 20px 0;
    .twotop {
      margin: 0 0 10px 0;
      .left {
        height: 357px;
        margin: 0 10px 0 0;
        background: url('~@/assets/dock1.png');
        p {
          float: left;
          width: 79%;
          font-size: 43px;
          color: #fff;
          font-weight: bold;
          padding: 13% 0 0 20px;
        }
        .el-image {
          float: left;
          width: 153px;
          height: 94px;
          margin: 4% 0 0 0;
        }
      }
      .right {
        background-color: #ffffff;
        width: 24%;
        height: 357px;
        text-align: center;
        padding: 0 10px;
        .el-image {
          width: 120px;
          height: 48px;
          margin: 50px 0 0px 0;
        }
        p:nth-child(2) {
          font-size: 18px;
          margin: 30px 0 5px 0;
        }
        p:nth-child(3) {
          font-size: 22px;
          font-weight: bold;
          margin-bottom: 30px;
        }
        p:nth-child(4) {
          background: #f5f5f5;
          padding: 20px 0px;
          border-radius: 5px;
          font-size: 30px;
        }
      }
      .right:hover {
        cursor: pointer;
        p:nth-child(3) {
          color: #535353;
        }
      }
    }
    .twocen {
      height: 130px;
      overflow: hidden;
      line-height: 130px;
      background-color: #fff;
      margin: 0 0 35px 0;
      .left {
        font-size: 18px;
        margin: 0 0 0 30px;
        span {
          font-size: 22px;
          font-weight: bold;
        }
      }
      .right {
        .btn1 {
          font-size: 16px;
          color: #fff;
          background: red;
          border: none;
          font-weight: bold;
        }
        .btn2 {
          font-size: 16px;
          color: #ff0000;
          border: 1px solid #ff0000;
          font-weight: bold;
        }
      }
    }
  }
  .three {
    height: 860px;
    overflow: hidden;
    position: relative;
    top: -50px;
    z-index: 999;
    .threeinfo {
      height: 860px;
      overflow: hidden;
      background-color: #fff;
      box-shadow: 0 5px 15px rgba(33, 82, 203, 0.35);
      padding: 30px;
      p:nth-child(1) {
        font-family: '微软雅黑';
        font-weight: 400;
        font-size: 26px;
      }
      .all {
        line-height: 46px;
        background: #f8f8f8;
        margin: 20px 0 40px 0;
        .field {
          font-size: 18px;
          display: inline-block;
          height: 46px;
          min-width: 106px;
          text-align: center;
          padding: 0 15px;
        }
        .field:hover {
          color: #fff;
          background-color: #2152cb;
          cursor: pointer;
        }
      }
      .list {
        .page1 {
          margin: 40px 0px;
          text-align: center;
        }
        .name:hover {
          color: #777;
          cursor: pointer;
        }
      }
    }
  }
  .four {
    border-top: 2px solid #305798;
    height: 250px;
    .info {
      .left {
        h1 {
          padding: 15px 0;
          font-weight: bold;
          color: #4d4d4d;
        }
        p {
          font-size: 16px;
          color: #4d4d4d;
          padding: 5px 0;
        }
      }
      .right {
        text-align: center;
      }
    }
  }
}
/deep/.el-table .cell {
  font-weight: 400;
  font-size: 14px;
  color: black;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
</style>
