<script name="annualPaymentPlan" setup>
import { ref } from 'vue'
const formData = ref({}),
  formRef = ref(),
  moneyValidator = (rule, value, callback) => {
    if (!value) callback()
    if (!/^\d+(\.\d{1,6})?$/.test(value)) {
      callback('请输入正确格式，最多保留六位小数')
    } else if (value * 1 >= 100000000) {
      callback('请输入正确格式，小于100000000')
    } else {
      callback()
    }
  },
  rules = {
    annualPlanAmount: [
      { required: true, message: '请输入年度支付金额', trigger: 'blur' },
      { validator: moneyValidator, trigger: 'blur' }
    ],
    annualPlanHaveAmount: [
      { required: true, message: '请输入自有资金', trigger: 'blur' },
      { validator: moneyValidator, trigger: 'blur' }
    ],
    annualPlanGovOwnFinanceAmount: [
      {
        required: true,
        message: '请输入政府投资-本级财政资金',
        trigger: 'blur'
      },
      { validator: moneyValidator, trigger: 'blur' }
    ],
    annualPlanGovSuperiorFinanceAmount: [
      {
        required: true,
        message: '请输入政府投资-上级补助资金',
        trigger: 'blur'
      },
      { validator: moneyValidator, trigger: 'blur' }
    ],
    annualPlanBankLendingAmount: [
      { required: true, message: '请输入银行贷款', trigger: 'blur' },
      { validator: moneyValidator, trigger: 'blur' }
    ],
    annualPlanOtherAmount: [{ required: true, message: '请输入其他', trigger: 'blur' },
      { validator: moneyValidator, trigger: 'blur' }]
  },
  // 校验
  validForm = (callback) => {
    formRef.value.validate(valid => {
      callback(valid)
    })
  },
  // 回显
  setFormData = (data) => {
    formData.value = {
      annualPlanAmount: data.annualPlanAmount,
      annualPlanHaveAmount: data.annualPlanHaveAmount,
      annualPlanGovOwnFinanceAmount: data.annualPlanGovOwnFinanceAmount,
      annualPlanGovSuperiorFinanceAmount: data.annualPlanGovSuperiorFinanceAmount,
      annualPlanBankLendingAmount: data.annualPlanBankLendingAmount,
      annualPlanOtherAmount: data.annualPlanOtherAmount
    }
  }
defineExpose({ validForm, formData, setFormData })
</script>

<template>
  <el-form
    ref="formRef"
    :model="formData"
    :rules="rules"
    label-position="right"
    label-width="180px"
    label-suffix=":"
    scroll-to-error
  >
    <el-row :gutter="40">
      <el-col :span="24">
        <el-form-item label="年度支付金额" prop="annualPlanAmount">
          <el-input-number
            v-model="formData.annualPlanAmount"
            placeholder="请填写"
            :min="0"
            :controls="false"
            @mousewheel.prevent
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="自有资金" prop="annualPlanHaveAmount">
          <el-input-number
            v-model="formData.annualPlanHaveAmount"
            placeholder="请填写"
            :min="0"
            :controls="false"
            @mousewheel.prevent
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item
          label="政府投资-本级财政资金"
          prop="annualPlanGovOwnFinanceAmount"
        >
          <el-input-number
            v-model="formData.annualPlanGovOwnFinanceAmount"
            placeholder="请填写"
            :min="0"
            :controls="false"
            @mousewheel.prevent
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item
          label="政府投资-上级补助资金"
          prop="annualPlanGovSuperiorFinanceAmount"
        >
          <el-input-number
            v-model="formData.annualPlanGovSuperiorFinanceAmount"
            placeholder="请填写"
            :min="0"
            :controls="false"
            @mousewheel.prevent
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="银行贷款" prop="annualPlanBankLendingAmount">
          <el-input-number
            v-model="formData.annualPlanBankLendingAmount"
            placeholder="请填写"
            :min="0"
            :controls="false"
            @mousewheel.prevent
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="其他" prop="annualPlanOtherAmount">
          <el-input-number
            v-model="formData.annualPlanOtherAmount"
            placeholder="请填写"
            :min="0"
            :controls="false"
            @mousewheel.prevent
          />
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>

<style lang="less">
.el-upload-list{
  width: 100%;
}
</style>
