<template>
  <el-form-item label="驻勤点类型" style="padding-top: 3px" v-if="isSecurity || isPoliceStation || isCompany">
    <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
    <el-checkbox-group v-model="stationType" @change="handleCheckedCitiesChange">
      <el-row style="height: 240px">
        <el-col style="padding-top: 10px" v-for="item in stationTypes.filter((x, i) => i <= 23)" :key="item.code" :span="8">
          <el-checkbox :label="item.code">
            <img class="type-icon" :src="item.icon" alt="" />
            <span style="font-size: 12px; padding-left: 2px">{{ item.name }}</span>
          </el-checkbox>
        </el-col>
        <el-col style="padding-top: 10px" v-for="item in stationTypes.filter((x, i) => i > 23)" :key="item.code" :span="12">
          <el-checkbox :label="item.code">
            <img class="type-icon" :src="item.icon" alt="" />
            <span style="font-size: 12px; padding-left: 2px">{{ item.name }}</span>
          </el-checkbox>
        </el-col>
      </el-row>
    </el-checkbox-group>
  </el-form-item>
</template>

<script>
export default {
  name: "index",
  props: {
    stationTypes: {
      type: Array,
      required: true,
    },
    isSecurity: Boolean,
    isPoliceStation: Boolean,
  },
  data() {
    return {
      isIndeterminate: false,
      checkAll: false,
      stationType: [],
    };
  },
  methods: {
    handleCheckAllChange(val) {
      this.stationType = val ? this.stationTypes.map((x) => x.code) : [];
      this.isIndeterminate = false;
      this.$emit("handleCheckChange", this.stationType);
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.stationTypes.length;
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.stationTypes.length;
      this.$emit("handleCheckChange", value);
    },
  },
};
</script>

<style scoped></style>
