<template>
  <div class="ui-wrap">

    <!----------------------------------单选-------------------------------------->
    <div>单选</div>
    <el-radio v-model="radio" label="1">备选项</el-radio>
    <el-radio v-model="radio" label="2">备选项</el-radio>
    <el-radio v-model="radio" label="1" disabled>备选项</el-radio>
    <el-radio v-model="radio" label="2" disabled>备选项</el-radio>

    <!----------------------------------复选-------------------------------------->
    <div>复选</div>
    <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
    <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
      <el-checkbox v-for="city in cities" :label="city" :key="city">{{city}}</el-checkbox>
    </el-checkbox-group>
    <el-checkbox v-model="checked" disabled>备选项</el-checkbox>
    <el-checkbox disabled>备选项</el-checkbox>
  </div>
</template>
<script>
 const cityOptions = ['上海', '北京', '广州', '深圳'];
 export default {
   data() {
     var checkAge = (rule, value, callback) => {
       if (!value) {
         return callback(new Error('年龄不能为空'));
       }
       setTimeout(() => {
         if (!Number.isInteger(value)) {
           callback(new Error('请输入数字值'));
         } else {
           if (value < 18) {
             callback(new Error('必须年满18岁'));
           } else {
             callback();
           }
         }
       }, 1000);
     };
     const generateData = _ => {
       const data = [];
       for (let i = 1; i <= 15; i++) {
         data.push({
           key: i,
           label: `备选项 ${ i }`,
           disabled: i % 4 === 0
         });
       }
       return data;
     };
     return {
       radio: '1',

       checkAll: false,
       checkedCities: ['上海', '北京'],
       cities: cityOptions,
       isIndeterminate: true,

       checked: true,

       input1: '',
       input2: '',
       input3: '',
       textarea: '',
       select: '',
       isClearable: true,

       visible: false,

       ruleForm: {
         age: ''
       },
       rules: {
         age: [
           { validator: checkAge, trigger: 'blur' }
         ]
       },
       switchvalue01: true,
       switchvalue02: false,
       switchvalue03: true,
       slidervalue01: 20,
       slidervalue02: [10, 30],
       slidervalue03: [50, 100],
       slidervalue04: 20,
       slidervalue05: 20,
       pagination01: {
         page: 2,
         size: 6,
         total: 6
       },
       pagination02: {
         page: 2,
         size: 8,
         total: 10
       },
       transferdata: generateData(),
       transfervalue: [1, 4],
       tableData01: [{
         date: '2016-05-02',
         name: '王小虎',
         address: '上海市普陀区金沙江路 1518 弄'
       }, {
         date: '2016-05-04',
         name: '王小虎',
         address: '上海市普陀区金沙江路 1517 弄'
       }, {
         date: '2016-05-01',
         name: '王小虎',
         address: '上海市普陀区金沙江路 1519 弄'
       }, {
         date: '2016-05-03',
         name: '王小虎',
         address: '上海市普陀区金沙江路 1516 弄'
       }]
     };
   },
   methods: {
     messageOpen1() {
       this.$message({
         message: '恭喜你，这是一条成功消息',
         type: 'success',
         duration: 0,
         showClose: true
       });
     },
     messageOpen2() {
       this.$message({
         message: '这是一条消息提示',
         duration: 0,
         showClose: true
       });
     },
     messageOpen3() {
       this.$message({
         showClose: true,
         message: '警告哦，这是一条警告消息',
         type: 'warning',
         duration: 0
       });
     },
     messageOpen4() {
       this.$message({
         showClose: true,
         message: '警告哦，这是一条警告消息',
         type: 'error',
         duration: 0
       });
     },
     handleCheckAllChange(val) {
       this.checkedCities = val ? cityOptions : [];
       this.isIndeterminate = false;
     },
     handleCheckedCitiesChange(value) {
       let checkedCount = value.length;
       this.checkAll = checkedCount === this.cities.length;
       this.isIndeterminate = checkedCount > 0 && checkedCount < this.cities.length;
     },
     submitForm(formName) {
       this.$refs[formName].validate((valid) => {
         if (valid) {
           alert('submit!');
         } else {
           console.log('error submit!!');
           return false;
         }
       });
     },
     progressformat(percentage) {
       return percentage === 100 ? '满' : `${percentage}%`;
     },
     progressformat02(percentage) {
       return (percentage > 0 && percentage < 100) ? '加载中' : `${percentage}%`;
     }
   }
 };
</script>
<style lang="scss">
.ui-wrap > div  {
  margin-bottom: 10px;
  margin-top: 20px;
}
.el-form-item__content {
  margin-left: 0 !important;
}
.el-select .el-input {
  width: 100px;
}
.input-with-select .el-input-group__prepend {
  background-color: #fff;
}
</style>