商品规格只有一列的情况逻辑优化

This commit is contained in:
devil_gong 2019-01-23 10:53:24 +08:00
parent bf4b333751
commit 72a5b77756
7 changed files with 44 additions and 6 deletions

View File

@ -144,7 +144,7 @@
<div class="cart-title">{{$spec.name}}</div>
<ul>
{{foreach $spec.value as $keys=>$specs}}
<li class="sku-line {{if !empty($specs['images'])}} sku-line-images{{/if}} {{if $key gt 0}} sku-dont-choose{{/if}}" data-type-value="{{$spec.name}}" data-value="{{$specs.name}}" {{if !empty($specs['images'])}} data-type-images="{{$specs.images}}"{{/if}}>
<li class="sku-line {{if !empty($specs['images'])}} sku-line-images{{/if}} {{if $key gt 0}} sku-dont-choose{{/if}} {{if isset($specs['is_only_level_one']) and isset($specs['inventory']) and $specs['inventory'] elt 0}}sku-items-disabled{{/if}}" data-type-value="{{$spec.name}}" data-value="{{$specs.name}}" {{if !empty($specs['images'])}} data-type-images="{{$specs.images}}"{{/if}}>
{{if !empty($specs['images'])}}
<img src="{{$specs.images}}" />
{{/if}}

View File

@ -35,7 +35,7 @@
{{include file="lib/gender" /}}
<div class="am-form-group">
<label>生日</label>
<input type="text" name="birthday" class="am-form-field am-input-sm am-radius Wdate" placeholder="生日" data-validation-message="生日格式有误" {{if !empty($data)}} value="{{$data.birthday_text}}" onclick="WdatePicker({firstDayOfWeek:1,dateFmt:'yyyy-MM-dd'})"{{/if}} autocomplete="off" required />
<input type="text" name="birthday" class="am-form-field am-input-sm am-radius Wdate" placeholder="生日" data-validation-message="生日格式有误" {{if !empty($data)}} value="{{$data.birthday_text}}" onclick="WdatePicker({firstDayOfWeek:1,dateFmt:'yyyy-MM-dd'})"{{/if}} autocomplete="off" />
</div>
<div class="am-form-group">
<button type="submit" class="am-btn am-btn-primary am-radius btn-loading-example am-btn-sm w100" data-am-loading="{loadingText:'处理中...'}">保存</button>

View File

@ -388,6 +388,26 @@ class GoodsService
$temp_type['value'] = $temp_type_value;
$temp_type['add_time'] = date('Y-m-d H:i:s');
}
// 只有一个规格的时候直接获取规格值的库存数
if(count($choose) == 1)
{
foreach($choose[0]['value'] as &$temp_spec)
{
$temp_spec_params = [
'id' => $params['goods_id'],
'spec' => [
['type' => $choose[0]['name'], 'value' => $temp_spec['name']]
],
];
$temp = self::GoodsSpecDetail($temp_spec_params);
if($temp['code'] == 0)
{
$temp_spec['is_only_level_one'] = 1;
$temp_spec['inventory'] = $temp['data']['inventory'];
}
}
}
}
return ['choose'=>$choose];
}

View File

@ -1323,14 +1323,15 @@ class UserService
'error_msg' => '昵称 2~16 个字符之间',
],
[
'checked_type' => 'empty',
'checked_type' => 'isset',
'key_name' => 'birthday',
'error_msg' => '请填写生日',
],
[
'checked_type' => 'isset',
'checked_type' => 'in',
'checked_data' => [0,1,2],
'key_name' => 'gender',
'error_msg' => '请选择性别',
'error_msg' => '性别选择有误',
],
[
'checked_type' => 'empty',
@ -1346,7 +1347,7 @@ class UserService
// 更新数据库
$data = [
'birthday' => strtotime($params['birthday']),
'birthday' => empty($params['birthday']) ? '' : strtotime($params['birthday']),
'nickname' => $params['nickname'],
'gender' => intval($params['gender']),
'upd_time' => time(),

View File

@ -157,8 +157,15 @@ Page({
temp_data[i]['value'][k]['is_disabled'] = '';
temp_data[i]['value'][k]['is_active'] = '';
}
// 当只有一个规格的时候
if(key == 0 && temp_data.length == 1)
{
temp_data[i]['value'][k]['is_disabled'] = ((temp_data[i]['value'][k]['is_only_level_one'] || null) != null && (temp_data[i]['value'][k]['inventory'] || 0) <= 0) ? 'spec-items-disabled' : '';
}
}
}
this.setData({goods_specifications_choose: temp_data});
},

View File

@ -154,6 +154,12 @@ Page({
temp_data[i]['value'][k]['is_disabled'] = '';
temp_data[i]['value'][k]['is_active'] = '';
}
// 当只有一个规格的时候
if(key == 0 && temp_data.length == 1)
{
temp_data[i]['value'][k]['is_disabled'] = ((temp_data[i]['value'][k]['is_only_level_one'] || null) != null && (temp_data[i]['value'][k]['inventory'] || 0) <= 0) ? 'spec-items-disabled' : '';
}
}
}
this.setData({goods_specifications_choose: temp_data});

View File

@ -294,6 +294,10 @@ $(function() {
{
$(this).find('ul>li').on('click', function()
{
// 切换规格购买数量清空
$('#text_box').val(1);
// 规格处理
var length = $('.theme-signin-left .sku-items').length;
var index = $(this).parents('.sku-items').index();