<template>
  <view>
    <block v-if="options.name === '便民办事'">
      <custom-nav-bar position="fixed" color="black" :left-text="options.name" left-arrow />
      <view class="second-model">
        <view class="second-line flex flex-v-center flex-between" :data-item="item" @tap="headleDetails"
          v-for="(item, index) in newsPageList" :key="index">
          <view class="line-name flex1 line-text-1">{{ item.title }}</view>

          <image class="line-you" src="/static/images/ic-you.png"></image>
        </view>
      </view>
    </block>

    <block v-if="options.name === '政策推送'">
      <custom-nav-bar :left-text="options.name" left-arrow />
      <image class="second-header" :src="recursionObj.icon"></image>

      <view class="second-section">
        <view class="section-item flex flex-between" :data-item="item" @tap="headleDetails"
          v-for="(item, index) in newsPageList" :key="index">
          <view class="section-item-left flex1 flex flex-between flex-col">
            <view class="consult-content-title text-line-2">{{ item.title }}</view>
            <view class="consult-content-block">
              <text class="block-first">{{ getDateTime(item.createTime) }}</text>
              <text>{{ item.publisher }}</text>
            </view>
          </view>

          <image class="section-item-right" :src="item.pics" mode="aspectFill"></image>
        </view>
      </view>
    </block>

    <!-- 此处归属于生活模块 -->
    <block v-if="options.pageType === '1'">
      <custom-nav-bar position="fixed" color="black" :left-text="options.name" left-arrow />
      <view class="second-model">
        <view class="second-line flex flex-v-center flex-between" :data-item="item" @tap="headleDetails2"
          v-for="(item, index) in newsPageList" :key="index">
          <view class="line-name flex1 line-text-1">{{ item.title }}</view>

          <image class="line-you" src="/static/images/ic-you.png"></image>
        </view>
      </view>
    </block>
  </view>
</template>
<!-- <script module="toods" lang="wxs" src="@/wxs/util.wxs"></script> -->
<script>
  // const app = getApp();
  // const {
  //   peopleApi,
  //   publicApi
  // } = app.globalData.api;
  import * as publicApi from '@/api/publicApi';
  import * as peopleApi from '@/api/peopleApi';
  import utils from '@/utils/util.map';
  export default {
    data() {
      return {
        options: {
          name: '',
          pageType: ''
        },
        recursionObj: {
          icon: ''
        },
        newsPageList: []
      };
    },
    onLoad(options) {
      this.options = options
      this.newsPageApi();
      if (this.options.name === '政策推送') {
        this.recursionApi();
      }
    },
    methods: {
      getDateTime(replyTime, key) {
      return utils.getDateTime(replyTime, key)
    },
      async newsPageApi() {
        const param = {
          pageNo: 1,
          pageSize: 99,
          categoryId: this.options.categoryId
        };
        const {
          data: {
            list = []
          }
        } = await peopleApi.newsPageApi(param);
        if (list.length) {
          this.newsPageList = list
        }
      },

      async recursionApi() {
        const res = await publicApi.recursionApi({
          bannerType: 3,
          parentId: this.options.parentId
        });
        if (res.data) {
          this.recursionObj = res.data[0]
        }
      },

      // 进入详情页
      headleDetails(event) {
        const {
          item
        } = event.currentTarget.dataset;
        uni.navigateTo({
          url: `/packages/public/pages/details/details-no-ops?name=${this.options.name}详情&referId=${item.id}`
        });
      },

      headleDetails2(event) {
        const {
          item
        } = event.currentTarget.dataset;
        uni.navigateTo({
          url: `/packages/public/pages/details/details-no-ops?name=介休政务百科-详情&referId=${item.id}`
        });
      }
    }
  };
</script>
<style lang="less">
  // 办事指南 start
  .second-model {
    margin-top: 32rpx;
    width: 100%;
    height: 100%;
    padding: 0 12rpx;

    .second-line {
      height: 120rpx;
      border-bottom: 1px solid #efefef;
      position: relative;

      .line-name {
        font-size: 34rpx;
        font-weight: 400;
        color: #007bd7;
        line-height: 34rpx;
        margin-left: 42rpx;
      }

      .line-you {
        width: 32rpx;
        height: 32rpx;
      }
    }
  }

  // 政策推送 start
  .second-header {
    width: 100%;
    height: 330rpx;
  }

  .second-section {
    margin-top: 50rpx;
    padding: 0 40rpx 0;

    .section-item {
      padding: 24rpx 0;
      border-bottom: 1px solid #e1e1e1;

      &:first-child {
        padding-top: 0;
      }

      .section-item-left {
        margin-right: 50rpx;

        .consult-content-title {
          font-size: 32rpx;
          font-weight: 400;
          color: #333333;
        }

        .consult-content-block {
          font-size: 24rpx;
          font-weight: 400;
          color: #999999;

          .block-first {
            margin-right: 18rpx;
          }
        }
      }

      .section-item-right {
        width: 200rpx;
        height: 150rpx;
        border-radius: 8rpx;
      }
    }
  }
</style>