houshuai
2025-06-30 4d5d871dd1cdc90cd1d913a0c696b7662b9d17e0
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<template>
  <a-card
    :bordered="false"
    title="线边库物料信息"
  >
    <a-button @click="handleAdd" type="primary" icon="plus">新增物料信息-测试</a-button>
    <a-spin :spinning="confirmLoading">
      <div>
        <!-- 主表单区域 -->
        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{ selectedRowKeys: selectedRowKeys,
  onChange: onSelectChange,
  type: 'radio'}"
          @change="handleTableChange">
        </a-table>
      </div>
      <!-- 子表单区域 -->
      <a-tabs v-model="activeKey" @change="handleChangeTabs">
        <a-tab-pane tab="物料库存信息" :key="refKeys[0]" :forceRender="true">
          <div style="display: flex; align-items: center; margin-bottom: 10px;">
            <span style="margin-right: 10px;">物料库存信息</span>
            <a-tag color="green" style="font-weight: bold;">
              库存总量:{{ totalInventoryQuantity }}
            </a-tag>
          </div>
          <j-vxe-table
            keep-source
            :ref="refKeys[0]"
            :loading="lswMaterialInventoryTable.loading"
            :columns="lswMaterialInventoryTable.columns"
            :dataSource="lswMaterialInventoryTable.dataSource"
            :maxHeight="300"
            :rowNumber="true"
            :rowSelection="true"
            :toolbar="false"
          />
        </a-tab-pane>
      </a-tabs>
    </a-spin>
    <lsw-material-modal ref="modalForm" @ok="modalFormOk" />
  </a-card>
</template>
 
<script>
 
import { getAction } from '@/api/manage'
import { JVxeTableModelMixin } from '@/mixins/JVxeTableModelMixin.js'
import { JVXETypes } from '@/components/jeecg/JVxeTable'
import { getRefPromise, VALIDATE_FAILED } from '@/components/jeecg/JVxeTable/utils/vxeUtils.js'
import { validateDuplicateValue } from '@/utils/util'
import JFormContainer from '@/components/jeecg/JFormContainer'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import LswMaterialModal from '@views/lsw/modules/LswMaterialModal.vue'
 
export default {
  name: 'LswMaterialForm',
  mixins: [JVxeTableModelMixin, JeecgListMixin],
  components: {
    LswMaterialModal,
    JFormContainer
  },
  data() {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      model: {},
      // 新增时子表默认添加几行空数据
      addDefaultRowNum: 1,
      validatorRules: {},
      selectedRowKeys: [], // 初始化为空数组(单选时存储单个key)
      selectedRowData: null,
      refKeys: ['lswMaterialInventory'],
      tableKeys: ['lswMaterialInventory'],
      activeKey: 'lswMaterialInventory',
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '物料编码',
          align: 'center',
          dataIndex: 'materialNumber',
          customRender: (text) => <strong>{text}</strong>
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName'
        },
        {
          title: '物料型号',
          align: 'center',
          dataIndex: 'materialModel'
        },
        {
          title: '物料类型',
          align: 'center',
          dataIndex: 'materialCategory_dictText'
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'materialUnit'
        }
      ],
      // 物料库存信息
      lswMaterialInventoryTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '批次号',
            key: 'batchNumber',
            type: JVXETypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          {
            title: '库存类型',
            key: 'inventoryCategory',
            type: JVXETypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          {
            title: '数量',
            key: 'quantity',
            type: JVXETypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          {
            title: '库存地ID',
            key: 'warehouseId',
            type: JVXETypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          {
            title: '库存状态',
            key: 'inventoryStatus',
            type: JVXETypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: ''
          }
        ]
      },
      url: {
        list: '/lswmaterial/lswMaterial/list',
        queryById: '/lswmaterial/lswMaterial/queryById',
        lswMaterialInventory: {
          list: '/lswmaterial/lswMaterial/queryLswMaterialInventoryByMainId'
        }
      }
    }
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
    totalInventoryQuantity() {
      if (!this.lswMaterialInventoryTable.dataSource || this.lswMaterialInventoryTable.dataSource.length === 0) {
        return '0';
      }
      return this.lswMaterialInventoryTable.dataSource.reduce((sum, item) => {
        const quantity = Number(item.quantity) || 0;
        return sum + quantity;
      }, 0);
    },
  },
  created() {
  },
  methods: {
    handleCustomAdd(){
      console.log('点击新增了')
    },
    handleTableChange() {
      console.log('test---->', this.selectedRowKeys[0])
    },
    async onSelectChange(selectedRowKeys) {
      // 单选模式下,selectedRowKeys 是数组,但长度最多为1
      console.log('点击了---->')
      this.selectedRowKeys = selectedRowKeys
 
      // 获取选中行的完整数据
      if (selectedRowKeys.length > 0) {
        const selectedId = selectedRowKeys[0] // 选中行的id
        const lswMaterialInventoryResult = await getAction(this.url.lswMaterialInventory.list, { 'id': selectedId })
        this.lswMaterialInventoryTable.dataSource = lswMaterialInventoryResult.result
      }
    }
 
  }
}
</script>
 
<style scoped>
</style>