马宇豪
2022-12-20 6ca4914a18d1b1561e537674292cf9374791de7c
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<template>
    <el-dialog v-model="equipmentDialog" title="关联物资标准" width="40%" center @close="closeMaterial">
      <div class="standard" v-for="item in materialList">
        <div>{{ item.name }}</div>
        <el-button @click="openList(item)" type="success">选用</el-button>
      </div>
 
      <el-dialog v-model="equipDetailDialog" title="物资标准详情" width="75%" center @open="openDetail">
        <div class="choose-receiver">
          <span>选择其他作业关联人员</span>
          <el-select v-model="receiveUids" multiple @change="changeReceiver">
            <el-option
                v-for="item in workerList"
                :key="item.uid"
                :label="item.username"
                :value="item.uid"
            />
          </el-select>
        </div>
        <table class="table">
          <tr>
            <th class="w-25">物资名称</th>
            <th class="w-15">标准值</th>
            <th class="w-15">级别</th>
            <th class="w-30">关联人员与个数</th>
            <th class="w-15">实际使用</th>
          </tr>
          <tr v-for="(item,index) in materialDetail">
            <td class="w-25">{{item.materialName}}</td>
<!--              <td class="w-1">-->
<!--                <el-select v-model="addList[index].depId" @change="changeDep($event,index)">-->
<!--                  <el-option-->
<!--                      v-for="i in item.msList"-->
<!--                      :key="i.depId"-->
<!--                      :label="i.depName"-->
<!--                      :value="i.depId"-->
<!--                  />-->
<!--                </el-select>-->
<!--              </td>-->
<!--              <td class="w-15">-->
<!--                  {{stockCount[index]}}-->
<!--              </td>-->
            <td class="w-15">{{item.standVal}}</td>
            <td class="w-15">{{item.configurationLevelName}}</td>
            <td class="w-30">
              {{item.receiveUnames}}
            </td>
<!--              <td class="w-15">-->
<!--                <el-input type="number" v-model.number="addList[index].useCount"/>-->
<!--              </td>-->
            <td class="w-15">
              {{item.receiveCount}}
            </td>
          </tr>
        </table>
        <template #footer>
          <span class="dialog-footer">
            <el-button @click="closeChoose()" size="default">取消</el-button>
            <el-button type="primary" @click="submitMaterials" size="default">确认</el-button>
          </span>
        </template>
      </el-dialog>
    </el-dialog>
</template>
 
<script lang="ts">
import {workApplyApi} from "/@/api/specialWorkSystem/workApply";
 
interface stateType {
  equipmentDialog:boolean
  materialList: Array<any>
  equipDetailDialog: boolean
  materialDetail: Array<any>
  stockCount: Array<number>
  chosenId: number | null,
  receiveUids: Array<number>
}
 
 
import { reactive, toRefs, ref } from 'vue';
import { approveBasicApi } from '/@/api/specialWorkSystem/approveBasic';
import {ElMessage, ElMessageBox} from 'element-plus';
import {useUserInfo} from "/@/stores/userInfo";
import {storeToRefs} from "pinia";
 
