goods buy

feat/task1-c-wallet
devil_gong 2018-09-13 18:36:54 +08:00
parent 0f7b59978a
commit 81bf8470da
24 changed files with 717 additions and 130 deletions

View File

@ -73,34 +73,12 @@ class CommonController extends Controller
*/
protected function ajaxReturn($msg = '', $code = 0, $data = '')
{
// ajax的时候success和error错误由当前方法接收
if(IS_AJAX)
{
if(isset($msg['info']))
{
// success模式下code=0, error模式下code参数-1
$result = array('msg'=>$msg['info'], 'code'=>-1, 'data'=>'');
}
}
// 默认情况下,手动调用当前方法
if(empty($result))
{
$result = array('msg'=>$msg, 'code'=>$code, 'data'=>$data);
}
// 错误情况下,防止提示信息为空
if($result['code'] != 0 && empty($result['msg']))
{
$result['msg'] = L('common_operation_error');
}
//清除缓冲区中的内容
ob_clean();
// 输出json
header('Content-Type:application/json; charset=utf-8');
exit(json_encode($result));
exit(json_encode(DataReturn($msg, $code, $data)));
}
/**

View File

@ -8,6 +8,43 @@
* @datetime 2016-12-01T21:51:08+0800
*/
/**
* [DataReturn 公共返回数据]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-07T22:03:40+0800
* @param [string] $msg [提示信息]
* @param [int] $code [状态码]
* @param [mixed] $data [数据]
* @return [json] [json数据]
*/
function DataReturn($msg = '', $code = 0, $data = '')
{
// ajax的时候success和error错误由当前方法接收
if(IS_AJAX)
{
if(isset($msg['info']))
{
// success模式下code=0, error模式下code参数-1
$result = array('msg'=>$msg['info'], 'code'=>-1, 'data'=>'');
}
}
// 默认情况下,手动调用当前方法
if(empty($result))
{
$result = array('msg'=>$msg, 'code'=>$code, 'data'=>$data);
}
// 错误情况下,防止提示信息为空
if($result['code'] != 0 && empty($result['msg']))
{
$result['msg'] = L('common_operation_error');
}
return $result;
}
/**
* 生成前台页面url地址

View File

@ -14,7 +14,7 @@ return array(
'IS_DEVELOP' => true,
// 显示页面Trace信息
'SHOW_PAGE_TRACE' => true,
'SHOW_PAGE_TRACE' => false,
// 允许访问的模块列表
'MODULE_ALLOW_LIST' => array('Admin', 'Api', 'Home'),

View File

@ -200,6 +200,8 @@ return array(
'common_confirm_error' => '确认失败',
'common_favor_success' => '收藏成功',
'common_favor_error' => '收藏失败',
'common_join_success' => '加入成功',
'common_join_error' => '加入失败',
'common_value_not_change' => '数据未改变',
'common_gender_tips' => '性别值范围不正确',
@ -283,6 +285,9 @@ return array(
'common_express_name' => '快递公司',
'common_background_color' => '背景色',
'common_favor_ok_text' => '已收藏',
'common_favor_not_text' => '收藏',
// 性别
'common_gender_list' => array(
0 => array('id' => 0, 'name' => '保密', 'checked' => true),

View File

@ -2,8 +2,7 @@
namespace Home\Controller;
use Service\SearchService;
use Service\BrandService;
use Service\BuyService;
/**
* 购物车
@ -25,6 +24,9 @@ class CartController extends CommonController
{
// 调用父类前置方法
parent::_initialize();
// 是否登录
$this->Is_Login();
}
/**
@ -38,5 +40,21 @@ class CartController extends CommonController
{
$this->display('Index');
}
/**
* 购物车保存
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-13
* @desc description
*/
public function Save()
{
$params = $_POST;
$params['user'] = $this->user;
$ret = BuyService::CartAdd($params);
$this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
}
}
?>

View File

