schangxiang@126.com
2025-04-01 afc3ef31921d5ca812f7db92dfb107e2c25eff4c
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="10">
                        <u-form-item label="工量具编号:" prop="code" required
                            style="font-size: 16px;font-weight: bold;padding: 0;">
                            <input v-model="warehouse.code" placeholder="请录入或扫码" @focus="warehouse.code = ''"
                                @blur="getOutWarehouse" style="font-weight: bolder;margin-left: 15rpx;"
                                class="width padding_left25rpx">
                            </input>
                        </u-form-item>
                    </u-col>
                    <u-col span="2">
                        <u-icon class="iconfont icon-saoma fontSize60rpx"></u-icon>
                    </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.exitQuantity}}
                                    </view>
                                </u-col>
                                <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.quantity"
                                        type="number" @focus="item.quantity = ''"  @blur="changeNum(item)" 
                                    />
                                </u-col>
                            </u-row>
                            
                            <u-row>
                                <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>
            <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 {getWarePersonList,getWareCount,wareBorrow} 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'
                        }
                    }
                ],
                warehouse: {
                    code: ''
                },
                warehouseRules: {
                    code: [{
                        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;
                })
            },
            //借用数判断
            changeNum(item) {
                if(item.quantity > item.exitQuantity) {
                    this.rescode = 400
                    this.resmessage = `借用数不能大于库存数`
                    this.$refs.resmodal.show = true
                    item.quantity = '';
                }
            },
            // 借用人选择
            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) {
                        //判断当前编号是否存在
                        let count = this.singlist.findIndex(item => item.code == this.warehouse.code);
                        if(count > -1) {
                            this.singlist.unshift(...this.singlist.splice(count,1))
                            return;
                        }
                        getWareCount(this.warehouse).then(res => {
                            if(res.data.rows.length == 0) {
                                this.rescode = 400
                                this.resmessage = `编号为${warehouse.code}工量具无库存或不存在`
                                this.$refs.resmodal.show = true
                            }
                            res.data.rows.map(item => {
                                item.createdUserName = '';
                                item.exitQuantity = item.quantity;
                                item.show = false;
                                item.showItem = false;
                            })
                            this.singlist.push(...res.data.rows);
                        })
                    }else {
                        this.rescode = 400
                        this.resmessage = `工量具编号不能为空`
                        this.$refs.resmodal.show = true
                    }
                })
            },
            //打开当前,关闭其他
            open(index) {
                this.singlist[index].show = true;
                this.singlist.map((val, idx) => {
                    if (index != idx) this.singlist[idx].show = false;
                })
            },
            // 点击事件
            longpress(index,eindex){
                this.singlist.splice(eindex,1);
            },
            submit() {
                //借用人是否存在为空
                const index = this.singlist.findIndex(item => item.createdUserName == '');
                if(index > -1) {
                    this.rescode = 400
                    this.resmessage = `存在借用人为空`
                    this.$refs.resmodal.show = true
                    return;
                }
                
                //借用数量校验
                const count = this.singlist.findIndex(item => item.quantity <= 0 || item.quantity > item.exitQuantity || item.quantity == '');
                if(count > -1) {
                    this.rescode = 400
                    this.resmessage = `借用数量存在异常`
                    this.$refs.resmodal.show = true
                    return;
                }
                
                this.singlist.map(item => {
                    item.createdTime = getDate();
                })
                
                wareBorrow(this.singlist).then(res => {
                    this.rescode = 200
                    this.resmessage = `借用成功`
                    this.$refs.resmodal.show = true
                })
                this.rest();
                
            },
            //重置
            rest() {
                this.singlist = [];
                this.warehouse.code = '';
                this.activeIndex = 100;
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .ware_content {
        width: 100vw;
        height: auto;
        margin: 15rpx 0 160rpx 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>