<template>

  <div class="title-div">
    <div class="title-span-div">
      <div class="title-icon"></div>
      <div class="title-span">添加招标代理信息</div>
    </div>
    <div class="close-button" @click="emits('changeAddModal',false)"></div>
  </div>
  <div class="interval"></div>
  <a-spin tip="加载中..." :spinning="loading">
    <div class="modal-content">
      <div class="left-content">
        <div class="item-title">企业名称</div>
        <a-input class="item-input" v-model:value="name" placeholder="请输入企业名称" />
        <div class="item-title">信用代码</div>
        <a-input class="item-input" v-model:value="code" placeholder="请输入信用代码" />
        <div class="item-title">企业法人</div>
        <a-input class="item-input" v-model:value="legalPerson" placeholder="请输入企业法人" />
        <div class="item-title">营业执照</div>
        <a-upload
          v-model:file-list="licenseList"
          accept=".zip"
          :maxCount="1"
          :custom-request="customRequest"
        >
          <a-button>
            <upload-outlined></upload-outlined>
            上传营业执照
          </a-button>
          <template #itemRender="{ file, actions }">
            <a-space>
              <span>{{ file.name }}</span>
            </a-space>
          </template>
        </a-upload>
      </div>
      <div class="right-content">
        <div class="item-title">联系人</div>
        <a-input class="item-input" v-model:value="contactPerson" placeholder="请输入联系人" />
        <div class="item-title">联系方式</div>
        <a-input class="item-input" v-model:value="phone" placeholder="请输入联系方式" />
        <div class="item-title">账号状态</div>
        <a-select
          class="item-select"
          v-model:value="accountState"
          :options="accountStateOptions"
          placeholder="请选择账号状态"
        >
          <template #suffixIcon>
            <div class="search-select-suffixIcon"></div>
          </template>
        </a-select>
      </div>
    </div>
    <div class="interval"></div>
    <div class="footer">
      <a-button class="cancel-button" @click="emits('changeAddModal',false)">取消</a-button>
      <a-button v-if="props.modalType == 'update'" class="delete-button" type="primary" @click="delData">删除</a-button>
      <a-button class="save-button" type="primary" @click="submit">确认提交</a-button>
    </div>
  </a-spin>
</template>

<script setup lang="ts">
import { ref, h, defineEmits, defineProps, onMounted, createVNode } from "vue"
import { ExclamationCircleOutlined, PlusOutlined, } from '@ant-design/icons-vue';
import { message, Modal } from "ant-design-vue";
import { AddBiddingAgency, EditBiddingAgency, DeleteBiddingAgency } from '@/api/demo/bidagency'
import { uploadFile } from '@/api/demo/enterprise'
import { accountStateOptions } from '@/views/demo/enterpriselist/util'
const props = defineProps(['modalType', 'info'])
const emits = defineEmits(['changeAddModal', 'query'])
onMounted(() => {
  if(props.modalType == 'update'){
    id.value = props.info.id
    name.value = props.info.name
    code.value = props.info.code
    legalPerson.value = props.info.legalPerson
    
    contactPerson.value = props.info.contactPerson
    phone.value = props.info.phone
    accountState.value = props.info.accountState
    license.value = props.info.license
    licenseList.value = [{
      uid: '-1',
      name: props.info.license,
    }]
  }
})
const id = ref('')
const name = ref('')
const code = ref('')
const legalPerson = ref('')
const license = ref('')
const licenseList = ref([])
const contactPerson = ref('')
const phone = ref('')
const accountState = ref(0)

const loading = ref(false)



const submit = () => {
  loading.value = true
  let params = {
    id: id.value,
    name: name.value,
    code: code.value,
    legalPerson: legalPerson.value,
    license: license.value,
    contactPerson: contactPerson.value,
    phone: phone.value,
    accountState: accountState.value,
  }
  console.log('params',params)
  if(props.modalType == 'insert'){
    AddBiddingAgency(params).then(res => {
      message.success('招标代理信息添加成功')
      emits('query')
      emits('changeAddModal',false)
    }).finally(() => {
      loading.value = false
    })
  }else{
    EditBiddingAgency(params).then(res => {
      message.success('招标代理信息修改成功')
      emits('query')
      emits('changeAddModal',false)
    }).finally(() => {
      loading.value = false
    })
  }
}
const delData = () => {
  Modal.confirm({
    title: `确认删除该招标代理信息吗？`,
    icon: createVNode(ExclamationCircleOutlined),
    okText: '确认',
    cancelText: '取消',
    centered: true,
    onOk() {
      return DeleteBiddingAgency(id.value).then(res => {
        message.success("删除成功")
        emits('query')
        emits('changeAddModal',false)
      })
    },
  });
}
const customRequest = (file) => {
  const formData = new FormData()
  formData.append('files', file.file)
  uploadFile(formData).then(res => {
    license.value = res[0].filePath
    console.log('licenseList',licenseList)
  })
}
</script>