@ -65,34 +65,12 @@ class CommonController extends Controller
*/
protected function ajaxReturn($msg = '', $code = 0, $data = '')
{
// ajax的时候success和error错误由当前方法接收
if(IS_AJAX)
{
if(isset($msg['info']))
{
// success模式下code=0, error模式下code参数-1
$result = array('msg'=>$msg['info'], 'code'=>-1, 'data'=>'');
}
}
// 默认情况下,手动调用当前方法
if(empty($result))
{
$result = array('msg'=>$msg, 'code'=>$code, 'data'=>$data);
}
// 错误情况下,防止提示信息为空
if($result['code'] != 0 && empty($result['msg']))
{
$result['msg'] = L('common_operation_error');
}
//清除缓冲区中的内容
ob_clean();
// 输出json
header('Content-Type:application/json; charset=utf-8');
exit(json_encode($result));
exit(json_encode(DataReturn($msg, $code, $data)));
}
/**
@ -149,6 +127,10 @@ class CommonController extends Controller
$this->assign('nav_header', $this->nav_header);
$this->assign('nav_footer', $this->nav_footer);
// 导航/底部默认显示
$this->assign('is_header', 1);
$this->assign('is_footer', 1);
// 当前页面选择导航状态
$nav_pid = 0;
$nav_id = 0;

View File

@ -45,6 +45,11 @@ class GoodsController extends CommonController
'is_attribute' => true,
];
$goods = GoodsService::GoodsList($params);
// 当前登录用户是否已收藏
$ret_favor = GoodsService::IsUserGoodsFavor(['goods_id'=>$id, 'user'=>$this->user]);
$goods[0]['is_favor'] = ($ret_favor['code'] == 0) ? $ret_favor['data'] : 0;
$this->assign('goods', $goods[0]);
$this->assign('home_seo_site_title', $goods[0]['title']);
@ -78,5 +83,25 @@ class GoodsController extends CommonController
$this->display('Index');
}
/**
* 商品收藏
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-13
* @desc description
*/
public function Favor()
{
// 是否登录
$this->Is_Login();
// 开始处理
$params = $_POST;
$params['user'] = $this->user;
$ret = GoodsService::GoodsFavor($params);
$this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
}
}
?>

View File

