<template>
  <view class="">
    <u-tabs
      :list="dataObj.catList"
      :current="current"
      :active-color="mainColor"
      @change="change"
      :active-item-style="activeTab"
      :bar-style="barStyle"
      style="margin-bottom: 30rpx"
      v-if="dataObj.showCat"
    >
    </u-tabs>
    <view v-if="dataObj.showCat">
      <u-empty
        v-if="curDataObj.goodsList.length == 0"
        text="暂无内容"
        mode="list"
      ></u-empty>
      <view
        v-if="curDataObj.goodsList.length > 0"
        :style="{
          'background-color': dataObj.backgroundColor
            ? dataObj.backgroundColor
            : '#fff',
        }"
      >
        <view class="con" v-if="dataObj.listStyle == 5">
          <view class="left">
            <view
              v-for="(item, index) in curDataObj.goodsList"
              :key="index"
              v-if="index % 2 == 0"
              class="left-item"
            >
              <image
                :src="item.picUrl"
                class="item-img"
                mode="widthFix"
                @click="jumpPage(item)"
              ></image>
              <view class="item-title">
                {{ item.name }}
              </view>
              <view class="flex between CreateByInfo">
                <view class="flex CreateByName" @click="jumpPagePerson(item)">
                  <image
                    :src="item.CreateByIco"
                    class="item-headimg"
                    mode="aspectFill"
                  ></image>
                  {{ item.CreateBy }}
                </view>
                <view class="flex zanNum">
                  <image
                    src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/weizan.png"
                    class="item-zanimg"
                    mode="aspectFill"
                    @click="dianzan(item)"
                    v-if="item.IsDianZan == 0"
                  ></image>
                  <image
                    src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/yizan.png"
                    class="item-zanimg"
                    mode="aspectFill"
                    @click="quxiaodianzan(item)"
                    v-if="item.IsDianZan > 0"
                  ></image
                  >{{ item.DianZanNum }}
                </view>
              </view>
            </view>
          </view>
          <view class="right">
            <view
              v-for="(item, index) in curDataObj.goodsList"
              :key="index"
              v-if="index % 2 == 1"
              class="left-item"
            >
              <image
                :src="item.picUrl"
                class="item-img"
                mode="widthFix"
                @click="jumpPage(item)"
              ></image>
              <view class="item-title">
                {{ item.name }}
              </view>
              <view class="flex between CreateByInfo">
                <view class="flex CreateByName" @click="jumpPagePerson(item)">
                  <image
                    :src="item.CreateByIco"
                    class="item-headimg"
                    mode="aspectFill"
                  ></image>
                  {{ item.CreateBy }}
                </view>
                <view class="flex zanNum">
                  <image
                    src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/weizan.png"
                    class="item-zanimg"
                    mode="aspectFill"
                    @click="dianzan(item)"
                    v-if="item.IsDianZan == 0"
                  ></image>
                  <image
                    src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/yizan.png"
                    class="item-zanimg"
                    mode="aspectFill"
                    @click="quxiaodianzan(item)"
                    v-if="item.IsDianZan > 0"
                  ></image
                  >{{ item.DianZanNum }}
                </view>
              </view>
            </view>
          </view>
        </view>
        <view class="con2" v-if="dataObj.listStyle == -1">
          <view class="list">
            <view
              v-for="(item, index) in curDataObj.goodsList"
              :key="index"
              class="list-item"
            >
              <image
                :src="item.picUrl"
                class="list-item-img"
                mode="widthFix"
                @click="jumpPage(item)"
              >
              </image>
              <view class="flex between CreateByInfo">
                <view class="flex CreateByName" @click="jumpPagePerson(item)">
                  <image
                    :src="item.CreateByIco"
                    class="item-headimg"
                    mode="aspectFill"
                  ></image>
                  {{ item.CreateBy }}
                </view>
                <view class="flex zanNum">
                  <image
                    src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/weizan.png"
                    class="item-zanimg"
                    mode="aspectFill"
                    @click="dianzan(item)"
                    v-if="item.IsDianZan == 0"
                  ></image>
                  <image
                    src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/yizan.png"
                    class="item-zanimg"
                    mode="aspectFill"
                    @click="quxiaodianzan(item)"
                    v-if="item.IsDianZan > 0"
                  ></image
                  >{{ item.DianZanNum }}
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <view v-if="!dataObj.showCat">
      <u-empty
        v-if="dataList.length == 0"
        text="暂无内容"
        mode="list"
      ></u-empty>
      <view
        v-if="dataList.length > 0"
        :style="{
          'background-color': dataObj.backgroundColor
            ? dataObj.backgroundColor
            : '#fff',
        }"
      >
        <view class="con" v-if="dataObj.listStyle == 5">
          <view class="left">
            <view
              v-for="(item, index) in dataList"
              :key="index"
              v-if="index % 2 == 0"
              class="left-item"
            >
              <image
                :src="item.picUrl"
                class="item-img"
                mode="widthFix"
                @click="jumpPage(item)"
              ></image>
              <view class="item-title">
                {{ item.name }}
              </view>
              <view class="item-title">
                {{ item.name }}
              </view>
              <view class="flex between CreateByInfo">
                <view class="flex CreateByName" @click="jumpPagePerson(item)">
                  <image
                    :src="item.CreateByIco"
                    class="item-headimg"
                    mode="aspectFill"
                  ></image>
                  {{ item.CreateBy }}
                </view>
                <view class="flex zanNum">
                  <image
                    src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/weizan.png"
                    class="item-zanimg"
                    mode="aspectFill"
                    @click="dianzan(item)"
                    v-if="item.IsDianZan == 0"
                  ></image>
                  <image
                    src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/yizan.png"
                    class="item-zanimg"
                    mode="aspectFill"
                    @click="quxiaodianzan(item)"
                    v-if="item.IsDianZan > 0"
                  ></image
                  >{{ item.DianZanNum }}
                </view>
              </view>
            </view>
          </view>
          <view class="right">
            <view
              v-for="(item, index) in dataList"
              :key="index"
              v-if="index % 2 == 1"
              class="left-item"
            >
              <image
                :src="item.picUrl"
                class="item-img"
                mode="widthFix"
                @click="jumpPage(item)"
              ></image>
              <view class="item-title">
                {{ item.name }}
              </view>
              <view class="flex between CreateByInfo">
                <view class="flex CreateByName" @click="jumpPagePerson(item)">
                  <image
                    :src="item.CreateByIco"
                    class="item-headimg"
                    mode="aspectFill"
                  ></image>
                  {{ item.CreateBy }}
                </view>
                <view class="flex zanNum">
                  <image
                    src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/weizan.png"
                    class="item-zanimg"
                    mode="aspectFill"
                    @click="dianzan(item)"
                    v-if="item.IsDianZan == 0"
                  ></image>
                  <image
                    src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/yizan.png"
                    class="item-zanimg"
                    mode="aspectFill"
                    @click="quxiaodianzan(item)"
                    v-if="item.IsDianZan > 0"
                  ></image
                  >{{ item.DianZanNum }}
                </view>
              </view>
            </view>
          </view>
        </view>
        <view class="con2" v-if="dataObj.listStyle == -1">
          <view class="list">
            <view
              v-for="(item, index) in curDataObj.goodsList"
              :key="index"
              class="list-item"
            >
              <image
                :src="item.picUrl"
                class="list-item-img"
                mode="widthFix"
                @click="jumpPage(item)"
              >
              </image>
              <view class="flex between CreateByInfo">
                <view class="flex CreateByName" @click="jumpPagePerson(item)">
                  <image
                    :src="item.CreateByIco"
                    class="item-headimg"
                    mode="aspectFill"
                  ></image>
                  {{ item.CreateBy }}
                </view>
                <view class="flex zanNum">
                  <image
                    src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/weizan.png"
                    class="item-zanimg"
                    mode="aspectFill"
                    @click="dianzan(item)"
                    v-if="item.IsDianZan == 0"
                  ></image>
                  <image
                    src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/yizan.png"
                    class="item-zanimg"
                    mode="aspectFill"
                    @click="quxiaodianzan(item)"
                    v-if="item.IsDianZan > 0"
                  ></image
                  >{{ item.DianZanNum }}
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>

    <view
      class="choosetype"
      :style="{ background: mainColor }"
      v-if="isShowFabu"
    >
      <view class="fabutiezi" @click="jumpfabu(1)">
        <image
          src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/tiezifabu.png"
          mode=""
          class="img"
        />
        发布帖子
      </view>
      <view class="fabuhuodong" @click="jumpfabu(2)">
        <image
          src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/huodongfabu.png"
          mode=""
          class="img"
        />
        发布活动
      </view>
    </view>

    <!-- <view
      class="fabuBtn"
     
      :style="{ background: mainColor }"
    >
      发布
    </view> -->
    <!-- 发布动态按钮 -->
    <view class="fbanniu" @click="toggleFabu">
      <image
        src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/fabupyq.png"
        style="height: 26rpx"
        mode="aspectFit"
      ></image>
      <text style="font-size: 10px; color: #fff">发布</text>
    </view>

    <auth
      v-if="showAuth"
      @changeuserinfo="reloadUserinfo"
      @gbAuth="gbAuth"
    ></auth>
    <u-modal
      v-model="show"
      :content="showtext"
      :show-cancel-button="true"
      @confirm="queren"
    ></u-modal>
  </view>
