meterSize.js 8.92 KB
/**
 * Created by ty on 2016/3/22.
 * 测量尺码管理
 */

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

new common.edit("#filter").init();

new common.dropDown({el: "#hasMeasure-filter"});
new common.dropDown({
    el: "#brand-filter", ajax: "brand", params: function () {
        return {status: 1};
    }
});

var tabTree = new common.tabTree("#category-filter", {
    columns: [{
        state: "prov",
        text: "一级分类",
        hide: false,
        addclass: ""
    }],
    datas: [{id: "", name: ""}]
});
tabTree.init();

var g = new common.grid({
    el: "#content-list",
    hash: false,
    parms: function () {
        return {
            productSkn: common.util.__input('skn-filter'),
            brandId: common.util.__input('brand-filter'),
            productSku: common.util.__input('sku-filter'),
            arriveStartTime: new Date(common.util.__input('startTime')).getTime() / 1000,
            arriveEndTime: new Date(common.util.__input('endTime')).getTime() / 1000,
            isMeasure: common.util.__input('hasMeasure-filter'),
            maxSortId: tabTree.getAddress()[0] ? tabTree.getAddress()[0].id : ""
        };
    },
    columns: [
        {display: "SKN", name: "productSkn"},
        {display: "名称", name: "productName"},
        {display: "品牌", name: "brandName"},
        {display: "分类", name: "productType"},
        {display: "性别", name: "genderName"},
        {
            display: "尺码",
            name: "sizeRelationsList",
            render: function (item) {
                return common.util.__template2($("#sizeinfo-template").html(), item);
            }
        },
        {
            display: "到货时间",
            name: "",
            render: function (item) {
                return Bll.getLocalTime(item.expectArrivalTime);
            }
        },
        {
            display: "操作", name: "", render: function (item) {
            console.log("item",item);
            var arr = [];
            arr.push('<a class="btn btn-info add2" data-index="' + item.__index + '">编辑</a>');
            return arr.join("");
        }
        }
    ]

});

g.init("/meterManage/productSize/queryProdSizeList");

