zrlibs
2025-03-21 cd24c776d772c7ad797891afd779b3b072293ec2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<template>
  <div class="form-dialog">
    <Modal
      :model-value="modelValue"
      title="修改查询表单"
      class-name="form-dialog"
      @update:model-value="(v) => this.$emit('update:modelValue', v)"
    >
      <Checkbox
        :indeterminate="indeterminate"
        :model-value="checkAll"
        @click.prevent="onCheckAll"
        >全选</Checkbox
      >
      <Divider size="small" />
      <CheckboxGroup v-model="showList" @on-change="onShowChange">
        <Checkbox v-for="(item, i) in list" :key="i" :label="item.field">{{
          item.label?.replace(":", "")
        }}</Checkbox>
      </CheckboxGroup>
      <template #footer>
        <Space>
          <Button type="text" @click="onCancel">取消</Button>
          <Button type="primary" @click="onOk">确定</Button>
        </Space>
      </template>
    </Modal>
  </div>
</template>
 
<script>
export default {
  name: "FormDialog",
  props: {
    modelValue: Boolean,
    list: Array,
  },
  data() {
    return {
      indeterminate: false,
      checkAll: true,
      showList: [],
    };
  },
  methods: {
    onOk() {
      this.$emit("ok", this.showList);
      this.$emit("update:modelValue", false);
    },
    onCancel() {
      this.$emit("update:modelValue", false);
    },
    onCheckAll() {
      if (this.indeterminate) {
        this.checkAll = false;
      } else {
        this.checkAll = !this.checkAll;
      }
      this.indeterminate = false;
 
      if (this.checkAll) {
        this.showList = this.list.map((l) => l.field);
      } else {
        this.showList = [];
      }
    },
    onShowChange(data) {
      if (data.length == this.list.length) {
        this.indeterminate = false;
        this.checkAll = true;
      } else if (data.length > 0) {
        this.indeterminate = true;
        this.checkAll = false;
      } else {
        this.indeterminate = false;
        this.checkAll = false;
      }
    },
  },
  watch: {
    list(list) {
      this.showList = list.map((l) => l.field);
    },
  },
};
</script>
 
<style lang="less">
.form-dialog {
  .ivu-modal {
    top: 40px;
  }
  .ivu-divider-horizontal {
    margin: 9px 0;
  }
  .ivu-checkbox-group {
    display: flex;
    flex-direction: column;
  }
}
</style>