index.js 2.35 KB
/**
 * 创建供应商
 */
'use strict';
var $ = require('jquery'),
    common = require('../common/common');


var sortmenu = require('../common/sortmenu');



var g = new common.grid({
    el: "#basicTable",
    parms: function () {
        return {
            sortId: window.sortid ? window.sortid : "",
        };
    },
    columns: [
        //分类ID  分类名称    尺码ID    尺码名 排序  操作
        {display: "分类ID", name: "sortId"},
        {display: "分类名称", name: "sortName"},
        {display: "尺码ID", name: "sizeId"},
        {display: "尺码名", name: "sizeName"},
        {display: "排序", name: "orderBy"},
        {
            display: "操作", name: 'id', render: function (item) {
            return '<a data-index="' + item.__index + '" href="javascript:void(0)" class="btn btn-success btn-xs delbtn">删除</a>';
        }
        }
    ]
});


sortmenu.init(function () {
    g.init('/erpproduct/sortsize/ajax/index');
});


var _model = JSON.parse($("#model").val());

$(document).on("click", "#btn-add", function () {
    var _title = $(this).text();
    common.dialog.confirm(_title, common.util.__template($("#template").html(), {
        name: _model.name,
        sortname: window.sortname
    }), function () {
        var data = {sortId: window.sortid, sizeId: $("#sizeId").val(), orderBy: $("#orderBy").val()};
        if (!data.sortId) {
            common.util.__tip("尺码不可为空", "warning");
            return;
        }
        if (!~data.sizeId) {
            common.util.__tip("尺码属性不可为空", "warning");
            return;
        }
        if (!data.orderBy) {
            common.util.__tip("排序不可为空", "warning");
            return;
        }
        common.util.__ajax({
            url: '/erpproduct/sortsize/ajax/add',
            data: data
        }, function () {
            g.reload();
        });
    });
    new common.dropDown({
        el: "#sizeId",
        ajax: "sortsize"
    });
});

$(document).on("click", ".delbtn", function () {
    var item = g.rows[$(this).data("index")];
    common.dialog.confirm("温馨提示", "你确定要删除吗?", function () {
        common.util.__ajax({
            url: '/erpproduct/sortsize/ajax/delete',
            data: {sortId: item.sortId, sizeId: item.sizeId}
        }, function () {
            g.reload();
        });
    });
});