<template>
  <div>
    <el-dialog :title="'预算记录详情'" width="1000px" v-model="props.modelValue" :before-close="handleClose">
      <div class="config">
        <el-form :model="ruleForm" :rules="rules" label-width="140px" class="demo-ruleForm.value" ref="ruleFormRef"
          :disabled="true">
          <el-form-item label="预算项目：" style="width: 80%">
            <el-input v-model="ruleForm.budgettitle" style="width: 100%" disabled></el-input>
          </el-form-item>
          <el-form-item label="预算类别：" style="width: 80%">
            <MOSTY.DictTree :zdbh="'D_BZ_YSFYLB'" v-model="ruleForm.ctype" :placeholder='"请选择预算类别"' :disabled='true'
              style="width: 100%;" />
          </el-form-item>
          <el-form-item label="费用明细：" prop="costDetailTitle" style="width: 80%">
            <el-input v-model="ruleForm.costDetailTitle" type="textarea" autosize style="width: 100%"></el-input>
          </el-form-item>
          <el-form-item style="width: 80%">
            <div>
              <span> 预算金额：{{ ruleForm.ndgkpfs }}万元，</span>
              <span> 已使用金额：{{ ruleForm.costFeer || 0 }}万元，</span>
              <span> 可使用金额：{{ ruleForm.ksyfree }}万元</span>
            </div>
          </el-form-item>
          <el-form-item label="使用金额：" prop="costFee" style="width: 80%;">
            <el-input v-model="ruleForm.costFee" type="number" style="width: 100%">
              <template #append>万元</template> </el-input>
          </el-form-item>
          <el-form-item label="情况说明：" style="width: 80%">
            <el-input v-model="ruleForm.costExplain" type="textarea" autosize style="width: 100%" />
          </el-form-item>
          <el-form-item label="备注：" style="width: 80%">
            <el-input v-model="ruleForm.bz" type="textarea" autosize style="width: 100%" />
          </el-form-item>
          <el-form-item label="附件：" style="width: 80%">
            <MOSTY.Upload :widthNumber="565" :limit="4" :nopicer="true" :isImg="false" :ShowfileList="true"
              v-model="ruleForm.fj" :showinput="true" :delrow="delrow">
            </MOSTY.Upload>
          </el-form-item>
        </el-form>
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="handleClose" type="primary">
            <el-icon>
              <DocumentDelete />
            </el-icon>
            <span>关闭</span>
          </el-button>
        </span>
      </template>
    </el-dialog>


  </div>
</template>

<script setup>
// 引入
import { reactive, onMounted, ref, defineProps, watch, getCurrentInstance } from "vue";
import { getApi, postApi, putApi } from "@/api/tobAcco_api.js";
import { numAdd } from "@/utils/tools.js";
import * as MOSTY from "@/components/MyComponents/index";
import * as rule from "@/utils/rules.js";
const delrow = ref({}); //删除文件列表
const ruleForm = ref({});
const emits = defineEmits(["changeAddVi"]);
//规则校验
const rules = reactive({
  costDetailTitle: [{ trigger: "blur", required: true, message: "费用明细不能为空" }],
  ...rule.numbernineRule({ validator: true, require: true, iszs: true, firstNum: 10, lastNum: 4 }, "costFee"),
});
const disabled = ref(false)
const props = defineProps({
  modelValue: {
    type: Boolean,
    default: true
  },
  rowid: String,
  id: {
    type: String,
    default: null
  },
});
const ruleFormRef = ref();
onMounted(() => {
  // 查询详情
  getApi({}, `/mosty-jcgl/budgets/showInfo?id=${props.id}`).then((item) => {
    if (item) {
      item.budget = item.budget ? item.budget : 0;
      item.gkpf = numAdd("add", 4, item.budget, item.gkshzj);
      item.ndgkpfs = numAdd("add", 4, item.gkpf, item.yeargkshzj);
      item.costFeer = item.costFee ? item.costFee : 0;
      item.ksyfree = numAdd("reduce", 4, item.ndgkpfs, item.costFee);
      ruleForm.value = {}
      ruleForm.value.fj = null;
      ruleForm.value.budgettitle = item.budgettitle;
      ruleForm.value.budgetid = item.id;
      ruleForm.value.ctype = item.ctype;
      ruleForm.value.ndgkpfs = item.ndgkpfs;
      ruleForm.value.costFeer = item.costFeer;
      ruleForm.value.ksyfree = item.ksyfree;
      getxqData(props.rowid)
    }
  });
});

//获取费用详情
function getxqData(id) {
  getApi({ id }, `/mosty-jcgl/budgetsCost/getJlbDetail`).then((res) => {
    ruleForm.value.costDetailTitle = res.costDetailTitle;
    ruleForm.value.costFee = res.costFee;
    ruleForm.value.costExplain = res.costExplain;
    ruleForm.value.bz = res.bz;
    ruleForm.value.id = res.id;
    ruleForm.value.fj = res.fj;
  });
}

// 关闭
const handleClose = () => {
  ruleForm.value = {}
  ruleForm.value.fj = null;
  ruleFormRef.value.clearValidate();
  ruleFormRef.value.resetFields();
  emits("changeAddVi", false);

};

</script>

<style lang="scss" scoped>
::v-deep .el-dialog__body {
  height: 70vh !important;
}

.fj {
  .el-form {
    padding: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .from_fix {
    display: flex;
    flex-wrap: wrap;
    padding: 10px;
    margin-top: 10px;


    .el-input {
      width: 100%;
    }
  }
}

::v-deep .el-form-item__content {
  flex-wrap: nowrap !important;
}

.txbj {
  display: flex;
  justify-content: space-between;
}

.config {
  .el-form {
    padding: 10px 40px;
    margin-top: 10px;
    display: block;
    // flex-wrap: wrap;
    // justify-content: space-between;
  }

  .el-form-item {
    text-align: center;
  }
}

.pxdx_box {
  width: 500px;
}

.titleBox {
  align-items: center;
  margin: 0;
  padding: 0;
  height: 60px;
  border: 1px solid rgb(32, 75, 54);
  padding: 20px;
}

.form>div {
  position: relative;
  margin-top: 30px;
  display: flex;
  justify-content: space-between;

  div {
    display: flex;
    align-items: center;

    .el-select {
      width: 65%;
    }
  }
}

.el-input {
  width: 75%;
}

.two .el-input {
  width: 65%;
}

.three {
  justify-content: flex-start !important;

  .el-select {
    width: 15%;
  }
}

.four {
  display: flex;
  align-items: center;

  span {
    width: 5%;
  }

  .el-textarea__inner {
    width: 95%;
  }
}

.group {
  margin-top: 50px;
  // background-color: red;
  position: relative;
}

.fj {
  margin-top: 50px;
  width: 100%;

  .content {
    width: 100%;
    display: flex;
    padding: 20px;

    div {
      display: flex;
      width: 85%;
      align-items: center;
    }

    justify-content: space-between;
  }
}

.jc {
  margin-top: 50px;
}

.el-form-item__content {
  flex-wrap: nowrap;
}

.el-collapse {
  border-color: var(--el-color-primary);
  height: 460px;
}

::v-deep .el-collapse-item__header {
  border-bottom-color: var(--el-color-primary);
}

::v-deep .el-collapse-item__header.is-active {
  border-bottom-color: transparent;
}
</style>
