<template>
  <ai-detail class="activitiesAdd">
    <template slot="title">
      <ai-title title="活动详情" isShowBack isShowBottomBorder @onBackClick="cancel(false)"></ai-title>
    </template>
    <template slot="content">
      <ai-card title="基本信息">
        <template #content>
          <ai-wrapper>
            <ai-info-item label="活动名称" :value="info.title"></ai-info-item>
            <ai-info-item label="创建人" :value="info.createUserName"></ai-info-item>
            <ai-info-item label="活动说明" isLine :value="info.detail"></ai-info-item>
            <ai-info-item label="活动图片" isLine>
              <ai-uploader
                disabled
                :instance="instance"
                :value="info.files">
                </ai-uploader>
            </ai-info-item>
            <ai-info-item label="活动地区" isLine :value="info.areaName"></ai-info-item>
            <ai-info-item label="活动地点" :value="info.address"></ai-info-item>
            <ai-info-item label="地图位置" isLine><div id="mapDetail"></div></ai-info-item>
            <ai-info-item label="积分类型" isLine :value="info.type === '0' ? '打卡得积分' : '报名得积分'"></ai-info-item>
            <ai-info-item label="活动状态">
              {{ dict.getLabel('fdIntegralTaskStatus',info.status) }}
            </ai-info-item>
            <ai-info-item v-if="info.type === '0'" label="打卡范围">{{ info.clockRange }}米</ai-info-item>
            <ai-info-item :label="info.type === '0' ? '进场打卡时间' : '报名时间'">{{ info.intoBegintime }}至{{ info.intoEndtime}}</ai-info-item>
            <ai-info-item v-if="info.type === '0'" label="进场得积分">{{ info.intoIntegral || 0 }}分</ai-info-item>
            <ai-info-item v-if="info.type === '0'" :label="info.type === '0' ? '离场打卡时间' : '离场时间'">{{ info.exitBegintime }}至{{ info.exitEndtime}}</ai-info-item>
            <ai-info-item v-if="info.type === '0'" label="离场得积分">{{ info.exitIntegral || 0 }}分</ai-info-item>
            <ai-info-item v-if="info.type === '1'" label="报名得积分">{{ info.enrollIntegral || 0 }}分</ai-info-item>
          </ai-wrapper>
        </template>
      </ai-card>
      <ai-card title="打卡记录" v-if="info.type === '0'">
        <template #content>
          <ai-wrapper>
            <ai-info-item label="参与人数" :value="search1.total"></ai-info-item>
          </ai-wrapper>
          <ai-table
            :tableData="tableData1"
            :col-configs="colConfigs1"
            :total="search1.total"
            :current.sync="search1.current"
            :size.sync="search1.size"
            @getList="getList1">
          </ai-table>
        </template>
      </ai-card>
      <ai-card title="报名记录" v-if="info.type === '1'">
        <template #content>
          <ai-wrapper>
            <ai-info-item label="参与人数" :value="search1.total"></ai-info-item>
          </ai-wrapper>
          <ai-table
            :tableData="tableData1"
            :col-configs="colConfigs2"
            :total="search1.total"
            :current.sync="search1.current"
            :size.sync="search1.size"
            @getList="getList1">
          </ai-table>
        </template>
      </ai-card>
    </template>
  </ai-detail>
</template>

<script>
  import AMapLoader from '@amap/amap-jsapi-loader'
  export default {
    props: {
      instance: Function,
      dict: Object,
      params: Object,
    },

    data () {
      return {
        id: '',
        info: {},
        mapDetail: null,
        map: null,
        search1: {
          total: 0,
          current: 1,
          size: 10
        },
        tableData1: [],
        colConfigs1: [
          {prop: 'realName', label: '姓名', align: 'center' },
          {prop: 'phone', label: '联系方式', align: 'center' },
          {prop: 'areaName', label: '所属地区', align: 'center' },
          {prop: 'intoClockTime', label: '进场打卡时间', align: 'center' },
          {prop: 'exitClockTime', label: '离场打卡时间', align: 'center' }
        ],
        colConfigs2: [
          {prop: 'realName', label: '姓名', align: 'center' },
          {prop: 'phone', label: '联系方式', align: 'center' },
          {prop: 'areaName', label: '所属地区', align: 'center' },
          {prop: 'enrollClockTime', label: '报名时间', align: 'center' }
        ]
      }
    },

    created () {
      this.id = this.params.id
      this.$dict.load('tfx_activityStatus').then(() => {
        this.getDetail()
      })

      this.getList1()
    },

    methods: {
      cancel (isRefresh) {
        this.$emit('change', {
          type: 'List',
          isRefresh: !!isRefresh
        })
      },

      getList1 () {
        this.instance.post(`/app/appintegraltask/clockList?taskId=${this.params.id}`,null, {
          params: {
            ...this.search1,
          }
        }).then(res=> {
          if(res?.data) {
            this.tableData1 = res.data.records
            this.search1.total = res.data.total
          }
        })
      },
      getMap(lng,lat,address) {
        AMapLoader.load({
          key: '54a02a43d9828a8f9cd4f26fe281e74e',
          version: '2.0',
          plugins: ['AMap.PlaceSearch', 'AMap.AutoComplete', 'AMap.Geocoder'],
        }).then((AMap) => {
          this.mapDetail = new AMap.Map(document.getElementById("mapDetail"), {
            resizeEnable: true,
            zooms: [6, 20],
            zoom: 11,
            center:[lng,lat],
          })
          let marker = new AMap.Marker({
            position: new AMap.LngLat(lng,lat),
            title: address
          })
          this.mapDetail.add(marker);
        })
      },

      update() {
        this.isEdit = true
        this.getDetail()
      },

      getDetail() {
        this.instance.post(`/app/appintegraltask/queryDetailById?id=${this.params.id}`).then((res) => {
          if(res.data) {
            this.info = res.data
            this.getMap(this.info.lng, this.info.lat, this.info.address)
          }
        })
      }
    }
  }
</script>

<style lang="scss" scope>
  .activitiesAdd {
    height: 100%;

    :deep( .amap-logo ){
      display: none!important;
    }
    :deep( .amap-copyright ){
      display: none!important;
    }

    :deep( .el-date-editor .el-input ){
      width: 100%;
    }

    .amap-container {
      height: 380px;
    }
  }
</style>
