<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('changeManageModal',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="companyName" placeholder="请输入企业名称" disabled/>
        <div class="item-title">账号分配</div>
        <a-select
          class="item-select"
          v-model:value="userId"
          :options="userOptions"
          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('changeManageModal',false)">取消</a-button>
      <a-button class="save-button" type="primary" @click="submit">确认提交</a-button>
    </div>
  </a-spin>
</template>

<script setup lang="ts">
import { ref, defineEmits, defineProps, onMounted } from "vue"
import { message, Modal } from "ant-design-vue";
import { AddBidCompanyInfo, AddCompanyAccount } from '@/api/demo/enterprise'
import { getAccountList } from '@/api/demo/system';
const props = defineProps(['info'])
const emits = defineEmits(['changeManageModal', 'query'])
onMounted(() => {
  companyId.value = props.info.id
  companyName.value = props.info.name
  getAccountList({page:1,limit:999}).then(res => {
    userOptions.value = res.items.map(item => {
      return { label: item.name, value: item.id }
    })
  })
})
const companyId = ref('')
const companyName = ref('')
const userId = ref()
const userOptions = ref([])
const loading = ref(false)



const submit = () => {
  if(!userId.value){
    return message.warning('请为企业分配账号！')
  }
  loading.value = true
  let params = [
    {
      companyId: companyId.value,
      userId: userId.value
    }
  ]
  console.log('params',params)
  AddCompanyAccount(params).then(res => {
    message.success('保存成功！')
    emits('query')
    emits('changeManageModal',false)
  }).finally(() => {
    loading.value = false
  })
}
</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: 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;
  }
  .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: 100%;
    // margin-right: 124px;
  }
}
.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>
