<template>
  <div class="kmc">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
      <el-row>
        <el-col :span="6">
          <el-form-item label="是否显示KOL入口" prop="resource">
            <el-radio-group v-model="ruleForm.resource">
              <el-radio label="2">否</el-radio>
              <el-radio label="1">是</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="入口文案" prop="name">
            <el-input v-model="ruleForm.name" placeholder="请输入入口文案，最长6个字"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-button type="primary">添加</el-button>
      </el-row>
    </el-form>
    <el-row class="table-content">
      <el-table
        :data="tableData"
        border
        style="width: 100%"
      >
        <el-table-column
          show-overflow-tooltip
          v-for="(item, key) in col"
          :key="`col_${key}`"
          :prop="col[key].prop"
          :label="item.label"
          align="center"
        >
          <template slot-scope="scope">
            <p>{{ scope.row[item.prop] }}</p>
            <div v-if="item.prop === 'operate'">
              <el-button size="small">移除</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
  </div>
</template>

<script>
import Sortable from 'sortablejs';
import kolCol from './util/common';

export default {
  components: {
    Sortable
  },
  data() {
    return {
      ruleForm: {
        name: '',
        resource: '2'
      },
      rules: {
        resource: [
          { required: true, message: '请选择是否展示入口', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '请输入入口文案', trigger: 'blur' },
          { max: 6, message: '入口文案长度不能多于6个字符', trigger: 'blur' }
        ]
      },
      kolCol,
      tableData: [
        {
          index: 1
        },
        {
          index: 2
        },
        {
          index: 3
        },
        {
          index: 4
        }
      ]
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.rowDrop();
    });
  },
  methods: {
    rowDrop() {
      const tbody = document.querySelector('.el-table__body-wrapper tbody');

      debugger
      Sortable.create(tbody);
    }
  },
}
</script>

<style lang="scss" scoped>
.table-content {
  margin-top: 15px;
}
</style>
