## 首页
功能:
#### 【显示数据】:
>[info]查询 `yf_good_cat` 商品分类表
/*
分类点击,显示对应的商品
*/
var categoryVue = new Vue({
el:"#category",
data:{
category:[] ,
activeId: '' ,
show: 1
},
/*
初始化分类数据
*/
created:function(){
var this_ = this;
$.get(base_url+"/home/welcome/index",function(rs){
this_.category = rs.data;
},'json')
},
methods: {
/**
* 点分类时
*/
category_change: function (id) {
$(".all_cat").removeClass('active');
var this_ = this;
this_.activeId = id;
productsVue.query.cat_id = id;
load_product(productsVue,'set')
},
all_category:function(){
this.activeId = " ";
$(".all_cat").addClass('active');
var this_ = this;
productsVue.loadPage = 1;
productsVue.products = [];
productsVue.loading = 1;
productsVue.query = {};
productsVue.total = "";
productsVue.show = 1;
productsVue.is_search = 0;
load_product(productsVue,'set')
}
}
});
>[info] 通过 `yf_goods_shop_common`中间表 来查询 `yf_goods_common` 商品数据表 显示商品详情;
/**
加载商品
*/
function load_product(this_ , method){
var query = this_.query;
if(method == 'push'){
++ this_.loadPage;
this_.prev = 1;
}
if(method == 'set'){
this_.loadPage = 1
}
if(method == 'prev'){
--this_.loadPage;
if(this_.loadPage == 1){
this_.prev = 0;
}
}
query.page = this_.loadPage;
console.log('load products method:'+method+" current page:"+this_.loadPage);
$.get(base_url+"/home/welcome/products",query,function(rs){
if(!rs.data || rs.total == this_.loadPage ){
this_.loading = 0;
this_.total = rs.total
}else{
this_.loading = 1
}
this_.products = rs.data;
/*判断此分类下有没有商品*/
if(this_.products == null){
productsVue.active = 1;
}else{
productsVue.active = 0;
}
//扫码枪直接录入产品
if(this_.products){
var i = 0;
$.each(this_.products, function(j){
i++
})
}
if(productsVue.is_search != 1){
if(i==1){
console.log('bind click');
var current_obj = this_.products[0];
this_.click_goods(current_obj);
searchVue.message = '';
}
this_.is_search = 0
}
},'json')
}
#### 【加入购物车】:
>[info]点击商品 把商品拼成数组 加入到右侧 购物车 如果此商品存在 购物车内 再点击 就是增加此商品的数量;
/*
加入购物车
*/
var cartVue = new Vue({
el:"#carts",
data:{
carts:[],
totalPrice:0,
isShow: true
},
created:function(){
var obj = cookie_get_cart();
if(obj){
this.carts = obj
}
},
watch: {
/*
监听carts内容变化
有变化写COOKIE
*/
carts:function(obj){
cookie_set_cart(obj)
}
},
methods:{
add:function(obj){
console.log(obj)
productsVueSet( obj , 'add' )
},
reduce:function(obj){
productsVueSet( obj , 'reduce')
},
change: function(obj){
if(obj.number>0){
if(parseInt(obj.number)>=parseInt(obj.common_stock)){
obj.number = obj.common_stock;
Public.tips.error('购买数量不能超过库存');
}
productsVueSet(obj,obj.number)
}
}
}
});
#### 【删除购物车商品】:
>[info]当购物车商品数量为1的时候 再点击 “-” 从购物车中删除此商品
也可点击 扫把 图标 直接清除购物车中所有商品 ;
/*
清空购物车
*/
var clearCatVue = new Vue({
el:"#clearCat",
methods:{
sure:function(){
var cart = cookie_get_cart();
if(cart['length']==0){
Public.tips.error('没有可删除的商品');
return false;
}
clearCat();
$('#clearCat').fadeOut()
},
close:function(){
$('#clearCat').fadeOut()
}
}
});
>[info]区别:直接清空数组 清空数组中指定数据
#### 【挂单】:
>[info]存入缓存 设置过期时间
1)、商品加入右侧购物车内 暂不结账时 可点击挂单 必须有商品才可以挂单 输入挂单备注信息 挂单成功 挂单列表显示红点 结账后或三小时后 消失。
>[info]2)、挂单列表可根据挂单备注信息 进行搜索 相应的挂单信息
/*
* 挂单
*/
var gdVue = new Vue({
el:"#confirm",
data:{
message : ''
},
methods:{
keyups: function(){
if(!/^.{0,20}$/.test(this.message)){
Public.tips.error('挂单备注限制在20个字符以内');
this.message='';
}
},
close: function() {
$('#confirm').hide();
},
sure: function(){
var cart = cookie_get_cart();
if(cart==''){
Public.tips.error('请选择商品');
return false;
}else{
$('.red').addClass('icon-dot');
}
if(this.message == ''){
Public.tips.error('请输入挂单信息');
return false;
}
var guadan = get_cache('guadan');
var message = get_cache('message');
var user = get_cache('user');
var carts = get_cache(user+"_carts");
var price = totalPrice(carts);
allVue.totalNum = totalNum(carts);
allVue.totalPrice = price;
if(!guadan) guadan = [];
if(!message)message = [];
if(guadan.toString().indexOf(user) == -1) {
if(!carts)carts = [];
message.unshift(this.message);
guadan.unshift(user);
if(!orderVue.orderList){
orderVue.orderList = [];
orderVue.priceList = [];
orderVue.goodsList = [];
}
orderVue.orderList.unshift(user);
orderVue.priceList.unshift(price);
orderVue.goodsList.unshift(carts);
orderVue.messageList = message;
} else {
for(var j in guadan) {
if(guadan[j] == user ) {
Vue.set(orderVue.messageList, j, this.message);
Vue.set(orderVue.goodsList, j, carts);
Vue.set(orderVue.priceList, j, price);
}
}
}
set_cache('guadan', guadan);
set_cache('message', orderVue.messageList);
clearCat('gd');
set_cache('user', new Date().toLocaleString());
$('#confirm').hide();
this.message = '';
}
}
});
#### 【搜索商品】:
/*
搜索
*/
var searchVue = new Vue({
el:"#search",
data:{
message:''
},
methods: {
keydown: function (ev) {
if(!orderVue.show){
productsVue.is_search = 0;
}
},
del: function(){
this.message='';
}
},
watch: {
/*
监听serach内容变化
*/
message:function(wq){
if(!orderVue.show){
productsVue.query.wq = wq;
productsVue.is_search = 1;
load_product(productsVue,'set')
}else{
gdSearch(this.message);
}
}
}
});
#### 【搜索会员】:
>[info]通过 `wp_users_discount`关联 `wp_users` 会员表
模糊查询 出 要搜索的 会员卡号和手机号
1)、点击左侧结账区域【点击选择会员】按钮,右侧跳转【搜索会员】页面;通过输入手机号码、会员名称,进行搜索。
2)、搜索会员有折扣并且折扣未开启状态 则可以享受折扣
/*
搜索会员
*/
var searchUserVue = new Vue({
el:"#searchUser",
data:{
search_user:'',
show: 0,
users:{ },
infos:{ },
ulist:{ },
zkname:' ',
} ,
methods: {
click: function(){
var this_ = this;
$('.zhekou').css('display','none');
var wq = $('#code').val();
if(!wq){
Public.tips.error('请输入正确的会员信息进行查询');
return false;
}
$.get(base_url+"/home/user_search/index",{wq:wq},function(rs){
if(!rs.data){
Public.tips.error( "搜索的会员不存在");
}
this_.users = rs.data;
var Swipersearch = new Swiper('.swiper-container4', {
scrollbar: '.swiper-scrollbar4',
direction: 'vertical',
slidesPerView: 'auto',
slidesPerView:5,
mousewheelControl: true,
freeMode: true,
initialSlide :0,
observer:true,//修改swiper自己或子元素时,自动初始化
observeParents:true//修改swiper的父元素时,自动初始化swiper
});
},'json')
},
confirm: function(userId,ucname){
this.zkname = ucname;
$('.zhekou').css('display','block');
var this_ = this;
$.get(base_url+"/home/user_search/infos",{userId:userId},function(rs){
if(!rs.data){
Public.tips.error( "此会员暂无折扣");
}
this_.infos = rs.data;
},'json')
var user = get_cache('user');
var cart = get_cache(user + '_carts');
set_cache(user + '_carts', null);
set_cache('user' , "user_"+userId);
set_cache('user_' + userId +'_carts', cart);
},
zhekou:function(discount,status){
if(status == 0){
lessVue.disc = 0 ;
set_cache('discount_status',0);
}else{
if(discount != 0){
set_cache('discount_status',1);
lessVue.disc = discount;
$('.less').css('display','block')
}
}
controlVue.show = 0;
this.show = 0;
$('#leftProduct').show();
$('#searchUser').hide();
},
retu:function(){
controlVue.show = 0;
this.show = 0;
$('#leftProduct').show();
$('#searchUser').hide();
}
}
});
#### 【功能菜单】:
>[info]1)会员管理:新增会员/编辑会员资料
>[info]2)交接班记录:收银员的交接班记录
>[info]3)退货处理:门店规定要求内进行退货处理。
>[info]4)小票扫码订单:通过扫描小票上的二维码进行支付。
>[info]5)关于我们:系统版本信息。
/**
* 导航栏
*/
var slideVue = new Vue({
el: '#slide',
data:{
active:0
},
methods: {
slide: function(obj){
this.active = obj;
var url = '';
switch(obj)
{
case 1:
url = '/home/welcome/member';
break;
case 2:
url = '/home/welcome/shift';
break;
case 3:
url = '/home/welcome/equipment';
break;
case 4:
url = '/home/welcome/return_products';
break;
case 5:
url = '/home/welcome/ticket';
break;
case 6:
url = '/home/welcome/logo';
break;
}
$.ajax({
type: 'GET',
url: base_url+ url,
data: {},
dataType: "json",
success: function(data) {
if(data.status) {
$(" body").html(data.html);
}
}
});
}
}
});
#### 【结算】:
>[info]1、支付方式包含:
1)现金支付
2)支付宝支付:扫码
3)微信支付:扫码
4)银联POS支付
5)小票扫码支付
>[info]实收金额 必须填写 且不能小于应收金额
/*
* 结算
*/
var countVue = new Vue({
el:"#count",
data:{
num:0,
price:0
},
methods: {
total: function(){
var cart = cookie_get_cart();
if(!cart) {
Public.tips.error('请选择商品');
return false;
}
this.num = totalNum(cart);
this.price = totalPrice(cart);
var that = this;
var user = get_cache('user');
var discount_status = get_cache('discount_status');
var goods = [];
for (var i in cart) {
var carts = [];
carts.push(cart[i].id);
carts.push(cart[i].number);
goods[i] = carts;
}
var prices = that.price.toFixed(2);
$.ajax({
type: "POST",
url: base_url+"/home/welcome/pay",
data: {user:user,discount_status:discount_status, goods:goods, price: prices, type:'common'},
dataType: "json",
success: function(data) {
if(data.status) {
$(" body").html(data.html);
}
}
});
}
}
});
#### 【作废】:
>[info]删除此订单数组
点击作废 弹出提示框
点击确定 返回首页
点击取消 弹出框消失 继续操作结算
/*
* 弹出框
*/
abolish: function() {
this.cancel = 1;
},
/**
* 作废订单
*/
sure: function() {
if(this.type == 'ticket'){
Public.tips.error('小票订单无法作废');
return false;
}
var user = get_cache('user');
cookie_clear();
payVue.back();
},
/**
* 取消作废
*/
not_sure: function() {
this.cancel = 0;
},
#### 【完成结算】:
>[info]生成订单 插入到 `wp_order`
>[info]完成结算 生成小票 订单结束
>[info]点击打印小票 打印机打印小票
>[info]点击继续收银 回到首页继续收银
/**
* 完成结算
*/
total: function() {
var obj = this.show;
this.way = 'ok';
if(!this.actual && obj == <?php echo config('payment.cash');?>) {
Public.tips.error('请输入实收金额');
return false;
}
if(parseFloat(this.actual) < parseFloat(this.price) && obj == "<?php echo config('payment.cash');?>") {
Public.tips.error('实收金额需大于等于订单金额');
return false;
}
var that = this;
if(obj != <?php echo config('payment.cash');?> ){
that.actual = '';
}
if(this.type == 'common'){
var user = get_cache('user');
var discount_status = get_cache('discount_status');
var carts = get_cache(user+ '_carts');
var goods = [];
for (var i in carts) {
var cart = [];
cart.push(carts[i].id);
cart.push(carts[i].number);
goods[i] = cart;
}
$.ajax({
type: "POST",
url: base_url+"/home/welcome/settlement",
data: {user:user,discount_status:discount_status, type:obj, goods:goods, price:that.price,return_price:this.give, actual:that.actual, num:that.num, kind:'common',order_id:that.order_id },
dataType: "json",
success: function(data) {
if(data.status) {
cookie_clear();
common(that.order_id);
}
}
});
} else {
$.ajax({
type: "POST",
url: base_url+"/home/welcome/settlement",
data: {type:obj, price:that.price, actual:that.actual, num:that.num,order_id:that.order_id, kind:'ticket'},
dataType: "json",
success: function(data)
{
if (data.status)
{
common(that.order_id);
}
}
});
}
},