info.js 2.7 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 = {};
                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 = {};
        }
    }
    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();
});
//保存试穿信息
$(document).on("click", "#addInfo", function () {
    var newList = [];
    for (var i = 0; i < modelLists.length; i++) {
        newList[i] = {};
        newList[i].model_id = modelLists[i].id;
        if (modelLists[i].tryInfo) {
            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 = "";
        }
    }
    common.util.__ajax({
        url: '/meterManage/tryInfo/add',
        data: {
            productSkn: param[2],
            productModelTry: JSON.stringify(newList)
        }
    }, function (res) {
        if (res.code == '200') {
            window.location.href = "/meterManage/tryInfo/index"
        }
        else {

        }
    });
});
//返回
$(document).on("click", ".back", function () {
    window.location.href = "/meterManage/tryInfo/index"
});