</template>

<script>
import auth from "@/components/auth/index.vue";
export default {
  props: ["dataObj"],
  components: {
    auth,
  },
  data() {
    return {
      current: 0,
      mainColor: "",
      curDataObj: {},
      dataList: [],
      isShowFabu: false,
      show: false,
      showtext: "",
      u: {},
      isAttestation: 0,
      activeTab: {
        color: "#111111",
        "font-weight": 800,
        "font-size": "34rpx",
      },
      barStyle: {
        height: "6rpx",
      },
    };
  },
  computed: {},
  methods: {
    change(e) {
      this.current = e;
      this.dataObj.catList.map((item, index) => {
        if (index === e) {
          this.curDataObj = JSON.parse(JSON.stringify(item));
          return;
        }
      });
    },
    jumpPage(item) {
      if (item.IsTieZi === 1) {
        uni.navigateTo({
          url: "/pages/blindDate/postDetails2?Id=" + item.id,
        });
      } else if (item.IsTieZi === 0) {
        uni.navigateTo({
          url: "/pages/blindDate/postDetails?Id=" + item.id,
        });
      }
    },
    jumpPagePerson(item) {
      uni.navigateTo({
        url: "/pages/blindDate/persondetails?UserId=" + item.CreateById,
      });
    },
    toggleFabu() {
      this.isShowFabu = !this.isShowFabu;
    },
    jumpfabu(type) {
      this.u = uni.getStorageSync("mall_UserInfo");
      if (!this.u) {
        this.u = {
          nickName: "未登录",
          avatarUrl: "",
        };
        this.showAuth = true;
      } else {
        if (this.isAttestation == 1) {
          //判断是否认证了
          // uni.navigateTo({
          //   url: "/pages/blindDate/postPublishing?ForumId=" + this.msg.ForumId,
          // });
          if (type === 1) {
            uni.navigateTo({
              url: "/pages/blindDate/releasePosts",
            });
          } else {
            uni.navigateTo({
              url: "/pages/blindDate/postPublishing",
            });
          }
        } else if (this.isAttestation == 0) {
          this.show = true;
          this.showtext = "还未认证，是否去认证？";
        } else if (this.isAttestation == 2) {
          this.show = true;
          this.showtext = "还未上传身份证信息,是否去上传？";
        }
      }
    },
    queren() {
      let mall_UserInfo = uni.getStorageSync("mall_UserInfo")
        ? uni.getStorageSync("mall_UserInfo")
        : null;
      if (mall_UserInfo != null) {
        if (this.isAttestation == 0) {
          uni.navigateTo({
            url:
              "/pages/blindDate/editData?UserId=" +
              mall_UserInfo.UserId +
              "&Jumptype=2&type=1",
          });
        } else if (this.isAttestation == 2) {
          uni.navigateTo({
            url: "/pages/blindDate/personal/IDidentification?Jumptype=2",
          });
        }
      }
    },
    //点赞
    dianzan(item) {
      let msg = {
        ID: 0,
        ActivityId: item.id,
        ActivityDiscussId: 0,
        IsSelectActivity: 1,
      };
      this.request2(
        {
          url: "/api/AppletMiai/GetDianZan",
          data: msg,
        },
        (res) => {
          if (res.resultCode == 1) {
            uni.showToast({
              title: res.message,
              duration: 2000,
              icon: "none",
            });
            this.$emit("refresh");
            uni.reLaunch({
              url: "/pages/index/index",
            });
          }
        }
      );
    },
    //取消点赞
    quxiaodianzan(item) {
      let msg = {
        ID: item.IsDianZan,
        ActivityId: item.id,
        ActivityDiscussId: 0,
        IsSelectActivity: 1,
      };
      this.request2(
        {
          url: "/api/AppletMiai/GetDianZan",
          data: msg,
        },
        (res) => {
          if (res.resultCode == 1) {
            uni.showToast({
              title: res.message,
              duration: 2000,
              icon: "none",
            });
            this.$emit("refresh");
            uni.reLaunch({
              url: "/pages/index/index",
            });
          }
        }
      );
    },
    getisAttestation() {
      //认证成功
      this.request2(
        {
          url: "/api/Mall/GetHome",
          data: {
            page_id: 0,
            open_school: 0,
            StoreId: 0,
          },
        },
        (res) => {
          uni.setStorageSync("basedata", res.data);
          let basedata = wx.getStorageSync("basedata");
          this.isAttestation = basedata.user_info.isAttestation
            ? basedata.user_info.isAttestation
            : 0;
          this.isFaTie = basedata.user_info.isFaTie
            ? basedata.user_info.isFaTie
            : 0;
        },
        (error) => {}
      );
    },
  },
  mounted() {
    this.getisAttestation();
    console.log("388", this.dataObj);
    this.mainColor = this.$uiConfig.mainColor;
    this.dataObj.catList.map((item, index) => {
      if (index === this.current) {
        this.curDataObj = JSON.parse(JSON.stringify(item));
        return;
      }
    });
    this.dataList = this.dataObj.list;
  },
};
</script>

