<template>
  <eagle-scheme
    :option="{ $http: $axios, url: '/dataDictionary', detailMethod: 'queryById', getMethod: 'queryById', editMethod: 'modify' }"
    :list="schemeList"
    :formProps="{ span: 24, 'label-width': '60px' }"
    :detailProps="{ span: 24, 'label-width': '50px' }"
    :dialogProps="dialogProps"
    @dialog-change="handleDialogChange"
  ></eagle-scheme>
</template>

<script>
export default {
  name: 'test',
  data() {
    return {
      schemeList: [
        { type: 'el-input', label: 'ID', key: 'id', include: 'form', visible: (model, { formMode } = {}) => { return formMode == 'edit' },
          props: { disabled: true },
        },
        { type: 'el-input', label: '编码', key: 'code', exclude: 'search',
          rules: [{ required: true, message: '编码不能为空', trigger: 'blur' }],
          props: { placeholder: '编码' },
        },
        { type: 'el-input', label: '名称', key: 'name',
          rules: [{ required: true, message: '名称不能为空', trigger: 'blur' }],
          props: { placeholder: '名称' },
        },
        { type: 'el-input', label: '备注', key: 'remark', include: 'table',
          props: { placeholder: '备注' },
        },
      ],
      dialogType: '',
    }
  },
  computed: {
    dialogProps() {
      return { width: this.dialogType === 'dialog-form' ? '500px' : '400px' };
    }
  },
  methods: {
    async searchAPI(param) {
      return this.$axios.get(`/dataDictionary/page?current=1&size=10`)
        .then((response) => {
          const { result = [], totalCount = 0 } = response || {};
          return { result, totalCount };
        }).catch(() => {
          return {};
        });
    },
    async getAPI(param) {
      return this.$axios.get(`/dataDictionary/queryById?id=${param.id}`)
        .then((response) => {
          const { result = {} } = response || {};
          return result;
        }).catch(() => {
          return {};
        });
    },
    async newAPI(param) {
      return this.$axios.post('/dataDictionary/add', param)
        .then((response) => {
          const { success = false } = response || {};
          return success;
        }).catch(() => {
          return false;
        });
    },
    async editAPI(param) {
      return this.$axios.post('/dataDictionary/modify', param)
        .then((response) => {
          const { success = false } = response || {};
          return success;
        }).catch(() => {
          return false;
        });
    },
    handleDialogChange(type) {
      this.dialogType = type;
    }
  }
}
</script>