<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="widtd=device-widtd, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" type="text/css" href="/static/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/css/css.css">
    <link rel="stylesheet" type="text/css" href="/static/css/iefilemaintain.css">
    <link rel="stylesheet" type="text/css" href="/static/css/bootstrap-select.min.css">
    <script src="/static/js/jquery.min.js"></script>
    <script src="/static/js/bootstrap.min.js"></script>
    <script src="/static/js/vue-2.4.0.js"></script>
    <script src="/static/js/axios.min.js"></script>
    <script src="/static/js/vue-Cookies.js"></script>
    <script type="text/javascript" src="/static/js/jquery.select.js"></script>

    <script src="/static/js/bootstrap-select_new.js"></script>
    <!-- 图标js -->
    <!-- <script src="/static/js/ionicons.js"></script> -->

    <title>Document</title>
</head>

<body>
    <div id="app">
        <div class="navbar navbar-default">
            <div class="container">
                <!-- navbar-header用于设置内容横向显示 -->
                <div class="navbar-header">
                    <a href="/index" class="navbar-brand"></a>
                </div>
                <!-- navbar-nav用来设置横向显示 -->
                <!-- navbar-right用来设置右浮动 -->
                <!-- hidden-xs用于当屏幕很小的情况下隐藏div里面的内容 -->
                <div class="hidden-xs">
                    <ul class="nav navbar-nav">
                        <li class="dropdown">
                            <!--订单一览表-->
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                订单一览表
                                <b class="caret"></b>
                            </a>
                            <ul class="nav dropdown-menu">
                                <li><a href="/index">订单一览表</a></li>
                            </ul>
                        </li>
                        <li class="dropdown">
                            <!--月度产能评估表-->
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                月度产能评估表
                                <b class="caret"></b>
                            </a>
                            <ul class="nav dropdown-menu">
                                <li><a href="/depps">月度产能评估表</a></li>
                                <li><a href="/dessettingtm">车间标准产能设置</a></li>
                            </ul>
                        </li>
                        <li class="dropdown">
                            <!--月度主排程计划-->
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                月度主排程计划
                                <b class="caret"></b>
                            </a>
                            <ul class="nav dropdown-menu">
                                <li><a href="/depps">计划主交期</a></li>
                                <li><a href="#">计划部门交期</a></li>
                            </ul>
                        </li>
                        <li class="dropdown">
                            <!--ie文件号管理-->
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                IE工艺文件号管理
                                <b class="caret"></b>
                            </a>
                            <ul class="nav dropdown-menu">
                                <li><a href="/iefiletm">新增IE工艺文件号</a></li>
                                <li><a href="/iefilemaintaintm">IE工艺文件号维护</a></li>
                                <li><a href="/iefilemaintaindetailtm">IE效率明细表</a></li>
                                <li><a href="/iefilemaintaininfotm">IE效率统计表</a></li>
                            </ul>
                        </li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li v-if="username !=''">
                            <a>{% verbatim %}{{ '欢迎'+username+'！！！' }} {% endverbatim %}</a>
                        </li>
                        <li v-else><a href="">请登录</a></li>
                        <li><a href="/login/" @click="logout()">退出登录</a></li>
                    </ul>
                </div>
            </div>
        </div>
        <!--表头-->
        <div class="filter">
            <div class="container ">
                <label>
                    <div class="navbar-nav">IE录入日期：</div>

                    <div class="navbar-nav"><input type='date' class="input form-control" v-model='data_timeqi' /></div>
                </label>
                <label>
                    <div class="navbar-nav">至：</div>
                    <div class="navbar-nav"><input type='date' class="input form-control" v-model='data_timezhi' />
                    </div>
                </label>
                <label>
                    <div class="navbar-nav">车间：</div>
                    <div class="navbar-nav">
                        <input class="input form-control" id="erp_dep" type="text" autocomplete="off" />
                    </div>
                </label>
                <label>
                    <div class="navbar-nav">缴库单号：</div>
                    <div class="navbar-nav">
                        <input class="input form-control" id="mf_mmo" type="text" autocomplete="off" />
                    </div>
                </label>
                <label>
                    <div class="navbar-nav">IE工艺文件号：</div>
                    <div class="navbar-nav">
                        <input class="input form-control" id="iefileno" type="text" autocomplete="off" />
                    </div>
                </label>
                <label class="save def" @click="seek()">
                    <div class="btn btn-primary navbar-nav">查询</div>
                </label>
                <label class="save def" @click="toiefile()">
                    <div class="btn btn-primary navbar-nav">新增</div>
                </label>
                <label class="save def" @click="delete_data()">
                    <div class="btn btn-primary navbar-nav">删除</div>
                </label>
                <label class="save def">
                    <div class="btn btn-primary navbar-nav" @click="save()">保存</div>
                </label>
                <label>
                    <div class="navbar-nav">更新日期范围：</div>

                    <div class="navbar-nav"><input type='date' class="input form-control" v-model='data_timeqi_mo' /></div>
                </label>
                <label>
                    <div class="navbar-nav">至：</div>
                    <div class="navbar-nav"><input type='date' class="input form-control" v-model='data_timezhi_mo' />
                    </div>
                </label>
                <label>
                    <div class="navbar-nav">指定缴库单号更新：</div>
                    <div class="navbar-nav">
                        <input class="input form-control" id="zdmf_mmo" type="text" autocomplete="off" />
                    </div>
                </label>
                <label class="save def">
                    <div class="btn btn-primary navbar-nav" @click="zdmf_mmoodd()">更新缴库IE工艺文件号</div>
                </label>
            </div>
        </div>
        <div class="container">
            <div style="background-color:#EFEDED; color: red;">
                注收到IE文件后录入更新文件。平衡率大于100%标注为蓝色；小于等于0%标注为绿色；等于100%标注为红色；大于0%小于90%标注为浅黄色</div>
            <table class="table table-hover">
                <tbody>
                    <tr v-for="(item,i) in seek_data" :key="i"
                        v-bind:class="{ 'tr_blue': item.scxphl > 1 ? true:false, 'tr_green': item.scxphl <=0 ? true:false, 'tr_red': item.scxphl == 1 ? true:false, 'tr_yellow': item.scxphl < 0.9 && item.scxphl >0 ? true:false }">
                        <td v-if="i>0"><input type="checkbox" v-model="item.choice" @click="selected(i,item)" /></td>
                        <td v-else><input type="checkbox" @click="selected(i,item,'all')" /><span>全选否</span></td>
                        <td v-if="i >0" v-text="i"></td>
                        <td v-else v-text="'行号'"></td>
                        <td v-text="item.bom_no"></td>
                        <td v-if="i>0">
                            <select class="input form-control" v-model="item.qiting">
                                <option value="T">T</option>
                                <option value="F">F</option>
                            </select>
                        </td>
                        <td v-else v-text="item.qiting"></td>
                        <td v-if="i >0 ">
                            <textarea rows="2" cols="10" v-model="item.qitingexplain"></textarea>
                        </td>
                        <td v-else v-text="item.qitingexplain"></td>
                        <td v-text="item.ae_date"></td>
                        <td v-text="item.hr_up"></td>
                        <td v-text="item.file_serial"></td>
                        <td v-text="item.workshop_name"></td>
                        <td v-text="item.dep_name"></td>
                        <td v-text="item.total_manpower"></td>
                        <td v-text="item.point"></td>
                        <td v-text="item.job_time"></td>
                        <td v-text="item.postil_up"></td>
                        <td v-text="item.rem"></td>
                        <td v-text="item.iefile_no"></td>
                        <td v-text="item.sys_date"></td>
                        <td v-text="item.user_no"></td>
                        <td v-text="item.bzsj"></td>
                        <td v-text="item.scxphl"></td>
                        <td v-text="item.scxbphl"></td>
                        <td v-text="item.scjp"></td>
                        <td v-text="item.xscn"></td>
                        <td v-text="item.rjcn"></td>
                        <td v-text="item.bxscn"></td>
                        <td v-text="item.djcb"></td>
                        <td v-text="item.bzzys"></td>
                    </tr>
                </tbody>
            </table>
        </div>

    </div>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                data_timeqi: '',  //查询时间起
                data_timezhi: '',  //查询时间止
                data_timeqi_mo:'',  //更新缴库单号开始日期
                data_timezhi_mo:'',  //更新缴库单号结束日期
                username: '',  //登录用户名
                seek_data: [],  //查询到的数据
                selected_data: [],  //选中的数据
                all_data: 0,   //用于处理全选
                isActiveblue: 0,
                isActivegreen: 0,
                isActivered: 0,
                isActiveyellow: 0
            },
            mounted() {
                // 获取登录名
                // this.username=getCookie('username');
                this.username = $cookies.get('username')
                console.log($cookies.get('username'))
            },
            methods: {
                // 查询
                seek() {
                    var erp_dep = $('#erp_dep').val().split("->")[0];
                    var mf_mmo = $('#mf_mmo').val().split("->")[0];
                    var iefileno = $('#iefileno').val().split("->")[0];

                    axios.get('/iefilemaintain/', {
                        params: {
                            erp_dep: erp_dep,
                            mf_mmo: mf_mmo,
                            iefileno: iefileno,
                            data_timeqi: this.data_timeqi,
                            data_timezhi: this.data_timezhi
                        }
                    }).then(res => {
                        var data = res.data.data
                        this.seek_data = data
                    }).catch(err => {
                        alert(err.response["data"] + err.response["status"])
                    })
                },
                // 选择按钮选择数据
                selected(i, item, enall) {
                    // 第一个参数表示项次，第二个参数表示选中的对象，第三个用于判断是否点击全选
                    // 这里是处理全选数据
                    if (enall == "all") {
                        if (this.all_data == 0) {
                            this.all_data = 1
                        }
                        else {
                            this.all_data = 0
                        }
                        //这里是处理了点击全选
                        if (this.all_data == 1) {
                            this.selected_data = []
                            this.selected_data = this.seek_data
                            for (i = 0; i < this.selected_data.length; i++) {
                                this.selected_data[i]["choice"]='T'
                            }
                            $("input:checkbox").prop("checked", "checked");
                        }
                        // 处理点击不全选
                        else {
                            this.selected_data = []
                            $("input:checkbox").removeAttr("checked");
                        }
                        console.log(this.selected_data)
                        console.log(this.all_data)
                        return
                    }
                    // 这里是处理单向选中数据
                    if (this.seek_data[i]["choice"]) {
                        this.selected_data.push(this.seek_data[i])
                    }
                    else {
                        var index = this.selected_data.findIndex(itemindex => {
                            if (itemindex == item) {
                                return true;
                            }
                        })
                        this.selected_data.splice(index, 1)
                    }
                    console.log(this.selected_data)
                },
                // 跳转到ie工艺文件新增界面
                toiefile() {
                    window.location.href = "/iefiletm";
                },
                // 设置启用状态
                save() {
                    if (this.selected_data.length <= 0) {
                        alert("请选择数据")
                        return
                    }
                    console.log("点击了保存")
                    axios.post('/iefilemaintain/', {
                        data: {
                            selected_data: this.selected_data
                        }
                    }).then(res => {
                        console.log("设置状态成功")
                    }).catch(err => {
                        alert(err.response["data"] + err.response["status"])
                    })

                },
                // 删除选中
                delete_data() {
                    if (this.selected_data.length <= 0) {
                        alert("请选择数据")
                        return
                    }
                    axios.delete('/iefilemaintain/', {
                        data: {
                            selected_data: this.selected_data
                        }
                    }).then(res => {
                        console.log("删除")
                    }).catch(err => {
                        alert(err.response["data"] + err.response["status"])
                    })
                },
                // 更新指定缴库单单号ie文件
                zdmf_mmoodd() {
                    if (this.selected_data.length <= 0) {
                        alert("请选择数据")
                        return
                    }
                    var mm_no = $('#zdmf_mmo').val()
                    if(mm_no.indexOf("->") != -1){
                        mm_no = mm_no.split("->")[0]
                    }
                    axios.put('/iefilemaintain/', {
                        data: {
                            mm_no: mm_no,
                            selected_data: this.selected_data,
                            data_timeqi_mo:this.data_timeqi_mo,
                            data_timezhi_mo:this.data_timezhi_mo
                        }
                    }).then(res => {
                        // console.log("更新成功")
                        alert("更新缴库单号成功")
                    }).catch(err => {
                        alert(err.response["data"] + err.response["status"])
                    })
                },
                //获取当前日期
                addDate() {
                    var date = new Date();
                    var seperator1 = "-";
                    var year = date.getFullYear();
                    var month = date.getMonth() + 1;
                    var strDate = date.getDate();
                    if (month >= 1 && month <= 9) {
                        month = "0" + month;
                    }
                    if (strDate >= 0 && strDate <= 9) {
                        strDate = "0" + strDate;
                    }
                    var currentdate = year + seperator1 + month + seperator1 + strDate;
                    // console.log(currentdate)
                    this.data_timeqi = this.data_timezhi = currentdate
                },
                //退出登录
                logout() {
                    console.log("qweq")
                    axios.delete('/login/', {
                        params: {
                            user_1: this.user_1,
                            pswd: this.pswd,
                        }
                    })
                        .then(res => {

                        })
                        .catch(err => {
                        })

                },

            },
            created() {
                this.addDate()
            }
        });

        $(function () {
            // 开始写 jQuery 代码...
            var timer = null;
            // 定义一个公用的搜索接口
            // console.log(vm.$data.list)
            function getStr(n, url, field, clickif) {
                //n为搜索的参数 url为请求的路由，filed是定位表单的id,
                //clickif用于判断是否是第一次加载，如果不是第一次加载则需要模拟点击

                var search = n
                // 配置路由
                if (typeof search === 'undefined') {
                    search = ''
                };
                // console.log(search)
                axios.get(url, {
                    params: {
                        search_no: search
                    }
                })
                    .then(res => {
                        // alert(res.data)
                        var data1 = res.data.data
                        datas = data1
                        // console.log(datas)
                        if (datas.length == 0) {
                            alert("没有搜索到数据")
                            return
                        }
                        $.selectSuggest(field, datas);
                        // 是否第一次进入
                        if (clickif !== 1) {
                            $("#" + field).trigger("click");
                        }
                    })
                    .catch(err => {
                        Console.log(err.response)
                        alert(err.response["data"] + err.response["status"])
                    })
            };

            //查询部门资料调用
            $("#erp_dep").bind("input propertychange", function (event) {
                var search = $("#erp_dep").val()
                // console.log($("#testInput").val())
                timer && clearTimeout(timer);
                timer = setTimeout(function () {
                    getStr(search, '/dept/', 'erp_dep');

                }, 1000);
            });
            getStr('', '/dept/', 'erp_dep', 1);
            // 查询缴库单号
            $("#mf_mmo").bind("input propertychange", function (event) {
                var search = $("#mf_mmo").val()
                // console.log($("#testInput").val())
                timer && clearTimeout(timer);
                timer = setTimeout(function () {
                    getStr(search, '/mfmmooddno/', 'mf_mmo');

                }, 1000);
            });
            getStr('', '/mfmmooddno/', 'mf_mmo', 1);
            // 查询指定缴库单号
            $("#zdmf_mmo").bind("input propertychange", function (event) {
                var search = $("#zdmf_mmo").val()
                // console.log($("#testInput").val())
                timer && clearTimeout(timer);
                timer = setTimeout(function () {
                    getStr(search, '/mfmmooddno/', 'zdmf_mmo');

                }, 1000);
            });
            getStr('', '/mfmmooddno/', 'zdmf_mmo', 1);
            // 查询ie文件号
            $("#iefileno").bind("input propertychange", function (event) {
                var search = $("#iefileno").val()
                // console.log($("#testInput").val())
                timer && clearTimeout(timer);
                timer = setTimeout(function () {
                    getStr(search, '/iefileno/', 'iefileno');

                }, 1000);
            });
            getStr('', '/iefileno/', 'iefileno', 1);
        });
    </script>
    <!-- <script type="text/javascript" src="/static/js/export/jquery-1.8.2.js"></script> -->

</body>

</html>