{extend name="common/common2" /}
{block name="main"}
<div class="row" id="formApp">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-content">
                <form method="post" action="{:url('add')}" class="form-horizontal">
                    <input type="hidden" name="id" value="{$info['id']|default='0'}">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label">部门</label></br>
                            <input type="hidden" name="dep_id" id="dep" value="{$info?$info['dep_id']:''}">
                            <el-select v-model="dep_id" size="small" clearable style="width: 100%" filterable placeholder="请选择">
                                <el-option
                                        v-for="item in dep"
                                        :key="item.id"
                                        :label="item.title"
                                        :value="item.id.toString()">
                                </el-option>
                            </el-select>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group" id="type2">
                            <label class="control-label">执行人<span class="text-danger">*</span></label></br>
                            <input type="hidden" name="to_user_ids" id="user_id" value="{$info?$info['to_user_ids']:''}">
                            <el-select v-model="user_id" filterable clearable placeholder="请选择" size="small"
                                       style="width:100%">
                                <el-option-group
                                        v-for="group in user"
                                        :key="group.id"
                                        :label="group.name">
                                    <el-option
                                            v-for="item in group.user"
                                            :key="item.id"
                                            :label="item.real_name"
                                            :value="item.id.toString()">
                                    </el-option>
                                </el-option-group>
                            </el-select>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label">运送类型<span class="text-danger">*</span></label></br>
                            <div class="rr">

                                <input type="hidden" name="type" id="type" value="{$info?$info['type']:''}">
                                <div>
                                    <el-select v-model="type" size="small" clearable  style="width: 100%" filterable placeholder="请选择">
                                        <el-option
                                                v-for="item in types"
                                                :key="item.id"
                                                :label="item.title"
                                                :value="item.id.toString()">
                                        </el-option>
                                    </el-select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label">优  &nbsp;先 &nbsp;级</label></br>
                            <input type="hidden" name="priority" id="priority">
                            <div style="padding-right: 10px">
                                <el-radio v-model="priority" label="2">常规</el-radio>
                                <el-radio v-model="priority" label="3">紧急</el-radio>
                            </div>

                        </div>
                    </div>

                    <div id="patient">
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="control-label">床号</label></br>
                                <div class="rr">
                                    <input type="text" class="form-control" name="bed_number" value="{$info?$info['bed_number']:''}">
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="control-label">姓名</label></br>
                                <div class="rr">
                                    <input type="text" class="form-control" name="name" value="{$info?$info['name']:''}">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-sm-6">
                        <div class="form-group" >
                            <label class="control-label">开始地点<span class="text-danger">*</span></label></br>
                            <input type="hidden"  value="" name="start" id="start" value="{$info?$info['start']:''}">
                            <div class="rr">
                                <el-select v-model="start" size="small" clearable style="width: 100%" filterable placeholder="请选择">
                                    <el-option
                                            v-for="item in starts"
                                            :key="item.id"
                                            :label="item.title"
                                            :value="item.id.toString()">
                                    </el-option>
                                </el-select>
                            </div>

                        </div>
                    </div>


                    <div class="col-sm-6">
                        <div class="form-group">
                            <label class="control-label">结束地点<span class="text-danger">*</span></label></br>
                            <input type="hidden" name="end" id="end" value="{$info?$info['end']:''}">
                            <el-select v-model="end" size="small" clearable style="width: 100%" filterable placeholder="请选择">
                                <el-option
                                        v-for="item in ends"
                                        :key="item.id"
                                        :label="item.title"
                                        :value="item.id.toString()">
                                </el-option>
                            </el-select>
                        </div>
                    </div>

                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label">途径地点</label></br>
                            <div style="padding-right: 10px">
                                <input type="hidden" name="tjaddrs" id="way_addr" value="{$info?$info['tjaddrs']:''}">
                                <el-select v-model="way_addr" size="small" collapse-tags style="width: 100%" multiple placeholder="请选择">
                                    <el-option
                                            v-for="item in way_addrs"
                                            :key="item.id"
                                            :label="item.title"
                                            :value="item.id.toString()">
                                    </el-option>
                                </el-select>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label">运送设备</label></br>
                            <input type="hidden" name="device_id" id="device" value="{$info?$info['device_id']:''}">
                            <el-select v-model="device" size="small" style="width: 100%" clearable filterable placeholder="请选择">
                                <el-option
                                        v-for="item in devices"
                                        :key="item.id"
                                        :label="item.title"
                                        :value="item.id.toString()">
                                </el-option>
                            </el-select>
                        </div>
                    </div>

                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label">需求时间<span class="text-danger">*</span></label></br>
                            <input type="hidden" name="xq_time" id="xqtime2" value="{$info?$info['xq_time']:''}">
                            <div class="rr">
                                <el-time-picker
                                        style="width: 100%"
                                        size="small"
                                        v-model="xq_time"
                                        type="time"
                                        :editable="false"
                                        value-format="HH:mm"
                                        :clearable="true"
                                        @change="xqDateChange"
                                        placeholder="选择日期时间">
                                </el-time-picker>
                            </div>
                        </div>
                    </div>

                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label">选择日期</label><span class="text-danger">*</span></br>
                            <input type="hidden" name="week" id="week" value="{$info?$info['week']:''}">
                            <el-select v-model="week" size="small" style="width: 100%" clearable filterable placeholder="请选择">
                                <el-option
                                        v-for="item in weeks"
                                        :key="item.id"
                                        :label="item.title"
                                        :value="item.id.toString()">
                                </el-option>
                            </el-select>
                        </div>
                    </div>

                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label">派单备注</label></br>
                            <textarea name="todo_content" class="form-control" cols="30" rows="3" >{$info?$info['todo_content']:''}</textarea>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label">任务备注</label></br>
                            <input type="text"  class="form-control" name="content" value="{$info?$info['content']:''}">

                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-6 col-sm-offset-2">
                            <button class="btn btn-primary ajax-post" data-layer="1" target-form="form-horizontal" type="submit">确 定</button>
                            <button  class="btn cancel-btn btn-default" type="button">取 消</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
    $(document).ready(function(){

    });


    var vdevices = {:json_encode($order_device)};
    new Vue({
        el: '#formApp',
        data: function() {
            return {
                starts: [],
                start: '',
                ends: [],
                end: '{$info?$info["end"]:""}',
                week:'{$info?$info["week"]:""}',
                weeks:[{"id":0,"title":"周日"},{"id":1,"title":"周一"},{"id":2,"title":"周二"},{"id":3,"title":"周三"},{"id":4,"title":"周四"},{"id":5,"title":"周五"},{"id":6,"title":"周六"}],
                way_addrs: {:json_encode($address)},
            way_addr:'',
                types: {:json_encode($order_convey_type)},
            type:  '',
                prioritys:{:json_encode($priority)},
            priority: '',
                devices: {:json_encode($order_device)},
            device: '{$info?$info["device_id"]:""}',
                xq_time: '{$info?$info["xq_time"]:""}',
                ywc_time:'',
                dep: {:json_encode($dep_list)},
            dep_id: '{$info?$info["dep_id"]:""}',
                user: {:json_encode($user_list)},
            user_id: '{$info?$info["to_user_ids"]:""}',
                to_roles: [],
            to_roles_id: '',
                roles_id:''

        }
        },
        watch: {
            type: function (newtype, oldtype) {
                var that  = this;
                $.post('{:url("getAddr")}',{id:newtype},function (res){
                    that.starts = res.data.s;
                    that.ends = res.data.e;
                },'json')
                $('#type').val(newtype);
                this.types.forEach((item) => {
                    if(item.id == newtype){
                        console.log(item);
                        // this.end = item.ends > 0?parseInt(item.ends):'';
                        if(item.starts >0){
                            this.start = parseInt(item.starts).toString();
                        }else {
                            if(item.startList.length ==0){

                            }
                        }
                        if(item.ends >0){
                            this.end = parseInt(item.ends).toString();
                        }else {
                            if(item.endList.length ==0){

                            }
                        }
                        // this.xq_time = item.xq_time?item.xq_time:'';
                        // this.ywc_time = item.ywc_time?item.ywc_time:'';
                        this.priority = item.priority > 0?item.priority.toString():'';
                        if(item.cate == 1){
                            let devices = [];
                            vdevices.forEach((item) => {
                                if(item.patient == 1){
                                    devices.push(item);
                                }
                            });
                            this.devices = devices;
                            $('#patient').show();
                        }else{
                            this.devices = vdevices;
                            $('#patient').hide();
                        }

                        $("#yy").css('display','block')
                        // if(item.cate==4){
                        //     $("#yy").css('display','block')
                        // }else {
                        //     $("#yy").css('display','none')
                        //
                        // }
                    }
                });
            },
            start: function (newtype, oldtype) {
                $('#start').val(newtype);
            },
            end: function (newtype, oldtype) {
                $('#end').val(newtype);
            },
            week: function (newtype, oldtype) {
                $('#week').val(newtype);
            },
            way_addr: function (newtype, oldtype) {
                console.log('way_addr',newtype);
                $('#way_addr').val(newtype.join(','));
            },
            priority: function (newtype, oldtype) {
                $('#priority').val(newtype);
            },
            device: function (newtype, oldtype) {
                $('#device').val(newtype);
            },
            xq_time: function (newtype, oldtype) {
                // var that = this;
                // $.post("{:url('getTime')}",{type:this.type,'start':newtype},function (res){
                //     if(res.code == 1){
                //         that.xq_time = res.data.xq_time;
                //         that.ywc_time = res.data.ywc_time;
                //     }
                //
                // })
                $('#xqtime2').val(newtype);
            },
            ywc_time: function (newtype, oldtype) {
                $('#ywctime').val(newtype);
            },
            dep_id: function (newtype, oldtype) {
                $('#dep').val(newtype);
            },
            user_id: function (newtype, oldtype) {
                console.log("user_id",newtype);
                // $('#user_id').val(newtype.join(','));
                $('#user_id').val(newtype);
            },
            roles_id: function (newtype, oldtype) {
                $('#to_roles_id').val(newtype);
            },
        },
        created(){
            let t = '{$info?$info["type"]:""}';
            if(t){
                this.type = t;
            }

            let way = '{$info?$info["tjaddrs"]:""}';
            if(way){
                this.way_addr = way.split(",");
            }

            let s = '{$info?$info["start"]:""}';
            if(s){
                this.start = s;
            }

            let e = '{$info?$info["end"]:""}';
            if(e){
                this.end = e;
            }

            let pp = '{$info?$info["priority"]:""}';
            if(pp){
                this.priority = pp;
            }
        },
        methods: {
            xqDateChange(e){
                var that = this;
                // $.post("{:url('getTime')}",{type:this.type,'start':e},function (res){
                //     if(res.code == 1){
                //         that.xq_time = res.data.xq_time;
                //         that.ywc_time = res.data.ywc_time;
                //     }
                //
                // })
                // $('#xqtime').val(e);
            }
        }

    })

</script>
{/block}