var Bll = {
    getLocalTime: function (nS) {
        var date = new Date(parseInt(nS) * 1000);
        var mm = date.getMonth() + 1;
        var dd = date.getDate();
        var h = date.getHours();
        var min = date.getMinutes();
        var second = date.getSeconds();
        return date.getFullYear() + "-" + (mm < 10 ? "0" + mm : mm) + "-" + (dd < 10 ? "0" + dd : dd) + " " + (h < 10 ? "0" + h : h) + ":"
            + (min < 10 ? "0" + min : min) + ":" + (second < 10 ? "0" + second : second);
    },
    toast: function (url, item, hint) {
        var e = new common.edit("#nidaye");

        var dialog = new common.dialog({
            title: hint,
            content: '<div id="nidaye"><input type="hidden" id="noMeasureIds" for="checkbox">'
            + common.util.__template2($("#modifySize-template").html(), item)
            + '<div id="faGrid" style="height: 600px;overflow:auto;"></div></div>',
            width: "90%",
            button: [{
                value: "提交",
                css: 'btn-info',
                callback: function () {
                    var flag = false;
                    $("input[name='noMeasureIds']").not("input:checked").each(function () {
                        $("." + $(this).val()).each(function () {
                            if (!$(this).val()) {
                                flag = true;
                                return false;
                            }
                        });
                        if (flag) return false;
                    });
                    if (flag) {
                        util.__tip("请将没有勾选无需测量的列填写完整!", "warning");
                        return false;
                    }

                    var noMeasureIds = JSON.stringify($("#noMeasureIds").val() ? $("#noMeasureIds").val().split("|") : []);//无需测量的列
                    //尺码信息列表
                    var sizeInfoList = [];
                    for (var i = 0; i < $(".sizeInfo").length; i++) {
                        var info = $($(".sizeInfo")[i]);//当前尺码input对象
                        var prdList = grid.rows[info.data("index")].prdSizeAttributeBoList;//当前列的对象的尺码列表
                        var attrIndex = parseInt(i % prdList.length);//在当前列的索引
                        sizeInfoList[i] = ({
                            productSkn: item.productSkn,
                            sizeId: grid.rows[info.data("index")].sizeId,
                            sizeAttributeId: prdList[attrIndex].sizeAttributeId,
                            sizeValue: info.val()
                        });
                    }
                    //商品参考尺码
                    var productSizeReferList = [];
                    for (var i = 0; i < $(".refInfo").length/2; i++) {
                        var ref1 = $($(".refInfo1")[i]);
                        var ref2 = $($(".refInfo2")[i]);
                        productSizeReferList.push({
                            sizeId: grid.rows[ref1.data("index")].sizeId,
                            gender: item.gender,
                            referenceName: ref1.val()+'/'+ref2.val()
                        });
                        console.log("productSizeReferList",productSizeReferList);
                    }
                    common.util.__ajax({
                        url: url,
                        data: {
                            productSkn: item.productSkn,
                            noMeasureIds: noMeasureIds,
                            sizeInfoList: JSON.stringify(sizeInfoList),
                            productSizeReferList: JSON.stringify(productSizeReferList)
                        }
                    }, function (res) {
                        if (res.code == '200') {
                            g.reload();
                            dialog.close();
                        }
                        else {
                            util.__tip(res.data.message, "warning");
                        }

                    });
                }
            },

                {
                    value: "取消",
                    css: 'btn-primary'
                }]
        });
        var headList = [];
        var j = 0;//创造一个变量以供赋值
        if (item.sizeRelationsList.length > 0) {
            headList.push({display: "尺码", name: "sizeName"});//尺码
            headList.push({
                display: "参考尺码(" + item.genderName + ")", name: "referenceName", render: function (item) {//参考尺码列
                    var refName = item.referenceName ? item.referenceName : "";//非空判断
                    var a =refName.split(/[,|/]/g);
                    var refName1=a[0]||"",refName2=a[1]||"";
                    console.log("refName",item);
                    return '<input class="col-sm-2 refInfo refInfo1" data-index="' + item.__index + '"' + 'value="' + refName1 + '"/>'+'<div class="col-sm-1">'+'/</div>'+'<input class="col-sm-2 refInfo refInfo2" data-index="' + item.__index + '"' + 'value="' + refName2 + '"/>';
                }
            });
            for (var i = 0; i < item.sizeRelationsList[0].prdSizeAttributeBoList.length; i++) {//尺码列
                var sizeAttributes = item.sizeRelationsList[0].prdSizeAttributeBoList[i];//参考尺码数组里的数据
                var chkbox = '<label style="cursor: pointer;"><input type="checkbox" name="noMeasureIds" value="' + sizeAttributes.sizeAttributeId + '"/>无需测量</label>';
                headList.push({
                    display: sizeAttributes.sizeAttributeName + "<br>" + chkbox,
                    name: "sizeValue",
                    render: function (item) {
                        var prdList = item.prdSizeAttributeBoList;
                        if (j == prdList.length) j = 0;//防止越界
                        var sizeVal = prdList[j].sizeValue ? prdList[j].sizeValue : "";
                        //j++;//
                        return '<input class="form-control sizeInfo ' + prdList[j++].sizeAttributeId
                            + '" data-index="' + item.__index + '"' + 'value="' + sizeVal + '"/>';
                    }
                });
            }
        }

        var grid = new common.grid({
            el: "#faGrid",
            hash: false,
            columns: headList
        });
        grid.init(item.sizeRelationsList);
        $("#noMeasureIds").val(item.noMeasureIds ? item.noMeasureIds.join("|") : "");
        e.init();
    }
};

$(document).on('click', '#filter-btn', function () {
    g.reload(1);
});

$(document).on('click', '.add2', function () {
    var item = g.rows[$(this).data("index")];
    Bll.toast("/meterManage/productSize/saveProdSizeInfo", item, "修改尺码");
});