<template>
  <div>
    <div class="bigBox" :style="{ height: bigHeight }">
      <MOSTY.FromPage :title="props.title" @closeDialog="CloseEvent">
        <template #content>
          <MOSTY.Assort :title="'上交时间'" />
          <div class="from_box">
            <el-form ref="ruleFormRef" :model="FromData" :rules="rules" label-width="120px" class="demo-ruleForm"
              status-icon :inline="true" :disabled="true">
              <el-form-item label="年份：" prop="years">
                <el-date-picker v-model="FromData.years" type="year" format="YYYY" value-format="YYYY"
                  style="width: 250px" />
              </el-form-item>
              <el-form-item label="预算项目：" prop="budgettitle">
                <el-input v-model="FromData.budgettitle" style="width: 250px"></el-input>
              </el-form-item>
              <el-form-item label="预算类别：" prop="ctype">
                <MOSTY.DictTree :zdbh="'D_BZ_YSFYLB'" v-model="FromData.ctype" :placeholder='"请选择预算类别"'
                  style="width: 250px;" />
              </el-form-item>
              <el-form-item label="审批单位：" prop="verifyorgname">
                <el-input v-model="FromData.verifyorgname" style="width: 250px" disabled></el-input>
              </el-form-item>
              <el-form-item label="审批人：" prop="verifyusername">
                <el-input v-model="FromData.verifyusername" style="width: 250px" disabled></el-input>
              </el-form-item>
              <el-form-item label="上年使用金额：" prop="lastyearmoney">
                <el-input v-model="FromData.lastyearmoney" type="number" style="width: 250px">
                  <template #append>万元</template> </el-input>
              </el-form-item>
              <el-form-item label="预算金额：" prop="budgetmoney">
                <el-input v-model="FromData.budgetmoney" type="number" style="width: 250px">
                  <template #append>万元</template> </el-input>
              </el-form-item>
              <el-form-item label="作业量：" prop="operation">
                <el-input v-model="FromData.operation" type="number" style="width: 250px"> </el-input>
              </el-form-item>
              <el-form-item label="定额标准：" prop="quotastandard">
                <el-input v-model="FromData.quotastandard" type="number" style="width: 250px"> </el-input>
              </el-form-item>
              <el-form-item label="年初批复数：" prop="budget" v-if="['nzdetails', 'nzexit'].includes(props.type)">
                <el-input v-model="FromData.budget" type="number" style="width: 250px">
                  <template #append>万元</template> </el-input>
              </el-form-item>
              <el-form-item label="调整增减数：" prop="tzzj" v-if="['nzdetails', 'nzexit'].includes(props.type)">
                <el-input v-model="FromData.tzzj" type="number" style="width: 250px">
                  <template #append>万元</template> </el-input>
              </el-form-item>

              <el-form-item label="批复金额：" prop="budget" v-if="!['nzexit', 'nzdetails'].includes(props.type)">
                <el-input v-model="FromData.budget" type="number" style="width: 250px"> <template #append>万元</template>
                </el-input>
              </el-form-item>
              <el-form-item label="预算说明：">
                <el-input v-model="FromData.yssm" style="width: 1055px" type="textarea" autosize></el-input>
              </el-form-item>
              <el-form-item label="备注：">
                <el-input v-model="FromData.bz" style="width: 1055px" type="textarea" autosize></el-input>
              </el-form-item>
              <el-form-item label="附件上传：">
                <MOSTY.Upload :widthNumber="1060" v-model="FromData.files" :limit="3" :delrow="delrow" :nopicer="true"
                  :showbut="props.saveBtnShow" @filehandleChange="changeFile" :ShowfileList="true" :isImg="false"
                  :showinput="true" :placeholder="'请上传pdf,ofd, doc, docx, xls, xlsx,wps'"
                  :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']" />
              </el-form-item>
            </el-form>
          </div>
        </template>
        <template #footer>
          <el-button type="primary" @click="CloseEvent">
            <el-icon>
              <DocumentDelete />
            </el-icon>
            <span>返回</span>
          </el-button>
        </template>
      </MOSTY.FromPage>

    </div>

  </div>
</template>

