<template>
  <view class="content">
    <view class="input-box">
      <image src="/static/policy/u377.png" alt="" />
      <input
        type="text"
        placeholder="请输入政策关键词搜索"
        v-model="input"
        @confirm="getNotice"
      />
    </view>
    <view class="notices">
      <view
        class="notice-content-box"
        v-for="(item, index) in noticeList"
        :key="index"
        confirm-type="search"
        @click="goNoticeDeatil(item.id)"
      >
        <image
          :src="item.icon"
          mode="aspectFit"
          style="width: 34px; height: 34px"
        ></image>
        <view class="notice-content display-around-column">
          <view class="notice-content-font">{{
          item.title
          }}</view>
          <view class="notice-content-time">{{
            item.publish_time | globalTime
          }}</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import md5 from "@/common/md5.js";
export default {
  data() {
    return {
      noticeList: [
        // {
        //   url: "/static/navList/policy-icon.png",
        //   title: "政策速览 | 小微企业、个体工商户税费...",
        //   time: "2021-08-05",
        // },
        // {
        //   url: "/static/navList/activity-icon.png",
        //   title: "活动预告 | 想了解跨境电商？8月5日带...",
        //   time: "2021-08-04",
        // },
        // {
        //   url: "/static/navList/notice-icon.png",
        //   title: "通知公告 | 2022年首批次重点新材料扶...",
        //   time: "2021-08-03",
        // },
      ],
      input: "",
      imgUrl: [
        "/static/navList/activity-icon.png", //活动 1
        "/static/navList/policy-icon.png", //政策 type2

        "/static/navList/notice-icon.png", //通知 3
      ],
      titleList: ["活动预告 | ", "政策速览 | ", "通知公告 | "],
    };
  },
  onLoad() {
    this.getNotice();
  },
  methods: {
    goNoticeDeatil(id) {
      uni.navigateTo({
        url: "/pages/notice/notice_deatil?id=" + id,
      });
    },
    getNotice() {
      let md5Sign = md5(
        "method=" +
          "common" +
          "&timestamp=" +
          getApp().globalData.globalTimestamp +
          "&secret=" +
          getApp().globalData.secret
      );
      let url =
        getApp().globalData.shareUrl +
        "api/api.php" +
        "?method=common&source=notice&action=list&timestamp=" +
        getApp().globalData.globalTimestamp +
        "&sign=" +
        md5Sign;
      let postData = {
        // s_title: this.input,
      };
      uni.request({
        url: url,
        method: "POST",
        header: {
          "content-type": "application/x-www-form-urlencoded",
        },
        data: postData,
        success: (res) => {
          if (res.data.code === 200) {
            // console.log(res.data.data.list);
            this.noticeList = res.data.data.list.map((item) => {
              switch (item.type) {
                case "1":
                  item.icon = "/static/navList/activity-icon.png";
                  item.title = "活动预告 | " + item.title;
                  break;
                case "2":
                  item.icon = "/static/navList/policy-icon.png";
                  item.title = "政策速览 | " + item.title;
                  break;
                case "3":
                  item.icon = "/static/navList/notice-icon.png";
                  item.title = "通知公告 | " + item.title;
                  break;
              }
              return item;
            });
            // this.noticeList = res.data.data.list;
          }
        },
        fail: () => {
          console.log("连接失败");
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  .notices {
    display: flex;
    // justify-content: center;
    align-items: center;
    flex-direction: column;
    .notice-content-box {
      width: 100%;
      display: flex;
      padding: 30rpx;
      background-color: #ffffff;
      box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
      border-radius: 32rpx;
      margin-top: 20rpx;
      // justify-content: space-between;
      .notice-content-font {
        margin-left: 40rpx;
        font-size: 26rpx;
        color: #0d1937;
        font-weight: 600;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .attract-content {
        color: #697594;
        font-weight: 600;
        font-size: 20rpx;
        margin-top: 8rpx;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .notice-content-time {
        margin-left: 40rpx;
        font-size: 18rpx;
        letter-spacing: 0.02em;
        color: #cfcfcf;
        margin-right: 14rpx;
      }
    }
  }
  .input-box {
    width: 100%;
    height: 100rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    image {
      position: absolute;
      left: 72rpx;
      width: 40rpx;
      height: 40rpx;
    }
    input {
      background-color: rgba($color: #000000, $alpha: 0.1);
      width: 90%;
      height: 70%;
      border-radius: 50rpx;
      padding: 3rpx;
      font-size: 26rpx;
      padding-left: 80rpx;
      box-sizing: border-box;
    }
  }
}
</style>