spring
4 天以前 435881d494e2be4ba5ce8bfccb02d6ef49e07314
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
<template>
    <view class="wrap">
        <view class="search">
            <u-search v-model="query.workstationNo" placeholder="请输入工作站编号" @clear="search" @custom="search" @search="search">
            </u-search>
        </view>
        <scroll-view class="scroll-list" scroll-y="true" @scrolltolower="loadMore">
 
            <u-cell-group class="list" :border="false">
                <view class="content" v-for="(item, index) in workStationList" :key="item.workstationNo" :index="index"
                    @click="selectWorkstation(item)">
                    <view class="row-list">
                        <span class="span-lable">工作站编号: </span>{{ item.workstationNo }}
                    </view>
                    <view class="row-list">
                        <span class="span-lable">工作站名称: </span>{{ item.name }}
                    </view>
                    <view class="row-list">
                        <span class="span-lable">备注: </span>{{ item.remark }}
                    </view>
                </view>
            </u-cell-group>
            <view class="loadmore" @click="loadMore">
                <u-loadmore :status="loadStatus"></u-loadmore>
            </view>
        </scroll-view>        
        <scan></scan>
    </view>
</template>
<script>
    import scan from "@/components/scan/scan.vue";
    export default {
        components: {
           scan
          },
        data() {
            return {
                query: {
                    current: 1,
                    size: 20
                },
                workStationList: [],
                loadStatus: 'loadmore',
            };
        },
        onLoad() {
            this.loadList();
        },
        onShow() {
            let that = this
              
            uni.$off('scan') // 每次进来先 移除全局自定义事件监听器
            uni.$on('scan', function(data) {
             console.log('onscan');
             //扫码成功后的回调,你可以写自己的逻辑代码在这里
             console.log('扫码结果:', data.code);
                let sanCode=data.code
                let formatData = JSON.parse(sanCode.replace(/\n/g,"").replace(/\s*/g,''));
                // console.log('formatData:', formatData);
                // console.log('formatData.lot_batch_no:', formatData.workstation);
                
                if(formatData.workstation!=""||formatData.workstation!=undefined)
                {
                    that.findWorkstation(formatData.workstation)
                }
                        
            })
        },
        onNavigationBarButtonTap(e) {
            uni.scanCode({
                success: res => {
                    try {
                        const result = JSON.parse(res.result)
        
                    } catch (e) {}
                }
            });
        },
        methods: {
            findWorkstation(workstationNo){
                let queryParam={
                    current:1,
                    size:20,
                    workstationNo:workstationNo
                }
                this.$u.api.outputRegister.fetchWorkstationList(queryParam).then(res => {
                    if (!res.data.records || res.data.records.length == 0) {
                        this.$u.toast('未找到对应工作站');
                    }else{
                        this.selectWorkstation(res.data.records[0])
                    }
                });
            },
            loadMore() {
                this.loadStatus = "loading";
                setTimeout(() => {
                    this.query.current += 1;
                    this.loadList();
                }, 100);
            },
            loadList() {
                // 查询工作站列表
                this.$u.api.outputRegister.fetchWorkstationList(this.query).then(res => {
                    if (!res.data.records || res.data.records.length == 0) {
                        this.loadStatus = "nomore";
                        return;
                    }
                
                    this.workStationList = this.workStationList.concat(res.data.records);
                    this.total = res.data.total;
                    this.query.current = res.data.current;
                    this.query.size = res.data.size;
                    this.loadStatus = "loadmore";
                });
            },
            search(value) {
                this.workStationList = [];
                this.query.current = 1;
                this.query.workstationNo = value;
                this.loadList();
            },
            selectWorkstation(workstation) {
                this.refreshLastPage(workstation)
            },
 
            //刷新上一个页面
            refreshLastPage(workstation) {
                // 告知 A.vue 更新数据
                // 获取页面栈
                let pages = getCurrentPages()
 
                // 获取上一页栈
                let prevPage = pages[pages.length - 2]
 
                // 触发上一页 upData 函数(并携带参数)
                prevPage.$vm.setWorkstation(workstation)
 
                // 返回上一页
                uni.navigateBack({
                    delta: 1
                })
            }
        }
    };
</script>
<style lang="scss">
    .list .content {
        font-size: 12px;
        background-color: #efefef;
        box-sizing: border-box;
        border-radius: 14rpx;
        margin: 8px;
        padding: 5px 10px;
        box-shadow: none;
    }
</style>