<template>
  <div>
    <div class="bigBox" :style="{ height: bigHeight }">
      <MOSTY.FromPage :title="props.title" @closeDialog="black">
        <template #content>
          <MOSTY.Assort :title="'基础信息'" />
          <div class="from_box">
            <el-form ref="ruleFormRef" :model="FromData" :rules="rules" label-width="135px" 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="使用部门:">
                <el-input v-model="FromData.usedeptname" clearable disabled style="width: 250px"></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="定额标准：">
                <el-input v-model="FromData.quotastandard" type="number" style="width: 250px"></el-input>
              </el-form-item>
              <el-form-item label="年初批复数：" prop="budget">
                <el-input v-model="FromData.budget" type="number" style="width: 250px" disabled>
                  <template #append>万元</template> </el-input>
              </el-form-item>
              <el-form-item label="中期批复数：" prop="ncpfs">
                <el-input v-model="FromData.ncpfs" type="number" style="width: 250px">
                  <template #append>万元</template> </el-input>
              </el-form-item>
              <el-form-item label="调整增减数：" prop="tzzj" v-if="['nddetails'].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="yeartzzj">
                <el-input v-model="FromData.yeartzzj" type="number" style="width: 250px">
                  <template #append>万元</template> </el-input>
              </el-form-item>
              <el-form-item label="预算说明：">
                <el-input v-model="FromData.yssm" autosize style="width: 1082px" type="textarea"></el-input>
              </el-form-item>
              <el-form-item label="备注：">
                <el-input v-model="FromData.bz" style="width: 1082px" autosize type="textarea"></el-input>
              </el-form-item>
              <el-form-item label="附件上传：" style='width:100%;'>
                <MOSTY.Upload :widthNumber="1082" 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']" :disabled="true" />
              </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 } 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", 'resttab']);
//规则校验
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: false, firstNum: 10, lastNum: 4 }, "budgetmoney"),
  ...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 }, "yeartzzj"),
  ...rule.numbernineRule({ validator: true, require: true, iszs: false, firstNum: 10, lastNum: 4 }, "yeargkshzj"),
  ...rule.numbernineRule({ validator: true, require: false, iszs: false, firstNum: 10, lastNum: 4 }, "lastyearmoney"),
  ...rule.numbernineRule({ validator: true, require: false, iszs: false, firstNum: 10, lastNum: 4 }, "budget"),
  ...rule.numbernineRule({ validator: true, require: false, iszs: false, firstNum: 10, lastNum: 4 }, "ncpfs"),
});

const props = defineProps({
  // 判断展示字段
  type: {
    default: 'ndexit',
    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: ''
})
onMounted(() => {
  bigHeightFn();
});
//获取审核人
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

      })
    }

  })
}

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

// 方法
const bigHeightFn = () => {
  bigHeight.value = window.innerHeight - 147 + "px";
};
//清空数据
function reset() {
  FromData.value = {};
  FromData.value.files = null;
  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()
    if (props.type == 'ndsh') {
      FromData.value.yeargkshzj = res.yeartzzj
    }

    ShowfileList.value = false


  })
}

</script>

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

}


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

::v-deep .el-form-item--default .el-form-item__content {
  line-height: 32px;
  color: #000;
  display: flex !important;
}

::v-deep .el-form--inline .el-form-item {
  display: inline-flex;
  vertical-align: middle;
  justify-content: space-between;
}

::v-deep .el-textarea.is-disabled .el-textarea__inner {
  color: #474545;
}

.el-form {
  margin: 0 auto;
  width: 1316px;
  justify-content: start;
  margin-top: 31px;
}

.from_box {
  width: 100%;
  margin: 0 auto;
}

.demo-ruleForm {
  display: block;

}

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