@ -175,6 +175,35 @@ class UserController extends CommonController
}
}
/**
* modal弹窗登录
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-13
* @desc description
*/
public function ModalLoginInfo()
{
$this->assign('is_header', 0);
$this->assign('is_footer', 0);
if(MyC('home_user_login_state') == 1)
{
if(empty($this->user))
{
$this->assign('referer_url', $this->GetrefererUrl());
$this->display('ModalLoginInfo');
} else {
$this->assign('msg', L('common_login_already_had_tips'));
$this->display('/Public/TipsError');
}
} else {
$this->assign('msg', L('common_close_user_login_tips'));
$this->display('/Public/TipsError');
}
}
/**
* [Reg 用户注册-数据添加]
* @author Devil

View File

@ -12,7 +12,7 @@
<!-- goods category -->
<include file="Public/GoodsCategory" />
<div class="detail">
<div class="goods-detail" data-id="{{$goods.id}}" data-login-url="{{:U('Home/User/ModalLoginInfo')}}">
<!-- 轮播 -->
<div class="scoll">
<div data-am-widget="slider" class="am-slider am-slider-a1" data-am-slider='{"directionNav":false}' >
@ -115,7 +115,7 @@
<div class="theme-signin-left">
<if condition="!empty($goods['attribute']['choose'])">
<foreach name="goods.attribute.choose" key="key" item="attribute">
<div class="theme-options">
<div class="theme-options sku-items">
<div class="cart-title">{{$attribute.name}}</div>
<ul>
<if condition="!empty($attribute['find'])">
@ -130,11 +130,6 @@
<div class="theme-options">
<div class="cart-title number">数量</div>
<dd>
<!-- <button id="min" class="am-btn am-btn-default" type="button">-</button>
<input id="text_box" name="" type="text" value="1" />
<button id="add" class="am-btn am-btn-default" type="button">+</button>
<span id="Stock" class="tb-hidden">库存<span class="stock">{{$goods.inventory}}</span>{{$goods.inventory_unit}}</span> -->
<div class="am-input-group am-input-group-sm number-tag">
<button class="am-input-group-label" id="min" type="button">-</button>
<input type="text" class="am-form-field" value="1" id="text_box" />
@ -145,7 +140,7 @@
</div>
<div class="btn-op">
<span class="btn am-btn am-btn-default confirm">确认</span>
<span class="btn am-btn am-btn-default confirm" data-type="cart" data-ajax-url="{{:U('Home/Cart/Save')}}">确认</span>
<span class="btn close am-btn am-btn-danger cancel">取消</span>
</div>
</div>
@ -157,7 +152,6 @@
<span class="price-now">¥{{$goods.price}}</span>
</div>
</div>
</form>
</div>
</div>
@ -168,17 +162,23 @@
<!--手机导航-->
<div class="buy-nav">
<div class="buy-nav-opt">
<a href="{{:__MY_URL__}}"><span class="am-icon-home am-icon-fw"> 首页</span></a>
<a><span class="am-icon-heart am-icon-fw"> 收藏</span></a>
<a href="{{:__MY_URL__}}">
<span class="am-icon-home am-icon-fw"> 首页</span>
</a>
<if condition="isset($goods['is_favor']) and $goods['is_favor'] eq 1">
<span class="am-icon-heart am-icon-fw favor-submit text-active" data-ajax-url="{{:U('Home/Goods/Favor')}}"> 已收藏</span>
<else />
<span class="am-icon-heart am-icon-fw favor-submit" data-ajax-url="{{:U('Home/Goods/Favor')}}"> 收藏</span>
</if>
</div>
<li>
<div class="clearfix tb-btn tb-btn-buy theme-login">
<a id="LikBuy" title="点此按钮到下一步确认购买信息" href="javascript:;">立即购买</a>
<button class="buy-submit" title="点此按钮到下一步确认购买信息" href="javascript:;" data-type="buy" type="button">立即购买</button>
</div>
</li>
<li>
<div class="clearfix tb-btn tb-btn-basket theme-login">
<a id="LikBasket" title="加入购物车" href="javascript:;"><i></i>加入购物车</a>
<button class="cart-submit" title="加入购物车" href="javascript:;" data-type="cart" data-ajax-url="{{:U('Home/Cart/Save')}}" type="button"><i></i>加入购物车</button>
</div>
</li>
</div>

View File

@ -27,7 +27,7 @@
</a>
</div>
<div class="am-u-sm-3">
<a href="#">
<a href="{{:U('Home/Cart/Index')}}">
<div class="nav-icon mini-nav-cart">
<img src="__PUBLIC__/Home/{{$default_theme}}/Images/home-mini-nav-cart-icon.png" />
</div>

View File

@ -8,9 +8,6 @@
<include file="Public/GoTop" />
<!-- go-top end -->
<!-- commom html start -->
<include file="Public/Common" />
<!-- commom html end -->
</body>
</html>

View File

@ -22,7 +22,7 @@
var __my_url__ = '{{:__MY_URL__}}';
var __public__ = '__PUBLIC__';
var __default_theme__ = '{{$default_theme}}';
var __user_id__ = '{{$user.id}}';
var __user_id__ = <if condition="empty($user['id'])">0<else />{{$user.id}}</if>;
</script>
</head>
<body>

View File

@ -20,11 +20,7 @@
<fieldset>
<if condition="in_array('sms', MyC('home_user_reg_state')) or in_array('email', MyC('home_user_reg_state'))">
<span class="">{{:L('user_login_on_accounts_text')}}</span>
<if condition="in_array('sms', MyC('home_user_reg_state'))">
<a href="{{:U('Home/User/RegInfo')}}" class="am-btn am-btn-secondary am-btn-xs am-radius">{{:L('user_login_immediately_reg_text')}}</a>
<elseif condition="in_array('email', MyC('home_user_reg_state'))" />
<a href="{{:U('Home/User/EmailRegInfo')}}" class="am-btn am-btn-secondary am-btn-xs am-radius">{{:L('user_login_immediately_reg_text')}}</a>
</if>
<a href="{{:U('Home/User/RegInfo')}}" class="am-btn am-btn-secondary am-btn-xs am-radius">{{:L('user_login_immediately_reg_text')}}</a>
<hr />
</if>
<label>{{:L('user_login_accounts_text')}}</label>
@ -37,7 +33,7 @@
</div>
<p>
<button type="submit" class="am-btn am-btn-primary am-radius am-btn-sm btn-loading-example" data-am-loading="{loadingText: '{{:L('common_login_loading_tips')}}'}">{{:L('user_login_submit_text')}}</button>
<a href="{{:U('Home/User/ForgetPwdInfo')}}" class="am-fr m-t-5">{{:L('user_reg_forget_pwd_text')}}</a>
<a href="{{:U('Home/User/ForgetPwdInfo')}}" class="am-fr">{{:L('user_reg_forget_pwd_text')}}</a>
</p>
</fieldset>
</form>
@ -46,9 +42,6 @@
</div>
<!-- conntent end -->
<!-- layuot common module start -->
<include file="Public/CommonModule" />
<!-- layuot common module end -->
<!-- footer start -->
<include file="Public/Footer" />

View File

@ -0,0 +1,51 @@
<include file="Public/Header" />
<!-- conntent start -->
<div class="am-g my-content">
<div class="am-u-md-6 am-u-sm-centered">
<!-- form start -->
<form class="am-form form-validation" method="post" action="{{:U('Home/User/Login')}}" request-type="ajax-fun" request-value="ViewModalBack">
<fieldset>
<if condition="in_array('sms', MyC('home_user_reg_state')) or in_array('email', MyC('home_user_reg_state'))">
<span class="">{{:L('user_login_on_accounts_text')}}</span>
<a href="{{:U('Home/User/RegInfo')}}" target="_blank" class="am-btn am-btn-secondary am-btn-xs am-radius">{{:L('user_login_immediately_reg_text')}}</a>
<hr />
</if>
<label>{{:L('user_login_accounts_text')}}</label>
<div class="am-form-group">
<input type="text" name="accounts" class="am-radius" minlength="1" placeholder="{{:L('user_login_accounts_text')}}" data-validation-message="{{:L('user_login_accounts_format')}}" required />
</div>
<label>{{:L('user_login_pwd_text')}}</label>
<div class="am-form-group">
<input type="password" name="pwd" class="am-radius" placeholder="{{:L('user_login_pwd_text')}}" pattern="{{:L('common_regex_pwd')}}" data-validation-message="{{:L('user_reg_pwd_format')}}" required />
</div>
<p>
<button type="submit" class="am-btn am-btn-primary am-radius am-btn-sm btn-loading-example" data-am-loading="{loadingText: '{{:L('common_login_loading_tips')}}'}">{{:L('user_login_submit_text')}}</button>
<a href="{{:U('Home/User/ForgetPwdInfo')}}" target="_blank" class="am-fr">{{:L('user_reg_forget_pwd_text')}}</a>
</p>
</fieldset>
</form>
<!-- form end -->
</div>
</div>
<!-- conntent end -->
<!-- footer start -->
<include file="Public/Footer" />
<!-- footer end -->
<script type="text/javascript">
// 返回处理
function ViewModalBack(e)
{
if(e.code == 0)
{
parent.location.reload();
} else {
$('form.form-validation').find('button[type="submit"]').button('reset');
$.AMUI.progress.done();
Prompt(e.msg);
}
}
</script>

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,112 @@
<?php
namespace Service;
/**
* 购买服务层
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class BuyService
{
/**
* 购物车添加
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-08-29
* @desc description
* @param [array] $params [输入参数]
*/
public static function CartAdd($params = [])
{
// 请求参数
$p = [
[
'checked_type' => 'empty',
'key_name' => 'goods_id',
'error_msg' => '商品id有误',
],
[
'checked_type' => 'empty',
'key_name' => 'stock',
'error_msg' => '购买数量有误',
],
[
'checked_type' => 'empty',
'key_name' => 'user',
'error_msg' => '用户信息有误',
],
];
$ret = params_checked($params, $p);
if($ret !== true)
{
return DataReturn($ret, -1);
}
// 获取商品
$goods_id = intval($params['goods_id']);
$goods = M('Goods')->where(['id'=>$goods_id, 'is_shelves'=>1, 'is_delete_time'=>0])->find();
if(empty($goods))
{
return DataReturn('商品不存在或已删除', -2);
}
// 属性处理
$attr = [];
if(!empty($params['attr']) && is_array($params['attr']))
{
foreach($params['attr'] as $k=>$v)
{
$attr_type_name = M('GoodsAttributeType')->where(['goods_id'=>$goods_id, 'id'=>$k])->getField('name');
$attr_name = M('GoodsAttribute')->where(['goods_id'=>$goods_id, 'id'=>$v])->getField('name');
if(!empty($attr_type_name) && !empty($attr_name))
{
$attr[] = [
'attr_type_id' => $k,
'attr_type_name' => $attr_type_name,
'attr_id' => $v,
'attr_name' => $attr_name,
];
}
}
}
// 添加购物车
$data = [
'user_id' => $params['user']['id'],
'goods_id' => $goods_id,
'title' => $goods['title'],
'images' => $goods['images'],
'original_price'=> $goods['original_price'],
'price' => $goods['price'],
'stock' => intval($params['stock']),
'attribute' => count($attr) == 0 ? '' : json_encode($attr),
];
// 存在则更新
$m = M('Cart');
$where = ['user_id'=>$data['user_id'], 'goods_id'=>$data['goods_id'], 'attribute'=>$data['attribute']];
$temp = $m->where($where)->find();
if(empty($temp))
{
$data['add_time'] = time();
if($m->add($data) > 0)
{
return DataReturn(L('common_join_success'), 0);
}
} else {
$data['upd_time'] = time();
$data['stock'] += $temp['stock'];
if($m->where($where)->save($data))
{
return DataReturn(L('common_join_success'), 0);
}
}
return DataReturn(L('common_join_error'), -100);
}
}
?>

