info.js 2.54 KB
/**
 * Created by JiangMin on 2016/3/24
 * 试穿详情.
 */

var $ = require('jquery');
var common = require('../common/common');
var param = location.href.match(/(info)\/(\d+)/);
//尺码列表
var modelLists = [];
common.util.__ajax({url: '/meterManage/tryInfo/info1', data: {productSkn: param[2]}}, 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 = {};
                tryInfo[modelLists[i].id].feel_id = feelIds[tryInfo[modelLists[i].id].feel_id];
                modelLists[i].tryInfo = tryInfo[modelLists[i].id];
            }
            else {
                modelLists[i].tryInfo = {};
                modelLists[i].tryInfo.fit_size = "";
                modelLists[i].tryInfo.feel_id = "";
                modelLists[i].tryInfo.fit_remark = "";
            }
        }
    }
    //不存在
    else {
        for (var j = 0; j < modelLists.length; j++) {
            modelLists[j].tryInfo = {};
        }
    }
    var a = common.util.__template2($("#template").html(), {modelLists: modelLists});
    $(".contentpanel1").html(a);
    new common.dropDown({
        el: '.fit_size',
        ajax: 'sortsize'
    });
}, true);

$(document).on("change", ".tryInfo1", function () {
    var _index = $(this).data("index");
    var item = modelLists[_index].tryInfo;
    var name = $(this).data('name');
    item[name] = $(this).val();
    console.log("item", item);
});
$(document).on("click", "#addInfo", function () {
    console.log("modelLists", modelLists);
    //var newList = [];
    //for (var i = 0; i < modelLists.length; i++) {
    //    console.log("modelLists");
    //    console.log(modelLists[i]);
    //    newList[i]={};
    //    newList[i].model_id = modelLists[i].id;
    //    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;
    //}
    //console.log("newList");
    //console.log(newList);
    common.util.__ajax({
        url: '/meterManage/tryInfo/add',
        data: {
            productSkn: param[2],
            productModelTry: JSON.stringify(modelLists)
        }
    }, function () {
        console.log("成功")
    });
})