<template>
  <div>
    <Modal :width="60" :title="name+'订单列表'" :value.sync="isShow" @on-visible-change="$emit('update:isShow',$event)"
       >
        <Button class="select" type="primary" style="margin-bottom: 10px;" @click="downloadExel">导出</Button>
      <xy-table id="print" :is-page="false" :list="list" :table-item="table" :height="300">
        <template v-slot:btns>
          <div></div>
        </template>
      </xy-table>
    </Modal>
  </div>
</template>

<script>
import {show} from "@/api/activity"
  import {
    download
  } from '@/utils/downloadRequest'
export default {
  props:{
    id:Number,
    name:String,
    isShow:{
      type:Boolean,
      default:false
    }
  },
  data() {
    return {
      list:[],
      table:[
        {
            prop: "name",
            label: "姓名",
            width: 120
          },
          {
            prop: "wechat_nickname",
            label: "微信昵称",
            width: 120
          },
          {
            label: "头像",
            width: 80,
            prop:"members.avatar",
            customFn: (row) => {
              return ( < div style = {
                {
                  display: 'flex',
                  alignItems: 'center',
                  justifyContent: 'center'
                }
              } > <el-avatar src = {
                row.members?.avatar
              } > </el-avatar></div > )
            }
          },

          {
            prop: "phone",
            label: "联系电话",
            width: 120
          },
          {
            prop: "area",
            label: "区域",
            width: 120
          },
          {
            prop: "address",
            label: "地址",
            width: 120
          },
          {
            prop: "budget_date",
            label: "预产期",
            // width: 120
          },
          {
            prop: "hospital",
            label: "建卡医院",
            width: 120
          },
          {
            prop: "spread_member_name",
            label: "推广渠道",
            width: 120
          },
          {
            prop: "spread_member_phone",
            label: "推广人号码",
            width: 120
          },
          {
            prop: "used_time_name",
            label: "是否核销",
            width: 120
          },

      ],
    }
  },
  methods: {
    async getOrder(){
      await show({
        id:this.id
      }).then(res=>{
        for(var k of res.apply){
            k.wechat_nickname = k.members?k.members.wechat_nickname:""
            k.used_time_name = k.used_time ? '已核销':'待核销'
            k.spread_member_name = k.spread_member?k.spread_member.name:''
            k.spread_member_phone = k.spread_member?k.spread_member.phone:''
        }
        this.list = res.apply
      })

    },
    downloadExel(){
      // this.$Print('#print')
        this.$Export.excel({
          title: this.name,
          columns: this.table,
          data: this.list
        });
        // download(
        //   '/api/admin/active/show',
        //   'get', {
        //     id:this.id
        //   },
        //   this.name+'.xlsx')
    }
  },
  watch:{
    isShow(newVal){
      if(newVal){
        this.getOrder()
      }
    }
  }

}
</script>

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