netsale-ty.js 11.1 KB
var $ = require('jquery'),
    common = require('../../common/common'),
    util = require('../../common/util');

if (window.NETSALEDATA) {

    { //搜索关键词
        var searchKeys = "";
        if (window.NETSALEDATA.productExtBo) {
            searchKeys = window.NETSALEDATA.productExtBo.searchKeys || "";
        }

        $("#searchKeys").val(searchKeys);
        var g = new common.grid({
            el: "#search-key",
            hash: false,
            columns: [{
                display: "ID",
                name: "id"
            }, {
                display: "内容",
                name: "content"
            }, {
                display: "操作",
                name: "",
                render: function (item) {
                    return '<a class="btn btn-info add" data-index="' + item.__index + '">添加</a>';
                }
            }]
        });

        g.init('/netSale/queryHotSearchTerms');

        $("#searchKeys").on('change', function () {
            searchKeys = $("#searchKeys").val();
        });

        $(document).on('click', '.add', function () {
            var item = g.rows[$(this).data("index")];
            var value = $("#searchKeys").val();
            if (value.indexOf(item.content) == -1) {
                if (value) value += ",";
                $("#searchKeys").val(value + item.content);
                searchKeys = $("#searchKeys").val();
            } else {
                util.__tip("商品关键词不能重复");
            }
        });

        $("#save-searchKey").on('click', function () {
            common.util.__ajax({
                url: '/product/saveNetSaleSearchKeys',
                data: {
                    productSkn: window.NETSALEDATA.baseProductInfo.baseProduct.productSkn,
                    searchKeys: searchKeys
                }
            });
            return false;
        });

        window.GOLABDATA.on('TYsearchKey', function () {
            var washTips = $("#washTips").val() || "";
            var productMaterial = $("#material").val() || "";
            return {
                "searchKeys": searchKeys
            };
        });

    }

    { //尺寸信息
        var productSkn = window.NETSALEDATA.baseProductInfo.baseProduct.productSkn;
        var dataList;
        if (productSkn) {
            common.util.__ajax({
                url: '/meterManage/productSize/queryProdSizeList',
                data: {
                    productSkn: productSkn
                }
            }, function (res) {
                if (res.data.list && res.data.list.length > 0) {
                    var e = new common.edit("#add-list");
                    dataList = res.data.list[0];
                    //拼接分类字符串
                    var a = dataList.productType.replace(/<br>/g, "/");
                    dataList.productType = a.substring(0, a.length - 1);
                    var headList = [];
                    var j = 0;//创造一个变量以供赋值
                    if (dataList.sizeRelationsList.length > 0) {
                        headList.push({display: "尺码", name: "sizeName"});//尺码
                        headList.push({
                            display: "参考尺码(" + dataList.genderName + ")",
                            name: "referenceName",
                            render: function (item1) {//参考尺码列
                                var refName = item1.referenceName ? item1.referenceName : "";//非空判断
                                var a = refName.split(/[|/]/g);
                                var refName1 = a[0] || "", refName2 = a[1] || "";
                                return '<div class="form-group"><div class="col-sm-3"><input class=" form-control" data-index="' + item1.__index + '"' + 'value="' + refName1 + '"/></div>' + '<div class="col-sm-1">' + '/</div>' + '<div class="col-sm-3"><input class=" form-control" data-index="' + item1.__index + '"' + 'value="' + refName2 + '"/></div></div>';
                            }
                        });
                        for (var i = 0; i < dataList.sizeRelationsList[0].prdSizeAttributeBoList.length; i++) {//尺码列
                            var sizeAttributes = dataList.sizeRelationsList[0].prdSizeAttributeBoList[i];//参考尺码数组里的数据
                            var chkbox = '<label style="cursor: pointer;"><input type="checkbox" name="noMeasureIds" data-index="' + i + '" value="' + sizeAttributes.sizeAttributeId + '"/>无需测量</label>';
                            headList.push({
                                display: sizeAttributes.sizeAttributeName + "<br>" + chkbox,
                                name: "sizeValue",
                                render: function (item1) {
                                    var prdList = item1.prdSizeAttributeBoList;
                                    if (j >= prdList.length) j = 0;//防止越界
                                    var sizeVal = prdList[j].sizeValue ? prdList[j].sizeValue : "";
                                    return '<div class="form-group"><input class="form-control sizeInfo ' + prdList[j++].sizeAttributeId
                                        + '" data-index="' + item1.__index + '"' + 'value="' + sizeVal + '"/><div>';
                                }
                            });
                        }
                    }
                    var grid = new common.grid({
                        el: "#content-list",
                        hash: false,
                        columns: headList
                    });
                    grid.init(dataList.sizeRelationsList);
                    $("#noMeasureIds").val(dataList.noMeasureIds ? dataList.noMeasureIds.join("|") : "");
                    e.init();
                    $(document).on('click', '#add-saveBtn', function () {
                        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 = dataList.sizeRelationsList[info.data("index")].prdSizeAttributeBoList;//当前列的对象的尺码列表
                            var attrIndex = parseInt(i % prdList.length);//在当前列的索引
                            sizeInfoList[i] = ({
                                productSkn: dataList.productSkn,
                                sizeId: dataList.sizeRelationsList[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: dataList.sizeRelationsList[ref1.data("index")].sizeId,
                                gender: dataList.gender,
                                referenceName: ref1.val() + '/' + ref2.val()
                            });
                        }
                        var data = {
                            productSkn: dataList.productSkn,
                            noMeasureIds: noMeasureIds,
                            sizeInfoList: JSON.stringify(sizeInfoList),
                            productSizeReferList: JSON.stringify(productSizeReferList)
                        };
                        common.util.__ajax({
                            url: "/meterManage/productSize/saveProdSizeInfo",
                            data: data
                        }, function () {
                        });
                        return false;
                    });
                }
            },true);
        }
    }
    { //搜索优先级
        var searchSortList = [];
        if (window.NETSALEDATA.searchSortList) {
            searchSortList = window.NETSALEDATA.searchSortList;
        }

        for (var i = 0; i < searchSortList.length; i++) {
            if (searchSortList[i].modelId == 1)
                $("#sort0").val(searchSortList[i].intValue);
            else if (searchSortList[i].modelId == 2)
                $("#sort1").val(searchSortList[i].intValue);
            else if (searchSortList[i].modelId == 3)
                $("#sort2").val(searchSortList[i].intValue);
        }

        var item = [];
        for (var i = 0; i < 3; i++) {
            item[i] = {
                productSkn: window.NETSALEDATA.baseProductInfo.baseProduct.productSkn,
                modelId: i + 1,
                projectId: 1,
                intValue: parseInt($("#sort" + i).val())
            };
        }

        for (var i = 0; i < 3; i++) {
            for (var j = 0; j < searchSortList.length; j++) {
                if (searchSortList[j].modelId == item[i].modelId) {
                    item[i].id = searchSortList[j].id;
                    break;
                }
            }
        }

        searchSortList = item;

        $('#sort-save').on('click', function () {
            common.util.__ajax({
                url: '/netSale/saveSearchSort',
                data: {
                    searchSortList: JSON.stringify(searchSortList)
                }
            });
            return false;
        });

        $("#sort0").on('change', function () {
            searchSortList[0].intValue = parseInt($("#sort0").val());
        });

        $("#sort1").on('change', function () {
            searchSortList[1].intValue = parseInt($("#sort1").val());
        });

        $("#sort2").on('change', function () {
            searchSortList[2].intValue = parseInt($("#sort2").val());
        });

        $("#sort0").keyup(function () {
            $(this).val($(this).val().replace(/\D/g, ""));
        });
        $("#sort1").keyup(function () {
            $(this).val($(this).val().replace(/\D/g, ""));
        });
        $("#sort2").keyup(function () {
            $(this).val($(this).val().replace(/\D/g, ""));
        });

        window.GOLABDATA.on('TYsearchSort', function () {
            if (!searchSortList[0] || !searchSortList[1] || !searchSortList[2])
                return "请将搜索排序填写完整!";
            return {
                "searchSortList": JSON.stringify(searchSortList)
            };
        });
    }
}

//当点击“无需测量”,该列输入框不可编辑
$(document).on("change", "input[name='noMeasureIds']", function () {
    var _index = $(this).data("index");
    var tbody = $(this).parents('table').children('tbody');
    if ($(this).is(':checked')) {
        tbody.children('tr').each(function () {
            $(this).find('td').eq(_index + 2).children().attr("readonly", true);
        });
    }
    else {
        tbody.children('tr').each(function () {
            $(this).find('td').eq(_index + 2).children().attr("readonly", false);
        });
    }
});