<script setup name="sealConfiguration">
import { ref, getCurrentInstance, onMounted } from 'vue'
import { fiscalAndSealSet, getFinancialCode } from '@/http/apis/systemManage/unitManage'
import { useRoute } from 'vue-router'
const route = useRoute(),
  { proxy } = getCurrentInstance(),
  props = defineProps({
    orgCode: {
      type: String,
      default: ''
    }
  }),
  form = ref({
  }),
  formRef = ref(),
  // 手机号码校验
  checkFiscalCode = (rule, value, callback) => {
    if (value === '') {
      return callback(new Error('请输入正确的财政编码：6位纯数字'))
    } else {
      const reg = /^\d{6}$/
      if (reg.test(value)) {
        callback()
      } else {
        return callback(new Error('请输入正确的财政编码：6位纯数字'))
      }
    }
  },
  rules = {
    sealSn: [{ required: true, message: '请输入印章编码' }],
    fiscalCode: [{ required: true, message: '请输入财政编码' }, { validator: checkFiscalCode, trigger: 'blur' }]
  },
  submit = async (formEl) => {
    if (!formEl) {
      return
    }
    await formEl.validate(async (valid) => {
      if (valid) {
        await fiscalAndSealSet({
          ...form.value,
          organizationCode: props.orgCode || route.query.id
        })
        proxy.$message.success('提交成功')
      }
    })
  }

onMounted(async () => {
  const res = await getFinancialCode({ organizationCode: props.orgCode || route.query.id })
  form.value = { ...res.data }
})
</script>

<template>
  <el-card shadow="never">
    <el-form
      ref="formRef"
      label-position="right"
      :model="form"
      :rules="rules"
    >
      <el-form-item label="印章编码" prop="sealSn">
        <el-input
          v-model="form.sealSn"
          style="width:200px"
          placeholder="请输入"
          :maxlength="20"
        />
        <span class="text-info ml-16">温馨提示：印章授权平台：https://zjyz.zjzwfw.gov.cn/main   </span>
      </el-form-item>
      <el-form-item v-if="false" label="财政编码" prop="fiscalCode">
        <el-input
          v-model="form.fiscalCode"
          style="width:200px"
          placeholder="请输入"
          :maxlength="6"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submit(formRef)">提交</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<style lang="less" scoped>
</style>