<style lang="scss" scoped>
.title-div{
  width: 100%;
  height: 64px;
  padding-top: 15px;
  padding-left: 26px;
  padding-right: 35px;
  padding-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .title-span-div{
    display: flex;
    align-items: center;
    .title-icon{
      width: 3px;
      height: 18px;
      background: #0B60BD;
      box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15);
      margin-right: 9px;
    }
    .title-span{
      font-family: PingFangSC-Medium;
      font-weight: 500;
      font-size: 20px;
      color: #11131B;
      line-height: 33px;
      text-shadow: 0px 10px 30px rgba(0,0,6,0.15);
    }
  }
  .close-button{
    width: 20px;
    height: 20px;
    background-image: url('/public/tender/tender_close_modal_button.png');
    cursor: pointer;
  }
}
.interval{
  width: 100%;
  height: 1px;
  box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15);
  border: 1px solid #DBDBDB;
  opacity: 0.66;
}
.modal-content{
  display: flex;
  padding-top: 24px;
  padding-left: 38px;
  padding-right: 40px;
  padding-bottom: 27px;
  .item-title{
    font-family: PingFangSC-Regular;
    font-weight: 400;
    font-size: 13px;
    color: #000000;
    line-height: 20px;
    text-shadow: 0px 10px 30px rgba(0,0,6,0.15);
    margin-bottom: 7px;
  }
  .item-input{
    width: 286px;
    height: 40px;
    background: #FFFFFF;
    // box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15);
    border-radius: 6px;
    border: 1px solid #A9BBD8;
    margin-bottom: 24px;
  }
  .item-select{
    width: 100%;
    margin-bottom: 24px;
    :deep(.ant-select-selector){
      height: 40px;
      background: #FFFFFF;
      // box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15);
      border-radius: 6px;
      border: 1px solid #A9BBD8;
    }
    :deep(.ant-select-selection-item){
      display: flex;
      align-items: center;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      font-size: 13px;
      color: #000000;
      line-height: 20px;
    }
    :deep(.ant-select-selection-placeholder){
      display: flex;
      align-items: center;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      font-size: 13px;
      color: rgba(0, 0, 0, 0.55);
      line-height: 20px;
      text-shadow: 0px 10px 30px rgba(0,0,6,0.15);
    }
    .search-select-suffixIcon{
      width: 10px;
      height: 6px;
      background-image: url('/public/tender/search_select_icon.png');
      background-size: 100% 100%;
    }
  }
  .item-date-picker{
    width: 100%;
    height: 40px;
    background: #FFFFFF;
    // box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15);
    border-radius: 6px;
    border: 1px solid #A9BBD8;
    margin-bottom: 24px;
  }
  .left-content{
    width: 286px;
    margin-right: 124px;
  }
  .right-content{
    width: 286px;
    
  }
}
.footer{
  height: 85px;
  padding-right: 34px;
  display: flex;
  align-items: center;
  justify-content: end;
  .cancel-button{
    width: 101px;
    height: 40px;
    box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15);
    border-radius: 4px;
    border: 1px solid #979797;
    font-family: PingFangSC-Medium;
    font-weight: 500;
    font-size: 16px;
    color: #222738;
    line-height: 33px;
    text-shadow: 0px 10px 30px rgba(0,0,6,0.15);
    margin-right: 24px;
  }
  .delete-button{
    width: 146px;
    height: 40px;
    background: #ed6f6f;
    box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15);
    border-radius: 4px;
    font-family: PingFangSC-Medium;
    font-weight: 500;
    font-size: 16px;
    color: #FFFFFF;
    line-height: 33px;
    text-shadow: 0px 10px 30px rgba(0,0,6,0.15);
    margin-right: 24px;
  }
  .save-button{
    width: 146px;
    height: 40px;
    background: #0081FF;
    box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15);
    border-radius: 4px;
    font-family: PingFangSC-Medium;
    font-weight: 500;
    font-size: 16px;
    color: #FFFFFF;
    line-height: 33px;
    text-shadow: 0px 10px 30px rgba(0,0,6,0.15);
  }
}
</style>
