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

    
    // new select({
    //     el:"#sizeId",
    //     ajax:"sortattribute"
    // });

    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:"attributeId"},
        {display:"尺码属性名",name:"attributeName"},
        {display:"排序",name:"orderBy"},
        {display:"操作",name:'id',render:function(item){

            if (window.sortid == item.sortId)
              return '<a data-index="'+item.__index+'" href="javascript:void(0)" class="btn btn-success btn-xs delbtn">删除</a>';
        }}
        ]
    });

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

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


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

    $(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,attributeId:$("#sizeId").val(),orderBy:$("#orderBy").val()};
            if(!data.sortId){
                common.util.__tip("尺码不可为空","warning");
                return;
            }
            if(!~data.attributeId){
                common.util.__tip("尺码属性不可为空","warning");
                return;
            }
            if(!data.orderBy){
                common.util.__tip("排序不可为空","warning");
                return;
            }

            if (data.orderBy < 0) {
                common.util.__tip("排序不可为负数", "warning");
                return;
            }

            common.util.__ajax({
                url:'/erpproduct/sortattribute/ajax/add',
                data:data
            },function(){
                g.reload();
            });
        });
        new common.dropDown({
            el:"#sizeId",
            ajax:"sortattribute"
        });
    });