View File

@ -297,5 +297,95 @@ class GoodsService
}
return $result;
}
/**
* 商品收藏
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-08-29
* @desc description
* @param [array] $params [输入参数]
*/
public static function GoodsFavor($params = [])
{
// 请求参数
$p = [
[
'checked_type' => 'empty',
'key_name' => 'goods_id',
'error_msg' => '商品id有误',
],
[
'checked_type' => 'empty',
'key_name' => 'user',
'error_msg' => '用户信息有误',
],
];
$ret = params_checked($params, $p);
if($ret !== true)
{
return DataReturn($ret, -1);
}
// 开始操作
$m = M('GoodsFavor');
$data = ['goods_id'=>intval($params['goods_id']), 'user_id'=>$params['user']['id']];
$temp = $m->where($data)->find();
if(empty($temp))
{
$data['add_time'] = time();
if($m->add($data) > 0)
{
return DataReturn(L('common_favor_success'), 0, ['text'=>L('common_favor_ok_text'), 'status'=>1]);
} else {
return DataReturn(L('common_favor_error'));
}
} else {
if($m->where($data)->delete() > 0)
{
return DataReturn(L('common_cancel_success'), 0, ['text'=>L('common_favor_not_text'), 'status'=>0]);
} else {
return DataReturn(L('common_cancel_error'));
}
}
}
/**
* 用户是否收藏了商品
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-08-29
* @desc description
* @param [array] $params [输入参数]
* @return [int] [1已收藏, 0未收藏]
*/
public static function IsUserGoodsFavor($params = [])
{
// 请求参数
$p = [
[
'checked_type' => 'empty',
'key_name' => 'goods_id',
'error_msg' => '商品id有误',
],
[
'checked_type' => 'empty',
'key_name' => 'user',
'error_msg' => '用户信息有误',
],
];
$ret = params_checked($params, $p);
if($ret !== true)
{
return DataReturn($ret, -1);
}
$m = M('GoodsFavor');
$data = ['goods_id'=>intval($params['goods_id']), 'user_id'=>$params['user']['id']];
$temp = $m->where($data)->find();
return DataReturn(L('common_operation_success'), 0, empty($temp) ? 0 : 1);
}
}
?>

