model.js 3.92 KB
'use strict';
var $ = require('jquery'),
    common = require('../../../common/common');

new common.dropDown({
    el: '#select—model',
    ajax: 'queryModelListForSelect',
    hash: true
});

new common.dropDown({
    el: '#select—size',
    ajax: 'queryProdSizeListForSel',
    hash: true,
    params:function(){
      	return{productSkn:NETSALEDATA.baseProductInfo.baseProduct.productSkn}
    }
});

var modelCardTable = new common.grid({
	el: "#model-card",
	hash: false,
	columns: [{
		display: '模特',
		name: 'modelName'
	}, {
		display: '尺码',
		name: 'size'
	}, {
		display: '模特卡',
		render: function(item) {
			return '<img src="' + item.modelImg + '"/>';
		}
	},{
		display: '操作',
		render: function(item) {
			return '<a href="JavaScript:;" class="btn btn-info btn-xs info-btn" id="btn-model-del" data-index="' + item.__index + '">删除</a>'
		}
	}]
});
modelCardTable.init(NETSALEDATA.modelcardList);

$(document).on('click', '#btn-model-add', function () {

  modelCardTable.init(NETSALEDATA.modelcardList);
  var productSkn = NETSALEDATA.baseProductInfo.baseProduct.productSkn;
  var modelCardId = $("#select—model").val();
  var size = $("#select—size").val();
  if(modelCardId==-1){
	common.util.__tip("模特姓名不能为空");
	return false;
  }
  if(size==-1){
  	common.util.__tip("商品尺寸不能为空");
	return false;
  }
   common.util.__ajax({
	    url: '/goods/product/addproductModelCard',
	    data: {
			productSkn:productSkn,
			modelCardId:modelCardId,
			size:size
	    }
	    }, function (res) {
	   		if(res.code==200){
	   			NETSALEDATA.modelcardList = res.data;
	   			 modelCardTable.init(res.data);
	   		}
	    });
   });

$(document).on('click', '#btn-model-del', function () {
 modelCardTable.init(NETSALEDATA.modelcardList);
 var item = modelCardTable.rows[$(this).data("index")];
var productSkn = NETSALEDATA.baseProductInfo.baseProduct.productSkn;
   common.util.__ajax({
	    url: '/goods/product/delproductModelCard',
	    data: {
			productSkn:productSkn,
			modelCardId:item.modelcardId,
			size:item.size
	    }
	    }, function (res) {
	   		if(res.code==200){
	   			NETSALEDATA.modelcardList = res.data;
	   			modelCardTable.init(res.data);
	   		}
	    });
   });
var modelTryTable = new common.grid({
	el: "#model-try",
	hash: false,
	columns: [{
		display: '',
        type: 'checkbox'
	},{
		display: '模特',
		name: 'modelName'
	}, {
		display: '身高/体重',
		render: function(item) {
			return item.height + 'cm/' + item.weight + 'kg';
		}
	}, {
		display: '三围',
		name: 'vitalStatistics',
		render: function(item) {
			return item.vitalStatistics + 'cm';
		}
	}, {
		display: '试穿尺码',
		render: function(item) {
			return item.fitModelBo.fit_size;
		}
	}, {
		display: '试穿描述',
		render: function(item) {
			return item.fitModelBo.feel;
		}
	}, {
		display: '备注',
		render: function(item) {
			return item.fitModelBo.fit_remark;
		}
	}]
});

// $(".wqt_checkbox").each(function(){
// 	this.checked="checked";                 
//     }); 
// setTimeout(function(){$(".wqt_all").attr("checked",'checked');},2000)
modelTryTable.init(NETSALEDATA.modelTryList);
var modelTryList = NETSALEDATA.modelTryList;

for(var i=0;i<modelTryList.length;i++){
	if(modelTryList[i].fitModelBo.is_show==1){
		$(".wqt_checkbox").eq(i).prop("checked", true);
	}
}

$(document).on('click', '#modelTry-save', function () {
//	modelTryTable.init(NETSALEDATA.modelTryList);
  	var productSkn = NETSALEDATA.baseProductInfo.baseProduct.productSkn;
	var erpFitModel = [];
	$(".wqt_checkbox").each(function(i,val){
		erpFitModel[i] = NETSALEDATA.modelTryList[i].fitModelBo;
		if(val.checked==false){
			 erpFitModel[i].is_show=0;
		}else{
			 erpFitModel[i].is_show=1;
		}    
    }); 

   common.util.__ajax({
	    url: '/meterManage/tryModel/addtryModelInfo',
	    data: {
			productSkn:productSkn,
			erpFitModel:JSON.stringify(erpFitModel)
	    }
	    }, function (res) {
	   		if(res.code==200){
	   		}
	    });
   });