export default {
    name: 'materialDialog',
    setup(props: any, context: any) {
        const userInfo = useUserInfo()
        const { userInfos } = storeToRefs(userInfo);
        const approveBasicFormRef = ref();
        const state = reactive<stateType>({
          chosenId: null,
          equipmentDialog: false,
          materialList: [],
          equipDetailDialog: false,
          materialDetail: [],
          stockCount: [],
          receiveUids: []
        });
 
      // 确认物资标准
      const getMaList = async(type:number,level:number) =>{
          const data = {workType: type,workLevel: level}
          const res = await workApplyApi().getMaterial(data)
          if (res.data.code === '200') {
            if(res.data.data && res.data.data.length>0){
              state.materialList = JSON.parse(JSON.stringify(res.data.data))
              state.equipmentDialog = true
            }else{
              ElMessage({
                type: 'warning',
                message: '暂时查询不到物资标准信息'
              });
            }
          } else {
            ElMessage({
              type: 'warning',
              message: res.data.msg
            });
          }
      }
      const openList = async(item:object)=>{
        state.chosenId = item.id
        const data = {maBaseId: state.chosenId,receiveUids:state.receiveUids}
        const res = await workApplyApi().getMaterialDetail(data)
        if (res.data.code === '200') {
          if(res.data.data && res.data.data.length>0){
            state.materialDetail = res.data.data
            state.equipDetailDialog = true
          }else{
            ElMessage({
              type: 'warning',
              message: '暂时查询不到物资标准信息'
            });
          }
        } else {
          ElMessage({
            type: 'warning',
            message: res.data.msg
          });
        }
        // state.stockCount = []
        // if(item.mcList && item.mcList.length>0){
        //   for(let j in item.mcList){
        //     if(item.mcList[j].msList == null || item.mcList[j].msList.length==0){
        //       item.mcList.splice(j,1)
        //     }
        //   }
        //   state.materialDetail = item.mcList
        //   for(let i in state.materialDetail){
        //       state.addList.push(
        //           {
        //             materialId: state.materialDetail[i].materialId,
        //             depId: null,
        //             depName: '',
        //             useCount: null
        //           }
        //       )
        //     for(let x in state.materialDetail[i].msList){
        //       if(state.materialDetail[i].msList[x].depId == userInfos.value.depId){
        //         state.addList[i].depId = userInfos.value.depId
        //         state.addList[i].depName = state.materialDetail[i].msList[x].depName
        //         state.stockCount[i] = state.materialDetail[i].msList.find((e) => e.depId == state.addList[i].depId).stockCount
        //       }
        //     }
        //   }
        // }
      }
      const changeReceiver = async ()=>{
        const data = {maBaseId: state.chosenId,receiveUids:state.receiveUids}
        const res = await workApplyApi().getMaterialDetail(data)
        if (res.data.code === '200') {
          if(res.data.data && res.data.data.length>0){
            state.materialDetail = res.data.data
          }else{
            ElMessage({
              type: 'warning',
              message: '暂时查询不到物资标准信息'
            });
          }
        } else {
          ElMessage({
            type: 'warning',
            message: res.data.msg
          });
        }
      }
      const openDetail = ()=>{
      }
      const submitMaterials = ()=>{
        // if(state.addList.length > 0 && (state.addList.some((e) => e.depId == null && e.useCount != null ) || state.addList.some((e) => e.useCount == null && e.depId != null))){
        //   ElMessage({
        //     type: 'warning',
        //     message: '出库部门或实际使用值不可为空'
        //   });
        //   return
        // }
        // for(let i in state.materialDetail){
        //   if(state.materialDetail[i].configurationLevelName == '必选' && state.addList[i].depId != null && state.addList[i].useCount <= 0){
        //     ElMessage({
        //       type: 'warning',
        //       message: '必选物资数量不能小于等于0'
        //     });
        //     return
        //   }
        //   if((state.stockCount[i] !=null && state.addList[i].useCount !=null) && (state.stockCount[i] < state.addList[i].useCount)){
        //     ElMessage({
        //       type: 'warning',
        //       message: '物资配置数量超出库存量,请重新配置'
        //     });
        //     return
        //   }
        // }
        // if(state.addList.length > 0){
        //   for(let n in state.addList){
        //     if(state.addList[n].depId == null && state.addList[n].useCount == null){
        //       state.addList.splice(n,1)
        //     }
        //   }
        // }
        console.log(state.receiveUids,state.chosenId,'666666666')
        context.emit('conFirmMaterials',state.receiveUids,state.chosenId)
        state.equipDetailDialog = false
        state.equipmentDialog = false
      }
 
      const closeMaterial = ()=>{
 
      }
      const closeChoose = () =>{
        state.equipDetailDialog = false
      }
        return {
            ...toRefs(state),
            getMaList,
            openList,
            changeReceiver,
            openDetail,
            closeChoose,
            closeMaterial,
            submitMaterials
        };
    }
};
</script>
 
<style lang="scss" scoped>
  .standard{
    width: 100%;
    display: flex;
    margin-bottom: 20px;
    align-items: center;
    justify-content: space-between;
  }
 
  .table{
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    tr{
      width: 100%;
      border: 1px solid #ccc;
      th,td{
        padding: 6px 0;
        border-left: 1px solid #ccc;
        &:first-of-type{
          border-left: none;
        }
      }
      td{
        font-weight: bolder;
      }
 
      .w-15{
        width: 15%;
        text-align: center;
      }
      .w-20{
        width: 20%;
        text-align: center;
      }
      .w-25{
        width: 25%;
        text-align: center;
      }
      .w-30{
        width: 30%;
        text-align: center;
      }
    }
  }
</style>