<template>
  <view>
    <view class="content-ul" v-if="haveData">
      <view class="item-ul">
        <block v-for="(item, index) in newDataList" :key="index">
          <view v-if="index % 2 == 0 && item.IsShowData">
            <block v-if="item.Source === 'article' || item.Source === 'yanxuanspecial'"> <ReportItem :list="item.Article" /></block>
            <block v-if="item.Source === 'newchart'">
              <ChartItem :list="item.Newchart" :isMyChartCollection="isMyChartCollection" @myChartIsTop="myChartIsTop" @myChartCollect="myChartCollect" />
            </block>
            <block v-if="item.Source === 'roadshow' || item.Source === 'activityvideo' || item.Source === 'activityvoice'">
              <RoadshowItem :list="item.Roadshow" @isCollectionHandeler="isCollectionHandeler" />
            </block>
            <block v-if="item.Source === 'activity' || item.Source === 'activityspecial'">
              <ActivityItem :list="item.Activity" />
            </block>
            <block v-if="item.Source === 'industrialsource'">
              <Industrialsource :list="item.IndustrialResource" />
            </block>
            <block v-if="['researchsummary', 'minutessummary', 'meetingreviewchapt', 'productinterior'].includes(item.Source)">
              <item-content :list="dataListItem(item)" @showMorningDialog="showMorningDialog" />
            </block>
          </view>
        </block>
      </view>
      <view class="item-ul">
        <block v-for="(item, index) in newDataList" :key="index">
          <view v-if="index % 2 !== 0 && item.IsShowData">
            <block v-if="item.Source === 'article' || item.Source === 'yanxuanspecial'"> <ReportItem :list="item.Article" /></block>
            <block v-if="item.Source === 'newchart'">
              <ChartItem :list="item.Newchart" :isMyChartCollection="isMyChartCollection" @myChartIsTop="myChartIsTop" @myChartCollect="myChartCollect" />
            </block>
            <block v-if="item.Source === 'industrialsource'">
              <Industrialsource :list="item.IndustrialResource" />
            </block>
            <block v-if="item.Source === 'roadshow' || item.Source === 'activityvideo' || item.Source === 'activityvoice'">
              <RoadshowItem :list="item.Roadshow" @isCollectionHandeler="isCollectionHandeler" />
            </block>
            <block v-if="item.Source === 'activity' || item.Source === 'activityspecial'">
              <ActivityItem :list="item.Activity" />
            </block>
            <block v-if="['researchsummary', 'minutessummary', 'meetingreviewchapt', 'productinterior'].includes(item.Source)">
              <item-content :list="dataListItem(item)" @showMorningDialog="showMorningDialog" />
            </block>
          </view>
        </block>
      </view>
    </view>
    <view class="nodata" v-else>
      <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/act_search.png" mode="" class="nodata_ico"></image>
      <text>暂时没有符合条件的活动</text>
    </view>
    <morning-dlg v-if="isMorningShow" :isMorningShow.sync="isMorningShow" :morningItem.sync="morningItem" />
    <view v-if="showAudioBox">
      <audioModule :showAudioPop.sync="showAudioPop" />
    </view>
  </view>
</template>

<script>
import { Search, Reports } from "@/config/api";
import ChartItem from "@/components/ItemComponent/chartItem.vue";
import ReportItem from "@/components/ItemComponent/reportItem.vue";
import RoadshowItem from "@/components/ItemComponent/roadshowItem.vue";
import ActivityItem from "@/components/ItemComponent/activityItem.vue";
import ItemContent from "./ItemContent.vue";
import MorningDlg from "./morningDlg.vue";
import Industrialsource from "./industrialsource.vue";
import audioModule from "@/components/audioModule/index";
export default {
  components: { Industrialsource, ChartItem, ReportItem, RoadshowItem, ActivityItem, ItemContent, MorningDlg, audioModule },
  props: {
    searchTxt: {
      type: String,
      default: "",
    },
    isSyntheticalShow: {
      type: Boolean,
      default: false,
    },
    pageNumSynthetical: {
      type: Number,
      default: "",
    },
  },
  data() {
    return {
      newDataList: [],
      isMorningShow: false, // 晨会的弹框
      morningItem: {}, // 晨会的弹框
      haveData: true,
      showAudioPop: false,
    };
  },
  watch: {
    pageNumSynthetical: {
      handler(val) {
        if (this.isSyntheticalShow) {
          this.getComprehensiveList();
        }
      },
      deep: true,
      immediate: true,
    },
  },
  computed: {
    showAudioBox() {
      return this.$store.state.audioBg.parseIntShow;
    },
  },
  methods: {
    // 获取数据
    async getComprehensiveList() {
      const res = await Search.getComprehensiveList({
        KeyWord: this.searchTxt.replace(/^\s+|\s+$/g, ""),
        CurrentIndex: this.pageNumSynthetical,
        PageSize: 10,
      });
      if (res.Ret === 200) {
        this.$parent.status = !res.Data.Paging.IsEnd ? "loadmore" : "nomore";
        let listArr = [];
        res.Data.List &&
          res.Data.List.forEach((item) => {
            let obj = {
              Source: item.Source,
              Article: item.Article || item.YanxuanSpecial,
              Newchart: item.Newchart,
              Activity: item.Activity || item.Activityspecial,
              Roadshow: item.Roadshow || item.Activityvideo || item.Activityvoice,
              ThreeSummary: item.Researchsummary || item.Minutessummary || item.Meetingreviewchapt || item.ProductInterior,
              IndustrialResource: item.IndustrialResource,
            };
            if (obj.Article && obj.Article.BodyHighlight) {
              obj.Article.Body = obj.Article.BodyHighlight;
            }
            listArr.push({ ...obj, IsShowData: obj.Article || obj.Newchart || obj.Roadshow || obj.Activity || obj.ThreeSummary || obj.IndustrialResource });
          });
        this.newDataList = this.pageNumSynthetical === 1 ? listArr : [...this.newDataList, ...listArr];
        this.haveData = this.newDataList && this.newDataList.length ? true : false;
      }
    },
    // 晨会弹框显示
    async showMorningDialog(item) {
      if (item.Source == "meetingreviewchapt") {
        await Reports.morning_meeting_history({ Id: item.Id, SourcePage: "首页" });
        this.isMorningShow = true;
        this.morningItem = item;
      }
    },
    // 处理数据
    dataListItem(item) {
      let obj = item.ThreeSummary ? { ...item.ThreeSummary, Source: item.Source } : {};
      return obj;
    },
  },
};
</script>

<style lang="scss" scoped>
.content-ul {
  padding: 30rpx 10rpx;
  display: flex;
  justify-content: space-between;
  .item-ul {
    width: 49%;
    &:first-child {
      margin-right: 10rpx;
    }
  }
}
</style>
