<template>
  <view class="container content-all-page">
    <view class="tab-content">
      <view class="item" v-for="item in tabList" :key="item.value" @click="tabClickHandler(item)">
        {{ item.name }}
        <view class="line-active" v-if="tabActive == item.value"> </view>
      </view>
    </view>
    <view class="content-ul" v-if="specialCenter && specialCenter.length > 0">
      <view class="content-li" v-for="item in specialCenter" :key="item.Id" @click="toExamineHandler(item)">
        <view class="type-time">
          <view class="type"> {{ item.Type == 1 ? "笔 记" : "观 点" }} </view>
          <view class="time"> {{ tabActive == 1 ? item.ModifyTime : item.PublishTime }}</view>
        </view>
        <view class="title-item"> {{ item.Title }}</view>
        <view class="btn-box">
          <view class="reject-box" v-if="tabActive == 1" @click.stop="deleteHandler(item)"> 删除</view>
          <view class="cancell-box" v-if="tabActive == 3" @click.stop="unpublishHandler(item)"> 取消发布</view>
          <view class="reject-box" v-if="tabActive == 4" @click.stop="rejectHandler(item)"> 驳回理由</view>
          <view class="edit-box" v-if="tabActive == 1 || tabActive == 4" @click.stop="modifyHandler(item)"> 修改 </view>
        </view>
      </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>
      <view class="nodata-text">暂无内容</view>
    </view>
    <Loading />
  </view>
</template>

<script>
import { purchaserApi } from "@/config/api";
export default {
  data() {
    return {
      tabList: [
        { name: "草稿箱", value: "1" },
        { name: "已发布", value: "3" },
        { name: "审核中", value: "2" },
        { name: "已驳回", value: "4" },
      ],
      tabActive: "1",
      specialCenter: [],
    };
  },
  methods: {
    // top标签点击事件
    tabClickHandler(item) {
      if (this.tabActive === item.value) return;
      this.specialCenter = [];
      this.tabActive = item.value;
      this.getDataList();
    },

    // 获取内容中心的数据
    async getDataList() {
      const res = await purchaserApi.yanxuanSpecialCenter({
        Status: this.tabActive,
      });
      if (res.Ret === 200) {
        this.specialCenter = res.Data || [];
      }
    },

    // 点击了修改
    modifyHandler(item) {
      uni.navigateTo({
        url: "/pages-purchaser/writeNote/writeNote?id=" + item.Id,
      });
    },

    // 点击驳回
    rejectHandler(item) {
      uni.showModal({
        title: "驳回理由",
        content: item.Reason,
        confirmColor: "#3385FF",
        confirmText: "知道了",
        showCancel: false,
        cancelColor: "#606266",
      });
    },

    // 取消发布
    unpublishHandler(item) {
      uni.showModal({
        title: "提醒",
        content: "取消发布后，内容将进入草稿箱想要重新发布需重新提交审核，确定要取消发布吗？",
        confirmColor: "#3385FF",
        cancelColor: "#606266",
        success: async (res) => {
          if (res.confirm) {
            const resCancel = await purchaserApi.yanxuanSpecialCancel({
              Id: item.Id,
            });
            if (resCancel.Ret == 200) {
              uni.showToast({
                title: "已取消发布",
                duration: 2000,
              });
              this.getDataList();
            }
          }
        },
      });
    },

    // 去往审核页面
    toExamineHandler(item) {
      if (item.Status == 2) {
        uni.navigateTo({
          url: "/pages-purchaser/toExamine/toExamine?id=" + item.Id,
        });
      }
    },

    // 删除
    async deleteHandler(item) {
      uni.showModal({
        content: "确定要删除此内容吗?",
        confirmColor: "#3385FF",
        cancelColor: "#606266",
        success: async (res) => {
          if (res.confirm) {
            const resCancel = await purchaserApi.yanxuanSpecialDel({
              Id: item.Id,
            });
            if (resCancel.Ret == 200) {
              this.$util.toast("已删除");
              this.getDataList();
            }
          }
        },
      });
    },
  },
  onLoad() {
    this.getDataList();
  },
};
</script>

<style lang="scss" scope>
.content-all-page {
  background-color: #f3f5f9;
  .tab-content {
    margin-top: 1rpx;
    background-color: #fff;
    height: 96rpx;
    display: flex;
    view {
      flex: 1;
      text-align: center;
      line-height: 96rpx;
      border-bottom: 2rpx solid #e7e7e7;
    }
    .item {
      position: relative;
      .line-active {
        position: absolute;
        left: 50%;
        bottom: 0rpx;
        width: 32rpx;
        height: 6rpx;
        border-radius: 6rpx;
        background-color: #376cbb;
        transform: translateX(-50%);
      }
    }
  }
  .content-ul {
    padding: 30rpx;
    .content-li {
      width: 100%;
      height: 256rpx;
      padding: 20rpx;
      border-radius: 16rpx;
      border-top: 10rpx solid #e7e0cd;
      background-color: #fff;
      .type-time {
        display: flex;
        align-items: center;
        justify-content: space-between;
        color: #666666;
        .type {
          width: 110rpx;
          height: 42rpx;
          line-height: 42rpx;
          text-align: center;
          border-radius: 38rpx;
          color: #928563;
          background-color: #fff6de;
          font-weight: 500;
        }
      }
      .title-item {
        margin: 10rpx 0 20rpx;
        color: #333;
        font-size: 32rpx;
        font-weight: 500;
        line-height: 46rpx;
      }
      .btn-box {
        display: flex;
        justify-content: flex-end;
        padding-top: 5rpx;
        view {
          display: flex;
          align-items: center;
          height: 48rpx;
          padding: 0 24rpx;
          border-radius: 150rpx;
          margin-left: 10rpx;
        }
        .cancell-box {
          color: #376cbb;
          border: 2rpx solid #376cbb;
        }
        .edit-box {
          color: #fff;
          background-color: #376cbb;
        }
        .reject-box {
          color: #d54941;
          border: 2rpx solid #d54941;
        }
      }
    }
  }
}
</style>