<script setup>
// 引入
import { reactive, onMounted, ref, defineProps, watch } from "vue";
import { getApi, postApi } from "@/api/tobAcco_api.js";
import * as MOSTY from "@/components/MyComponents/index";
import { numAdd } from "@/utils/tools.js";
import * as rule from "@/utils/rules.js";
const emits = defineEmits(["close"]);
//规则校验
const rules = reactive({
  years: [{ required: true, message: "年份不能为空", trigger: "blur" }],
  budgettitle: [{ required: true, message: "预算项目不能为空", trigger: "blur" }],
  ctype: [{ required: true, message: "预算类别不能为空", trigger: "blur" }],
  verifyorgname: [{ required: true, message: "审批单位不能为空", trigger: "blur" }],
  verifyusername: [{ required: true, message: "审批人不能为空", trigger: "blur" }],
  ...rule.numbernineRule({ validator: true, require: true, iszs: true, firstNum: 10, lastNum: 4 }, "budgetmoney"),
  ...rule.numbernineRule({ validator: true, require: false, iszs: true, firstNum: 10, lastNum: 4 }, "lastyearmoney"),
  ...rule.numbernineRule({ validator: true, require: false, iszs: true, firstNum: 10, lastNum: 4 }, "operation"),
  ...rule.numbernineRule({ validator: true, require: false, iszs: true, firstNum: 10, lastNum: 4 }, "quotastandard"),
  ...rule.numbernineRule({ validator: true, require: true, iszs: false, firstNum: 10, lastNum: 4 }, "tzzj"),
  ...rule.numbernineRule({ validator: true, require: true, iszs: false, firstNum: 10, lastNum: 4 }, "gkshzj"),
  budget: [
    {
      validator: (rule, value, callback) => {
        if (!value && value != 0) {
          callback(new Error('请输入年初批复数'));
        } else if (value < 0 && (Number(FromData.value.budgetmoney) + Number(value)) < 0) {
          callback(new Error('批复金额不能比预算金额多'));
        } else if (value > 0 && !/^[0-9]{0,10}(\.[0-9]{0,4})?$/.test(value)) {
          callback(new Error(`只能输入10位整数，4位小数`));
        } else {
          callback();
        }
      },
      trigger: 'blur',
      required: true
    }
  ]
});
const props = defineProps({
  // 判断展示字段
  type: {
    default: 'ncadd',
    type: String
  },
  orgcode: {
    default: '5200520100',
    type: String
  },
  // 标题
  title: {
    default: '',
    type: String
  },
  //id
  id: {
    default: null,
    type: String
  },

});
const ShowfileList = ref(true); //是否展示文件列表
const ruleFormRef = ref();
const orgcode = ref(props.orgcode);
const bigHeight = ref(); //整个高度
const delrow = ref({}); //删除文件列表
const FromData = ref({
  years: new Date().getFullYear().toString(),
  verifyorgname: '',
  verifyorgid: '',
  verifyusername: '',
  verifyuserid: '',
  files: ''
})
// 方法
const bigHeightFn = () => {
  bigHeight.value = window.innerHeight - 147 + "px";
};
const total = ref(0);
// 初始化
onMounted(() => {
  bigHeightFn();
});

//监听当前弹窗类型
watch(
  () => props.id,
  (val) => {
    if (val) {
      getxqData(val)
    } else {
      reset()
    }
  }, { deep: true, immediate: true }
);

//获取审核人
function shData() {
  // 审批人查询接口换成（安全部门接口中的查询部门负责人接口）
  getApi({ ssdwid: orgcode.value }, '/mosty-jcgl/securitychild/getAqbm').then(Res => {
    if (Res) {
      FromData.value.verifyorgname = Res.ssdwmc
      FromData.value.verifyorgid = Res.ssdwid
      getApi({}, `/mosty-jcgl/securitychild/getFzrByDeptid?deptid=${Res.ssbmid}`).then((res) => {
        FromData.value.verifyusername = res.userName
        FromData.value.verifyuserid = res.id

      })
    }

  })

}
//清空数据
function reset() {
  FromData.value.files = null
  FromData.value = {};
  FromData.value.years = new Date().getFullYear().toString()
  props.id = null;
}
//关闭综合配置表
const CloseEvent = () => {
  reset();
  emits("close");
};



//获取详情
function getxqData(id) {
  getApi({ id }, `/mosty-jcgl/budgets/getJlbDetail`).then((res) => {
    res.budget = res.budget ? res.budget : 0
    res.gkshzj = res.gkshzj ? res.gkshzj : 0
    res.yeartzzj = res.yeartzzj ? res.yeartzzj : 0
    FromData.value = res
    FromData.value.ncpfs = numAdd("add", 4, res.budget, res.gkshzj);
    orgcode.value = res.departid
    shData()
    ShowfileList.value = false
  })
}

</script>

<style lang="scss" scoped>
.bigBox {
  display: block;
}

::v-deep .el-collapse {
  padding: 20px !important;
}

.from_box {
  width: 1300px;
  margin-top: 31px;
  margin: 0 auto;
  color: #000;
}

.demo-ruleForm {
  display: block;
}

.txbj {
  display: flex;
  font-size: #000;
}
</style>