<template>
  <el-tabs type="border-card">
    <el-tab-pane label="属性">
      <el-form ref="form" disabled label-width="82px">
        <el-row :gutter="15">
          <el-col :span="13">
            <el-form-item label="名称" prop="name">
              <el-input v-model="parentData.name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="13">
            <el-form-item label="描述" prop="remark">
              <el-input v-model="parentData.remark" type="textarea"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="13">
            <el-form-item label="使用对象" prop="useObjList"> </el-form-item>
          </el-col>
          <el-col :span="13">
            <el-form-item label="状态" prop="status"> </el-form-item>
          </el-col>
          <el-col :span="13">
            <el-form-item label="创建人" prop="createUserName"> 
              <el-input v-model="parentData.createUserName" ></el-input>

            </el-form-item>
          </el-col>
          <el-col :span="13">
            <el-form-item label="创建时间" prop="createTime">
              <el-input v-model="parentData.createTime" ></el-input>
              
            </el-form-item>
          </el-col>
          <el-col :span="13">
            <el-form-item label="修改人" prop="updateUserName">
              <el-input v-model="parentData.updateUserName" ></el-input>
              
            </el-form-item>
          </el-col>
          <el-col :span="13">
            <el-form-item label="修改时间" prop="updateTime"> 
              <el-input v-model="parentData.updateTime" ></el-input>


            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-tab-pane>
    <el-tab-pane label="编码码段">
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        height="calc(100vh - 335px)"
        full-height="calc(100vh - 116px)"
        tool-class="ele-toolbar-form"
        cache-key="systemOrgUserTable"
        :selection.sync="selection"
        :needPage="false"
      >
        <template v-slot:toolbar>
          <el-button type="primary" @click.native="openEdit('add')">
            新建
          </el-button>

          <el-button
            type="primary"
            :disabled="selection.length != 1"
            @click.native="openEdit('edit')"
          >
            编辑
          </el-button>
          <el-popconfirm
            class="ele-action"
            title="确定要删除此码段吗？"
            @confirm="remove()"
          >
            <template v-slot:reference>
              <el-button type="danger" :disabled="selection.length == 0">
                删除
              </el-button>
            </template>
          </el-popconfirm>

          <!-- <el-button type="primary"> 启用 </el-button>
      <el-button type="primary"> 停用 </el-button> -->
        </template>

        <codeSegmentEdit
          ref="codeSegmentEditRef"
          :businessCodeCategoryId="parentData.id"
          @done="done"
        ></codeSegmentEdit>
      </ele-pro-table>
    </el-tab-pane>
  </el-tabs>
  <!-- 数据表格 -->
</template>
   
  <script>
import codeSegmentEdit from './components/codeSegmentEdit.vue';
import { roughRule, fineRule } from '@/enum/dict.js';
import { pageSegment, removeSegment } from '@/api/businessCode';
export default {
  components: {
    codeSegmentEdit
  },
  props: {
    // 上级
    parentData: {
      type: Object,
      default: () => {}
    }
  },

  data() {
    return {
      form: {},
      selection: [],
      // 表格列配置
      columns: [
        {
          width: 45,
          type: 'selection',
          columnKey: 'selection',
          align: 'center'
        },
        {
          label: '名称',
          prop: 'name',
          align: 'center',
          showOverflowTooltip: true,
          fixed: 'left'
        },
        {
          prop: 'remark',
          label: '描述',
          align: 'center',
          showOverflowTooltip: true
        },
        {
          prop: 'length',
          label: '长度',
          align: 'center',
          showOverflowTooltip: true
        },
        {
          prop: 'roughRule',
          label: '粗规则',
          align: 'center',
          showOverflowTooltip: true,
          formatter: (_row, _column, cellValue) => {
            return roughRule.find((item) => item.value == cellValue)?.label;
          }
        },
        {
          prop: 'fineRule',
          label: '细规则',
          align: 'center',
          showOverflowTooltip: true,
          formatter: (_row, _column, cellValue) => {
            let _fineRule=fineRule.filter(item=>item.pid==_row.roughRule)
            return _fineRule.find((item) => item.value == cellValue)?.label;
          }
        },
        {
          prop: 'createUserName',
          label: '创建人',
          align: 'center',
          showOverflowTooltip: true
        },
        {
          prop: 'createTime',
          label: '创建时间',
          align: 'center',
          showOverflowTooltip: true
        }
      ]
    };
  },
  created() {},

  methods: {
    /* 表格数据源 */
    datasource({ page, limit, where, order }) {
      return pageSegment({
        ...where,
        pageNum: page,
        size: limit,
        businessCodeCategoryId: this.parentData?.id
      });
    },
    /* 刷新表格 */
    reload(where) {
      this.$nextTick(() => {
        this.$refs.table.reload({ pageNum: 1, where: where });
      });
    },

    /* 显示编辑 */
    openEdit(type, row = '') {
      this.$refs.codeSegmentEditRef.open(type, this.selection[0]);
    },

    /* 删除 */
    remove() {
      removeSegment(this.selection.map((item) => item.id))
        .then((msg) => {
          this.$message.success('操作成功');
          this.$emit('done', this.parentData);
        })
        .catch((e) => {
          // this.$message.error(e.message);
        });
    },
    done() {
      this.$emit('done', this.parentData);
    }
  }
};
</script>
  