{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('selfAdd',[],'')}/mode/{$mode}" class="form-horizontal">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label">任务内容</label></br>
                            <textarea name="content" class="form-control" cols="30" rows="3"  id="value"></textarea>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="control-label">部门</label></br>
                            <input type="hidden" name="dep_id" id="dep">
                            <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-6">
                        <div class="form-group">
                            <label class="control-label">运送类型<span class="text-danger">*</span></label></br>
                            <input type="hidden" name="type" id="type">
                            <div style="padding-right: 10px">
                                <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">
                                    </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" value="{$user.addr_id==0?'':$user.addr_id}" name="start" id="start">
                            <div >
                                <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">优  &nbsp;先 &nbsp;级</label></br>
                            <input type="hidden" name="priority" id="priority">
                            <div style="padding-right: 10px">
                                <el-select v-model="priority" size="small" clearable style="width: 100%" placeholder="请选择">
                                    <el-option
                                            v-for="(item,index) in prioritys"
                                            :key="index"
                                            :label="item"
                                            :value="index.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">
                            <div >
                                <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">
                                    </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">
                            <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">
                                </el-option>
                            </el-select>
                        </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="xq_time" id="xqtime">
                            <div style="padding-right: 10px">
                                <el-date-picker
                                        style="width: 100%"
                                        size="small"
                                        v-model="xq_time"
                                        type="datetime"
                                        :editable="false"
                                        value-format="yyyy-MM-dd HH:mm"
                                        :clearable="true"
                                        placeholder="选择日期时间">
                                </el-date-picker>
                            </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="ywc_time" id="ywctime">
                            <el-date-picker
                                    style="width: 100%"
                                    size="small"
                                    v-model="ywc_time"
                                    type="datetime"
                                    :editable="false"
                                    value-format="yyyy-MM-dd HH:mm"
                                    :clearable="true"
                                    placeholder="选择日期时间">
                            </el-date-picker>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group">
                            <label class="control-label">联系人</label></br>
                            <div style="padding-right: 10px">
                                <input type="text" class="form-control" name="name">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group">
                            <label class="control-label">联系电话</label></br>
                            <input type="text" class="form-control" name="phone">
                        </div>
                    </div>
                    <div id="patient">
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="control-label">床号</label></br>
                                <div style="padding-right: 10px">

                                    <input type="text" class="form-control" name="bed_number">
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="control-label">姓名</label></br>
                                <div style="padding-right: 10px">
                                    <input type="text" class="form-control" name="p_name">
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="control-label">病案号</label></br>
                                <input type="text" class="form-control" name="ba_number">
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="control-label">性别</label></br>
                                <div style="padding-right: 10px">
                                    <select name="gender" class="form-control">
                                        <option value="0">未知</option>
                                        <option value="1">男</option>
                                        <option value="2">女</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="control-label">是否往返</label></br>
                                <select name="back" class="form-control">
                                    <option value="0">否</option>
                                    <option value="1">是</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="hr-line-dashed">
                        </div>
                    </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(){
        formSetValue("back", {$info.back|default=0});
    });
    $('#patient').hide();
    var vdevices = {:json_encode($order_device)};
    new Vue({
        el: '#formApp',
        data: function() {
            return {
                starts: {:json_encode($address)},
                start: "{$user.addr_id==0?'':$user.addr_id}",
                ends: {:json_encode($address)},
                end: '',
                types: {:json_encode($order_convey_type)},
                type: '',
                prioritys:{:json_encode($priority)},
                priority: '',
                devices: {:json_encode($order_device)},
                device: '',
                xq_time: '',
                ywc_time:'',
                dep: {:json_encode($dep_list)},
                dep_id: '{$dep_id}',
        }
        },
        watch: {
            type: function (newtype, oldtype) {
                $('#type').val(newtype);
                this.types.forEach((item) => {
                    if(item.id == newtype){
                    console.log(item);
                    this.end = item.ends > 0?parseInt(item.ends):'';
                    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();
                    }
                }
            });
            },
            start: function (newtype, oldtype) {
                $('#start').val(newtype);
            },
            end: function (newtype, oldtype) {
                $('#end').val(newtype);
            },
            priority: function (newtype, oldtype) {
                $('#priority').val(newtype);
            },
            device: function (newtype, oldtype) {
                $('#device').val(newtype);
            },
            xq_time: function (newtype, oldtype) {
                $('#xqtime').val(newtype);
            },
            ywc_time: function (newtype, oldtype) {
                $('#ywctime').val(newtype);
            },
            dep_id: function (newtype, oldtype) {
                $('#dep').val(newtype);
            }
        }
    })

    $('.cancel-btn').click(function () {
        parent.layer.closeAll();
    })
</script>
{/block}