<style>
.koraNews {
  width: 100%;
  height: 100vh;
  background: #f6f6f6;
  overflow: hidden;
}
.koraNewsList {
  width: 100%;
  padding: 0 15px;
  margin-top: 20px;
}
.koraNews-time {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #b9bcca;
  font-family: aa;
}
.koraNews-box {
  width: 100%;
  border-radius: 6px;

  background: #fff;
  overflow: hidden;
  margin-top: 10px;
}
.newsimgs {
  width: 100%;
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
  height: 145px;
}
.n-img {
  width: 100%;
  height: 100%;
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
}
.box-conet {
  width: 100%;
  padding: 10px 15px;
}
.koraRName {
  color: #111111;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 28rpx;
  line-height: 30rpx;
  font-weight: 600;
}
.koraRName-f {
  font-size: 12px;
  color: #999999;
  margin-top: 5px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.koraNewsSearch {
  padding: 0px 10px 10px;
}
</style>
<template>
  <view class="koraNews">
    <view class="koraNewsSearch">
      <u-search
        action-text="搜索"
        :clearabled="true"
        style="width: 95%"
        :show-action="false"
        radius="40"
        v-model="msg.Title"
        @search="getList(1)"
        @custom="getList(1)"
      ></u-search>
    </view>
    <view
      style="
        display: flex;
        align-items: center;
        margin-bottom: 30rpx;
        padding: 0px 15px;
      "
    >
      <image
        @click="goNewFirstShop"
        src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Test/Upload/Goods/1616490607000_36.png"
        style="flex: 1; width: 1px; margin-right: 15rpx"
        mode="widthFix"
      ></image>
      <image
        @click="goMyFirstShop"
        src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Test/Upload/Goods/1616490607000_108.png"
        style="flex: 1; width: 1px; margin-left: 15rpx"
        mode="widthFix"
      ></image>
    </view>
    <u-empty v-if="dataList.length == 0" text="暂无数据" mode="data"></u-empty>
    <scroll-view
      v-else
      :scroll-y="true"
      :enable-back-to-top="true"
      :enable-flex="true"
      @scrolltolower="lower"
      style="height: calc(100vh - 189px)"
    >
      <view
        style="font-size: 30rpx; font-weight: 700; color: #111; padding: 0 15px"
        >资讯信息</view
      >
      <view>
        <view
          class="koraNewsList"
          v-for="(item, index) in dataList"
          :key="index"
          @click="goNewsDetail(item)"
        >
          <view class="koraNews-time">{{
            item.CreateDate ? item.CreateDate.replace("T", " ") : ""
          }}</view>
          <view class="koraNews-box">
            <view class="newsimgs" style="position: relative">
              <image :src="item.CoverImg" mode="aspectFill" class="n-img" />
              <view
                style="top: 10px; left: 10px; position: absolute"
                v-if="item.Industry && item.Industry.length > 0"
              >
                <u-tag
                  :text="item.Industry"
                  mode="dark"
                  bg-color="rgba(0,0,0,.4)"
                  color="#FFF"
                  size="mini"
                ></u-tag>
              </view>
            </view>
            <view class="box-conet">
              <view class="koraRName">{{ item.Title }}</view>
              <view class="koraRName-f">{{ item.Subtitle }}</view>
            </view>
          </view>
        </view>
      </view>

      <u-loadmore
        :status="status"
        :load-text="loadText"
        :font-size="24"
        :margin-top="20"
        :margin-bottom="20"
        bg-color="#F6F6F6"
      />
    </scroll-view>
    <tabbars></tabbars>
  </view>
</template>

<script>
import tabbars from "@/components/tabbar/index";
export default {
  components: {
    tabbars,
  },
  data() {
    return {
      pageTitle: "首店经济",
      msg: {
        pageIndex: 1,
        pageSize: 10,
        Title: "",
        // Type:1
      },
      pageCount: 1,
      dataList: [],
      loadText: {
        loadmore: "轻轻上拉，加载更多",
        loading: "努力加载中",
        nomore: "",
      },
      status: "",
      CommpanyStatus: 0, //公司认证状态
      FirstShopType: 0, //1：品牌，2：载体
    };
  },
  onShareTimeline() {
    //朋友圈
    let uid = uni.getStorageSync("mall_UserInfo")
      ? uni.getStorageSync("mall_UserInfo").UserId
      : 0;
    if (uid == 0) {
      uid = uni.getStorageSync("pid") ? uni.getStorageSync("pid").pid : 0;
    }
    let SmallShopId = uni.getStorageSync("mall_UserInfo")
      ? uni.getStorageSync("mall_UserInfo").SmallShopId
      : 0;
    if (SmallShopId == 0) {
      //如果微店id为0 去找所属微店id
      SmallShopId = uni.getStorageSync("mall_UserInfo")
        ? uni.getStorageSync("mall_UserInfo").UserSmallShopId
        : 0;
    }
    let Up = uni.getStorageSync("mall_UserInfo")
      ? uni.getStorageSync("mall_UserInfo").UserPageType
      : 0;
    return {
      title: "首店经济",
      query: "user_id=" + uid + "&SmallShopId=" + SmallShopId + "&Up=" + Up,
      imageUrl: "",
    };
  },
  onShareAppMessage(res) {
    //朋友
    let uid = uni.getStorageSync("mall_UserInfo")
      ? uni.getStorageSync("mall_UserInfo").UserId
      : 0;
    if (uid == 0) {
      uid = uni.getStorageSync("pid") ? uni.getStorageSync("pid").pid : 0;
    }
    let SmallShopId = uni.getStorageSync("mall_UserInfo")
      ? uni.getStorageSync("mall_UserInfo").SmallShopId
      : 0;
    if (SmallShopId == 0) {
      //如果微店id为0 去找所属微店id
      SmallShopId = uni.getStorageSync("mall_UserInfo")
        ? uni.getStorageSync("mall_UserInfo").UserSmallShopId
        : 0;
    }
    let Up = uni.getStorageSync("mall_UserInfo")
      ? uni.getStorageSync("mall_UserInfo").UserPageType
      : 0;
    return {
      title: "首店经济",
      path:
        "/pages/kotra/news?user_id=" +
        uid +
        "&SmallShopId=" +
        SmallShopId +
        "&Up=" +
        Up,
      imageUrl: "",
    };
  },
  mounted() {
    uni.setNavigationBarTitle({
      title: this.pageTitle,
    });
    this.getList(1);
    this.getCommpanyStatus();
  },
  methods: {
    //获取数据
    getList(num) {
      if (num == 1) {
        this.dataList = [];
      }
      uni.showLoading({
        title: "加载中",
      });
      this.request2(
        {
          url: "/api/AppletTrade/GetNewsPage",
          data: this.msg,
        },
        (res) => {
          uni.hideLoading();
          if (res.resultCode == 1) {
            this.dataList = this.dataList.concat(res.data.pageData);
            this.pageCount = res.data.pageCount;
          }
        }
      );
    },
    //滚动加载
    lower(e) {
      if (this.msg.pageIndex < this.pageCount) {
        this.msg.pageIndex++;
        this.status = "loading";
        this.getList();
      } else {
        this.status = "nomore";
      }
    },
    //跳转至新闻详情
    goNewsDetail(item) {
      uni.navigateTo({
        url: "/pages/kotra/newsInDetail?Id=" + item.Id,
      });
    },
    goNewFirstShop() {
      this.auth("/pages/kotra/firstShop/firstShop");

      //   uni.navigateTo({
      //     url: "/pages/kotra/firstShop/firstShop",
      //   });
    },
    goMyFirstShop() {
      this.auth("/pages/kotra/firstShop/list");
      //   uni.navigateTo({
      //     url: "/pages/kotra/firstShop/list",
      //   });
    },
    auth(url) {
      console.log(308, this.CommpanyStatus, this.FirstShopType);
      if (this.CommpanyStatus === 1 || this.CommpanyStatus === 4) {
        uni.showModal({
          title: "提示",
          content: "请您先完成实名认证",
          // showCancel: false,
          confirmText: "立即认证",
          success: function (res) {
            if (res.confirm) {
              uni.navigateTo({
                url: "/pages/kotra/identification",
              });
            } else if (res.cancel) {
            }
          },
        });
      } else if (this.CommpanyStatus === 3) {
        uni.showModal({
          title: "提示",
          content: "感谢您的厚爱，请等待认证通过以后再来尝试吧",
          showCancel: false,
          confirmText: "我知道了",
          success: function (res) {
            if (res.confirm) {
            }
          },
        });
      } else if (this.CommpanyStatus === 2) {
        uni.showModal({
          title: "提示",
          content: "认证待完善",
          // showCancel: false,
          confirmText: "立即完善",
          success: function (res) {
            if (res.confirm) {
              uni.navigateTo({
                url: "/pages/kotra/identification",
              });
            } else if (res.cancel) {
            }
          },
        });
      } else if (this.CommpanyStatus === 5 && this.FirstShopType === 1) {
        uni.navigateTo({
          url: url,
        });
      }
    },
    getCommpanyStatus() {
      this.request2(
        {
          url: "/api/AppletTrade/GetCommpanyStatus",
          data: {},
        },
        (res) => {
          if (res.resultCode == 1) {
            this.CommpanyStatus = res.data.CompanyStatus;
            this.FirstShopType = res.data.FirstShopType;
          }
        }
      );
    },
  },
};
</script>
