tryInfo.js 6.06 KB

/**
 * Created by JiangMin on 2016/3/22.
 * 试穿信息管理
 */
var $ = require('jquery');
var common = require('../common/common');
/**
 * 列表显示数据
 * @type {common.grid}
 */
var g = new common.grid({
    el: '#content-list',
    hash: false,
    //查询参数
    parms: function () {
        return {
            productSku: common.util.__input('content-filter1'),
            productSkn: common.util.__input('content-filter2'),
            productName: common.util.__input('content-filter3')
        };
    },
    //列表显示
    columns: [
        {
            display: "图片", name: "defaultImg", render: function (item) {
            return '<img src="' + item.defaultImg + '?imageView/2/w/100/h/100" width="100" height="60"/>'
        }
        },//图片显示
        {display: "skn", name: "productSkn"},
        {display: "产品名称", name: "productName"},
        {display: "品牌", name: "brandName"},
        {
            display: "操作", name: "", render: function (item) {
            var arr = [];
            arr.push('<a class="btn btn-info info" data-index="' + item.__index + '">详情</a>');
            return arr.join('');
        }
        }
    ]
});
g.init("/meterManage/tryInfo/index2");
var modelLists = [];
//根据productSkn获取所有试穿信息并拼接返回
var getAllInfo = function (item, callback) {
    console.log("item11",item);
    common.util.__ajax({url: '/meterManage/tryInfo/info1', data: {productSkn: item.productSkn}}, function (data) {
        var feelIds = {
            1: "合适",
            2: "偏大",
            3: "偏小"
        };
        var infoLists = data.data || {};
        modelLists = infoLists.tryModelList || [];
        //如果存在试穿信息
        if (infoLists.tryInfoBoMap) {
            var tryInfo = infoLists.tryInfoBoMap;
            for (var i = 0; i < modelLists.length; i++) {
                if (tryInfo[modelLists[i].id]) {
                    modelLists[i].tryInfo = {};
                    modelLists[i].tryInfo = tryInfo[modelLists[i].id];
                    modelLists[i].tryInfo.fell_name = feelIds[tryInfo[modelLists[i].id].feel_id];
                }
                else {
                    modelLists[i].tryInfo = {};
                    modelLists[i].tryInfo.fit_size = "";
                    modelLists[i].tryInfo.fit_remark = "";
                }
            }
        }
        //不存在
        else {
            for (var j = 0; j < modelLists.length; j++) {
                modelLists[j].tryInfo = {};
            }
        }
        callback(modelLists);
        var e = new common.edit("#baseInfo");
        e.init();
        var sortId;
        if(item.smallSortId&&item.smallSortId>1){
            sortId=item.smallSortId;
        }else{
            if(item.middleSortId||item.middleSortId>1){
                sortId=item.middleSortId;
            }
            else{
                sortId=item.maxSortId;
            }
        }
        new common.dropDown({
            el: '.fit_size',
            ajax: 'sortsize2',
            params: function () {
                return {
                    "sortId": sortId
                };
            }
        });
        new common.dropDown({el: '.feel_id'});
    }, true);
};
//整合修改后的所有试穿信息
var newList = [];
var getNewLists = function (modelLists, callback) {
    for (var i = 0; i < modelLists.length; i++) {
        newList[i] = {};
        newList[i].model_id = modelLists[i].id;
        if (modelLists[i].tryInfo.feel_id || modelLists[i].tryInfo.fit_size || modelLists[i].tryInfo.fit_remark) {
            newList[i].feel_id = modelLists[i].tryInfo.feel_id || "";
            newList[i].fit_size = modelLists[i].tryInfo.fit_size || "";
            newList[i].fit_remark = modelLists[i].tryInfo.fit_remark || "";
        }
        else {
            newList[i].feel_id = "";
            newList[i].fit_size = "";
            newList[i].fit_remark = "";
        }
    }
    callback(newList);
};

//详情模态
var Bll = {
    toast: function (url, item) {
        getAllInfo(item, function (data) {
            var a = new common.dialog({
                title: "试穿信息",
                width: '80%',
                content: common.util.__template2($("#template").html(), {
                    productSkn: item.productSkn,
                    productName: item.productName,
                    modelLists: data
                }),
                button: [
                    {
                        value: "提交", callback: function () {
                        getNewLists(data, function (newList1) {
                            common.util.__ajax({
                                url: url,
                                data: {
                                    productSkn: item.productSkn,
                                    productModelTry: JSON.stringify(newList1)
                                }
                            }, function (res) {
                                if (res.code == '200') {
                                    g.reload();
                                    a.close();
                                }
                            });
                            return false;
                        })

                    }, css: "btn-info"
                    },
                    {
                        value: "取消",
                        css: "btn btn-primary"
                    }
                ]
            });
        })

    }
};

//编辑按钮
$(document).on('click', '.info', function () {
    var item = g.rows[$(this).data("index")];
    Bll.toast('/meterManage/tryInfo/add', item);
});


//输入变化时触发
$(document).on("change", ".tryInfo1", function () {
    var _index = $(this).data("index");
    var item = modelLists[_index].tryInfo;
    var name = $(this).data('name');
    if (name == 'fit_size') {
        item[name] = $(this).find("option[value='" + $(this).val() + "']").text();
    }
    else {
        item[name] = $(this).val();
    }
    console.log(item);
});
//查询按钮--点击事件
$(document).on('click', '#filter-btn', function () {
    g.reload(1);
});