/**
 *
 * @author BOGON
 * @version 1.0
 */

var page = {
    submitFlag: 0,
    openPurchaseCategoryDialog: function () {
        let url = g.ctx + 'pc/sys/purchaseCategory/index?select=1';
        url= url + "&notInCodes=" + purchaseCategoryCodes
        var purchaseCategoryDialog = openDialog("purchaseCategoryDialog", url, {
            title: '采购品类选择器',
            width: '80%',
            height: '80%',
            cache: false,
            modal: true,
            border: false,
            draggable: true,
            shadow: false,
            onClose: function () {
                purchaseCategoryDialog.dialog('destroy');
            },
            buttons: [{
                text: itablei8n.save, handler: function () {
                    topWin.frames['purchaseCategoryDialog'].chooseRow(function (row) {
                        purchaseCategoryDialog.dialog('close');
                        $('input[textboxname="purchaseCategoryCode"]').textbox("setValue", row.firstLevelPurchaseCode)
                        $('input[textboxname="purchaseCategoryName"]').textbox("setValue", row.firstLevelPurchaseName)
                    });
                }
            }, {
                text: itablei8n.close, handler: function () {
                    purchaseCategoryDialog.dialog('close');
                }
            }]
        })
    },
    submit: function (call) {
        if (!$('#category').form("validate")) {
            return
        }
        if (page.submitFlag === 1) {
            return
        }
        page.submitFlag = 1
        var loadIndex = topWin.layer.load(1, {
            shade: [0.5, '#eee'] //0.1透明度的白色背景
        });
        let data = $('#category').serializeJson();
        data['supplierId'] = supplierId
        $.ajax({
            url: g.ctx + "pc/supplier/purchaseCategory/rest/saveOrUpdate",
            type: 'POST',
            contentType: "application/json",
            data: JSON.stringify(data),
            complete: function () {
                page.submitFlag = 0
                topWin.layer.close(loadIndex)
            },
            success: function () {
                topWin.layer.alert("操作成功", {
                    icon: 1,
                    closeBtn: 0,
                    yes: function (iindex) {
                        topWin.layer.close(iindex);
                        call();
                    }
                });
            },
            error: function (data) {
                topWin.layer.alert(data.responseJSON.message, {icon: 2});
            }
        });
    },
    paymentMethodChange: function (data) {
        let paymentMethod = $("#acceptanceMethod");
        let oldVal = paymentMethod.combobox("getValue")
        paymentMethod.combobox("clear")
        if (data.code === 'C') {
            $("#acceptanceMethod1").addClass("required")
        } else {
            $("#acceptanceMethod1").removeClass("required")
        }
        paymentMethod.combobox({required: data.code === 'C'})
        paymentMethod.combobox("readonly", !(data.code === 'C'))
    }
}
$(function () {
})