<template>
  <div class="app-container">
    <van-nav-bar
      title="我的咨询"
      left-arrow
      right-text="发布"
      fixed
      placeholder
      @click-left="goClickLeft"
      @click-right="goAdd"
    />
    <van-list
      v-model="loading"
      :finished="finished"
      :immediate-check="false"
      finished-text="没有更多了"
      style="margin-top: 10px;"
      @load="getList()"
    >
      <van-cell v-for="(item,index) in interactionList" :key="index">
        <template #title>
          <van-row>
            <van-col span="20"><van-icon name="../../static/images/icon/questions.png" size="18" style="top: 5px;margin-right: 5px;"/>
              {{item.content}}</van-col>
            <van-col span="4" style="text-align: right;font-size: 0.2rem;color: #007E72;" v-if="item.reply">已回复</van-col>
            <van-col span="4" style="text-align: right;font-size: 0.2rem;color: #c21F3a;" v-if="!item.reply">未回复</van-col>
          </van-row>
        </template>
        <template #label>
          <van-icon name="../../static/images/icon/answer.png" size="18" style="top: 5px;margin-right: 5px;"/>{{item.reply}}
          <van-row>
            <van-col span="18">发布时间：{{item.logintime}}</van-col>
            <van-col span="3" style="color: #007E72;text-align: right;" @click="goAdd('update',item.id)" v-if="!item.reply">
              <van-icon name="edit" size="15" style="top:3px"/>修改
            </van-col>
            <van-col span="3" style="color: #007E72;text-align: right;" @click="deleteInteraction(item.id)" v-if="!item.reply">
              <van-icon name="delete-o" size="15" style="top:3px"/>删除
            </van-col>
          </van-row>
          <p></p>
        </template>
      </van-cell>
    </van-list>
  </div>
</template>

<script>
import { getMember , userConsulting , deleteInteraction } from "@/api/user/index";
import { getInfo } from "@/api/login/index";
import {Dialog} from "vant";
export default {
  name: "interaction",
  data() {
    return {
      //是否显示加载
      loading: false,
      //是否滚动到底部
      finished: false,
      //数据集合
      interactionList:[],
      //查询参数
      queryParams:{
        memberId:'',
        pageNum:1,
        pageSize:10
      }
    };
  },
  created() {
    getInfo().then(response => {
      getMember(response.user.userId).then(response => {
        this.queryParams.memberId = response.data.id;
        this.getList()
      });
    });
  },
  methods: {
    goAdd(type,id){
      console.log(id)
      if (id == undefined){
        window.location='interactionAdd';
      }else{
        window.location='interactionAdd?type='+type+'&id='+id;
      }
    },
    goClickLeft(){
      window.location='user';
    },
    getList(){
      this.loading = true;
      userConsulting(this.queryParams).then(response => {
        for (var i = 0; i < response.rows.length; i++) {
          this.interactionList.push(response.rows[i]);
        }
        if(this.interactionList.length >= response.total){
          this.finished = true;
          return;
        }
        this.queryParams.pageNum += 1 ;
        this.loading = false;
      });
    },
    deleteInteraction(id){
      Dialog.confirm({
        title: '系统提示',
        message: '是否删除？',
        confirmButtonText: '确定',
      }).then(() => {
        deleteInteraction(id).then(response => {
          Dialog.confirm({
            title: '系统提示',
            message: '删除成功',
            confirmButtonText: '确定',
            showCancelButton:false
          }).then(() => {
            this.interactionList = [];
            this.getList();
          })
        });
      })
    }
  },
};
</script>

<style scoped lang="scss">
.app-container {
}
  .titleClass{

  }
</style>
