<style>
.checked {
  width: 100%;
}
.checked .ant-checkbox-wrapper {
  width: 20%;
}
</style>
<template>
  <div>
    <a-modal title="账户选择" v-model="showEdit" @ok="handleOk" @cancel="close" width="60%">
      <a-checkbox :indeterminate="indeterminate" @change="onCheckAllChange" :checked="checkAll">全选</a-checkbox>
      <br />
      <a-checkbox-group :options="showList" v-model="dataValue" class="checked" @change="onChange" />
    </a-modal>
  </div>
</template>

<script>
import { deleteAction, getAction } from '@/api/manage'
// import lifting from './components/lifting'

export default {
  name: 'modules',
  components: {},

  data: function() {
    return {
      showEdit: false,
      dataList: [],
      showList: null,
      dataValue: [],
      indeterminate: false,
      checkAll: false
    }
  },
  methods: {
    handleOk(e) {
      console.log(e)
      this.showEdit = false
      this.$emit('synchro', this.dataValue)
    },
    close() {
      this.showEdit = false
      this.dataList = []
      this.showList = null
      this.dataValue = []
      this.indeterminate = false
      this.checkAll = false
    },
    onCheckAllChange(e) {
      Object.assign(this, {
        dataValue: e.target.checked
          ? this.showList.map(item => {
              return item.value
            })
          : [],
        indeterminate: false,
        checkAll: e.target.checked
      })
    },
    onChange(checkedList) {
      this.indeterminate = !!this.dataValue.length && this.dataValue.length < this.showList.length
      this.checkAll = this.dataValue.length === this.showList.length
    },
    getData(url, item) {
      this.showEdit = true
      this.dataList = []
      this.showList = null
      this.dataValue = []
      this.indeterminate = false
      this.checkAll = false
      console.log(url, item)
      getAction(url, item).then(res => {
        if (res.code == 0) {
          this.showList = res.result.map(item => {
            return {
              label: item.authName,
              value: item.accountId
            }
          })
        }
        console.log(res)
      })
    }
  },
  computed: {}
}
</script>
