<template>
    <div class="content">
        <e-row :gutter="24">
            <e-col :span="24" class="box-card">
                <e-card shadow="always">
                    <div slot="header" class="clearfix">
                        <span>基本用法</span>
                    </div>
                    <div>
                        <e-transfer v-model="value" :data="data"></e-transfer>
                    </div>
                </e-card>
            </e-col>
            <!-- 可搜索 -->
            <e-col :span="24" class="box-card">
                <e-card shadow="always">
                    <div slot="header" class="clearfix">
                        <span>可搜索</span>
                    </div>
                    <div>
                        <e-transfer
                            filterable
                            :filter-method="filterMethod"
                            filter-placeholder="请输入城市拼音"
                            v-model="value2"
                            :data="data2">
                        </e-transfer>
                    </div>
                </e-card>
            </e-col>
            <!-- 可自定义 -->
            <e-col :span="24" class="box-card">
                <e-card shadow="always">
                    <div slot="header" class="clearfix">
                        <span>可自定义</span>
                    </div>
                    <div>
                        <p style="text-align: center; margin: 0 0 20px">使用 render-content 自定义数据项</p>
                        <div style="text-align: center">
                            <e-transfer
                            style="text-align: left; display: inline-block"
                            v-model="value3"
                            filterable
                            :left-default-checked="[2, 3]"
                            :right-default-checked="[1]"
                            :render-content="renderFunc3"
                            :titles="['Source', 'Target']"
                            :button-texts="['到左边', '到右边']"
                            :format="{
                                noChecked: '${total}',
                                hasChecked: '${checked}/${total}'
                            }"
                            @change="handleChange"
                            :data="data3">
                            <el-button class="transfer-footer" slot="left-footer" size="small">操作</el-button>
                            <el-button class="transfer-footer" slot="right-footer" size="small">操作</el-button>
                            </e-transfer>
                        </div>
                        <p style="text-align: center; margin: 50px 0 20px">使用 scoped-slot 自定义数据项</p>
                        <div style="text-align: center">
                            <e-transfer
                            style="text-align: left; display: inline-block"
                            v-model="value4"
                            filterable
                            :left-default-checked="[2, 3]"
                            :right-default-checked="[1]"
                            :titles="['Source', 'Target']"
                            :button-texts="['到左边', '到右边']"
                            :format="{
                                noChecked: '${total}',
                                hasChecked: '${checked}/${total}'
                            }"
                            @change="handleChange"
                            :data="data3">
                            <span slot-scope="{ option }">{{ option.key }} - {{ option.label }}</span>
                            <el-button class="transfer-footer" slot="left-footer" size="small">操作</el-button>
                            <el-button class="transfer-footer" slot="right-footer" size="small">操作</el-button>
                            </e-transfer>
                        </div>
                    </div>
                </e-card>
            </e-col>
            <!-- 数据项属性别名 -->
            <e-col :span="24" class="box-card">
                <e-card shadow="always">
                    <div slot="header" class="clearfix">
                        <span>数据项属性别名</span>
                    </div>
                    <div>
                        <e-transfer
                        v-model="value5"
                        :props="{
                            key: 'value',
                            label: 'desc'
                        }"
                        :data="data5">
                    </e-transfer>
                    </div>
                </e-card>
            </e-col>
        </e-row>
    </div>
</template>
<script>

export default {
    components: {},
    data() {
        const generateData = _ => {
        const data = [];
        for (let i = 1; i <= 15; i++) {
          data.push({
            key: i,
            label: `备选项 ${ i }`,
            disabled: i % 4 === 0
          });
        }
        return data;
      };
      const generateData2 = _ => {
        const data = [];
        const cities = ['上海', '北京', '广州', '深圳', '南京', '西安', '成都'];
        const pinyin = ['shanghai', 'beijing', 'guangzhou', 'shenzhen', 'nanjing', 'xian', 'chengdu'];
        cities.forEach((city, index) => {
          data.push({
            label: city,
            key: index,
            pinyin: pinyin[index]
          });
        });
        return data;
      };
      const generateData3 = _ => {
        const data = [];
        for (let i = 1; i <= 15; i++) {
          data.push({
            key: i,
            label: `备选项 ${ i }`,
            disabled: i % 4 === 0
          });
        }
        return data;
      };
      const generateData5 = _ => {
        const data = [];
        for (let i = 1; i <= 15; i++) {
          data.push({
            value: i,
            desc: `备选项 ${ i }`,
            disabled: i % 4 === 0
          });
        }
        return data;
      };
        return {
            data: generateData(),
            value: [1, 4],
            data2: generateData2(),
            value2: [],
            filterMethod(query, item) {
            return item.pinyin.indexOf(query) > -1;
            },
            data3: generateData3(),
            value3: [1],
            value4: [1],
            renderFunc3(h, option) {
            return <span>{ option.key } - { option.label }</span>;
            },
            data5: generateData5(),
            value5: []
        }
    },
    mounted() {
    },
    methods: {
      handleChange(value, direction, movedKeys) {
        console.log(value, direction, movedKeys);
      }
    }
}
</script>
  
<style>
.marginLeft {
    margin-left: 10px
}
.content {
    height: 100%;
    padding: 30px;
    background:#fff;
}

.block {
    display: inline-block;
    margin-left: 10px;
}

.box-card .el-col{
    margin-bottom:10px;
}
.transfer-footer {
    margin-left: 20px;
    padding: 6px 5px;
  }
  </style>
