schangxiang@126.com
2025-09-17 ff43ddf18764629ff875478e4e47a7281cbd230a
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
<template>
    <view class="overflow">
        <cu-custom bgColor="bg-white" :isBack="true">
            <block slot="backText">
            </block>
            <block slot="content">工量具归还</block>
        </cu-custom>
        <view class="flex justify-end align-center padding_right30rpx padding_top12rpx">
            <text class="fontSize12rpx"> 操作人:{{operator}} </text>
        </view>
        <modal-code ref="resmodal" :rescode='rescode' :resmessage='resmessage' />
        <view class="">
            <u-form labelPosition="top" :model="warehouse" ref="warehouseRef">
                <u-row class="border_bottom margin_top10rpx padding10" style="background-color: #fff;">
                    <u-col span="12">
                        <u-form-item label="借用人:" prop="name" required
                            style="font-size: 16px;font-weight: bold;padding: 0;">
                            <u-input v-model="warehouse.name"  @click="showPerson = true" type="select" placeholder="选择借用人" 
                                style="font-weight: bolder;margin-left: 15rpx;"
                                class="width padding_left25rpx">
                            </u-input>
                        </u-form-item>
                    </u-col>
                </u-row>
            </u-form>
            <view  class="ware_content">
                <view v-for="(item, eindex) in singlist" :key="item.code" style="margin-top: 10rpx;">
                    <u-swipe-action :show="item.show" :index="eindex" @click="longpress" @open="open" :options="options" style="width: 100vw;">
                        <view class="ware_item" :class="item.showItem ? 'bg_item' : ''" style="width: 100vw;">
                            <u-row>
                                <u-col span="1">
                                    <view class="circle">
                                        {{eindex+1}}
                                    </view>
                                </u-col>
                                <u-col span="10">
                                    <view class="color_f18202">
                                        {{item.code}} ({{item.name}})
                                    </view>
                                </u-col>
                            </u-row>
                            <u-row>
                                <u-col span="6">
                                    <view class="" style="padding: 10rpx 0 10rpx 45rpx;color: #808080;">
                                        借用数:{{item.borrowQuantity}}
                                    </view>
                                </u-col>
                                <u-col span="6">
                                    <view class="" style="padding: 10rpx 0 10rpx 45rpx;color: #808080;">
                                        已归还数:{{item.returnQuantity}}
                                    </view>
                                </u-col>
                            </u-row>
                            
                            <u-row>
                                <u-col span="6" class="flex">
                                    <view class="" style="color: #808080;">
                                        本次归还数:
                                    </view>
                                    <input
                                        class="border_bottom_f18202 text-left color_f18202 fontSize32rpx"
                                        style="background-color: #f2f2f2;height: 70rpx;width: 115rpx;" v-model="item.returnNum"
                                        type="number" @focus="item.returnNum = ''"  @blur="changeNum(item)" 
                                    />
                                </u-col>
                                <u-col span="6" class="flex">
                                    <view class="" style="color: #808080;padding: 10rpx 0 10rpx 45rpx;">
                                        归还人:
                                    </view>
                                    <u-input
                                        class="border_bottom_f18202 text-left color_f18202 fontSize32rpx"
                                        type="select"
                                        placeholder="请选择"
                                        style="background-color: #f2f2f2;height: 70rpx;width: 115rpx;" v-model="item.createdUserName"
                                        @click="selectPerson(eindex)"/>
                                </u-col>
                            </u-row>
                        </view>
                    </u-swipe-action>
                </view>
            </view>
            <u-select v-model="show"  :list="borrowPersonList" value-name="name" label-name="name" @confirm="confirm"></u-select>
            <u-select v-model="showPerson"  :list="borrowPersonList" value-name="name" label-name="name" @confirm="confirmPerson"></u-select>
            <!-- <button-modal :empTytowerShow='true' cleaningTitle="重置" garmenTitle='提交' @submit='submit' @reset='rest' /> -->
        </view>
    </view>
    </view>
</template>
 
