<template>
  <view class="body-background"></view>
  <u-navbar
      :title="title"
      :auto-back="true"
      left-icon-size="40rpx"
      :safe-area-inset-top="true"
      :placeholder="true"
      bgColor="#ffffff"
  ></u-navbar>
  <view class="app-wallpaper">

    <view class="leave-advisor-tab" v-if="userInfo?.advisor?.id">
      <u-tabs
          :list="listAdvisor"
          u-sticky
          lineWidth="40"
          lineHeight="4"
          :inactiveStyle="{color:'#AFB5BE'}"
          :activeStyle="{color:'#F47210'}"
          lineColor="#F47210"
          :custom-style="{margin:'auto',width:'100%'}"
          :scrollable="false"
          @change="tabsAdvisorChange"
      ></u-tabs>
    </view>

    <view class="leave-tab">
      <u-tabs
          :list="listItem"
          u-sticky
          lineWidth="40"
          lineHeight="4"
          :inactiveStyle="{color:'#AFB5BE'}"
          :activeStyle="{color:'#F47210'}"
          lineColor="#F47210"
          :custom-style="{margin:'auto',width:'100%'}"
          :scrollable="false"
          :current="current"
          @change="tabsChange"
      ></u-tabs>
    </view>
    <view class="leave-content">
      <view class="leave-item" v-for="item in lists">
        <view class="ask row">
          <view class="icon col">
            <u-image mode="widthFix" :src="staticImage.ask" width="64" height="64"></u-image>
          </view>
          <view class="body col">
            <view class="name">
              <u-text line-height="50" :text="item.name" size="32" color="#020b18"></u-text>
            </view>
            <view class="content">
              <u-text line-height="50" :text="item.content" size="28" color="#020b18"></u-text>
            </view>
            <view class="" v-if="item.pictures?.length > 0">
              <u-album :urls="item.pictures" key-name="url"></u-album>
            </view>
          </view>
        </view>
        <view class="answer row">
          <view class="icon col">
            <u-image mode="widthFix" :src="staticImage.answer" width="64" height="64"></u-image>
          </view>
          <view class="body col">
            <view class="content">
<!--              状态：1=未回答,2=已回答-->
              <u-text v-if="item.status === 2" line-height="50" size="28" color="#020b18" :text="item.answer_content"></u-text>
              <u-text v-else-if="userInfo?.advisor?.id && pages.user_type === 2"
                      @click="api.navTo('/pages/LeaveMsg/index?questions_id='+item.id)"
                      line-height="50"
                      size="28"
                      color="#FF9545"
                      text="立即回答"
                      suffix-icon="arrow-right"
                      icon-style="color:#ff9545;"></u-text>
              <u-text v-else line-height="50" size="28" color="#020b18" text="顾问暂时还没有回答哦"></u-text>

              <view class="" v-if="item.status === 2 && item.answer_pictures?.length > 0">
                <u-album :urls="item.answer_pictures" key-name="url"></u-album>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
  <u-loadmore :custom-style="{display:'flex'}" :status="status" fontSize="28"
              marginBottom="30" marginTop="30" @loadmore="getUserLeave()"/>
</template>

<script>
import {
  imghost
} from '@/config/host.js'
import MzSubsection from '@/components/MzSubsection/Index.vue';
import api from '@/utils/functions.js';
import {goodsOrder, orderLogistics, roomOrder, tabCount} from "@/api/user";
import {userLeave} from "@/api/other";
import {goodsList} from "@/api/shop";

export default {
  components: {
    MzSubsection
  },
  data() {
    return {
      userInfo:{},
      listItem:[
        {name:'全部留言',id:''},
        {name:'已回答',id:2},
        {name:'未回答',id:1},
      ],
      listAdvisor:[
        {name:'我的提问',id:1},
        {name:'提问我的',id:2},
      ],
      tabCheck:'room',
      title: '我的留言',
      loading: true,
      staticImage: {
        bg: imghost + '/BG.png',
        newIcon: imghost + '/new-icon.png',
        shopThumb: imghost + '/new-1.png',
        ask:imghost+ '/ask.png',
        answer:imghost+ '/answer.png',
      },
      pages:{
        page:1,
        limit:10,
        user_type:1,
        status:'',
      },
      lists:[],
      status:'loadmore',
      current:0,
    }
  },
  onLoad() {

  },
  onReady() {

  },
  computed: {
    api() {
      return api
    }

  },
  methods: {
    tabsAdvisorChange(e){
      this.pages.user_type = e.id;
      this.getUserLeave(true);
    },
    tabsChange(e){
      this.tabCheck = e.id
      this.pages.status = e.id
      this.getUserLeave(true);
    },
    getUserLeave(clear = false){
      if (clear) {
        this.status = 'loadmore'
        this.pages.page = 1;
        // this.pages.status = '';
        this.lists = [];
      }
      if (this.status === 'nomore') {
        return false;
      }
      userLeave(this.pages).then(res => {
        this.lists.push.apply(this.lists, res.data);
        if (res.data.length === 0) {
          this.status = 'nomore'
        }
      })
      this.pages.page++;
    },
  },
  onReachBottom() {
    this.getUserLeave();
  },
  onPageScroll(res) {

  },
  mounted() {
    this.getUserLeave();
    this.userInfo = uni.getStorageSync('user');
  },
  created() {

  }
}
</script>

<style lang="scss">
@import './components/leave.scss';
::v-deep .u-tabs__wrapper__nav__line{
  left:24rpx;
}
</style>