<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="projectName" placeholder="请输入项目名称" />
        <div class="item-title">项目编号</div>
        <a-input class="item-input" v-model:value="projectNum" placeholder="请输入项目编号" />
        <div class="item-title">招标类型</div>
        <a-select
          class="item-select"
          v-model:value="biddingType"
          :options="props.biddingtypeOptions"
          placeholder="请输入招标类型"
        >
          <template #suffixIcon>
            <div class="search-select-suffixIcon"></div>
          </template>
        </a-select>
        <div class="item-title">招标金额（元）</div>
        <a-input class="item-input" v-model:value="biddingAmount" placeholder="请输入招标金额" />
        <div class="item-title">招标形式</div>
        <a-select
          class="item-select"
          v-model:value="biddingForm"
          :options="props.biddingformOptions"
          placeholder="请输入招标形式"
        >
          <template #suffixIcon>
            <div class="search-select-suffixIcon"></div>
          </template>
        </a-select>
      </div>
      <div class="right-content">
        <div class="item-title">报名截止</div>
        <a-date-picker class="item-date-picker" v-model:value="registrationDeadline" placeholder="请输入日期时间"/>
        <div class="item-title">开标时间</div>
        <a-date-picker class="item-date-picker" v-model:value="bidOpeningTime" placeholder="请输入日期时间"/>
        <div class="item-title">当前状态</div>
        <a-select
          :disabled="modalType == 'insert'"
          class="item-select"
          v-model:value="nowStatus"
          :options="props.nowStatusOptions"
          placeholder="请输入当前状态"
        >
          <template #suffixIcon>
            <div class="search-select-suffixIcon"></div>
          </template>
        </a-select>
        <div class="item-title">中标金额（元）</div>
        <a-input class="item-input" v-model:value="bidWinningAmount" placeholder="请输入金额" />
        <div class="item-title">招标代理</div>
        <a-input class="item-input" v-model:value="bidAgent" placeholder="请输入招标代理" />
      </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 { AddBiddingInfo, EditBiddingInfo, DeleteBiddingInfo } from '@/api/demo/tender'
import dayjs from "dayjs";
const props = defineProps(['modalType', 'info', 'biddingformOptions', 'biddingtypeOptions', 'nowStatusOptions'])
const emits = defineEmits(['changeAddModal', 'query'])
onMounted(() => {
  if(props.modalType == 'update'){
    id.value = props.info.id
    projectName.value = props.info.projectName
    projectNum.value = props.info.projectNum
    biddingType.value = props.info.biddingType
    biddingAmount.value = props.info.biddingAmount
    biddingForm.value = props.info.biddingForm
    registrationDeadline.value = props.info.registrationDeadline? dayjs(props.info.registrationDeadline): ''
    bidOpeningTime.value = props.info.bidOpeningTime? dayjs(props.info.bidOpeningTime): ''
    nowStatus.value = props.info.nowStatus
    bidWinningAmount.value = props.info.bidWinningAmount
    bidAgent.value = props.info.bidAgent
  }
  if(props.modalType == 'insert'){
    nowStatus.value = '待审核'
  }
})
const id = ref('')
const projectName = ref('')
const projectNum = ref('')
const biddingType = ref(null)
const biddingAmount = ref('')
const biddingForm = ref(null)
const registrationDeadline = ref('')
const bidOpeningTime = ref('')
const nowStatus = ref(null)
const bidWinningAmount = ref('')
const bidAgent = ref('')
const loading = ref(false)


const submit = () => {
  loading.value = true
  let params = {
    id: id.value,
    projectName: projectName.value,
    projectNum: projectNum.value,
    biddingType: biddingType.value,
    biddingAmount: biddingAmount.value,
    biddingForm: biddingForm.value,
    registrationDeadline: registrationDeadline.value,
    bidOpeningTime: bidOpeningTime.value,
    nowStatus: nowStatus.value,
    bidWinningAmount: bidWinningAmount.value,
    bidAgent: bidAgent.value,
  }
  console.log('params',params)
  if(props.modalType == 'insert'){
    AddBiddingInfo(params).then(res => {
      message.success('招标信息添加成功')
      emits('query')
      emits('changeAddModal',false)
    }).finally(() => {
      loading.value = false
    })
  }else{
    EditBiddingInfo(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 DeleteBiddingInfo(id.value).then(res => {
        message.success("删除成功")
        emits('query')
        emits('changeAddModal',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: 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>
