<template>
  <el-drawer title="通告主详情" :visible.sync="drawer" size="55%">
    <!--  基本信息  -->
    <el-card class="box-card">
      <el-descriptions class="margin-top" :column="3" size="medium" border>
        <el-descriptions-item>
          <template slot="label">
            <image-preview :src="announcerDetail.avatar" :width="50" :height="50"/>
          </template>
          {{ announcerDetail.nickName }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            手机号
          </template>
          {{ announcerDetail.phonenumber }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            身份类型
          </template>
          <dict-tag v-if="announcerDetail.identityType != null" :options="dict.type.dl_identity_type"
                    :value="announcerDetail.identityType"/>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            会员
          </template>
          {{ announcerDetail.memberCardName }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            剩余额度
          </template>
          {{ announcerDetail.tremaining }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            通告数量
          </template>
          {{ announcerDetail.ttotalNum }}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            粉丝数量
          </template>
          {{ announcerDetail.tfansNum }}
        </el-descriptions-item>
<!--        <el-descriptions-item>-->
<!--          <template slot="label">-->
<!--            收款人姓名-->
<!--          </template>-->
<!--          {{ announcerDetail.trecipientName }}-->
<!--        </el-descriptions-item>-->
        <el-descriptions-item>
          <template slot="label">
            报名免打扰
          </template>
          <span v-if="announcerDetail.topenDisturb == 0"> 否 </span>
          <span v-if="announcerDetail.topenDisturb == 1"> 是 </span>
        </el-descriptions-item>
<!--        <el-descriptions-item>-->
<!--          <template slot="label">-->
<!--            收款码-->
<!--          </template>-->
<!--          <image-preview :src="announcerDetail.trecipientImage" :width="50" :height="50"/>-->
<!--        </el-descriptions-item>-->
      </el-descriptions>
    </el-card>

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>评价</span>
      </div>
      <el-tag style="margin-right: 10px" v-for="item in announcerDetail.evaluates" type="success">{{ item.evaluate }}({{item.num}})</el-tag>
    </el-card>

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>已发布通告</span>
      </div>
      <el-table
        size="small"
        :data="noticeList"
        height="150">
        <el-table-column prop="title" width="150" align="center" label="标题"/>
        <el-table-column prop="feeDown" align="center" label="稿费下限"/>
        <el-table-column prop="feeUp" align="center" label="稿费上限"/>
        <el-table-column label="粉丝下限" align="center" prop="fansDown" />
        <el-table-column label="粉丝上限" align="center" prop="fansUp" />
        <el-table-column label="截止日期" width="150" align="center" prop="endDate">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="100px" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleDetail(scope.row)"
          >详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getNoticeList"
      />
    </el-card>

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>会员开卡记录</span>
      </div>
      <el-table
        size="small"
        :data="announcerDetail.cards"
        height="150">
        <el-table-column align="center" prop="cardName" label="会员卡" />
        <el-table-column align="center" prop="startDate" label="生效日期" />
        <el-table-column align="center" prop="endDate" label="失效日期" />
      </el-table>
    </el-card>

    <el-dialog append-to-body :title="title" :visible.sync="open" width="1500px" append-to-body>
      <EditForm ref="editForm" :is-detail="isDetail"></EditForm>
    </el-dialog>
  </el-drawer>
</template>

<script>
import {getAnnouncer} from "@/api/member/member";
import {listNotice} from "@/api/busi/notice";
import {getNotice} from "@/api/busi/notice";
import EditForm from "@/views/busi/notice/component/EditForm.vue"
export default {
  name: "AnnouncerDraw",
  dicts: ['dl_identity_type', 'dl_approval_status','true_or_false'],
  components: {EditForm},
  data() {
    return {
      //抽屉打开框
      drawer: false,
      //通告主id
      id: null,
      //用户id
      userId: null,
      //通告主详情
      announcerDetail: {},
      //通告详情
      noticeList:[],
      //查看通告详情
      isDetail:true,
      title:'',
      open:false,
      //通告查询参数
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
      },
      // 总条数
      total: 0,
    }
  },
  methods: {
    /**初始化抽屉*/
    initDraw(announcerId, userId) {
      this.id = announcerId
      this.userId = userId
      this.drawer = true
      this.getAnnouncerDetail(userId)
      this.getNoticeList()
    },
    /**获取通告主详情*/
    getAnnouncerDetail(userId) {
      this.announcerDetail = {};
      getAnnouncer(userId).then(response => {
        this.announcerDetail = response.data;
      });
    },

    /**获取已发布通告*/
    getNoticeList(){
      this.queryParams.userId = this.userId
      listNotice(this.queryParams).then(response => {
        this.noticeList = response.data.records;
        this.total = response.data.total;
      });
    },

    /**查看通告详情*/
    handleDetail(row){
      const id = row.id || this.ids
      getNotice(id).then(response => {
        this.isDetail = true
        this.open = true;
        this.$nextTick(() => {
          this.$refs.editForm.form = response.data;
        });
        this.title = "通告详情";
      });
    },

  }
}
</script>

<style scoped>
  /deep/.el-drawer__header {
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    color: #72767b;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    margin-bottom: 10px;
    padding: 10px;
    padding-bottom: 0;
  }
  /deep/.el-card__body {
    padding: 5px 5px 5px 9px;
  }
  /deep/.el-card__header {
    padding: 7px 5px 5px;
    min-height: 35px;
  }
</style>