<style lang="scss">
.flex {
  display: flex;
  align-items: center;
}

.between {
  justify-content: space-between;
}

.con {
  display: flex;
  justify-content: space-between;
  box-sizing: border-box;
  padding-bottom: 90rpx;
  padding: 30rpx;
  // background-color: #eaebec;
}
.item-title {
  font-family: PingFang SC;
  font-size: 28rpx;
  font-weight: bold;
  color: #111111;
  box-sizing: border-box;
  padding: 20rpx 20rpx 0 20rpx;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.CreateByInfo {
  background-color: #fff;
  height: 90rpx;
  box-sizing: border-box;
  padding: 0 20rpx;
}

.CreateByName,
.zanNum {
  font-size: 22rpx;
  font-family: PingFang SC;
  // font-weight: 500;
  color: #111111;
}

.item-img {
  width: 100%;
  height: auto;
  display: block;
  min-height: 20rpx;
  border-radius: 8rpx 8rpx 0 0;
}

.item-headimg {
  width: 50rpx;
  height: 50rpx;
  border-radius: 50%;
  margin-right: 10rpx;
}

.item-zanimg {
  width: 26rpx;
  height: 28rpx;
  border-radius: 50%;
  margin-right: 10rpx;
}

.left,
.right {
  width: 330rpx;

  .left-item {
    width: 100%;
    height: auto;
    margin-bottom: 30rpx;
    border-radius: 8rpx;
    overflow: hidden;
    box-shadow: 0rpx 10rpx 30rpx 0rpx rgba(36, 36, 36, 0.2);
    // display: flex;
    // flex-wrap: wrap;
  }
}

// -----------列表模式样式-----------
.con2 {
  box-sizing: border-box;
  padding-bottom: 90rpx;
  padding: 30rpx;
  // background-color: #eaebec;
}

.list-item {
  width: 100%;
  margin-bottom: 30rpx;
  border-radius: 30rpx;
  overflow: hidden;
}

.list-item-img {
  width: 100%;
  height: 20rpx;
}

.choosetype {
  position: fixed;
  right: 20rpx;
  bottom: 270rpx;
  width: 480rpx;
  height: 100rpx;
  //   background-color: #00c6c1;
  border-radius: 50rpx;
  display: flex;
  align-items: center;
  font-size: 30rpx;
  font-family: PingFang SC;
  font-weight: 500;
  color: #ffffff;

  .fabutiezi,
  .fabuhuodong {
    width: 50%;
    display: flex;
    align-items: center;
    justify-content: center;

    .img {
      width: 30rpx;
      height: 30rpx;
      margin-right: 10rpx;
    }
  }
}

// .fabuBtn {
//   position: fixed;
//   right: 30rpx;
//   bottom: 130rpx;
//   width: 100rpx;
//   height: 100rpx;
//   //   background-color: #00c6c1;
//   border-radius: 50%;
//   text-align: center;
//   line-height: 99rpx;
//   font-size: 32rpx;
//   font-family: PingFang SC;
//   font-weight: 500;
//   color: #ffffff;
// }
.fbanniu {
  width: 42px;
  height: 42px;
  border-radius: 21px;
  position: fixed;
  right: 20rpx;
  bottom: 180rpx;
  background: #40766e;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 99;
}
</style>
