index.js 5.31 KB
//内部变量
let variableObj = {
    progressBar: document.querySelector("#progressBar")
};

/*设置head标题  */
String.prototype.setHeadTitle = function (element, value) {
    document.querySelector(element).innerText = value;
};

/*load */
String.prototype.loadTips = function (isshow = false) {
    var txt = ";display:none;";
    if (isshow) {
        txt = ";display:block;";
    }
    variableObj.progressBar.style = txt;
};


(() => {
   var appVm = new Vue({
        el: '#bodyApp',
        data: {
            /* 物料,工序 */
            materia1: {},
            materia2: {},
            materia3: {},
            materia4: {},
            materia5_1: {},
            materia5_2: {},
            materia6: {},

            /* 工单 */
            pipeOrderList: {
                title: null,
                sumcount: 0,
                pipeOrderAll: null,
                pipeOrderfinished: null
            },

            /* 桁车任务 */
            girderVehicleList: {},

            /* 切割方案 */
            cutplan: {},
            cutplanTitle: {
                index: "序号",
                WONumber: "缓存位编码",
                wcsProductType: "材质",
                materialLength: "长度",
                thickness: "壁厚",
                flange1: "法兰1",
                flange2: "法兰2",
            },

            /* AGV信息 */
            avgList: {},

            /* 设备状态 */
            equipmentState: null,

            /* 页面公共配置数据 */
            sysData: {
                headTitle: "三一油管看板",
                // 华湘
                // url: "http://172.16.35.184:10001/api/HuaXiang/Mes/V1/Read",
               //  华湘
                // url: "http://192.168.0.235:10001/api/HuaXiang/Mes/V1/Read",
                // 本地
                url: "http://172.16.43.88:10001/api/HuaXiang/Mes/V1/Read",
            }
        },

        created: function () {
            /* 所有请求 */
            this.init();
        },

        methods: {
            /* 获取数据 */
            getData: function () {
                "".loadTips(true);
                var vm = this;
                fetch(this.sysData.url, {
                    method: 'GET',
                    mode: 'cors',
                }).then(res => res.json()).then(json => {
                    if (vm.getDataBefore(json)) return;

                    vm.materia1 = json.Result.materialList.material1[0];
                    vm.materia2 = json.Result.materialList.material2[0];
                    vm.materia3 = json.Result.materialList.material3[0];
                    vm.materia4 = json.Result.materialList.material4[0];
                    vm.materia5_1 = json.Result.materialList.material5[0];
                    vm.materia5_2 = json.Result.materialList.material5[1];
                    vm.materia6 = json.Result.materialList.material6[0];

                    vm.girderVehicleList = json.Result.girderVehicleList;
                    vm.equipmentState = json.Result.equipmentState;

                    vm.cutplan = json.Result.cutplanList;
                    vm.avgList = json.Result.avgList;
                 
                    vm.pipeOrderList.sumcount = json.Result.pipeOrderList.pipeOrderfinished.length == 0 ? 0 : json.Result.pipeOrderList.pipeOrderfinished[0].sumcount;
                    vm.pipeOrderList.pipeOrderfinished = json.Result.pipeOrderList.pipeOrderfinished;
                    vm.pipeOrderList.pipeOrderAll = json.Result.pipeOrderList.pipeOrderAll;

                    vm.cutplan = json.Result.cutplanList;
                    return json;
                }).catch(err => {
                    this.getDataCatch(err);
                });
            },

            /* 获取数据之前判断 */
            getDataBefore: function (json) {
                var result = false;
                console.log('获取的结果', json);
                "".loadTips();
                if (json.Code != 200 || !json.Status) {
                    alert(json.Message);
                    result = true;
                } 
                return result;
            },

            /* 获取数据异常处理 */
            getDataCatch: function (err) {
                "".loadTips();
                if (err == "TypeError: Failed to fetch") {
                    alert("app服务404,请检查服务是否开启!当前url"+" \n "+this.sysData.url);
                } else {
                    alert(err);
                }
                console.log('请求错误', err);
            },

            /* 设备状态查找 */
            getEquipmentState: function (value) {
                var isOk = true;
                for (var item in this.equipmentState) {
                    if (item == value) {
                        isOk = false;
                        return this.equipmentState[item]
                    }
                }
                if (!isOk) return "未知状态"
            },

            /* 入口 */
            init: function () {
                this.getData();
            }
        },

        mounted: function () {
            // 设置页面title属性值
            "".setHeadTitle("#headTitle", this.sysData.headTitle);

            this.pipeOrderList.title = `目前${new Date().getFullYear()}${new Date().getMonth() + 1}月自动生产总产量:`;
        }
    });
})();