cdk
2 天以前 65e595c85e7ff31252c651f05949b711209f45ec
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
var vm = new Vue({
    el: '#app',
    data: function () {
        return {
            isLoading: false,
            XBar: '',     // 扫到的条码
            Weight: '',   // 显示的重量
            userInfo: { loginGuid: '', loginAccount: '' } // 如需传 userName
        }
    },
    mounted() {
        try {
            var info = this.GetLoginInfor();
            if (info) {
                this.userInfo.loginGuid = info.loginGuid || '';
                this.userInfo.loginAccount = info.loginAccount || '';
            }
            // 初始将焦点放到条码输入
            this.$nextTick(() => this.$refs.XBar && this.$refs.XBar.focus());
        } catch (e) {
            // ignore
        }
    },
    methods: {
        // 扫码后调用后端获取重量
        getWeight() {
            var that = this;
            if (!that.XBar || that.XBar.toString().trim().length === 0) {
                that.$playSound && that.$playSound('error');
                that.$toast && that.$toast.fail("条码不能为空");
                that.$refs.XBar && that.$refs.XBar.focus();
                return;
            }
 
            that.isLoading = true;
 
            that.AxiosHttp("post", 'Womdaa/GetWeightByXt_new', {
                LsBar: that.XBar,
                userName: that.userInfo.loginAccount || ''
            }, false)
                .then(function (res) {
                    var json = res;
                    if (json && json.status == 0) {
                        // 后端返回的重量字段(沿用现有代码习惯)
                        var weight = (json.data && json.data.tbBillList && json.data.tbBillList.weight) || '';
                        that.Weight = weight;
                        that.$playSound && that.$playSound('success');
                        that.$notify && that.$notify({ type: 'success', message: "称重成功" });
                    } else {
                        that.Weight = '';
                        that.$playSound && that.$playSound('error');
                        var msg = (json && json.message) ? json.message : "称重失败";
                        that.$dialog && that.$dialog.alert({ message: msg, theme: 'round-button' });
                    }
                    that.isLoading = false;
                    // 清空并聚焦准备下一个扫码
                    that.XBar = '';
                    that.$nextTick(() => that.$refs.XBar && that.$refs.XBar.focus());
                })
                .catch(function () {
                    that.isLoading = false;
                    that.Weight = '';
                    that.$playSound && that.$playSound('error');
                    that.$dialog && that.$dialog.alert({ message: "网络错误,请重试!", theme: 'round-button' });
                    that.XBar = '';
                    that.$nextTick(() => that.$refs.XBar && that.$refs.XBar.focus());
                });
        }
    }
});