View File

@ -36,6 +36,12 @@
#common-prompt { max-width: 280px;margin: 0 auto; }
}
/**
* iframe
*/
iframe { width: 100%; height: 100%; border: 0; }
.popup-iframe .am-popup-inner { overflow: hidden; }
/**
* H5

View File

@ -554,6 +554,38 @@ function img_file_upload_show(class_name, show_img, default_images)
});
}
/**
* 弹窗加载
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-13
* @desc description
* @param {[string]} url [加载url]
* @param {[string]} title [标题]
* @param {[string]} tag [指定id标记]
*/
function ModalLoad(url, title, tag)
{
tag = tag || 'common-popup-modal';
if($('#'+tag).length > 0)
{
$('#'+tag).remove();
}
var html = '<div class="am-popup popup-iframe" id="'+tag+'">';
html += '<div class="am-popup-inner">';
html += '<div class="am-popup-hd">';
html += '<h4 class="am-popup-title">'+(title || '温馨提示')+'</h4>';
html += '<span data-am-modal-close class="am-close">&times;</span>';
html += '</div>';
html += '<iframe src="'+url+'"></iframe>';
html += '</div>';
html += '</div>';
$('body').append(html);
$('#'+tag).modal();
}
// 公共数据操作
$(function()

View File

@ -19,7 +19,7 @@ strong.total-price-content, .selected-tips strong, .nav-total-price { color: #d2
.am-table > tbody > tr > td { border-top: 1px solid #F5F5F5; }
.cart-content table td.base input[type="checkbox"] { float: left; }
.cart-nav { background: #eee; height: 50px; line-height: 50px; padding: 0 5px; }
.cart-nav { background: #eee; height: 50px; line-height: 50px; padding: 0 0 0 5px; }
.cart-nav .separate-submit { height: 50px; width: 100px; font-size: 20px; }
.selected-tips { margin-right: 15px; }
.cart-nav label { font-weight: 100; }

View File

@ -564,4 +564,6 @@ background:url(../Images/ibar_sprites.png) no-repeat;background-position:0px -23
.am-btn-primary.am-disabled, .am-btn-primary[disabled], fieldset[disabled] .am-btn-primary, .am-btn-primary.am-disabled:hover, .am-btn-primary[disabled]:hover, fieldset[disabled] .am-btn-primary:hover, .am-btn-primary.am-disabled:focus, .am-btn-primary[disabled]:focus, fieldset[disabled] .am-btn-primary:focus, .am-btn-primary.am-disabled:active, .am-btn-primary[disabled]:active, fieldset[disabled] .am-btn-primary:active, .am-btn-primary.am-disabled.am-active, .am-btn-primary[disabled].am-active, fieldset[disabled] .am-btn-primary.am-active {
background-color: #d31e37;
border-color: #d31e37;
}
}
.am-popup-hd .am-popup-title { font-size: 18px; }

View File

@ -10,7 +10,7 @@ input{font-size:12px;font-size:100%;outline:none;line-height:normal;color:#444;}
.ipt:focus{border-color:#95C8F1;box-shadow:0 0 4px #95C8F1;}
.theme-login,.item-props-can{cursor: pointer;}
.theme-popover-mask{z-index:10000000;position:fixed;left:0;top:0;width:100%;height:100%;background:#333;opacity:0.5;filter:alpha(opacity=50);-moz-opacity:0.5;display:none;}
.theme-popover-mask{z-index:1000;position:fixed;left:0;top:0;width:100%;height:100%;background:#333;opacity:0.5;filter:alpha(opacity=50);-moz-opacity:0.5;display:none;}
.theme-popover{z-index:10000009;position:fixed;bottom:0;left:0;width:100%;display:none;}
.theme-poptit{padding:12px;position:relative;overflow: hidden;background:#fff ;height:80px ;}
.theme-poptit .close{float:right;color:#999;padding:5px;margin:-2px -5px -5px;font:bold 14px/14px simsun;text-shadow:0 1px 0 #ddd}
@ -31,7 +31,7 @@ input{font-size:12px;font-size:100%;outline:none;line-height:normal;color:#444;}
.theme-signin-right .img-info img{margin:5px 5px ;width:80px;height:80px ;}
.theme-signin-right .text-info{position:absolute;left:110px;top:20px ;}
.text-info .price-now{display:block;font-size:16px ;color:#C40000;}
.stock-tips{font-size:12px ;}
.stock-tips{ font-size:12px; }
/*可选规格*/
.iteminfo_parameter { margin-bottom: 10px; }
@ -49,21 +49,23 @@ input{font-size:12px;font-size:100%;outline:none;line-height:normal;color:#444;}
.introduce-main .am-sticky-placeholder { margin: 0px !important; }
.am-sticky-placeholder .am-nav-tabs > li span { color: #888; }
.am-sticky-placeholder .am-nav-tabs > li.am-active span { color: #333; }
.buy-nav-opt span { font-size: 12px; color: #555; }
/* 购买导航 */
.buy-nav-opt a { color: #666; }
.text-active { color: #cf2915 !important; }
@media only screen and (min-width:640px)
{
.theme-span{height:0px;background:#fff ;}
.theme-popover{box-shadow:0 0 10px #666;position:fixed;top:20%;left:calc(50% - 130px);width:260px;bottom:auto;border:solid 2px #e4e4e4;border-radius:5px;}
.theme-popover{box-shadow:0 0 10px #666;position:fixed;top:20%;left:calc(50% - 130px);width:260px;bottom:auto;border:solid 6px #d3d3d3;border-radius:3px;}
.theme-poptit{display: none;}
/*商品规格*/
.theme-signin-left{padding-top:10px ;float: left;max-width:300px;max-height: none;overflow: visible;}
.theme-options .cart-title{margin-top:10px ;}
.theme-options .cart-title{margin-top:5px ;}
.theme-options ul{float: left;}
.theme-signin-left .sku-line {background: none;border-radius:0 ;margin:5px;padding:0px 8px;border:2px solid #F5F5F5 ;color:#333 ;}
@ -87,6 +89,10 @@ input{font-size:12px;font-size:100%;outline:none;line-height:normal;color:#444;}
.btn.close {display:block;float: left;position: static;}
i.theme-login{display: inline-block;}
.btn.confirm { float: right; }
.buy-nav .buy-nav-opt { position: absolute; margin-left: 283px; display: block; }
.buy-nav .buy-nav-opt a { display: none; }
.buy-nav .buy-nav-opt .favor-submit { width: 60px; border: 0; margin-top: 5px; }
}
@media only screen and (min-width:1025px)
@ -175,13 +181,15 @@ flex: 1 1 0%;line-height: 16px;cursor: pointer;}
/*购物车*/
.tb-btn a, .buy-nav li,.buy-nav .buy-nav-opt, .buy-nav span { height: 35px; line-height: 35px; }
.tb-btn a {margin-right: 0px;float: left;overflow: hidden; position: relative;width:100%; background-color: #FFEDED;
color:#F03726;font-size: 14px;text-align: center;}
.tb-btn-basket a {background-color:#F03726;color: #FFF;}
.tb-btn button, .buy-nav li,.buy-nav .buy-nav-opt, .buy-nav span { height: 35px; line-height: 35px; }
.tb-btn button {margin-right: 0px;float: left;overflow: hidden; position: relative;width:100%; background-color: #FFEDED;
color:#F03726;font-size: 14px;text-align: center;border: 0;}
.tb-btn-basket button {background-color:#F03726;color: #FFF;}
.buy-nav li,.buy-nav .buy-nav-opt{float:left; width:33.33%; }
.buy-nav span{display:inline-block;width: 50%;float: left;font-size:14px ; ;cursor: pointer; border-top: 1px solid #f5f5f5;}
.buy-nav .buy-nav-opt, .buy-nav li { float:left; }
.buy-nav .buy-nav-opt { width: 40%; }
.buy-nav li { width: 30%; }
.buy-nav span{display:inline-block;width: 50%;float: left; ;cursor: pointer; border-top: 1px solid #f5f5f5; border-left: 1px solid #f5f5f5;}
.tb-detail-hd h1 {padding-bottom:0.4em; line-height: 1;font-size: 14px;font-weight: 600;color: #333; line-height: 20px;}
@ -265,7 +273,7 @@ li.am-comment{ width:100%}
.scoll img{width:100%; margin-left:0}
.am-comment-main,#J_AttrUL{ text-align:left;}
.tb-r-filter-bar{ margin-top:20px;}
.buy-nav{ position:fixed; bottom:0px;right:0px; z-index:10000;width:100% ;background:#fff ;}
.buy-nav{ position:fixed; bottom:0px;right:0px; z-index:1000;width:100% ;background:#fff ;}
.nav.white,.tip{z-index:999}
@ -306,13 +314,11 @@ li.am-comment{ width:100%}
.tb-detail-hd,.tb-detail-price{text-align: left;}
.tb-detail-price li {margin-left: 0px;}
.tb-detail-hd h1 {font-size: 16px;}
.cart-title.number{margin-top:5px ;}
.match{margin:0px auto;max-width: 1000px;padding-top:20px ;background: #fff;}
/*购物车*/
.tb-btn-buy{margin-left:60px; margin-right:10px;}
.tb-btn a{width:98px ;border: 1px solid #F03726;}
.buy-nav .buy-nav-opt{display:none ;}
.tb-btn-buy{margin-left:50px; margin-right:20px;}
.tb-btn button{width:98px ;border: 1px solid #F03726;}
.buy-nav li{width: auto;}
/*印象*/
@ -368,7 +374,7 @@ li.am-comment{ width:100%}
.theme-options ul{overflow: hidden;float: none;}
.theme-signin-left {max-width:100%;margin-bottom: 0;}
.theme-signin-left .sku-line{margin: 5px;cursor: pointer; padding: 0px 8px; }
.theme-signin-left .cart-title{margin-left: -46px;margin-top:10px;font-size:12px ;font-weight: 100;color:#888 ;float: left;}
.theme-signin-left .cart-title{margin-left: -46px;font-size:12px ;font-weight: 100;color:#888 ;float: left;}
.scoll{display: none;}
.item-inform{max-width:1000px ;margin:0px auto;background:#fff; margin-top: 20px; margin-bottom: 20px;}
@ -420,14 +426,14 @@ li.am-comment{ width:100%}
@media only screen and (max-width:1025px)
{
ul.am-tabs-nav.am-nav.am-nav-tabs { width:100% !important; left: 0px !important; }
.detail { padding: 10px; }
.goods-detail { padding: 10px; }
}
/* 手机模式下 */
@media only screen and (max-width:640px)
{
.nav-search { display: none; }
.detail { padding: 0px; }
.goods-detail { padding: 0px; }
.detail-title, .tb-detail-price, .detail-attr { padding: 0px 5px; }
ul.tm-ind-panel li { border-left: 0px; }
ul.tm-ind-panel li:first-child { text-align: left; }

View File

@ -1,9 +1,121 @@
// 规格弹窗PC显示
function poptit_pc_show()
{
$(document.body).css("position", "static");
$('.theme-signin-left').scrollTop(0);
$('.theme-popover-mask').hide();
$('.theme-popover').slideDown(0);
}
// 规格弹窗关闭
function poptit_close()
{
if($(window).width() < 1010)
{
$(document.body).css("position", "static");
$('.theme-signin-left').scrollTop(0);
$('.theme-popover-mask').hide();
$('.theme-popover').slideUp(100);
}
}
/**
* 购买/加入购物车
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-13
* @desc description
* @param {[object]} e [当前标签对象]
*/
function CartAdd(e)
{
// 参数
var type = e.attr('data-type');
console.log(type)
var stock = $('#text_box').val();
if((stock || 0) <= 0)
{
Prompt('购买数量有误');
return false;
}
// 属性
var attr = {};
var sku_count = $('.sku-items').length;
if(sku_count > 0)
{
var attr_count = $('.sku-line.selected').length;
if(attr_count < sku_count)
{
Prompt('请选择属性');
return false;
} else {
$('.sku-line.selected').each(function(k, v)
{
attr[$(this).data('parent-id')] = $(this).data('id');
});
}
}
// 操作类型
switch(type)
{
// 立即购买
case 'buy' :
console.log('buy', stock, attr);
break;
// 加入购物车
case 'cart' :
// 开启进度条
$.AMUI.progress.start();
var $button = e;
$button.attr('disabled', true);
// ajax请求
$.ajax({
url: e.data('ajax-url'),
type: 'post',
dataType: "json",
timeout: 10000,
data: {"goods_id": $('.goods-detail').data('id'), "stock": stock, "attr": attr},
success: function(result)
{
poptit_close();
$.AMUI.progress.done();
$button.attr('disabled', false);
if(result.code == 0)
{
Prompt(result.msg, 'success');
} else {
Prompt(result.msg);
}
},
error: function(xhr, type)
{
poptit_close();
$.AMUI.progress.done();
$button.attr('disabled', false);
Prompt('网络异常错误');
}
});
break;
// 默认
default :
Prompt('操作参数配置有误');
}
return true;
}
//商品规格选择
$(function() {
$(".theme-options").each(function() {
var i = $(this);
var p = i.find("ul>li");
p.click(function() {
p.on('click', function() {
if (!!$(this).hasClass("selected")) {
$(this).removeClass("selected");
@ -17,30 +129,94 @@ $(function() {
// 放大镜初始化
$(".jqzoom").imagezoom();
$("#thumblist li a").click(function() {
$("#thumblist li a").on('click', function() {
$(this).parents("li").addClass("tb-selected").siblings().removeClass("tb-selected");
$(".jqzoom").attr('src', $(this).find("img").attr("mid"));
$(".jqzoom").attr('rel', $(this).find("img").attr("big"));
});
//弹出规格选择
var $ww = $(window).width();
if ($ww <1025) {
$('.theme-login').click(function() {
$('.theme-login').on('click', function() {
if ($(window).width() < 1010) {
$(document.body).css("position", "fixed");
$('.theme-popover-mask').show();
$('.theme-popover').slideDown(200);
})
} else {
poptit_pc_show();
}
});
$('.theme-poptit .close,.btn-op .close').on('click', function() {
poptit_close();
});
$('.theme-poptit .close,.btn-op .close').click(function() {
$(document.body).css("position", "static");
// 滚动条复位
$('.theme-signin-left').scrollTop(0);
// 购买
$('.buy-submit, .cart-submit').on('click', function()
{
// 是否登录
if(__user_id__ == 0)
{
ModalLoad($('.goods-detail').data('login-url'), '登录');
return false;
}
if($(window).width() >= 1010)
{
CartAdd($(this));
} else {
$('.theme-popover .confirm').attr('data-type', $(this).data('type'));
}
});
// 购买 确认
$('.theme-popover .confirm').on('click', function()
{
if($(window).width() < 1010)
{
CartAdd($(this));
}
});
// 收藏
$('.favor-submit').on('click', function()
{
var $this = $(this);
// 开启进度条
$.AMUI.progress.start();
// ajax请求
$.ajax({
url: $(this).data('ajax-url'),
type: 'post',
dataType: "json",
timeout: 10000,
data: {"goods_id": $('.goods-detail').data('id')},
success: function(result)
{
poptit_close();
$.AMUI.progress.done();
if(result.code == 0)
{
$this.text(' '+result.data.text);
if(result.data.status == 1)
{
$this.addClass('text-active');
} else {
$this.removeClass('text-active');
}
Prompt(result.msg, 'success');
} else {
Prompt(result.msg);
}
},
error: function(xhr, type)
{
poptit_close();
$.AMUI.progress.done();
Prompt('网络异常错误');
}
});
});
$('.theme-popover-mask').hide();
$('.theme-popover').slideUp(200);
})
}
});
// 购买导航动画显示/隐藏
@ -88,7 +264,17 @@ $(window).scroll(function()
}
});
// 浏览器窗口实时事件
$(window).resize(function()
{
// 规格显示/隐藏处理
if($(window).width() < 1010)
{
poptit_close();
} else {
poptit_pc_show();
}
});
$(document).ready(function() {
//获得文本框对象
@ -97,10 +283,18 @@ $(document).ready(function() {
$('#min').attr('disabled', true);
//数量增加操作
$("#add").on('click', function() {
t.val(parseInt(t.val()) + 1)
if (parseInt(t.val()) != 1) {
var stock = parseInt($('.stock-tips .stock').text());
var number = parseInt(t.val());
if(number < stock)
{
t.val(number + 1)
if (parseInt(t.val()) > 1) {
$('#min').attr('disabled', false);
}
} else {
$('#add').attr('disabled', true);
}
});
//数量减少操作
@ -109,7 +303,7 @@ $(document).ready(function() {
if (parseInt(t.val()) == 1) {
$('#min').attr('disabled', true);
}
$('#add').attr('disabled', false);
})
});

File diff suppressed because one or more lines are too long