<template>
  <sd-form ref="form" :init-values="fields">
    <template v-slot="{ model }">
      <sd-form-item
        v-for="field in fields"
        :key="field.name"
        :name="field.name"
        :label="field.dataType === 'collection' ? null : undefined"
        :hidden="!!field.sdHidden"
        @change="(value) => valueChange(value, field.name)"
      >
      </sd-form-item>
    </template>
  </sd-form>
</template>

<script>
import components from './_import-components/xm-law-sub-case-import'
export const metaInfo = {
  name: '案件分案',
  order: 100,
}
export default {
  name: 'XmLawSubCase',
  components,
  props: {
    dataSource: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      visible: false,
      confirmLoading: false,
      fields: [
        {
          name: 'divisionType',
          caption: '分案类型',
          dataType: 'selectlist',
          attr: {
            defaultValue: 'PROGRESS',
            selectListItem: [
              { label: '案件进展', value: 'PROGRESS' },
              { label: '案件执行', value: 'EXECUTE' },
            ],
          },
        },
      ],
    }
  },
  created() {
    // 编辑时
    if (Object.keys(this.dataSource).length > 0) {
      this.fields.forEach((f) => {
        const value = this.dataSource[f.name]
        if (value && typeof value === 'object') {
          f.value = JSON.stringify(value)
        } else {
          f.value = value
        }
      })
    }
  },
  methods: {
    validate() {
      return this.$refs.form.validateFields()
    },
    valueChange(value, field) {
      this.dataSource[field] = value.target ? value.target.value : value
    },
    handleOk() {
      return true
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
</style>
