qushaowei
2023-08-19 ddfa6f728c57b5d072544c5d79a8c5fc47d1baf9
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<template>
  <div>
    <a-card
      :bordered="true"
      style="height: 50%"
    >
      <a-row type="flex">
        <a-col><a-button
            type="primary"
            @click="handleAdd(da)"
          >新建</a-button></a-col>
        <a-col><a-button
            type="primary"
            @click="handleEdit(da)"
          >编辑</a-button></a-col>
        <a-col><a-button
            type="primary"
            @click="batchDel(da)"
          >删除</a-button></a-col>
        <a-col style="left: 5%"><a-button type="primary">模板</a-button></a-col>
        <a-col style="left: 5%"><a-button type="primary">导入</a-button></a-col>
        <a-col style="left: 5%"><a-button type="primary">导出</a-button></a-col>
      </a-row>
    </a-card>
    <a-row
      type="flex"
      :gutter="16"
    >
      <a-col
        :md="5"
        :sm="24"
      >
             
        <MomBaseUnitCategoryListLeft
          ref="MomBaseUnitCategoryListLeft"
          class="MomBaseUnitCategoryListLeft"
          @treeSelect="treeSelect"
        />
           
      </a-col>
      <a-col
        :md="24 - 5"
        :sm="24"
      >
        <MomBaseUnitCategoryListRight
          ref="MomBaseUnitCategoryListRight"
          class="MomBaseUnitCategoryListRight"
          @searchkeys="selectedKeys"
        />
      </a-col>
    </a-row>
    <mom-base-unit-category-modal
      ref="modalForm"
      @ok="modalFormOk"
    ></mom-base-unit-category-modal>
  </div>
</template>
 
<script>
import MomBaseUnitCategoryListLeft from './modules/unitCategory/MomBaseUnitCategoryListLeft'
import MomBaseUnitCategoryListRight from './modules/unitCategory/MomBaseUnitCategoryListRight'
import MomBaseUnitCategoryModal from './modules/unitCategory/MomBaseUnitCategoryModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { deleteAction } from '@/api/manage'
 
export default {
  name: 'MomBaseUnitCategoryList',
  mixins: [JeecgListMixin],
  components: { MomBaseUnitCategoryListLeft, MomBaseUnitCategoryListRight, MomBaseUnitCategoryModal },
  data() {
    return {
      description: '计量单位分类页面',
      currentOrgCode: '',
      selectedRowKeys: [],
      selectionRows: [],
      url: {
        list: '/base/getTree',
        deleteBatch: '/base/delete',
      },
      da: [],
    }
  },
 
  methods: {
    //新增数据(新建按钮触发)
    handleAdd(da) {
      if (this.da.length <= 0) {
        this.$message.warning('请选择一个树节点!')
        return
      } else {
        this.$refs.modalForm.add(da, { cb: this.callback })
      }
    },
    //修改数据(修改按钮触发)
    handleEdit(da) {
      if (this.da.length <= 0) {
        this.$message.warning('请选择一个树节点!')
        return
      } else {
        this.$refs.modalForm.edit(da, { cb: this.loadTree })
      }
    },
    //批量删除右侧数据(删除按钮触发)
    batchDel(da) {
      if (!this.url.deleteBatch) {
        this.$message.error('请设置url.deleteBatch属性!')
        return
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录!')
        return
      } else {
        var ids = ''
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ','
        }
        var that = this
        this.$confirm({
          title: '确认删除',
          content: '是否删除选中数据?',
          onOk: function () {
            that.loading = true
            deleteAction(that.url.deleteBatch, { ids: ids })
              .then((res) => {
                if (res.success) {
                  that.$message.success(res.message)
                } else {
                  that.$message.warning(res.message)
                }
              })
              .finally(() => {
                that.loading = false
                //重新计算分页问题
                that.reCalculatePage(that.selectedRowKeys.length)
                that.onClearSelected()
                that.$refs.MomBaseUnitCategoryListRight.loadData({ id: da.id })
                that.loadTree()
              })
          },
        })
      }
    },
    //重新计算分页
    reCalculatePage(count) {
      //总数量-count
      let total = this.ipagination.total - count
      //获取删除后的分页数
      let currentIndex = Math.ceil(total / this.ipagination.pageSize)
      //删除后的分页数<所在当前页
      if (currentIndex < this.ipagination.current) {
        this.ipagination.current = currentIndex
      }
      console.log('currentIndex', currentIndex)
    },
    //清除右侧选中项
    onClearSelected() {
      this.selectedRowKeys = []
      this.selectionRows = []
    },
    //左右联动(da为左侧选中树的数据,子控件中返回)
    treeSelect(da) {
      let id = da.id
      this.da = da
      this.onClearSelected()
      this.$refs.MomBaseUnitCategoryListRight.loadData({ id })
    },
    //右侧列表选中事件
    selectedKeys(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    //加载左侧树
    loadTree() {
      this.$refs.MomBaseUnitCategoryListLeft.queryTreeData()
    },
    //新增编辑保存后回调函数回显页面数据
    callback(id) {
      this.$refs.MomBaseUnitCategoryListLeft.queryTreeData()
      this.$refs.MomBaseUnitCategoryListRight.loadData({ id: id })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>