<template>
  <div>
    <el-table :data='fiveTableData' row-key="id" border :tree-props="{children: 'list', hasChildren: 'hasChildren'}">
      <el-table-column align="center" prop="yearScope" label="年度范围" width="130"></el-table-column>
      <el-table-column align="center" prop="segmentNo" label="序号" width="60"></el-table-column>
      <el-table-column align="center" prop="segmentChnName" label="档号组成项"></el-table-column>
      <el-table-column align="center" prop="segmentVal" label="组成项值"></el-table-column>
      <!-- <el-table-column align="center" prop="segmentLenth" label="长度" width="80"> </el-table-column> -->
      <el-table-column align="center" prop="segmentZero" label="取值或补零"> </el-table-column>
      <el-table-column align="center" prop="segmentSeparator" label="分隔符" width="80"> </el-table-column>
      <el-table-column align="center" width="180" label="操作">
        <template slot-scope="scope">
          <el-button v-if="scope.row.list" @click="addItem('新增',scope.row)" size="mini" type="text">新增组成项</el-button>
          <el-button @click="edit('修改',scope.row)" size="mini" type="text">修改</el-button>
          <el-button @click="del(scope.row)" size="mini" style="color:#FF4949" type="text">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
  import {
    mapState
  } from "vuex";
  export default {
    props: {
      treeRow: {
        type: Object,
        default: () => {},
      },
      fondsname: {
        type: String,
        default: () => ""
      }
    },
    data() {
      return {
        expands: false
      }
    },
    computed: {
      ...mapState({
        fiveTableData: (state) => state.categoryManagement.fiveTableData,
      })
    },
    methods: {
      addItem(val, tableRow) {
        this.$emit('addItem', val, tableRow)
      },
      edit(str, row) {
        this.$emit('edit', str, row)
      },
      del(row) {
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          if (row.list) {
            let data = {
              classId: this.treeRow.id,
              filingYearStart: row.yearScope.split('-')[0],
              filingYearEnd: row.yearScope.split('-')[1],
              fondscode: this.fondsname
            }
            this.$store.dispatch('categoryManagement/deleteYearScope', data).then(res => {
              this.$emit('handleNodeClick', this.treeRow)
            })
          } else {
            this.$store.dispatch('categoryManagement/deleteArchiveNoFormat', {
              id: row.id
            }).then(res => {
              this.$emit('handleNodeClick', this.treeRow)
            })
          }
        }).catch((err) => {
          console.log(err)
        });

      }
    }

  }

</script>
