<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main">
        <div class="w_1200">
          <el-col :span="24" class="common one">
            <el-col :span="12" class="left">
              <top topText="科技成果" @more="more('0')"></top>
              <list type="1" :list="oneList" @detail="detail"></list>
            </el-col>
            <el-col :span="12" class="left">
              <top topText="专利信息" @more="more('1')"></top>
              <list type="2" :list="twoList" @detail="detail"></list>
            </el-col>
          </el-col>
          <el-col :span="24" class="common two">
            <el-col :span="12" class="left">
              <top topText="专家智库" @more="more('2')"></top>
              <list type="3" :list="thrList" @detail="detail"></list>
            </el-col>
            <el-col :span="12" class="left">
              <top topText="项目路演" @more="more('3')"></top>
              <list type="4" :list="fourList" @detail="detail"></list>
            </el-col>
          </el-col>
          <el-col :span="24" class="common thr">
            <el-col :span="12" class="left">
              <top topText="科技需求" @more="more('4')"></top>
              <list type="5" :list="fiveList" @detail="detail"></list>
            </el-col>
            <el-col :span="12" class="left">
              <top topText="商务服务" @more="more('5')"></top>
              <list type="6" :list="sixList" @detail="detail"></list>
            </el-col>
          </el-col>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import top from './parts/top.vue';
import list from './parts/list.vue';
const { productType } = require('@common/dict/index');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: product } = createNamespacedHelpers('product');
const { mapActions: patent } = createNamespacedHelpers('patent');
const { mapActions: roadShow } = createNamespacedHelpers('roadShow');
const { mapActions: expert } = createNamespacedHelpers('expert');

export default {
  name: 'index',
  props: {},
  components: { top, list },
  data: function () {
    return {
      oneList: [],
      twoList: [],
      thrList: [],
      fourList: [],
      fiveList: [],
      sixList: [],
      productType: productType,
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    ...product({ productQuery: 'query' }),
    ...patent({ patentQuery: 'query' }),
    ...roadShow({ roadShowQuery: 'query' }),
    ...expert({ expertQuery: 'query' }),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      for (const val of this.productType) {
        if (val.value == '0') {
          // 科技需求
          let res = await this.productQuery({ skip, limit: 6, type: val.value, ...info });
          if (this.$checkRes(res)) this.$set(this, `fiveList`, res.data);
        } else if (val.value == '1') {
          // 技术成果
          let res = await this.productQuery({ skip, limit: 6, type: val.value, ...info });
          if (this.$checkRes(res)) this.$set(this, `oneList`, res.data);
        } else if (val.value == '2') {
          // 商务服务
          let res = await this.productQuery({ skip, limit: 5, type: val.value, ...info });
          if (this.$checkRes(res)) this.$set(this, `sixList`, res.data);
        }
      }
      // 专利信息
      let res = await this.patentQuery({ skip, limit: 6, ...info });
      if (this.$checkRes(res)) this.$set(this, `twoList`, res.data);
      // 项目路演
      res = await this.roadShowQuery({ skip, limit: 5, ...info });
      if (this.$checkRes(res)) this.$set(this, `fourList`, res.data);
      // 专家智库
      res = await this.expertQuery({ skip, limit: 6, ...info });
      const { img_url } = res.data;
      if (this.$checkRes(res)) this.$set(this, `thrList`, res.data);
    },
    // 更多
    more(index) {
      this.$router.push({ path: '/market/list', query: { index: index } });
    },
    // 详情
    detail({ id, index }) {
      this.$router.push({ path: '/market/list', query: { id: id, index: index } });
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  min-height: 500px;
  margin: 10px 0 0 0;
  .common {
    margin: 0 0 10px 0;
    .left {
      width: 49.5%;
      height: 500px;
      overflow: hidden;
      box-shadow: 0 0 4px #409eff;
      border-radius: 10px;
      margin: 0 10px 10px 0;
      padding: 10px;
    }
    .left:nth-child(2n) {
      margin: 0 0 10px 0;
    }
  }
}
</style>
