attr.js 2.74 KB
/*
 *@time: 2016/2/1
 *@author: chenglong
 */


var $ = require('jquery');
common = require('../common/common');

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

// 把Y、N转换成是、否
function convertNorY(val) {
    if (val === 'N') {
        return '否';
    } else {
        return '是';
    }
}


var tableGird = new common.grid({

    el: "#attr-table",
    parms: function () {

        console.log(window.sortid);

        return {
            categoryId: window.sortid
        };
    },
    columns: [
        {display: "属性名称", name: "attributeName"},
        {display: "属性类型", name: "attributeValues"},
        {display: "输入类型", name: "inputType"},
        {
            display: "是否必选",
            name: "isMust",
            render: function (item) {
                return convertNorY(item.isMust);
            }
        }, {
            display: "是否可搜索",
            name: "isSearch",
            render: function (item) {
                return convertNorY(item.isSearch);
            }
        }, {
            display: "操作",
            name: "categoryId",
            render: function (items) {

                return ('<button  data-index="' + items.__index + '" class="btn btn-success btn-xs edit-class-btn">编辑</button>');
            }
        }
    ]
});

sortmenu.init(function () {
    tableGird.init('/product/attr/queryProductAttributeList');
});

$('#add-attri').click(function () {

    attributeOp("添加", '/product/attr/add', {categoryId: window.sortid});

});


// 编辑产品属性
$(document).on('click', '.edit-class-btn', function () {
    var item = tableGird.rows[$(this).data('index')];
    attributeOp("修改", '/product/attr/update', item);
    // $("#select2-shopsId-container").val(item.)
});


function attributeOp(prefix, url, item) {

    var a = new common.edit(".confirm");
    common.dialog.confirm(prefix + "属性", common.util.__template($("#template").html(), item), function () {

        return a.submit(url, function (option) {
            option.data.categoryId = item.categoryId;
            option.data.attributeId = item.attributeId;
            option.success = function (res) {
                res = res.data;
                if (res.code == "200") {
                    a.$tip("提交成功", function () {
                        tableGird.reload();
                    }, 'growl-success');
                } else {
                    a.$tip(res.message);
                }
                return false;
            },
                option.error = function (res) {
                    a.$tip(res.message);
                }
        });

    });


    a.init();
}