<template>
  <view class="page-container">
    <z-paging ref="paging" v-model="dynamicList" @query="queryList">

      <!-- 我的动态 @refreshList="queryList"-->
      <my-dynamic-list :data-list="dynamicList"></my-dynamic-list>


      <template v-slot:empty>
        <!-- !isLogin ? '您还没有登录' :  -->
        <u-empty :text="'暂未发表任何动态'" icon="/static/workbench/emptyIcon.png">
          <!-- <u-button size="small" text="去登录" color="linear-gradient(to right, #35c99d, #27aea7)"
            :customStyle="{ marginTop: '20rpx' }" v-if="!isLogin" @click="goLogin">
          </u-button> -->
        </u-empty>
      </template>
    </z-paging>

    <!-- 发布动态 -->
    <view v-if="isLogin" class="add-btn" @click="goPublish">
      <image src="/static/workbench/editIcon.png" />
    </view>


    <!-- 未入驻提示 -->
    <u-popup :show="showModal" mode="center" :round="16" :mask-close-able="false">
      <view class="modal-wrap">
        <!-- 标题居中 -->
        <view class="title">{{ auditStatus == 0 ? '提示' : '入驻审核驳回' }}</view>
        <!-- 正文 -->
        <view class="content">
          请提交入驻资料并由后台人员审核通过后,即可开通操作权限
        </view>
        <!-- 底部双按钮（必显示） -->
        <view class="btn-box">
          <view v-if="auditStatus == 3" class="btn">修改入驻信息</view>
          <view v-if="auditStatus == 0" class="btn left" @click="cancel">我在想想</view>
          <view v-if="auditStatus == 0" class="btn right" @click="goEnter">立即入驻</view>
        </view>
      </view>
    </u-popup>
  </view>
</template>

<script>
import { myDynamicList, draftDynamicList } from '@/api/dynamic.js'
import { normalizeStorageValue } from '@/utils/technicianProfile.js'
import MyDynamicList from './components/my_list.vue'
import DraftDynamicList from './components/draft_list.vue'

export default {
  components: {
    MyDynamicList,
    DraftDynamicList,
  },
  data() {
    return {
      showModal: false,
      isLogin: false,
      dynamicList: [],
      current: 0,
      tabList: [
        {
          name: '我的动态',
          value: -1,
        },
        {
          name: '草稿箱',
          value: 0,
        },
      ],
      auditStatus: 0,
    }
  },
  onLoad() {
    this.isLogin = !!uni.getStorageSync('access-token')
    console.log(this.isLogin, 'this.isLogin')
  },
  onShow() {
    this.queryList(1, 10)
    this.checkMerchantStatus()
  },
  methods: {
    //查询商户状态  auditStatus 审核状态：-1-申请入住,0-待入驻，1-待审核，2-审核通过，3-审核驳回"
    async checkMerchantStatus() {
      const openid = uni.getStorageSync('wx_copenid')
      const merchantInfo = await this.$utils.checkMerchantStatus(openid)
      if (!merchantInfo) return
      this.cJsId = merchantInfo.id; //用户id
      /**
       * 服务标签（1：按摩推拿 2：陪玩）
       */
      // this.serviceTag = merchantInfo.merchant.serviceTag
      // uni.setStorageSync('serviceTag', normalizeStorageValue(merchantInfo.merchant.serviceTag))
      // uni.setStorageSync('userId', normalizeStorageValue(merchantInfo.merchant.id))
      // return merchantInfo.merchant.auditStatus//用户状态


      this.serviceTag = merchantInfo.serviceTag
      uni.setStorageSync('serviceTag', merchantInfo.serviceTag)
      uni.setStorageSync('userId', merchantInfo.id)
      uni.setStorageSync('auditStatus', merchantInfo.auditStatus)

    },
    // 我在想想：关闭弹窗
    cancel() {
      this.showModal = false
    },
    // 立即入驻：跳转入驻页
    goEnter() {
      this.showModal = false
      uni.navigateTo({
        url: '/pages/join/applyJoin' // 替换你的入驻页面路径
      })
    },
    queryList(pageNo, pageSize) {
      let params = {
        pageNum: pageNo,
        pageSize: pageSize,
      }
      const api = myDynamicList
      //0-草稿 1-待审核 2-审核通过 3-审核拒绝
      api(params).then(res => {
        if (
          res.data.code === 200 &&
          res.data.data.records &&
          res.data.data.records.length > 0
        ) {
          let data = res.data.data.records
          this.$refs.paging.complete(data)
          //this.$refs.paging.complete([])
        } else {
          this.$refs.paging.complete([])
        }
      })


    },
    onTabChange(index) {
      this.current = index
      this.$refs.paging.reload()
    },
    goLogin() {

      uni.navigateTo({
        url: '/setting/myNew/phone',
      })
      // uni.navigateTo({
      //   url: '/pages/login/wxLogin',
      // })
    },
    async goPublish() {
      this.auditStatus = uni.getStorageSync('auditStatus')
      if (this.auditStatus == 0 || this.auditStatus == 3) {
        this.showModal = true
        return
      }
      if (this.auditStatus == 1) {
        uni.showToast({
          title: '入驻审核中，暂无操作权限',
          icon: 'none'
        })
        return

      }
      uni.navigateTo({
        url: '/pages/my/dynamic/add_dynamic',
      })
    },
  },
}
</script>

<style scoped lang="scss">
.page-container {
  background-color: #F7F8FA ;
  font-family: PingFang SC, PingFang SC;

  .tab-box {
    height: 90rpx;
    display: flex;
    justify-content: start;
    align-items: center;
    font-size: 28rpx;
    color: #333333;
    padding-left: 20rpx;
    background: linear-gradient(180deg, #c1fff8 0%, #b8fff3 34%, #f5ffff 100%);
    z-index: 999;

    .item {
      height: 55%;
      padding: 0 12rpx;
      display: flex;
      align-items: center;
    }

    .active {
      font-weight: 500;
      font-size: 30rpx;
      color: #03c8be;
      position: relative;

      &::after {
        content: '';
        width: 48rpx;
        height: 4rpx;
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
        background-color: #03c8be;
      }
    }
  }

  .add-btn {
    position: fixed;
    bottom: 150rpx;
    right: 40rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100rpx;
    height: 100rpx;
    background: #1D2129;
    border-radius: 50%;
    z-index: 99;

    image {
      width: 48rpx;
      height: 48rpx;
    }
  }
}
</style>
