<template>
  <el-dialog
    title="社保申报信息"
    v-model="visible"
    :width="width"
    append-to-body
    draggable
    @close="close"
    :close-on-click-modal = "false"
  >
    <!-- 功能按钮 -->
    <div style="padding: 8px 24px 16px 24px">
      <el-form size="small" label-width="100px" v-model="form">
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="客户名称">
              <div>{{ form.companyName }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属月份">
              <div>{{ form.year }}-{{ form.month }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-divider />
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位养老金：">
              <div>{{ rowNum(form.unitPension) }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位医疗险：">
              <div>{{ rowNum(form.unitMedical) }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位工伤险：">
              <div>{{ rowNum(form.unitInjury) }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位失业金：">
              <div>{{ rowNum(form.unitUnemployment) }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位生育险：">
              <div>{{ rowNum(form.unitProcreate) }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位大病险：">
              <div>{{ rowNum(form.unitSeriousIllness) }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位采暖费：">
              <div>{{ rowNum(form.unitHeatingFee) }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="个人养老金：">
              <div>{{ rowNum(form.individualPension) }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="个人医疗险：">
              <div>{{ rowNum(form.individualMedical) }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="个人失业金：">
              <div>{{ rowNum(form.individualUnemployment) }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="个人大病险：">
              <div>{{ rowNum(form.individualSeriousIllness) }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合计：">
              <div>{{ rowNum(form.amount) }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-divider />
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注">
              <div>{{ form.content }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="凭证" required>
              <el-table
                ref="dbTable"
                :data="form.evidenceFiles"
                size="small"
                border
                header-row-class-name="list-header-row"
                row-class-name="list-row"
              >
                <el-table-column
                  label="文件名"
                  prop="originalFileName"
                  align="center"
                  show-overflow-tooltip
                >
                  <template #default="scope">
                    <el-button
                      size="small"
                      type="text"
                      @click="openFile(scope.row)"
                      >{{
                        scope.row.originalFileName == ""
                          ? "打开文件"
                          : scope.row.originalFileName
                      }}</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="form-btns-container" style="height: 40px">
      <el-button size="small" style="float: right" @click="close"
        ><i class="fa fa-close" aria-hidden="true" f /> 取消</el-button
      >
    </div>
  </el-dialog>
</template>
<script setup>
import { getAmountView } from "@/api/business/production/deduction";
import { uploadFile } from "@/api/tool/file";
import { rowNum } from "@/utils/index";
import { ref } from "vue";
const { proxy } = getCurrentInstance();
const visible = ref(false);
const width = ref(800);
const selections = ref([]);
const currentSource = ref(null);
const editStatus = ref(false);
const canSave = ref(false);
const baseUrl = ref(import.meta.env.VITE_APP_BASE_API);
const props = defineProps({
  getList: {
    type: Function,
    default: () => {},
  },
});

const { getList } = toRefs(props);
const total = ref(0);

const employeeEmptyData = {
  id: null,
  title: "",
  remark: "",
  employeeName: "",
  departmentName: "",
  idCardImage: "",
  idCardImageBack: "",
  idiograph: "",
  details: [],
  editStatus: true,
};

const form = ref({});
const conditions = ref({});

const emptyForm = {
  details: [],
};

function open(detail) {
  visible.value = true;
  conditions.value = detail;
  loadData();
}

function loadData() {
  console.log(conditions.value);
  getAmountView(conditions.value).then((res) => {
    form.value = res.data.socialSecurity;
  });
}

function close() {
  visible.value = false;
  reset();
}

function reset() {
  form.value = proxy.deepClone(emptyForm);
  canSave.value = false;
}

function handleCurrentChange(row) {
  currentSource.value = row;
}

function openFile(row) {
  window.open(`${baseUrl.value}${row.fileUrl}`);
}

// 暴露给父组件的方法
defineExpose({
  open,
});
</script>
<style scoped>
.img {
  width: 23px;
  height: 23px;
  display: flex;
  justify-content: center;
  align-items: center;
}

::v-deep(.el-upload) {
  display: flex;
  text-align: center;
  justify-content: center;
  cursor: pointer;
  outline: 0;
}

.required::after {
  content: "*";
  color: red;
}
</style>