<script>
    import ButtonModal from '../../components/buttonModal.vue'
    import ModalCode from '../../components/ModalCode.vue'
    import {getUnReturnList,getWarePersonList,wareReturn} from '../../api/wareTool/index.js'
    import {getDate} from '../../utils/dateTime.js'
    export default {
        data() {
            return {
                renameFocus: true,
                rescode: 0,
                resmessage: "",
                singlist: [], //物料详情
                options: [
                    {
                        text: '归还',
                        style: {
                            backgroundColor: '#fc9f35'
                        }
                    }
                ],
                showPerson: false, //选择借用人
                warehouse: {
                    name: ''
                },
                warehouseRules: {
                    name: [{
                        required: true,
                        message: '借用人不能为空',
                        trigger: 'blur'
                    }],
                },
                activeIndex: 100,
                show: false,
                borrowPersonList: [],
                operator: '',
            };
        },
        components: {
            ButtonModal,
            ModalCode
        },
        onLoad(){
            //获取借用人列表
            this.getPersonList();
        },
        onReady() {
            this.$refs.warehouseRef.setRules(this.warehouseRules)
        },
        mounted() {
            this.operator = JSON.parse(uni.getStorageSync('userInfo')).name
        },
        methods: {
            //获取借用人/归还列表
            getPersonList() {
                getWarePersonList().then(res => {
                    if(res.data.rows.length == 0){
                        return;
                    }
                    this.borrowPersonList = res.data.rows;
                })
            },
            //借用人选择
            confirmPerson(con) {
                this.warehouse.name = con[0].value;
                this.getOutWarehouse();
            },
            //归还数
            changeNum(item) {
                let num1 =  Number(Number(item.borrowQuantity) - Number(item.returnQuantity)).toFixed(3)  //必须保留3位小数 -否则会造成剩余物料是小数的时候,无法收货
                if(Number(item.returnNum)  > Number(num1)) {
                    this.rescode = 400
                    this.resmessage = `本次归还数不能大于借用数减去已归还数`
                    this.$refs.resmodal.show = true
                    item.returnNum = '';
                }
            },
            // 借用人选择
            selectPerson(index) {
                this.activeIndex = index;
                this.show = true;
            },
            //借用人确定
            confirm(con) {
                this.singlist[this.activeIndex].createdUserName = con[0].value;
            },
            //获取当前借用人名下借用工量具列表
            getOutWarehouse() {
                this.$refs.warehouseRef.validate(valid => {
                    if (valid) {
                        getUnReturnList(this.warehouse).then(res => {
                            if(res.data.rows.length == 0) {
                                this.rescode = 400
                                this.resmessage = `当前借用人没有需要归还工量具`
                                this.$refs.resmodal.show = true
                                return;
                            }
                            
                            const index = res.data.rows.reduce((curr,item) => {
                                if(item.borrowQuantity == item.returnQuantity) {
                                    curr++
                                }
                                return curr;
                            },0) 
                            if(index == res.data.rows.length) {
                                this.rescode = 400
                                this.resmessage = `当前借用人没有需要归还工量具`
                                this.$refs.resmodal.show = true
                                return;
                            }
                            
                            res.data.rows.map(item => {
                                item.returnNum = '';
                                item.createdUserName = '';
                                item.show = false;
                                item.showItem = false;
                            })
                            
                            this.singlist = res.data.rows.filter(item => item.borrowQuantity != item.returnQuantity)
                        })
                    }
                })
            },
            //打开当前,关闭其他
            open(index) {
                this.singlist[index].show = true;
                this.singlist.map((val, idx) => {
                    if (index != idx) this.singlist[idx].show = false;
                })
            },
            // 点击事件
            longpress(index,eindex){
                const matInfo = this.singlist[eindex];
                if(matInfo.returnNum == '' || matInfo.returnNum <= 0 || matInfo.createdUserName == '') {
                    this.rescode = 400
                    this.resmessage = `归还数量或者归还人数据异常`
                    this.$refs.resmodal.show = true
                    return;
                }
                
                const arr = [{
                    orderId: matInfo.id,
                    quantity: matInfo.returnNum,
                    returnId: this.borrowPersonList.find(person => person.name == matInfo.createdUserName).nickName,
                    returnName: matInfo.createdUserName,
                    remark: "string"
                }]
                
                wareReturn(arr).then(res => {
                    this.rescode = 200
                    this.resmessage = `归还成功`
                    this.$refs.resmodal.show = true
                    this.getOutWarehouse();
                })
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .ware_content {
        width: 100vw;
        height: auto;
        margin: 15rpx 0 10rpx 0;
        .ware_item {
            background: #fff;
            margin: 10rpx auto;
            padding: 8rpx;
            font-size: 16px;
            box-sizing: border-box;
            .circle {
                width: 40rpx;
                height: 40rpx;
                border-radius: 50%;
                background: #f18202;
                color: #fff;
                font-size: 30rpx;
                line-height:40rpx;
                text-align: center;
            }
            .u-col {
                font-size: 40rpx;
            }
        }
    }
    .bg_item {
           background: #FFEBCD !important;
    }
    
</style>