/**
 *  预约送货的供应商配置新增编辑
 */

let el = {
    id: '#id',
    form: '#form',
    status: "#status",
    dockerCode: "#dockerCode",
    dockerName: "#dockerName",
    factoryCode: "#factoryCode",
    factoryName: "#factoryName",
    week: "#week",
    viewType:"#viewType"
};

$(function () {
    $(el.status).combobox({
        valueField: 'value',
        textField: 'label',
        value: 1,
        data: [
            {label: '禁用', value: 0},
            {label: '启用', value: 1}
        ],
        editable: false,
        panelHeight: 'auto',
    });

    $(el.dockerCode).combogrid({
        panelWidth: 450,
        idField: 'dockerCode',
        textField: 'dockerCode',
        prompt: '-- 请选择 --',
        editable: false,
        url: g.ctx+'pc/order/appointmentDocker/rest/listAll',
        columns: [[
            {field: 'dockerCode', title: '卸货点编码', width: 60},
            {field: 'dockerName', title: '卸货点名称', width: 100},
            {field: 'factoryCode', title: '工厂编码', width: 100},
            {field: 'factoryName', title: '工厂名称', width: 200}
        ]],
        onSelect: function (value) {
            var g = $(el.dockerCode).combogrid('grid');
            var rows = g.datagrid('getRows');
            var r = rows[value];
            $(el.factoryName).val(r.factoryName);
            $(el.factoryCode).val(r.factoryCode);
            $(el.dockerName).val(r.dockerName);
        }
    });

    //获取字典数据
    initDict("week");

    $(el.week).combobox({
        valueField: 'code',
        textField: 'name',
        data: getDictList("week"),
        editable: false,
        panelHeight: 'auto',
    });

});

/**
 * 表单提交
 */
function submitForm(callback) {
    if ($(el.form).form('validate')) {
        let data = $(el.form).serializeJson();
        parent.layer.load(1);
        $.post(g.ctx+'pc/order/appointmentTime/rest/save', {data: JSON.stringify(data)},
            function (data) {
                parent.layer.msg("保存成功");
                callback();
            }).error(function (data) {
            layer.msg('保存失败！ ' + data.responseJSON.message);
        }).complete(function () {
            parent.layer.closeAll('loading');
        })
    }
}
