/**
 *  view/delivery/appointment/appointment.ftl
 *  预约送货的供应商配置新增编辑
 */

let el = {
    id: '#id',
    form: '#form',
    status: "#status",
    warehouse:"#warehouse"
};

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

    $(el.warehouse).combobox({
        valueField: 'value',
        textField: 'label',
        data: [
            {label: '否', value: 0},
            {label: '是', value: 1}
        ],
        editable: false,
        panelHeight: 'auto',
    });
});

/**
 * 选择供应商数据
 */
function searchSupplier(){
    var userOrgyDialog = openDialog('userOrgyDialog', g.ctx + 'pc/supplier/supplierSelect?single=1', {
        title: "选择供应商",
        width: '650px',
        height: '80%',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            userOrgyDialog.dialog('destroy');
        },
        buttons: [
            {
                text: itablei8n.confirm,
                handler: function () {
                    topWin.frames['userOrgyDialog'].chooseRow(function (cbox) {console.log(cbox)
                        $('#supplierCode').textbox('setValue', cbox.supplierCode)
                        $('#supplierName').textbox('setValue', cbox.supplierName)
                        userOrgyDialog.dialog('close');
                    });
                }
            },
            {
                text: itablei8n.close,
                handler: function () {
                    userOrgyDialog.dialog('close');
                }
            }
        ]
    });
}


/**
 * 表单提交
 */
function submitForm(callback) {
    if ($(el.form).form('validate')) {
        let data = $(el.form).serializeJson();
        $.post(g.ctx+'pc/order/appointmentSupplier/rest/save', {data: JSON.stringify(data)}, function () {
            parent.layer.msg('保存成功');
            callback();
        }).error(function (data) {
            let msg = JSON.parse(data['responseText'])['message'];
            layer.msg('保存失败！ ' + msg);
        })
    }
}



