<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/loader.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 type="text/javascript" src="/static/js/jquery.select.js"></script>

    <script src="/static/js/bootstrap-select_new.js"></script>


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

<body>
    <!-- <input id="testInput" type="text" /> -->
    <div id="app">
        <!-- navbar-default这个类是设置导航栏 -->
        <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>
                                <li><a href="#">已结案订单</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="#">汇总分析</a></li>
                                <li><a href="#">订单完成情况</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>
                    </ul>
                </div>
            </div>
        </div>
        <!--搜索-->
        <div class="filter">
            <div class="container ">
                <label>
                    <div class="navbar-nav">开始时间：</div>

                    <div class="navbar-nav"><input type='date' class="input form-control" v-model="st_time" /></div>
                </label>
                <label>
                    <div class="navbar-nav">结束时间：</div>
                    <div class="navbar-nav"><input type='date' class="input form-control" v-model="sh_time" /></div>
                </label>
                <label>
                    <div class="navbar-nav">品名：</div>
                    <div class="navbar-nav">
                        <input class="input form-control" id="testInput" type="text" v-model="prd_no"
                            autocomplete="off" />
                    </div>
                </label>
                <label>
                    <div class="navbar-nav">客户：</div>
                    <div class="navbar-nav">
                        <!-- <select class="selectpicker form-control" data-live-search="true"id="field"></select> -->
                        <input class="input form-control" id="testInput1" type="text" v-model="cust_cus_no"
                            autocomplete="off" />
                    </div>
                </label>
                <label>
                    <div class="navbar-nav">结案否：</div>
                    <div class="navbar-nav">
                        <select class="input form-control" v-model="cls_id">
                            <option value="1" selected="selected">全部</option>
                            <option value="2">结案</option>
                            <option value="3">未结案</option>
                        </select>
                    </div>
                </label>
                <label>
                    <div class="navbar-nav">是否回复：</div>
                    <div class="navbar-nav">
                        <select class="input form-control" v-model="pmc_ok">
                            <option value="1">全部</option>
                            <option value="2">已回复</option>
                            <option value="3">未回复</option>
                        </select>
                    </div>
                </label>
                <label>
                    <div class="navbar-nav">排序：</div>
                    <div class="navbar-nav">
                        <select class="input form-control" v-model="sort">
                            <option value="1">单号</option>
                            <option value="2">类别</option>
                            <option value="3">客户</option>
                            <option value="4">回复交期</option>
                        </select>
                    </div>
                </label>
                <label class="navbar-nav">
                    <button class="btn btn-primary" data-toggle="modal" data-target="#myModal">更多</button>
                    <div class="modal fade" id="myModal">
                        <div class="modal-dialog">
                            <div class="modal-content" style="width: 550px;">
                                <div class="modal-header">
                                    <div class="modal-title">选择条件</div>
                                </div>
                                <div class="modal-body">
                                    <table>
                                        <tr>
                                            <td><span class="navbar-nav  filtrate_w">业务交期：</span>
                                                <input type="date" class="navbar-nav filtrate" v-model="business_time">
                                            </td>
                                            <td><span class="navbar-nav  filtrate_w">合并否：</span>
                                                <select class="input form-control filtrate" v-model="ifmerge">
                                                    <option value="1">否</option>
                                                    <option value="2">是</option>
                                                </select></td>
                                        </tr>
                                        <tr>
                                            <td><span class="navbar-nav filtrate_w">订单类别：</span>
                                                <select class="input form-control filtrate" v-model="os_type">
                                                    <option value="1">全部</option>
                                                    <option value="2">订单</option>
                                                    <option value="3">返工单</option>
                                                </select>
                                            </td>
                                            <td><span class="navbar-nav filtrate_w">生产部门：</span>
                                                <select class="selectpicker form-control filtrate"
                                                    data-live-search="true" id="field1"></select></td>
                                        </tr>
                                        <tr>
                                            <td><span class="navbar-nav filtrate_w">容器：</span>
                                                <input type="text" class="navbar-nav filtrate" v-model="vessel"></td>
                                            <td><span class="navbar-nav filtrate_w">容量：</span>
                                                <input type="text" class="navbar-nav filtrate" v-model="capacity"></td>
                                        </tr>
                                    </table>
                                </div>
                                <div class="modal-footer">
                                    <button class="btn btn-primary" data-dismiss="modal">确定</button>
                                    <button class="btn btn-primary" data-dismiss="modal">取消</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </label>
                <!-- <label class="save" @click="seek()">确定查询</label> -->
                <label class="save def" id="def" @click="seek(1)">
                    <div class="btn btn-primary navbar-nav">确定查询</div>
                </label>
                <label class="save def">
                    <div class="btn btn-primary navbar-nav" @click="exportaa()">导出数据</div>
                </label>
            </div>
        </div>
        <!-- 内容 -->
        <!-- container这个类是设置居中对齐 -->
        <div class="container">
            <!-- row这个类是用于设置取消内边距 -->
            <table class="table table-bordered table-hover table-striped">
                <tbody>
                    <!-- <tr v-for="(item,i) in list" :key="item.OS_NO" style="background-color: yellowgreen;"> -->
                    <tr class="save" v-for="(item,i) in list" :key="item.OS_NO"
                        :class="i == activeIndex?'tr_active':''">
                        <td v-if="i >0" width="50px" v-text="i"></td>
                        <td v-else width="50px" v-text="'行号'"></td>
                        <td v-if="i >0" width="50px"><input type='text' class="input itm" v-model="item.ITM"
                                disabled="disabled" /></td>
                        <td v-else width="50px" v-text="item.ITM"></td>
                        <td width="50px" v-text="item.ORDER0"></td>
                        <td width="100px" v-text="item.OS_DD"></td>
                        <td width="100px" v-text="item.CUS_SNM"></td>
                        <td width="120px" v-text="item.OS_NO"></td>
                        <td width="120px" v-text="item.PRD_NO"></td>
                        <td width="100px" v-text="item.DZRL"></td>
                        <td width="80px" v-text="item.QY"></td>
                        <td width="90px" v-text="item.YSSL"></td>
                        <td width="90px" v-text="item.YMXH"></td>
                        <td width="90px" v-text="item.QTY"></td>
                        <td width="90px" v-text="item.GZSL"></td>
                        <td width="90px" v-text="item.EST_DD"></td>
                        <td width="90px" v-text="item.PD_DEP"></td>
                        <td width="90px" v-text="item.REM"></td>
                        <td v-if="i >0" width="120px"><input type='date' class="input" v-model="item.PMC_DD" /></td>
                        <td v-else width="120px" v-text="item.PMC_DD"></td>
                        <td v-if="i >0" width="110px">
                            <!-- <input type='text' class="input" style="width: 100px !important;"v-model="item.WH_REM" /> -->
                            <textarea rows="1" cols="10" v-model="item.WH_REM"></textarea>
                        </td>
                        <td v-else width="110px" v-text="item.WH_REM"></td>
                        <td v-if="i >0" width="50px"><input type='submit' class="save"
                                @click="ok_save(item.OS_NO,item.PMC_DD,item.WH_REM,item.ITM,i)" value="保存" /></td>
                        <td v-else width="50px" v-text="item.operation"></td>
                    </tr>
                </tbody>
            </table>

        </div>
        <div class="footer">
            <div class="load">
                <span></span>
                <span></span>
                <span></span>
                <span></span>
                <span></span>
                <span></span>
                <span></span>
                <span></span>
            </div>
        </div>
    </div>

    <script type="text/javascript" src="/static/js/export/exports.js"></script>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                st_time: '',
                sh_time: '',
                cus_no: '',
                cls_id: '1',
                pmc_ok: '1',
                activeIndex: 0,
                list: [],
                list_cust: [],
                list_dep: [],
                cust_cus_no: '',
                sort: '1',
                cust_cus_no_aa: '',
                page: 0,
                business_time: '',
                prd_no: '',
                sc_dep: '',
                sc_dep_aa: '',
                ym_type: '',
                os_type: '1',
                capacity: '',
                vessel: '',
                ifmerge: '1'
            },
            methods: {
                async seek(i) { // 添加的方法
                    // console.log('ok')
                    // 添加一个对象用于增加数据
                    // 获取货品
                    this.prd_no = $("#testInput").val()
                    console.log(this.prd_no)
                    // 获取客户
                    this.cust_cus_no = $("#testInput1").val()
                    console.log(this.cust_cus_no)

                    if ($("#field1").selectpicker('val') != '') {
                        this.sc_dep_aa = $("#field1").selectpicker('val')
                        this.sc_dep = $("#field1").selectpicker('val')
                    }

                    if ($("#field1").selectpicker('val') == '') {
                        this.sc_dep = this.sc_dep_aa
                    }
                    // 清空数据
                    this.list = ''
                    $(".footer").show();
                    // console.log($("#field").selectpicker('val'))
                    var seek = { st_time: this.st_time, sh_time: this.sh_time, cus_no: this.cust_cus_no, cls_id: this.cls_id, pmc_ok: this.pmc_ok, sort: this.sort }
                    //当第一次进入时设置客户编码值为空
                    // if (this.cust_cus_no == null) {
                    //     this.cust_cus_no = ''
                    // }
                    //当第一次进入时设置部门编码值为空
                    if (this.sc_dep == null) {
                        this.sc_dep = ''
                    }
                    console.log(this.prd_no)
                    axios.get('/listtb', {
                        params: {
                            st_time: this.st_time,   //订单开始时间
                            sh_time: this.sh_time,   //订单结束日期
                            cus_no: this.cust_cus_no,//客户编码
                            cls_id: this.cls_id,     //结案否
                            pmc_ok: this.pmc_ok,     //回复否
                            sort: this.sort,         //排序
                            business_time: this.business_time,//业务交期
                            prd_no: this.prd_no,        //产品编码
                            sc_dep: this.sc_dep,      //生产部门
                            ym_type: this.ym_type,    //研磨类型
                            os_type: this.os_type,    //订单类型
                            capacity: this.capacity,  //容量
                            vessel: this.vessel,      //容器
                            select: i,
                            ifmerge:this.ifmerge                //查询或者第一次进入状态标识
                        }
                    })
                        .then(res => {
                            // alert(res.data)
                            var data1 = res.data.data
                            this.list = data1
                            // this.list.push(data1)
                            console.log(this.list)
                            $(".footer").hide();
                            // $("table").attr("id","test_table")
                        })
                        .catch(err => {
                            console.log('error:' + err)
                        })
                },
                async ok_save(OS_NO, PMC_DD, WH_REM, ITM, i) {
                    // console.log('ok1')
                    // console.log(OS_NO, PMC_DD, WH_REM, ITM)
                    // this.activeIndex = i
                    var OS_NO = OS_NO
                    var PMC_DD = PMC_DD
                    var WH_REM = WH_REM
                    var ITM = ITM

                    axios.put('/listtb/', {
                        params: {
                            OS_NO: OS_NO,
                            PMC_DD: PMC_DD,
                            WH_REM: WH_REM,
                            ITM: ITM
                        }
                    })
                        .then(res => {
                            // alert(res.data)
                            var data1 = res.data.data
                        })
                        .catch(err => {
                            console.log('error:' + err)
                        })

                },
                // 修改list数据
                async uplist() {
                    // console.log('ok2')
                    axios.get('/listtb', {
                        params: {
                            st_time: '',
                            sh_time: '',
                            cus_no: '',
                            cls_id: '',
                            pmc_ok: '',
                            sort: ''
                        }
                    })
                        .then(res => {
                            // alert(res.data)
                            var data1 = res.data.data
                            // console.log(typeof(data1))
                            // console.log(typeof(list))

                            this.list = data1
                            $(".footer").hide();
                            // console.log(this.list)
                        })
                        .catch(err => {
                            console.log('error:' + err)
                        })
                },
                //获取当前日期
                async 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.st_time = this.sh_time = currentdate
                },
                async select_prd_no() {
                    console.log(1111)
                    $.selectSuggest('testInput', this.datas);
                },
                //获取客户资料
                async select_cust() {
                    axios.get('/cust/', {
                        // params: {
                        //     st_time: '',
                        //     sh_time: '',
                        //     cus_no: '',
                        //     cls_id: '',
                        //     pmc_ok: '',
                        // }
                    })
                        .then(res => {
                            // alert(res.data)
                            var data1 = res.data.data
                            this.list_cust = data1
                            // console.log(this.list_cust)
                            // 设置下拉搜索
                            var tempIdStr = '<option  value="">选择客户</option>';
                            // var tempIdStr = '<option  value="' + this.list[0]['DEP'] + '" v-bind:value="DEP_DEP">' + this.list[0]['DEP'] + '---' + this.list[0]['DEP'] + '</option>';
                            $("#field").append(tempIdStr);
                            $.each(this.list_cust, function (i, item) {
                                var tempId = '<option  value="' + item.CUS_NO + '" v-bind:value="cust_cus_no">' + item.CUS_NO + '---' + item.NAME + '</option>';
                                $("#field").append(tempId);
                                // alert(tempId)
                            });
                            // 更新 。 这一步很重要
                            $('#field').selectpicker('refresh');

                            //  $('#field').selectpicker('refresh');

                        })
                        .catch(err => {
                            console.log('error:' + err)
                        })
                },
                //获取部门资料
                async select_dep() {
                    axios.get('/dept/', {
                        // params: {
                        //     st_time: '',
                        //     sh_time: '',
                        //     cus_no: '',
                        //     cls_id: '',
                        //     pmc_ok: '',
                        // }
                    })
                        .then(res => {
                            // alert(res.data)
                            var data1 = res.data.data
                            this.list_dep = data1
                            // console.log(this.list)
                            // 设置下拉搜索
                            var tempIdStr = '<option  value="">选择部门</option>';
                            // var tempIdStr = '<option  value="' + this.list[0]['DEP'] + '" v-bind:value="DEP_DEP">' + this.list[0]['DEP'] + '---' + this.list[0]['DEP'] + '</option>';
                            $("#field1").append(tempIdStr);
                            $.each(this.list_dep, function (i, item) {
                                var tempId = '<option  value="' + item.DEP + '" v-bind:value="sc_dep">' + item.DEP + '---' + item.DEP_NAME + '</option>';
                                $("#field1").append(tempId);
                                // alert(tempId)
                            });
                            // 更新 。 这一步很重要
                            $('#field1').selectpicker('refresh');

                        })
                        .catch(err => {
                            console.log('error:' + err)
                        })
                },

                // 导出数据
                exportaa() {
                    console.log(this.list)
                    var filter = [];
                    var title = [];
                    exportExcel(this.list, '订单一览表数据', title, filter);
                }
            },

            created() {
                setTimeout(() => {
                    this.seek(2)
                }, 0)
                this.select_dep()
                this.addDate()
                // this.select_cust()
            }
        });

        $(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('error:' + err)
                    })
            };
            //查询货品资料调用
            $("#testInput").bind("input propertychange", function (event) {
                var search = $("#testInput").val()
                console.log($("#testInput").val())
                timer && clearTimeout(timer);
                timer = setTimeout(function () {
                    getStr(search, '/prdt/', 'testInput');

                }, 2000);
            });
            getStr('', '/prdt/', 'testInput', 1);
            //查询客户资料
            $("#testInput1").bind("input propertychange", function (event) {
                var search = $("#testInput1").val()
                console.log($("#testInput1").val())
                timer && clearTimeout(timer);
                timer = setTimeout(function () {
                    getStr(search, '/cust/', 'testInput1');

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

</body>

</html>