<template>
  <el-dialog title="采购审核" v-model="dialogVisible" width="800px">
    <Descriptions :data="form" :schema="schema" :columns="3" />
    <el-form v-if="canEdit" :model="form" ref="auditForm" :rules="rules" label-width="80px">
      <el-row :gutter="20">
        <el-col :span="24" :offset="0">
          <el-form-item label="审核" prop="status">
            <el-radio-group v-model="form.status">
              <el-radio :label="2">通过</el-radio>
              <el-radio :label="3">驳回</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24" :offset="0">
          <el-form-item label="备注" prop="auditRemark">
            <Editor v-model:modelValue="form.auditRemark" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <span>
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleSave">保 存</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
const dialogVisible = ref(false) // 弹窗的是否展示

const form = ref({})
const rules = ref({})
const canEdit = ref(true)

const schema = ref([
  {
    field: 'name',
    label: '产品名称'
  },
  {
    field: 'specsName',
    label: '规格名称'
  },
  {
    field: 'supplier',
    label: '供应商'
  },
  {
    field: 'purchaseCount',
    label: '采购数量'
  },
  {
    field: 'unitPrice',
    label: '采购单价'
  },
  {
    field: 'totalPrice',
    label: '总金额'
  },
  {
    field: 'warehouse',
    label: '仓库'
  },
  {
    field: 'warehouse',
    label: '申请人'
  },
  {
    field: '',
    label: '申请时间'
  },
  {
    field: 'remark',
    label: '备注',
    isEditor: true,
    span: 3
  }
])

const open = (val, flag) => {
  dialogVisible.value = true
  form.value = { ...val, status: 2, remark: '<p style="color: red;">哈哈哈</p>' }
  canEdit.value = flag
  if (!canEdit.value) {
    const arr = [
      {
        field: 'status',
        label: '采购状态'
      },
      {
        field: 'auditUser',
        label: '审核人'
      },
      {
        field: 'auditTime',
        label: '审核时间'
      },
      {
        field: 'auditRemark',
        label: '审核备注',
        isEditor: true,
        span: 3
      }
    ]
    schema.value = [...schema.value, ...arr]
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

function handleSave() {
  console.log('保存')
}
</script>

<style scoped></style>
