作者 王晓刚
1 个管道 的构建 通过 耗费 32 秒

搜索页

... ... @@ -187,4 +187,14 @@ if(!function_exists('time_tran')){
}
}
}
}
if(!function_exists('getLocation')){
function getLocation(){
$ip = "111.164.175.116";//request()->ip(0, false);
$url = "http://api.map.baidu.com/location/ip?ak=lu7CH9ucr6STjUk1GQgkfzjhpHbb7hPd&ip=$ip&coor=bd09ll";
$data = \fast\Http::get($url);
$data = json_decode($data,true);
return $data;
}
}
\ No newline at end of file
... ...
... ... @@ -13,9 +13,15 @@ use app\common\controller\HomeBase;
use app\index\model\Evaluate;
use app\index\model\Goodstype;
use app\index\model\Pic;
use app\index\model\Province;
use app\index\model\Store;
class Goods extends HomeBase
{
/**
* 采购中心页面
* @return mixed
*/
public function index(){
//获取分类
$goodstypeModel = new Goodstype();
... ... @@ -27,18 +33,18 @@ class Goods extends HomeBase
//幻灯片
$picModel = new Pic();
$slide = $picModel->selectData([]);
$goodsModel = new \app\index\model\Goods();
//特价清仓
$clearance_goods = $goodsModel->selectData(['is_clearance'=>1]);
//产品热卖
$goods = $goodsModel->selectPageData([],18);
$this->assign('goodstype_one',$goodstype_one);
$this->assign('slide',$slide);
$this->assign('clearance_goods',$clearance_goods);
$this->assign('goods',$goods);
$this->assign('clearance_goods',[]);
$this->assign('goods',[]);
$this->assign('title','采购中心');
return $this->fetch();
}
/**
* 商品详情页
* @return mixed
*/
public function detail(){
$goods_id = $this->request->param('goods_id',0,'intval');
if(empty($goods_id)){
... ... @@ -82,6 +88,10 @@ class Goods extends HomeBase
return $this->fetch();
}
/**
* 产品热卖商品列表页面
* @return mixed
*/
public function goods_list(){
//获取分类
$goodstypeModel = new Goodstype();
... ... @@ -99,8 +109,102 @@ class Goods extends HomeBase
return $this->fetch();
}
/**
* 搜索结果页面
* @return mixed
*/
public function search(){
$keyword = $this->request->param('keyword');
$this->assign('keyword',$keyword);
$this->assign('title','搜索');
return $this->fetch();
}
public function get_all(){
$param = $this->request->param();
$where['g.status'] = ['eq','1'];
if(!empty($param['province_id'])){
$storeModel = new Store();
$store = $storeModel->selectData(['province_ids'=>['like',"%,$param[province_id],%"]]);
$store_ids = [];
foreach($store as $key => $s){
$store_ids[] = $s['id'];
}
$where['g.store_id'] = ['in',$store_ids];
}
if(!empty($param['is_clearance'])){
$where['g.is_clearance'] = ['eq',$param['is_clearance']];
}
if(!empty($param['keyword'])){
$where['t.name|s.name|g.goodsname|g.brand'] = ['like',"%$param[keyword]%"];
}
$order = 'g.weigh desc';
if(!empty($param['sort'])){
if($param['sort'] == 1){
//销量降序
$order = "g.sale desc";
}else if($param['sort'] == 2){
//评分降序
$order = "";
}else if($param['sort'] == 3){
//发布时间降序
$order = "g.createtime desc";
}else if($param['sort'] == 4){
//库存降序
$order = "g.inventory desc";
}else if($param['sort'] == 5){
//价格升序
$order = "g.price asc";
}else if($param['sort'] == 6){
//价格降序
$order = "g.price desc";
}else if($param['sort'] == 7){
//店铺属性筛选
$where['s.property'] = ['like',"%供应商%"];
}else if($param['sort'] == 8){
//店铺属性筛选
$where['s.property'] = ['like',"%一级代理%"];
}else if($param['sort'] == 9){
//店铺属性筛选
$where['s.property'] = ['like',"%厂家直销%"];
}
}
$goodsModel = new \app\index\model\Goods();
$data = $goodsModel
->alias('g')
->field('g.*,t.name as goodstype_name,s.name as store_name,s.address as store_address,s.property,s.type,s.content as store_content,s.thumbnail as store_thumbnail,s.money as store_money')
->join('sto_goodstype t','t.id = g.goodstype_id')
->join('sto_store s','s.id = g.store_id')
->where($where)
->order($order);
if(!empty($param['paginate'])){
$data = $data->paginate($param['pageNum'],'',['page'=>$param['page']]);
}else{
$data = $data->select();
}
$storeModel = new Store();
$evaluateModel = new Evaluate();
foreach($data as $key => $vo){
$insurance = '2';
$store = $storeModel->findData(['id'=>$vo['store_id']]);
if($store['is_vip'] == '1' && $store['is_svip'] == '1'){
$insurance = '1';
}
$data[$key]['store_is_vip'] = $store['is_vip'];
$data[$key]['store_ids_svip'] = $store['is_svip'];
$data[$key]['insurance'] = $insurance;
//计算平均分
$score_count = $evaluateModel->where(['goods_id'=>$vo['id']])->count();
$score_sum = $evaluateModel->where(['goods_id'=>$vo['id']])->sum('level');
$average_score = !empty($score_sum) ? round($score_sum/$score_count,2) : 0;
$data[$key]['average_score'] = $average_score;
}
if(!empty($param['sort'])){
if($param['sort'] == 2){
$sort = array_column($data->items(),"average_score");
array_multisort($sort,SORT_DESC,$data->items());
}
}
$this->success('SUCCESS','',$data);
}
}
\ No newline at end of file
... ...
... ... @@ -10,6 +10,7 @@ namespace app\index\controller;
use app\common\controller\HomeBase;
use app\index\model\Province;
use fast\Http;
/**
... ... @@ -23,7 +24,7 @@ class Sundry extends HomeBase
* 关键字输入提示
*/
public function get_address(){
$keyword = $this->request->param('keyword','壹江城');
$keyword = $this->request->param('keyword');
if(empty($keyword)){
$this->error('缺少必要参数');
}
... ... @@ -37,4 +38,17 @@ class Sundry extends HomeBase
$data['list'] = $result['data'];
$this->success('SUCCESS','',$data);
}
/**
* 省份名称转换id
*/
public function get_province_id(){
$province_name = $this->request->param('province_name');
if(empty($province_name)){
$this->error('缺少必要参数');
}
$provinceModel = new Province();
$province_id = $provinceModel->where(['name'=>$province_name])->value('id');
$this->success('SUCCESS','',['province_id'=>$province_id]);
}
}
\ No newline at end of file
... ...
... ... @@ -17,10 +17,10 @@ class Test extends HomeBase
{
public function index(){
$ip = request()->ip(0, false);
dump($ip);
$url = "http://api.map.baidu.com/location/ip?ak=lu7CH9ucr6STjUk1GQgkfzjhpHbb7hPd&ip=$ip&coor=bd09ll";
$result = Http::get($url);
dump(json_decode($result));
$data = Http::get($url);
$data = json_decode($data,true);
return $data;
return $this->fetch();
}
}
\ No newline at end of file
... ...
... ... @@ -30,6 +30,17 @@ class Goods extends Model
->where($where)
->order('weigh desc')
->select();
$storeModel = new Store();
foreach($data as $key => $vo){
$insurance = '2';
$store = $storeModel->findData(['id'=>$vo['store_id']]);
if($store['is_vip'] == '1' && $store['is_svip'] == '1'){
$insurance = '1';
}
$data[$key]['store_is_vip'] = $store['is_vip'];
$data[$key]['store_ids_svip'] = $store['is_svip'];
$data[$key]['insurance'] = $insurance;
}
return $data;
}
public function selectPageData($where,$pageNum){
... ... @@ -42,6 +53,17 @@ class Goods extends Model
->where($where)
->order('weigh desc')
->paginate($pageNum);
$storeModel = new Store();
foreach($data as $key => $vo){
$insurance = '2';//保险logo
$store = $storeModel->findData(['id'=>$vo['store_id']]);
if($store['is_vip'] == '1' && $store['is_svip'] == '1'){
$insurance = '1';
}
$data[$key]['store_is_vip'] = $store['is_vip'];
$data[$key]['store_ids_svip'] = $store['is_svip'];
$data[$key]['insurance'] = $insurance;
}
return $data;
}
public function findData($where){
... ... @@ -52,6 +74,15 @@ class Goods extends Model
->join('sto_store s','s.id = g.store_id')
->where($where)
->find();
$storeModel = new Store();
$insurance = '2';//保险logo
$store = $storeModel->findData(['id'=>$data['store_id']]);
if($store['is_vip'] == '1' && $store['is_svip'] == '1'){
$insurance = '1';
}
$data['store_is_vip'] = $store['is_vip'];
$data['store_ids_svip'] = $store['is_svip'];
$data['insurance'] = $insurance;
return $data;
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/5/8
* Time: 13:24
*/
namespace app\index\model;
use think\Model;
class Store extends Model
{
public function selectData($where){
$data = $this->where($where)->select();
foreach($data as $key => $vo){
//判断是否为会员
$is_vip = '2';
if(!empty($vo['vip_pasttime'])){
if($vo['vip_pasttime'] > time()){
$is_vip = "1";
}
}
$is_svip = '2';
if(!empty($vo['svip_passtime'])){
if($vo['svip_passtime'] > time()){
$is_svip = "1";
}
}
$data[$key]['is_vip'] = $is_vip;
$data[$key]['is_svip'] = $is_svip;
}
return $data;
}
public function findData($where){
$data = $this->where($where)->find();
//判断是否为会员
$is_vip = '2';
if(!empty($data['vip_pasttime'])){
if($data['vip_pasttime'] > time()){
$is_vip = "1";
}
}
$is_svip = '2';
if(!empty($data['svip_passtime'])){
if($data['svip_passtime'] > time()){
$is_svip = "1";
}
}
$data['is_vip'] = $is_vip;
$data['is_svip'] = $is_svip;
return $data;
}
}
\ No newline at end of file
... ...
... ... @@ -38,4 +38,9 @@ class User extends Model
$result = $this->insertGetId($data);
return $result;
}
public function selectData($where){
$where['status'] = ['eq',"normal"];
$data = $this->where($where)->select();
return $data;
}
}
\ No newline at end of file
... ...
... ... @@ -178,7 +178,7 @@
position: relative;
display: inline-block;
width: 182px;
height: 301px;
/*height: 301px;*/
margin-right: 10px;
}
.content .bestSellersBox .bestSellersMain .bestSellersList .commodityBox a .insurance_icon{
... ... @@ -220,7 +220,7 @@
}
.content .bestSellersBox .bestSellersMain .bestSellersList .commodityBox .commodityName{
width: 100%;
height: 42px;
/*height: 42px;*/
line-height: 21px;
margin: 0 0 4px 0;
text-align: left;
... ... @@ -382,8 +382,8 @@
<span></span>
<span>采购中心 > 产品热卖</span>
</div>
<div class="bestSellersList">
<div class="commodityBox">
<div class="bestSellersList goods_dom">
<!--<div class="commodityBox">
<a href="commodityDetail.html?commodityId=1">
<div class="imgBox">
<img src="__CDN__/assets/store/images/commodity.png" alt="img">
... ... @@ -397,7 +397,7 @@
</div>
<img class="insurance_icon" src="__CDN__/assets/store/images/insurance_icon.png" alt="img">
</a>
</div>
</div>-->
</div>
<div class="pagingBox">
<div class="paginationMyOrder" id="paginationAllOrder">
... ... @@ -408,12 +408,52 @@
</div>
</div>
{include file="public/footer"/}
{include file="public/js"/}
<script>
$(function () {
initBanner();//初始化轮播图
initPaging();//初始化分页
initLocation();//获取定位信息
});
//定位当前位置
function initLocation(){
// 百度地图API功能
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);
map.centerAndZoom(point,12);
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r){
if(this.getStatus() == BMAP_STATUS_SUCCESS){
var mk = new BMap.Marker(r.point);
map.addOverlay(mk);
map.panTo(r.point);
//省份名称转换为id
$.ajax({
url:"{:url('index/sundry/get_province_id')}",
type:"POST",
data:{"province_name":r.address.province},
async:false,
success:function(res){
if(res.code == 1){
province_id = res.data.province_id;
lng = r.point.lng;
lat = r.point.lat;
//初始化产品热卖
initGoodsList();
}else{
toast(res.msg);
}
},
error:function(res){
toast('与服务器断开连接');
}
});
} else {
toast('failed'+this.getStatus());
}
},{enableHighAccuracy: true})
}
//加载轮播图
function initBanner() {
var mySwiper = new Swiper('#banner-container', {
... ... @@ -422,15 +462,64 @@
})
}
//初始化商品列表
function initGoodsList(page = 1, pageNum = 18){
$.ajax({
url:"{:url('index/goods/get_all')}",
type:"POST",
data:{"province_id":province_id,"page":page,"pageNum":pageNum,'paginate':1},
success:function(res){
console.log(res);
var goods_html = "";
$(res.data.data).each(function (key1, vo) {
var property = "";
$(vo.property).each(function (key2, p) {
property += "<span>"+p+"</span>";
});
var insurance = "<img class=\"insurance_icon\" src=\"__CDN__/assets/store/images/insurance_icon.png\" alt=\"img\">";
if(vo.insurance == '1'){
insurance = "";
}
var str = "<div class=\"commodityBox\">\n" +
" <a href=\"{:url('index/goods/detail',array('goods_id'=>'GOODS_ID'))}\">\n" +
" <div class=\"imgBox\">\n" +
" <img src=\""+vo.thumbnail+"\" alt=\"img\">\n" +
" <span>"+vo.store_name+"</span>\n" +
" </div>\n" +
" <p class=\"commodityPrice\">¥"+vo.price+"</p>\n" +
" <p class=\"commodityName\">"+vo.goodsname+"</p>\n" +
" <div class=\"labelBox\">\n" +
" "+property+"\n" +
" </div>\n" +
" "+insurance+"\n" +
" </a>\n" +
" </div>";
goods_html += str.replace("GOODS_ID",vo.id);
});
$('.goods_dom').html(goods_html);
//初始化分页
var totalPage = Math.ceil(res.data.total/pageNum);
initPaging(res.data.total,res.data.current_page,totalPage,pageNum);
},
error:function(res){
toast('与服务器断开连接');
}
});
}
//初始化分页
function initPaging() {
function initPaging(totalSize = 0, current_page = 1, totalPage = 0, pageNum, showPageNum = 5) {
$("#paginationAllOrder").whjPaging({
//每页显示数据条数
pageNum: pageNum,
//当前页
current_page: current_page,
//可选,总条数
totalSize: 90,
totalSize: totalSize,
//可选,总页数
totalPage: 18,
totalPage: totalPage,
//可选,展示页码数量,默认5个页码数量
showPageNum: 5,
showPageNum: showPageNum,
//可选,css设置,可设置值:css-1,css-2,css-3,css-4,css-5,默认css-1,可自定义样式
css: 'css-1',
//可选,上一页按钮展示文本,默认显示文本为上一页
... ... @@ -454,6 +543,7 @@
//必选,回掉函数,返回参数:第一个参数为页码,第二个参数为每页显示N条
callBack: function (currPage, pageSize) {
console.log('currPage:' + currPage + ' pageSize:' + pageSize);
initGoodsList(currPage, pageSize)
}
});
}
... ...
... ... @@ -406,7 +406,7 @@
</div>
<div class="clearanceList">
<div id="clearanceList-container" class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-wrapper clearance_goods_dom">
{foreach name="$clearance_goods" item="c_g"}
<div class="swiper-slide">
<a href="{:url('index/goods/detail',array('goods_id'=>$c_g.id))}">
... ... @@ -436,7 +436,7 @@
<span>产品热卖</span>
<a class="moreBtn" href="{:url('index/goods/goods_list')}">更多 ></a>
</div>
<div class="bestSellersList">
<div class="bestSellersList goods_dom">
{foreach name="$goods" item="g"}
<div class="commodityBox">
<a href="{:url('index/goods/detail',array('goods_id'=>$g.id))}">
... ... @@ -464,9 +464,50 @@
<script>
$(function () {
initBanner(); //初始化轮播图
initClearanceList(); //初始化清仓列表
initLocation();//获取定位信息
});
//定位当前位置
function initLocation(){
// 百度地图API功能
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);
map.centerAndZoom(point,12);
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r){
if(this.getStatus() == BMAP_STATUS_SUCCESS){
var mk = new BMap.Marker(r.point);
map.addOverlay(mk);
map.panTo(r.point);
//省份名称转换为id
$.ajax({
url:"{:url('index/sundry/get_province_id')}",
type:"POST",
data:{"province_name":r.address.province},
async:false,
success:function(res){
if(res.code == 1){
province_id = res.data.province_id;
lng = r.point.lng;
lat = r.point.lat;
//初始化清仓列表
initClearanceList();
//初始化产品热卖
initGoodsList();
}else{
toast(res.msg);
}
},
error:function(res){
toast('与服务器断开连接');
}
});
} else {
toast('failed'+this.getStatus());
}
},{enableHighAccuracy: true})
}
//加载轮播图
function initBanner() {
var mySwiper = new Swiper('#banner-container', {
... ... @@ -477,14 +518,83 @@
//加载清仓列表
function initClearanceList() {
var myClearance = new Swiper('#clearanceList-container', {
loop: true,
slidesPerView: 6,
autoplay: 3000,
// 前进后退按钮
nextButton: '#clearanceList-button-next',
prevButton: '#clearanceList-button-prev',
})
$.ajax({
url:"{:url('index/goods/get_all')}",
type:"POST",
data:{"province_id":province_id,'is_clearance':1},
success:function(res){
console.log(res);
var clearance_goods_html = "";
$(res.data).each(function (key, vo) {
var str = "<div class=\"swiper-slide\">\n" +
" <a href=\"{:url('index/goods/detail',array('goods_id'=>'GOODS_ID'))}\">\n" +
" <img src=\""+vo.thumbnail+"\" alt=\"img\">\n" +
" <p class=\"commodityTitle\">"+vo.goodsname+"</p>\n" +
" <div class=\"priceBox\">\n" +
" <p class=\"presentPrice\">¥"+vo.price+"</p>\n" +
" <p class=\"originalPrice\">¥"+vo.lineation+"</p>\n" +
" </div>\n" +
" </a>\n" +
" </div>";
clearance_goods_html += str.replace("GOODS_ID",vo.id);
});
$('.clearance_goods_dom').html(clearance_goods_html);
//初始化swiper
var myClearance = new Swiper('#clearanceList-container', {
loop: false,
slidesPerView: 6,
autoplay: 3000,
//前进后退按钮
nextButton: '#clearanceList-button-next',
prevButton: '#clearanceList-button-prev',
})
},
error:function(res){
toast('与服务器断开连接');
}
});
}
//初始化商品列表
function initGoodsList(){
$.ajax({
url:"{:url('index/goods/get_all')}",
type:"POST",
data:{"province_id":province_id},
success:function(res){
console.log(res);
var goods_html = "";
$(res.data).each(function (key1, vo) {
var property = "";
$(vo.property).each(function (key2, p) {
property += "<span>"+p+"</span>";
});
var insurance = "<img class=\"insurance_icon\" src=\"__CDN__/assets/store/images/insurance_icon.png\" alt=\"img\">";
if(vo.insurance == '1'){
insurance = ""
}
var str = "<div class=\"commodityBox\">\n" +
" <a href=\"{:url('index/goods/detail',array('goods_id'=>'GOODS_ID'))}\">\n" +
" <div class=\"imgBox\">\n" +
" <img src=\""+vo.thumbnail+"\" alt=\"img\">\n" +
" <span>"+vo.store_name+"</span>\n" +
" </div>\n" +
" <p class=\"commodityPrice\">¥"+vo.price+"</p>\n" +
" <p class=\"commodityName\">"+vo.goodsname+"</p>\n" +
" <div class=\"labelBox\">\n" +
" "+property+"\n" +
" </div>\n" +
" "+insurance+"\n" +
" </a>\n" +
" </div>";
goods_html += str.replace("GOODS_ID",vo.id);
});
$('.goods_dom').html(goods_html);
},
error:function(res){
toast('与服务器断开连接');
}
});
}
//打开二级悬浮导航
... ...
... ... @@ -83,6 +83,9 @@
border-radius: 0 8px 8px 0;
}
.content .contentMain #tableBox .tableButtons{
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
}
.content .contentMain #tableBox .tableButtons button{
... ... @@ -96,6 +99,9 @@
font-family: PingFang SC;
font-weight: 400;
color: rgba(4, 17, 33, 1);
display: flex;
justify-content: space-between;
align-items: center;
}
.content .contentMain #tableBox .tableButtons .dropdown{
display: inline-block;
... ... @@ -506,11 +512,11 @@
<div class="locationBox">
<img src="__CDN__/assets/store/images/location_fill.png" alt="">
<p class="title">当前区域</p>
<p id="locationText">天津市河东区大直沽西路</p>
<p id="locationText"></p>
</div>
<!--搜索框-->
<div class="searchBox">
<input id="searchVal" type="text" class="search form-control" placeholder="请输入型号、参数查找元器件" />
<input id="searchVal" type="text" class="search form-control" placeholder="请输入型号、参数查找元器件" value="{$keyword}"/>
<span class="input-group-btn">
<button class="btn" onclick="searchData()">
<img src="__CDN__/assets/store/images/search.png" alt="user">
... ... @@ -523,44 +529,48 @@
<!--搜索结果表格-->
<div id="tableBox">
<div class="tableButtons">
<button class="btn activeBtn" onclick="sortSearch(this, 'salesVolume')">
销量
<img src="__CDN__/assets/store/images/dropDwon_select.png" alt="">
<button class="btn" data-sort="1" onclick="sortSearch(this, 'salesVolume')">
<div>销量</div>
<div style="width: 18px;">
<img src="__CDN__/assets/store/images/dropDwon.png" alt="">
</div>
</button>
<button class="btn" onclick="sortSearch(this, 'score')">
评分
<img src="__CDN__/assets/store/images/dropDwon.png" alt="">
<button class="btn" data-sort="2" onclick="sortSearch(this, 'score')">
<div>评分</div>
<div style="width: 18px;"><img src="__CDN__/assets/store/images/dropDwon.png" alt=""></div>
</button>
<button class="btn" onclick="sortSearch(this, 'releaseTime')">
发布时间
<img src="__CDN__/assets/store/images/dropDwon.png" alt="">
<button class="btn" data-sort="3" onclick="sortSearch(this, 'releaseTime')">
<div>发布时间</div>
<div style="width: 18px;"><img src="__CDN__/assets/store/images/dropDwon.png" alt=""></div>
</button>
<button class="btn" onclick="sortSearch(this, 'stock')">
库存
<img src="__CDN__/assets/store/images/dropDwon.png" alt="">
<button class="btn" data-sort="4" onclick="sortSearch(this, 'stock')">
<div>库存</div>
<div style="width: 18px;"><img src="__CDN__/assets/store/images/dropDwon.png" alt=""></div>
</button>
<button class="btn priceBtn" onclick="sortSearch(this, 'price')">
价格
<img src="__CDN__/assets/store/images/dropDwon_up.png" alt="">
<img src="__CDN__/assets/store/images/dropDwon.png" alt="">
<button class="btn priceBtn" data-sort="0" onclick="sortSearch(this, 'price')">
<div>价格</div>
<div style="display: flex;flex-direction: column;align-items: center;height: 18px;width: 30px">
<img src="__CDN__/assets/store/images/dropDwon_up.png" alt="">
<img src="__CDN__/assets/store/images/dropDwon.png" alt="">
</div>
</button>
<div class="dropdown dropdownBtn">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<span class="distributorName">全部商家</span>
<span class="caret"></span>
<button class="btn btn-default dropdown-toggle activeBtn" data-sort="0" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<div><span class="distributorName">全部商家</span></div>
<div style="width: 18px;"><span class="caret"></span></div>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a href="#" onclick="selectDistributor(this)">全部商家</a></li>
<li><a href="#" data-sort="0" onclick="selectDistributor(this)">全部商家</a></li>
<li role="separator" class="divider"></li>
<li><a href="#" onclick="selectDistributor(this)">供应商</a></li>
<li><a href="#" data-sort="7" onclick="selectDistributor(this)">供应商</a></li>
<li role="separator" class="divider"></li>
<li><a href="#" onclick="selectDistributor(this)">一级代理</a></li>
<li><a href="#" data-sort="8" onclick="selectDistributor(this)">一级代理</a></li>
<li role="separator" class="divider"></li>
<li><a href="#" onclick="selectDistributor(this)">厂家直销</a></li>
<li><a href="#" data-sort="9" onclick="selectDistributor(this)">厂家直销</a></li>
</ul>
</div>
<p>
为你找到<span id="resultsNum">5999</span>相关商品
为你找到<span id="resultsNum">0</span>相关商品
</p>
</div>
... ... @@ -587,137 +597,17 @@
</tr>
</thead>
<tbody>
<tr>
<td width="54px">1</td>
<td width="100px"><img src="__CDN__/assets/store/images/tableImg.png" alt=""></td>
<td width="180px">TOGIALED(统佳)
TJ-L3FYTSARMFCSFLX2R-A5
发光二极管 DIP 红发红</td>
<td width="102px">80000</td>
<td width="102px">buerklin<span class="myLable">厂家直销</span></td>
<td width="140px">TOGIALED(统佳)</td>
<td width="128px">单价:¥0.0675</td>
<td width="131px">天津市河东区
大直沽西路(10km)</td>
</tr>
<tr>
<td width="54px">2</td>
<td width="100px"><img src="__CDN__/assets/store/images/tableImg.png" alt=""></td>
<td width="180px">TOGIALED(统佳)
TJ-L3FYTSARMFCSFLX2R-A5
发光二极管 DIP 红发红</td>
<td width="102px">80000</td>
<td width="102px">buerklin<span class="myLable">厂家直销</span></td>
<td width="140px">TOGIALED(统佳)</td>
<td width="128px">单价:¥0.0675</td>
<td width="131px">天津市河东区
大直沽西路(10km)</td>
</tr>
<tr>
<td width="54px">3</td>
<td width="100px"><img src="__CDN__/assets/store/images/tableImg.png" alt=""></td>
<td width="180px">TOGIALED(统佳)
TJ-L3FYTSARMFCSFLX2R-A5
发光二极管 DIP 红发红</td>
<td width="102px">80000</td>
<td width="102px">buerklin<span class="myLable">厂家直销</span></td>
<td width="140px">TOGIALED(统佳)</td>
<td width="128px">单价:¥0.0675</td>
<td width="131px">天津市河东区
大直沽西路(10km)</td>
</tr>
<tr>
<td width="54px">4</td>
<td width="100px"><img src="__CDN__/assets/store/images/tableImg.png" alt=""></td>
<td width="180px">TOGIALED(统佳)
TJ-L3FYTSARMFCSFLX2R-A5
发光二极管 DIP 红发红</td>
<td width="102px">80000</td>
<td width="102px">buerklin<span class="myLable">厂家直销</span></td>
<td width="140px">TOGIALED(统佳)</td>
<td width="128px">单价:¥0.0675</td>
<td width="131px">天津市河东区
大直沽西路(10km)</td>
</tr>
<tr>
<td width="54px">5</td>
<td width="100px"><img src="__CDN__/assets/store/images/tableImg.png" alt=""></td>
<td width="180px">TOGIALED(统佳)
TJ-L3FYTSARMFCSFLX2R-A5
发光二极管 DIP 红发红</td>
<td width="102px">80000</td>
<td width="102px">buerklin<span class="myLable">厂家直销</span></td>
<td width="140px">TOGIALED(统佳)</td>
<td width="128px">单价:¥0.0675</td>
<td width="131px">天津市河东区
大直沽西路(10km)</td>
</tr>
<tr>
<td width="54px">6</td>
<td width="100px"><img src="__CDN__/assets/store/images/tableImg.png" alt=""></td>
<td width="180px">TOGIALED(统佳)
TJ-L3FYTSARMFCSFLX2R-A5
发光二极管 DIP 红发红</td>
<td width="102px">80000</td>
<td width="102px">buerklin<span class="myLable">厂家直销</span></td>
<td width="140px">TOGIALED(统佳)</td>
<td width="128px">单价:¥0.0675</td>
<td width="131px">天津市河东区
大直沽西路(10km)</td>
</tr>
<tr>
<td width="54px">7</td>
<td width="100px"><img src="__CDN__/assets/store/images/tableImg.png" alt=""></td>
<td width="180px">TOGIALED(统佳)
TJ-L3FYTSARMFCSFLX2R-A5
发光二极管 DIP 红发红</td>
<td width="102px">80000</td>
<td width="102px">buerklin<span class="myLable">厂家直销</span></td>
<td width="140px">TOGIALED(统佳)</td>
<td width="128px">单价:¥0.0675</td>
<td width="131px">天津市河东区
大直沽西路(10km)</td>
</tr>
<tr>
<td width="54px">8</td>
<td width="100px"><img src="__CDN__/assets/store/images/tableImg.png" alt=""></td>
<td width="180px">TOGIALED(统佳)
TJ-L3FYTSARMFCSFLX2R-A5
发光二极管 DIP 红发红</td>
<td width="102px">80000</td>
<td width="102px">buerklin<span class="myLable">厂家直销</span></td>
<td width="140px">TOGIALED(统佳)</td>
<td width="128px">单价:¥0.0675</td>
<td width="131px">天津市河东区
大直沽西路(10km)</td>
</tr>
<tr>
<td width="54px">9</td>
<td width="100px"><img src="__CDN__/assets/store/images/tableImg.png" alt=""></td>
<td width="180px">TOGIALED(统佳)
TJ-L3FYTSARMFCSFLX2R-A5
发光二极管 DIP 红发红</td>
<td width="102px">80000</td>
<td width="102px">buerklin<span class="myLable">厂家直销</span></td>
<td width="140px">TOGIALED(统佳)</td>
<td width="128px">单价:¥0.0675</td>
<td width="131px">天津市河东区
大直沽西路(10km)</td>
</tr>
<tr>
<td width="54px">10</td>
<td width="100px"><img src="__CDN__/assets/store/images/tableImg.png" alt=""></td>
<td width="180px">TOGIALED(统佳)
TJ-L3FYTSARMFCSFLX2R-A5
发光二极管 DIP 红发红</td>
<td width="102px">80000</td>
<td width="102px">buerklin<span class="myLable">厂家直销</span></td>
<td width="140px">TOGIALED(统佳)</td>
<td width="128px">单价:¥0.0675</td>
<td width="131px">天津市河东区
大直沽西路(10km)</td>
</tr>
<tbody class="goods_dom">
<!--<tr>
<td>1</td>
<td><img src="__CDN__/assets/store/images/tableImg.png" alt=""></td>
<td>TOGIALED(统佳) TJ-L3FYTSARMFCSFLX2R-A5 发光二极管 DIP 红发红</td>
<td>80000</td>
<td>buerklin<span class="myLable">厂家直销</span></td>
<td>TOGIALED(统佳)</td>
<td>单价:¥0.0675</td>
<td>天津市河东区大直沽西路(10km)</td>
</tr>-->
</tbody>
</table>
... ... @@ -734,8 +624,8 @@
<div id="mapShowNoResultsBox">
<img src="__CDN__/assets/store/images/noResults.png" alt="img">
<p id="mapShowTipsTitle">温馨提示</p>
<p id="mapShowTipsText">抱歉,未找到与‘XXXXXXXXXX’相关的商品</p>
<a href="helpBuy.html">帮买服务</a>
<p id="mapShowTipsText">抱歉,未找到与‘{$keyword}’相关的商品</p>
<a href="">帮买服务</a>
</div>
</div>
... ... @@ -768,13 +658,8 @@
<p id="tipsText">未搜索到,换个试试</p>
</div>
</div>
<div id="allmap"></div>
{include file="public/footer"/}
{include file="public/js"/}
<!--百度地图引入-->
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=lu7CH9ucr6STjUk1GQgkfzjhpHbb7hPd"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=lu7CH9ucr6STjUk1GQgkfzjhpHbb7hPd"></script>
<script type="text/javascript" src="http://api.map.baidu.com/library/CityList/1.2/src/CityList_min.js"></script>
<script>
var noResults = false;
var mapShow = false;
... ... @@ -783,35 +668,119 @@
var locationLng = 117.233;
var locationLat = 39.11365;
$(function () {
var val = decodeURI(window.location.href.split('searchKey=')[1]);
$('#searchVal').val(val);
searchData();
showTableData();
// showTableData();
initMap();
tableClick();
initPaging();
initLocation();
initLocation();//获取定位信息
});
//表格点击事件
function tableClick() {
$('#searchTable tbody tr').click(function (e) {
console.log(e)
console.log(this)
$("#searchTable").on("click","tbody tr",function (e){
// $('#searchTable tbody tr').click(function (e) {
// console.log(e);
// console.log(this);
$('.activeTr').removeClass('activeTr');
$(this).addClass('activeTr');
})
}
//定位当前位置
function initLocation(){
// 百度地图API功能
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);
map.centerAndZoom(point,12);
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r){
$('#locationText').html(r.address.province + "" + r.address.city);
if(this.getStatus() == BMAP_STATUS_SUCCESS){
var mk = new BMap.Marker(r.point);
map.addOverlay(mk);
map.panTo(r.point);
//省份名称转换为id
$.ajax({
url:"{:url('index/sundry/get_province_id')}",
type:"POST",
data:{"province_name":r.address.province},
async:false,
success:function(res){
if(res.code == 1){
province_id = res.data.province_id;
lng = r.point.lng;
lat = r.point.lat;
//初始化产品热卖
initGoodsList();
}else{
toast(res.msg);
}
},
error:function(res){
toast('与服务器断开连接');
}
});
} else {
toast('failed'+this.getStatus());
}
},{enableHighAccuracy: true})
}
//初始化商品列表
function initGoodsList(page = 1, pageNum = 10){
//排序规则
var sort = $('.activeBtn').attr('data-sort');
//关键字
var keyword = $('#searchVal').val();
$.ajax({
url:"{:url('index/goods/get_all')}",
type:"POST",
data:{"province_id":province_id,"page":page,"pageNum":pageNum,'paginate':1,'sort':sort,'keyword':keyword,'lng':lng,'lat':lat},
success:function(res){
console.log(res);
var goods_html = "";
$(res.data.data).each(function (key1, vo) {
var property = "";
$(vo.property).each(function (key2, p) {
property += "<span class=\"myLable\">"+p+"</span>";
});
var str = "<tr>\n" +
" <td>"+vo.id+"</td>\n" +
" <td><img src=\""+vo.thumbnail+"\" alt=\"\" style='width: 100px;height:50px'></td>\n" +
" <td>"+vo.goodsname+"</td>\n" +
" <td>"+vo.inventory+"</td>\n" +
" <td>"+vo.store_name+property+"\n" +
" <td>"+vo.brand+"</td>\n" +
" <td>单价:¥"+vo.price+"</td>\n" +
" <td>"+vo.store_address+"(10km)</td>\n" +
" </tr>";
goods_html += str.replace("GOODS_ID",vo.id);
});
$('.goods_dom').html(goods_html);
$('#resultsNum').html(res.data.total+"件");
//初始化分页
var totalPage = Math.ceil(res.data.total/pageNum);
initPaging(res.data.total,res.data.current_page,totalPage,pageNum);
},
error:function(res){
toast('与服务器断开连接');
}
});
}
//初始化分页
function initPaging() {
function initPaging(totalSize = 0, current_page = 1, totalPage = 0, pageNum, showPageNum = 5) {
$("#paginationAllOrder").whjPaging({
//每页显示数据条数
pageNum: pageNum,
//当前页
current_page: current_page,
//可选,总条数
totalSize: 90,
totalSize: totalSize,
//可选,总页数
totalPage: 18,
totalPage: totalPage,
//可选,展示页码数量,默认5个页码数量
showPageNum: 5,
showPageNum: showPageNum,
//可选,css设置,可设置值:css-1,css-2,css-3,css-4,css-5,默认css-1,可自定义样式
css: 'css-1',
//可选,上一页按钮展示文本,默认显示文本为上一页
... ... @@ -835,6 +804,7 @@
//必选,回掉函数,返回参数:第一个参数为页码,第二个参数为每页显示N条
callBack: function (currPage, pageSize) {
console.log('currPage:' + currPage + ' pageSize:' + pageSize);
initGoodsList(currPage, pageSize)
}
});
}
... ... @@ -842,6 +812,7 @@
//切换经销商
function selectDistributor(obj) {
$(obj).closest('.dropdown').find('.distributorName').html($(obj).html());
$('#dropdownMenu1').attr('data-sort',$(obj).attr('data-sort'));
sortSearch($('#dropdownMenu1')[0], $(obj).html());
}
... ... @@ -849,31 +820,37 @@
function searchData(val) {
var searchKey = $('#searchVal').val();
if(searchKey == ''){
$.message({
message:'请输入要搜索的内容',
type:'warning'
});
toast('请输入要搜索的内容');
return;
}
initGoodsList();
//noResultsTips();
}
//排序查询
function sortSearch(obj, type) {
if(!$('.activeBtn').hasClass('priceBtn')){
$('.activeBtn img').attr('src', '__CDN__/assets/store/images/dropDwon.png')
$('.activeBtn img').attr('src', '__CDN__/assets/store/images/dropDwon.png');
}
$('.activeBtn').removeClass('activeBtn');
$(obj).addClass('activeBtn');
if(type != 'price'){
$(obj).find('img').attr('src', '__CDN__/assets/store/images/dropDwon_select.png')
$(obj).find('img').attr('src', '__CDN__/assets/store/images/dropDwon_select.png');
$('.priceBtn').attr('data-sort',0);
$('.priceBtn').find('img').eq(0).attr('src', '__CDN__/assets/store/images/dropDwon_up.png');
$('.priceBtn').find('img').eq(0).attr('src', '__CDN__/assets/store/images/dropDwon.png');
}else{
if($.inArray($(obj).attr('data-sort'),['0','5']) != -1){
$(obj).find('img').eq(1).attr('src', '__CDN__/assets/store/images/dropDwon_select.png');
$(obj).find('img').eq(0).attr('src', '__CDN__/assets/store/images/dropDwon_up.png');
$(obj).attr('data-sort',6);
}else{
$(obj).find('img').eq(0).attr('src', '__CDN__/assets/store/images/dropDwon_up_select.png');
$(obj).find('img').eq(1).attr('src', '__CDN__/assets/store/images/dropDwon.png');
$(obj).attr('data-sort',5);
}
}
console.log(type);
}
//显示表格数据
function showTableData() {
return
initGoodsList();
}
//无搜索结果提示
... ... @@ -912,6 +889,7 @@
})
mapShow = true;
noResultsTips();
initMap();
}
//收回地图
... ... @@ -935,6 +913,8 @@
mapObj.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
mapObj.setDefaultCursor('pointer');
addMarker(point, 999);
rangeSearch50();
var size = new BMap.Size(405, 43);
mapObj.addControl(new BMap.CityListControl({
... ... @@ -945,20 +925,37 @@
geoc = new BMap.Geocoder();
mapObj.addEventListener("click", function(e){
console.log(e);
var allOverlay = this.getOverlays();
for (var i=0; i<allOverlay.length; i++){
this.removeOverlay(allOverlay[i]);
}
locationLng = e.point.lng;
locationLat = e.point.lat;
geoc.getLocation(e.point, function(rs){
var addComp = rs.addressComponents;
$('#locationText').html(addComp.province + "" + addComp.city + "" + addComp.district + "" + addComp.street + "" + addComp.streetNumber);
//省份名称转换为id
$.ajax({
url:"{:url('index/sundry/get_province_id')}",
type:"POST",
data:{"province_name":addComp.province},
async:false,
success:function(res){
console.log(res);
if(res.code == 1){
province_id = res.data.province_id;
lng = locationLng;
lat = locationLat;
rangeSearch50();
}else{
toast(res.msg);
}
},
error:function(res){
toast('与服务器断开连接');
}
});
});
var point = new BMap.Point(locationLng, locationLat);
addMarker(point, 999);
})
... ... @@ -970,6 +967,7 @@
// 创建标注对象并添加到地图
var marker = new BMap.Marker(point, {icon: myIcon});
mapObj.addOverlay(marker);
console.log(marker);
}
//查询50KM范围内在售商品
... ... @@ -990,10 +988,7 @@
console.log(circle.getRadius()); //返回圆形覆盖物的半径
});
}
//测试搜索,正式使用时应创建point坐标传入addMarker
var local = new BMap.LocalSearch(mapObj, {renderOptions: {map: mapObj, autoViewport: false}});
local.searchNearby('地铁站',mPoint,5000);
initGoodsList();
}
</script>
</body>
... ...
<!--begin:提示弹层-->
<div class="toast">提示框</div>
<div class="bg"></div>
<!--百度地图-->
<div id="allmap" class="hidden"></div>
<!--百度地图引入-->
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=lu7CH9ucr6STjUk1GQgkfzjhpHbb7hPd"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=lu7CH9ucr6STjUk1GQgkfzjhpHbb7hPd"></script>
<script type="text/javascript" src="http://api.map.baidu.com/library/CityList/1.2/src/CityList_min.js"></script>
<script>
//腾讯地图key
var key = "keyword=$keyword&key=M4ABZ-MM7W3-WH43F-YXSKV-XYCBT-2NB2J";
//省份id
var province_id = 0;
//当前位置经度
var lng= "";
//当前位置纬度
var lat = "";
//提示弹层
function toast(msg='玩命加载中~',time=2000){
$('.toast').text(msg);
... ... @@ -63,24 +75,4 @@
var pos=$.inArray(src,idCardImgFileArr);
idCardImgFileArr.splice(pos,1);*/
});
//定位当前位置
//获取当前位置
function initLocation(){
// 百度地图API功能
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);
map.centerAndZoom(point,12);
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r){
if(this.getStatus() == BMAP_STATUS_SUCCESS){
var mk = new BMap.Marker(r.point);
map.addOverlay(mk);
map.panTo(r.point);
alert('您的位置:'+r.point.lng+','+r.point.lat);
} else {
alert('failed'+this.getStatus());
}
},{enableHighAccuracy: true})
}
</script>
\ No newline at end of file
... ...
... ... @@ -28,10 +28,10 @@
}
} else {
if (b != null) {
var o = [{value: 5, text: "5条/页", selected: true}, {value: 10, text: "10条/页"}, {
value: 15,
text: "15条/页"
}, {value: 20, text: "20条/页"}];
var o = [{value: 6, text: "6条/页", selected: b.pageNum == 6 ? true : false}, {value: 18, text: "18条/页", selected: b.pageNum == 18 ? true : false}, {
value: 36,
text: "36条/页", selected: b.pageNum == 36 ? true : false
}, {value: 54, text: "54条/页", selected: b.pageNum == 54 ? true : false}];
if (b.pageSizeOpt != null) {
o = b.pageSizeOpt
}
... ... @@ -73,7 +73,7 @@
css: d,
pageSizeOpt: o,
totalPage: b.totalPage != null ? b.totalPage : null,
showPageNum: b.showPageNum != null ? b.showPageNum : 5,
showPageNum: b.showPageNum != null ? b.showPageNum : 6,
firstPage: b.firstPage != null ? b.firstPage : "首页",
previousPage: b.previousPage != null ? b.previousPage : "上一页",
nextPage: b.nextPage != null ? b.nextPage : "下一页",
... ... @@ -89,7 +89,7 @@
isShowTotalPage: b.isShowTotalPage === false ? false : true,
isResetPage: b.isResetPage === true ? true : false,
callBack: b.callBack,
currPage: 1,
currPage: b.current_page,
pageSize: b.isShowPageSizeOpt === false ? null : s,
totalSize: b.totalSize != null ? b.totalSize : null,
isShowTotalSize: b.isShowTotalSize === false ? false : true,
... ...