<template>
  <q-dialog v-model="show" class="col-6" position="right" persistent full-width maximized @hide="hideDialog">
    <q-card class="full-height">
      <q-card-section class="row items-center q-pb-none">
        <div class="text-h6">
          <slot name="head">
            导入
          </slot>
        </div>
        <q-space />
        <q-btn icon="close" flat round dense v-close-popup />
      </q-card-section>

      <q-card-section class="q-pt-none">
        <div class="row q-my-md" style="width:55vw ;max-width:55vw">
          <div class="q-mb-sm">
            <slot name="top"></slot>
          </div>
          <n-upload accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" multiple
          :custom-request="customUploadFile" >
            <n-upload-dragger>
              <i class="iconfont icon-Excel" style="font-size:48px;margin-bottom: 12px"></i>
              <div style="font-size: 14px;color:#000">将文件拖到此处，或 点击上传</div>
            </n-upload-dragger>
          </n-upload>
          <div class="uplaod-tips">
            请上传xls、xlsx文件
             <q-btn flat color="primary" label="下载模板" @click="getTemplate"/><br/>
            每次最多可上传10000条数据
          </div>
          <div class="q-mt-sm full-width">
            <slot name="bottom"></slot>
          </div>
        </div>
      </q-card-section>

      <q-card-actions align="right" class="bg-white text-teal q-pa-md">
        <q-btn flat label="取消" v-close-popup />
        <q-btn color="primary" unelevated label="确定" @click="confirm"/>
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>
<script lang="ts">
  import {
    ref,
    watch
  } from 'vue'
  // import {UploadSelfFile} from '@/utils/upload'
  import {getStoreGetter} from '@/store/utils'
  import CustomerService from '@/api/customer'
  import {UploadLocalSystem} from '@/utils/upload'
  export default {
    props: {
      modelValue: {
        type: Boolean,
        default: false,
        required: true,
      },
    },

    setup(props, ctx) {
      let show = ref(false)
      watch(
        () => props.modelValue,
        val => {
          show.value = val
        }
      )
      let hideDialog = () => {
        ctx.emit('update:modelValue', false)
      }
       let FileList = ref<any[]> ([])
      let customUploadFile = file => {
        // UploadSelfFile('/horse', file.file.file, res => {
        //   FileList.value.push({
        //     FileName: res.FileName,
        //     FileUrl: res.FileUrl,
        //   })
        // })
         const LoginUserInfo = getStoreGetter('user', 'getLoginUserInfo') 
         const fileParams = {
          Excel: 1,
          Analysis: 1,
          Uid:LoginUserInfo.Id
        }
        UploadLocalSystem(fileParams,file.file.file,(res)=>{
          console.log(88,res)
        })
      }
      const confirm=()=>{
        console.log(FileList.value)
          ctx.emit('confirm', FileList.value)
          show.value = false
      }
      const getTemplate=()=>{
        CustomerService.getCustomerClueTemplateUrl({}).then(res=>{
          console.log(89,res)
        })
      }
      return {
        show,
        hideDialog,
        FileList,
        customUploadFile,
        confirm,
        getTemplate
      }
    }
  }

</script>
<style scoped>
  ::-webkit-scrollbar {
    height: 7px;
    width: 7px;
  }

  ::-webkit-scrollbar-thumb {
    /*滚动条里面小方块*/
    border-radius: 3px;
    background-color: #ddd;
  }

  ::-webkit-scrollbar-track-piece {
    background-color: #fff;
    -webkit-border-radius: 12px;
  }

  .list-title {
    height: 50px;
    padding-bottom: 10px;
    color: #606266;
    font-size: 14px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
  }

  .list-box {
    height: 420px;
    overflow-y: scroll;
  }

  .list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 0 0 10px;
    border-radius: 5px;
    height: 30px;
  }

  :deep(.n-upload-dragger) {
    width: 55vw;
  }
   .uplaod-tips {
    width: 100%;
    margin-top: 10px;
    font-size: 14px;
    color: #333;
   }
</style>
