<template>
  <ai-detail>
    <template slot="title">
      <ai-title title="详情" isShowBack isShowBottomBorder @onBackClick="cancel(false)">
      </ai-title>
    </template>
    <template slot="content">
      <AiSidebar :tabTitle="tabList" v-model="currIndex"></AiSidebar>
      <ai-card title="基本信息" v-show="currIndex === 0">
        <template #content>
          <ai-wrapper
            label-width="120px">
            <ai-info-item label="活动标题" isLine :value="info.title"></ai-info-item>
            <ai-info-item label="发布地区" isLine :value="info.areaName"></ai-info-item>
            <ai-info-item label="活动开始时间" :value="info.beginTime"></ai-info-item>
            <ai-info-item label="活动结束时间" :value="info.endTime"></ai-info-item>
            <ai-info-item label="活动地点" isLine :value="info.address"></ai-info-item>
            <ai-info-item label="联系人" :value="info.contactPerson"></ai-info-item>
            <ai-info-item label="联系电话" :value="info.contactPhone"></ai-info-item>
            <ai-info-item label="活动介绍" isLine>
              <AiArticle :value="info.content"></AiArticle>
            </ai-info-item>
            <ai-info-item label="活动介绍">
              <ai-uploader
                :instance="instance"
                disabled
                v-model="info.url"
                :limit="1">
              </ai-uploader>
            </ai-info-item>
          </ai-wrapper>
        </template>
      </ai-card>
      <ai-card title="报名情况" v-show="currIndex === 1">
        <template #content>
          <ai-table
            class="detail-table__table"
            :border="true"
            :tableData="tableData"
            :col-configs="colConfigs"
            :total="total"
            :current.sync="search.current"
            :size.sync="search.size"
            :stripe="false"
            @getList="getList">
          </ai-table>
        </template>
      </ai-card>
      <ai-card title="活动动态" v-show="currIndex === 2">
        <template #content>
          <Dynamic :instance="instance" :dict="dict" :id="params.id" v-show="currIndex === 2"></Dynamic>
        </template>
      </ai-card>
    </template>
  </ai-detail>
</template>

<script>
  import Dynamic from './Dynamic'
  export default {
    name: 'Detail',

    props: {
      instance: Function,
      dict: Object,
      params: Object
    },

    components: {
      Dynamic
    },

    data () {
      return {
        total: 0,
        info: {},
        id: '',
        search: {
          current: 1,
          size: 10
        },
        currIndex: 0,
        tableData: [],
        colConfigs: [
          {prop: 'name', label: '报名人员名称', align: 'center' },
          {prop: 'createTime', label: '报名时间', align: 'center'},
          {prop: 'phone', label: '联系方式', align: 'center' }
        ],
        tabList: ['基本信息', '报名情况', '活动动态']
      }
    },

    created () {
      if (this.params && this.params.id) {
        this.id = this.params.id
        this.getInfo(this.params.id)
        this.getList(this.params.id)
      }
    },

    methods: {
      getInfo (id) {
        this.instance.post(`/app/appvillageactivityinfo/queryDetailById?id=${id}`).then(res => {
          if (res.code === 0) {
            this.info = res.data
            this.info.url = res.data.url ? JSON.parse(res.data.url) : []
          }
        })
      },

      getList (id) {
        this.instance.post(`/app/appvillageactivityuser/list`, null, {
          params: {
            ...this.search,
            activityId: id
          }
        }).then(res => {
          if (res.code == 0) {
            this.tableData = res.data.records
            this.total = res.data.total
          }
        })
      },

      cancel (isRefresh) {
        this.$emit('change', {
          type: 'list',
          isRefresh: !!isRefresh
        })
      }
    }
  }
</script>

<style scoped lang="scss">
</style>
