<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-progress-open-task-import'

export const metaInfo = {
  name: '打开纠纷/案件作业',
  order: 150,
}

export default {
  name: 'XmLawProgressOpenTask',
  components: {
    ...components,
  },
  props: {
    dataSource: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      fields: [
        {
          name: 'comTaskLink',
          caption: '页面地址',
          dataType: 'string',
        },
        {
          name: 'appModuleId',
          caption: '模块表单ID',
          dataType: 'string',
        },
        // {
        //   name: 'businessTypeId',
        //   caption: '业务类型',
        //   dataType: 'string',
        // },
        {
          name: 'newWindow',
          caption: '新窗口打开',
          dataType: 'selectlist',
          attr: {
            defaultValue: '1',
            selectListItem: [
              { label: '是', value: '1' },
              { label: '否', value: '0' },
            ],
          },
        },
        {
          name: 'strtype',
          caption: '所属业务',
          dataType: 'selectlist',
          attr: {
            defaultValue: '1',
            selectListItem: [
              { label: '纠纷', value: '1' },
              { label: '案件', value: '2' },
            ],
          },
        },
        {
          name: 'strjftype',
          caption: '所属类型',
          dataType: 'selectlist',
          attr: {
            defaultValue: '1',
            selectListItem: [
              { label: '进展', value: '1' },
              { label: '结案', value: '2' },
              { label: '查看', value: 'view' },
            ],
            displayExpr: '#bean.strtype == "1"',
          },
        },
        {
          name: 'strcasetype',
          caption: '所属类型',
          dataType: 'selectlist',
          attr: {
            defaultValue: '1',
            selectListItem: [
              { label: '案件进展', value: '1' },
              { label: '案件结案', value: '2' },
              { label: '案件执行', value: '3' },
              { label: '执行结案', value: '4' },
              { label: '查看', value: 'view' },
            ],
            displayExpr: '#bean.strtype == "2"',
          },
        },
      ],
      businessTypeOptions: [],
    }
  },
  computed: {},
  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
        }
      })
    } else {
      // 新建，赋默认值
      this.dataSource.newWindow = '1' // 新窗口
      this.dataSource.strtype = '1' // 纠纷
      this.dataSource.strjftype = '1' // 进展
      this.dataSource.strcasetype = '1' // 案件进展
    }
  },
  methods: {
    validate() {
      return this.$refs.form.validateFields()
    },
    valueChange(value, field) {
      this.dataSource[field] = value.target ? value.target.value : value
    },
  },
}
</script>

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