商品快捷操作

This commit is contained in:
devil_gong 2019-09-20 19:02:08 +08:00
parent a4da3f4029
commit f7b6b4088d
2 changed files with 130 additions and 46 deletions

View File

@ -171,7 +171,7 @@
<div class="spec-quick am-margin-bottom-lg">
<span class="business-operations-submit quick-spec-title-add">+快捷操作</span>
<span class="business-operations-submit am-margin-left-sm am-icon-gg quick-spec-created">生成规格</span>
<div class="goods-specifications">
<div class="goods-specifications" style="display: none;">
<table class="am-table am-table-bordered am-table-centered">
<thead>
<tr>
@ -179,50 +179,7 @@
<th class="spec-quick-th-value">规格值</th>
</tr>
</thead>
<tbody>
<tr>
<td class="am-text-middle">
<i class="am-close am-close-spin quick-title-remove" data-index="168">×</i>
<input type="text" name="spec_quick_title_0" placeholder="规格名" />
</td>
<td class="spec-quick-td-value am-cf">
<div class="am-fl am-margin-xs value-item">
<input type="text" class="am-fl" name="spec_quick_value_0" placeholder="规格值" />
<i class="am-close am-close-spin quick-value-remove" data-index="168">×</i>
</div>
<div class="am-fl am-margin-xs value-item">
<input type="text" class="am-fl" name="spec_quick_value_0" placeholder="规格值" />
<i class="am-close am-close-spin quick-value-remove" data-index="168">×</i>
</div>
<div class="am-fl am-margin-xs value-item am-text-left">
<span class="business-operations-submit quick-spec-value-add">+添加规格值</span>
</div>
</td>
</tr>
<tr>
<td class="am-text-middle">
<i class="am-close am-close-spin quick-title-remove" data-index="168">×</i>
<input type="text" name="spec_quick_title_0" placeholder="规格名" />
</td>
<td class="spec-quick-td-value am-cf">
<div class="am-fl am-margin-xs value-item">
<input type="text" class="am-fl" name="spec_quick_value_0" placeholder="规格值" />
<i class="am-close am-close-spin quick-value-remove" data-index="168">×</i>
</div>
<div class="am-fl am-margin-xs value-item">
<input type="text" class="am-fl" name="spec_quick_value_0" placeholder="规格值" />
<i class="am-close am-close-spin quick-value-remove" data-index="168">×</i>
</div>
<div class="am-fl am-margin-xs value-item am-text-left">
<span class="business-operations-submit quick-spec-value-add">+添加规格值</span>
</div>
</td>
</tr>
</tbody>
<tbody></tbody>
</table>
</div>
</div>

View File

@ -277,6 +277,133 @@ $(function()
// 生成规格
$('.quick-spec-created').on('click', function()
{
Prompt('world');
var spec = [];
$('.spec-quick table tbody tr').each(function(k, v)
{
spec[k] = {
"title": $(this).find('td.am-text-middle input').val(),
"value": []
}
$(this).find('td.spec-quick-td-value .value-item').each(function(ks,vs)
{
var value = $(this).find('input').val() || null;
if(value != null)
{
spec[k]['value'][ks] = $(this).find('input').val();
}
});
});
// 是否存在规格
if(spec.length <= 0)
{
Prompt('快捷操作规格为空');
}
spec = [
{
"title": "套餐",
"value": ["套餐1", "套餐2", "套餐3"]
},
{
"title": "颜色",
"value": ["黑色", "红色"]
},
{
"title": "容量",
"value": ["64G", "128G"]
},
{
"title": "配置",
"value": ["高级", "钻石", "555"]
}
];
// 自动生成规格
var data = [];
var length = spec.length;
// 规格最大总数
var all = spec.map(function(v){return v.value.length});
var count = 0;
for(var t in all)
{
count = (count == 0) ? all[t] : count*all[t]
}
console.log(all, count)
for(var i in spec)
{
data = ssssss(length, spec, data, spec[i]['value'], count, i);
//break;
//console.log(spec[0]['value'][i])
//data[a][i] = spec[0]['value'][i];
// for(var k=1; k<length; k++)
// {
// data[a][i] += spec[k]['value'][i];
// //console.log(spec[i]['title'], spec[i]['value'])
// }
}
console.log(data, 'data');
function ssssss(specs_length, specs, data, spec, count, level)
{
level = parseInt(level);
var temp_index = 0;
var length = spec.length;
var avg = parseInt((count/length)/(level+(level <= 0 ? 1 : 2)));
avg = count/specs[level]['value'].length;
if(level > 0 && level < specs_length-1)
{
avg = ((specs[level+1] || null) == null) ? 1 : specs[level+1]['value'].length;
console.log(level, specs_length, avg, 'join')
}
if(level >= specs_length-1)
{
avg = 0;
console.log(level, specs_length, avg, 'end')
}
if(level == 1)
{
avg = count/specs[0]['value'].length/2;
}
//console.log((count/length), (parseInt(level)+(level <= 0 ? 1 : 2)), avg)
var temp_avg = 0;
for(var i=0; i<count; i++)
{
//console.log(avg, temp_avg, temp_index)
if((data[i] || null) == null)
{
data[i] = '';
}
data[i] += spec[temp_index];
if(temp_avg < avg-1)
{
temp_avg++;
} else {
temp_avg = 0;
temp_index++;
}
if(temp_index > length-1)
{
temp_index = 0;
}
}
//console.log(length, data, spec, count, level)
return data;
}
});
});