商家调整

master
wangxinglong 2021-11-29 17:32:48 +08:00
parent e7aa946766
commit 66ec88ccfe
19 changed files with 6483 additions and 30 deletions

View File

@ -0,0 +1,30 @@
<?php
namespace app\controller\api;
use think\facade\Db;
use app\model\Area as AreaModel;
/**
* Area
*
* Class Business
* @package app\controller\api
*/
class Area extends Base
{
protected $middleware = [];
protected function initialize()
{
}
/**
* 根据上级行政代码 获取下级
* */
public function index()
{
$pcode = input("areaId/d",86);
return json(AreaModel::getByPCode($pcode,false));
}
}

View File

@ -6,14 +6,16 @@ use app\exception\RepositoryException;
use app\model\BusinessFlow;
use app\model\Coupon;
use app\model\CouponMain;
use app\model\Recharge;
use app\model\Category as CategoryModel;
use app\model\Business as BusinessModel;
use app\model\Member;
use app\model\BusinessCircle as BusinessCircleModel ;
use app\repository\BusinessRepository;
use app\repository\RechargeRepository;
use app\service\wx\WechatPay;
use Exception;
use think\exception\ValidateException;
use think\facade\Db;
use think\response\Json;
use think\response\View;
@ -183,14 +185,57 @@ class Business extends Base
public function businessDetail()
{
$businessCode = input("business_code/s", "");
$business = $repo = BusinessRepository::getInstance()->findOneByWhere(['code' => $businessCode]);
if ($this->request->isPost()) {
if(empty($business)){
return $this->json(4001,"商家不存在");
}
$item = input('post.');
$validate = $this->validateByApi($item, [
'business_name|商家名称' => 'require|max:100',
'business_subtitle|商家简称' => 'max:100',
'lat|纬度' => 'require',
'lng|经度' => 'require',
'province|省市区' => 'require',
'city|省市区' => 'require',
'county|省市区' => 'require',
'business_address|地址' => 'require|min:3',
'contact_name|联系人' => 'require|min:1',
'contact_phone|联系电话' => 'require|mobile',
'state|审核状态' => 'require|in:0,1,2',
'enable|启用状态' => 'require|in:0,1',
'type|分类' => 'require|number',
'characteristic|特色' => 'max:100',
'intro|介绍' => 'require',
'business_circle_id|商圈' => 'require',
'background|背景图' => 'require',
'score|评分' => 'require|in:1,2,3,4,5',
'reason|驳回原因' => 'max:100',
]);
if ($validate !== true) {
return $validate;
}
Db::startTrans();
try {
$business->save($item);
Db::commit();
return $this->json();
} catch (ValidateException $e) {
Db::rollback();
return $this->json(4001, $e->getError());
}
}
$business = $repo = BusinessRepository::getInstance()->findOneByWhere(['code' => $businessCode]);
if (empty($business)) {
return $this->error("商家不存在");
}
$this->data["item"] = $business;
$this->data["type"] = CategoryModel::getByGroup();
$this->data["businessCircle"] = BusinessCircleModel::getList();
return $this->view();
}

View File

@ -0,0 +1,169 @@
<?php
namespace app\controller\manager;
use app\model\BusinessCircle as BusinessCircleModel;
use Exception;
use think\facade\Db;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\exception\ValidateException;
use think\response\Json;
use think\response\View;
/**
* 商圈管理
*
* Class BusinessCircle
* @package app\controller\manager
*/
class BusinessCircle extends Base
{
/**
* 编辑
*
* @return Json|View
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws Exception
*/
public function edit()
{
$id = input('id/d', 0);
if (!$info = BusinessCircleModel::findById($id)) {
return $this->json(4001, '记录不存在');
}
if ($this->request->isPost()) {
$item = input('post.');
$validate = $this->validateByApi($item, [
'sort|标题' => 'require|number',
'name|标题' => 'require|max:100',
]);
if ($validate !== true) {
return $validate;
}
Db::startTrans();
try {
$info->save($item);
Db::commit();
return $this->json();
} catch (ValidateException $e) {
Db::rollback();
return $this->json(4001, $e->getError());
}
}
$disabled[] = $id;
$this->data['item'] = $info;
return $this->view();
}
/**
* 添加
*
* @return Json|View
* @throws Exception
*/
public function add()
{
if ($this->request->isPost()) {
$item = input('post.');
$validate = $this->validateByApi($item, [
'name|标题' => 'require|max:100',
]);
if ($validate !== true) {
return $validate;
}
try {
BusinessCircleModel::create($item);
return $this->json();
} catch (ValidateException $e) {
return $this->json(4001, $e->getError());
}
}
return $this->view();
}
/**
* 删除
* @return Json
*/
public function del()
{
if (!$this->request->isPost()) {
return $this->json(4000, '非法请求');
}
$ids = $this->request->param('ids/a', []);
BusinessCircleModel::destroy($ids);
return $this->json();
}
/**
* 单个字段编辑
*
* @return Json
* @throws Exception
*/
public function modify(): Json
{
if ($this->request->isPost()) {
$item = input('post.');
$validate = $this->validateByApi($item, [
'field' => 'require',
'value' => 'require',
]);
if ($validate !== true) {
return $validate;
}
if (!$info = BusinessCircleModel::findById($item['id'])) {
return $this->json(4001, '记录不存在');
}
$update = [$item['field'] => $item['value']];
try {
$info->save($update);
return $this->json();
} catch (ValidateException $e) {
return $this->json(4001, $e->getError());
}
}
return $this->json(4000, '非法请求');
}
/**
* 列表
*
* @return Json|View
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function index()
{
if ($this->request->isPost()) {
$menus = BusinessCircleModel::getList();
$res = [
'code' => 0,
'msg' => 'success',
'count' => $menus->count(),
'data' => $menus->toArray(),
];
return json($res);
}
return $this->view();
}
}

25
app/model/Area.php Normal file
View File

@ -0,0 +1,25 @@
<?php
namespace app\model;
class Area extends Base
{
/**
*
* @param $PCode
* @param $filter bool 是否过滤屏蔽的地区
* @return Area[]|array|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getByPCode($PCode,bool $filter = false)
{
return self::where("pcode",$PCode ) ->when($filter,function ($q){
$q->where("status",self::COMMON_ON);
})->order("id asc")->select();
}
}

View File

@ -6,6 +6,7 @@ use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;
/**
* 商圈
@ -14,4 +15,22 @@ use think\db\exception\ModelNotFoundException;
*/
class BusinessCircle extends Base
{
/**
* 获取全部列表
*
* @return Disease[]|array|Collection
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function getList()
{
return self::field('id,name,sort')->order('id', 'desc')->select();
}
public static function onAfterInsert($obj)
{
$obj->sort = $obj->id;
$obj->save();
}
}

View File

@ -15,7 +15,7 @@ use think\db\exception\ModelNotFoundException;
class Category extends Base
{
/**
* 根据父级ID 获取病种列表
* 根据父级ID 获取列表
*
* @param int $pid
* @param string[] $fields
@ -29,6 +29,22 @@ class Category extends Base
return self::where('pid', $pid)->order('id', 'desc')->field($fields)->select();
}
/**
* 获取上下级
* */
public static function getByGroup()
{
$top = self::column(['pid', 'name', 'id'], "id");
foreach ($top as $key => $value) {
if (isset($top[$value["pid"]])) {
$top[$value["pid"]]['children'][] = $value;
unset($top[$key]);
}
}
return $top;
}
/**
* 获取全部列表
*
@ -39,7 +55,7 @@ class Category extends Base
*/
public static function getList()
{
return self::field('id,pid,name,commision')->order('id', 'desc')->order('id')->select();
return self::field('id,pid,name,commision')->order('id', 'desc')->select();
}
/**

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -37,4 +37,7 @@ layui.config({
//自定义第三方
xmSelect: '../../../manager/js/xm-select', //下拉组件
iPicker: '../../../js/iPicker/iPicker.min', //省市区联动
location: 'location/location', //地图经纬度
locationX: 'location/locationX', //地图经纬度
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -0,0 +1,101 @@
.ew-map-select-tool {
padding: 5px 15px;
box-shadow: 0 1px 0 0 rgba(0, 0, 0, .05);
}
.inline-block {
display: inline-block;
}
.layui-btn.icon-btn {
padding: 0 10px;
}
.pull-right {
float: right;
}
.map-select:after, .map-select:before {
content: '';
display: block;
clear: both;
}
.ew-map-select-poi {
height: 505px;
width: 250px;
overflow-x: hidden;
overflow-y: auto;
float: left;
position: relative;
display: block;
box-sizing: border-box;
}
.ew-map-select-search-list-item {
padding: 10px 30px 10px 15px;
border-bottom: 1px solid #e8e8e8;
cursor: pointer;
position: relative;
}
.ew-map-select-search-list-item .ew-map-select-search-list-item-title {
font-size: 14px;
color: #262626;
}
.ew-map-select-search-list-item .ew-map-select-search-list-item-address {
font-size: 12px;
color: #595959;
padding-top: 5px;
}
.ew-map-select-search-list-item-icon-ok {
position: absolute;
right: 15px;
top: 50%;
transform: translateY(-50%);
}
#ew-map-select-tips {
position: absolute;
z-index: 999;
background: #fff;
max-height: 430px;
overflow: auto;
top: 48px;
left: 56px;
width: 280px;
box-shadow: 0 2px 4px rgba(0,0,0,.12);
border: 1px solid #d2d2d2;
}
#ew-map-select-tips .ew-map-select-search-list-item {
padding: 10px 15px 10px 35px;
}
.ew-map-select-search-list-item-icon-search {
position: absolute;
left: 10px;
top: 50%;
transform: translateY(-50%);
}
.ew-map-select-search-list-item .ew-map-select-search-list-item-title {
font-size: 14px;
color: #262626;
}
.ew-map-select-search-list-item .ew-map-select-search-list-item-address {
font-size: 12px;
color: #595959;
padding-top: 5px;
}
.cur-load0 {
display: none;
background: url('./img/location.cur');
}
.cur-load1 {
display: none;
background: url('./img/location_blue.cur');
}

View File

@ -0,0 +1,759 @@
layui.define(['layer', 'locationX'], function (exports) {
var $ = layui.jquery,
layer = layui.layer,
MOD_NAME = "location",
GPS = layui.locationX;
var tpl0 = '<div class="cur-load0"></div>\n' +
'<div class="cur-load1"></div>\n' +
'<div class="ew-map-select-tool" style="position: relative;">\n' +
' 经度:<input id="lng" class="layui-input inline-block" style="width: 190px;" autocomplete="off"/>\n' +
' &nbsp;&nbsp;&nbsp;纬度:<input id="lat" class="layui-input inline-block" style="width: 190px;" autocomplete="off"/>\n' +
' <button id="ew-map-select-btn-ok" class="layui-btn icon-btn pull-right" type="button"><i\n' +
' class="layui-icon">&#xe605;</i>确定\n' +
' </button>\n' +
'</div>\n' +
'<div id="map" style="width: 100%;height: calc(100% - 48px);"></div>';
var tpl1 ='<div class="cur-load0"></div>\n' +
'<div class="cur-load1"></div>\n' +
'<div class="ew-map-select-tool" style="position: relative;">\n' +
' 搜索:<input id="ew-map-select-input-search" class="layui-input icon-search inline-block" style="width: 190px;" placeholder="输入关键字搜索" autocomplete="off" />\n' +
' <div id="ew-map-select-tips" class="ew-map-select-search-list layui-hide" style="left: 0px;width: 248px;"></div>\n' +
' &nbsp;&nbsp;经度:<input id="lng" class="layui-input inline-block" style="width: 190px;" autocomplete="off" />\n' +
' &nbsp;&nbsp;&nbsp;纬度:<input id="lat" class="layui-input inline-block" style="width: 190px;" autocomplete="off" />\n' +
' <button id="ew-map-select-btn-ok" class="layui-btn icon-btn pull-right" type="button"><i class="layui-icon">&#xe605;</i>确定</button>\n' +
'</div>\n' +
'<div class="map-select">\n' +
'\n' +
' <div id="map" style="width: 600px;height: 505px;float: right;"></div>\n' +
' <div id="ew-map-select-poi" class="layui-col-sm5 ew-map-select-search-list ew-map-select-poi">\n' +
' </div>\n' +
'\n' +
'</div>';
var obj = function (config) {
this.config = {
// 默认中心点位置是北京天安门,所有坐标系都用此坐标,偏的不大
type: 0, // 0 : 仅定位 1 带有搜索的定位
longitude: 116.404,
latitude: 39.915,
title: '定位',
zoom: 18,
apiType: "baiduMap",
coordinate: "baiduMap",
mapType: 0,
searchKey: '村',
init: function () {
return {longitude: 116.404, latitude: 39.915};
},
success: function () {
},
onClickTip: function (data) {
console.log(data);
}
}
this.config = $.extend(this.config, config);
// 初始化经纬度信息
var initData = this.config.init();
this.config.longitude = initData.longitude;
this.config.latitude = initData.latitude;
this.lng = this.config.longitude;
this.lat = this.config.latitude;
// 转换初始坐标
this.initCoordinate = function (lng, lat) {
var o = this;
if (o.config.apiType == o.config.coordinate) {
return {lng: lng, lat: lat};
} else if (o.config.apiType == 'baiduMap' && o.config.coordinate == 'tiandiMap') {
var res = GPS.WGS84_bd(lat, lng);
return {lng: res.lon.toFixed(5), lat: res.lat.toFixed(5)};
} else if (o.config.apiType == 'tiandiMap' && o.config.coordinate == 'baiduMap') {
var res = GPS.bd_WGS84(lat, lng);
return {lng: res.lon.toFixed(5), lat: res.lat.toFixed(5)};
} else if (o.config.apiType == 'gaodeMap' && o.config.coordinate == 'baiduMap') {
var res = GPS.bd_decrypt(lat, lng);
return {lng: res.lon.toFixed(5), lat: res.lat.toFixed(5)};
} else if (o.config.apiType == 'baiduMap' && o.config.coordinate == 'gaodeMap') {
var res = GPS.bd_encrypt(lat, lng);
return {lng: res.lon.toFixed(5), lat: res.lat.toFixed(5)};
} else if (o.config.apiType == 'gaodeMap' && o.config.coordinate == 'tiandiMap') {
var res = GPS.gcj_encrypt(lat, lng);
return {lng: res.lon.toFixed(5), lat: res.lat.toFixed(5)};
} else if (o.config.apiType == 'tiandiMap' && o.config.coordinate == 'gaodeMap') {
var res = GPS.gcj_decrypt(lat, lng);
return {lng: res.lon.toFixed(5), lat: res.lat.toFixed(5)};
}
}
if (this.config.longitude && this.config.latitude && this.config.mapType != this.config.coordinate) {
var tbd = this.initCoordinate(this.config.longitude, this.config.latitude);
this.config.longitude = tbd.lng;
this.config.latitude = tbd.lat;
}
this.transformCoordinate = function (lng, lat) {
var o = this;
if (o.config.apiType == o.config.coordinate) {
return {lng: lng, lat: lat};
} else if (o.config.apiType == 'baiduMap' && o.config.coordinate == 'tiandiMap') {
var res = GPS.bd_WGS84(lat, lng);
return {lng: res.lon.toFixed(5), lat: res.lat.toFixed(5)};
} else if (o.config.apiType == 'tiandiMap' && o.config.coordinate == 'baiduMap') {
var res = GPS.WGS84_bd(lat, lng);
return {lng: res.lon.toFixed(5), lat: res.lat.toFixed(5)};
} else if (o.config.apiType == 'gaodeMap' && o.config.coordinate == 'baiduMap') {
var res = GPS.bd_encrypt(lat, lng);
return {lng: res.lon.toFixed(5), lat: res.lat.toFixed(5)};
} else if (o.config.apiType == 'baiduMap' && o.config.coordinate == 'gaodeMap') {
var res = GPS.bd_decrypt(lat, lng);
return {lng: res.lon.toFixed(5), lat: res.lat.toFixed(5)};
} else if (o.config.apiType == 'gaodeMap' && o.config.coordinate == 'tiandiMap') {
var res = GPS.gcj_decrypt(lat, lng);
return {lng: res.lon.toFixed(5), lat: res.lat.toFixed(5)};
} else if (o.config.apiType == 'tiandiMap' && o.config.coordinate == 'gaodeMap') {
var res = GPS.gcj_encrypt(lat, lng);
return {lng: res.lon.toFixed(5), lat: res.lat.toFixed(5)};
}
}
this.openBaiduMap = function () {
var o = this;
var map; // 创建地图实例
if (o.config.mapType == 1) {
map = new BMap.Map("map", {enableMapClick: false, mapType: BMAP_SATELLITE_MAP});
} else if (o.config.mapType == 2) {
map = new BMap.Map("map", {enableMapClick: false, mapType: BMAP_HYBRID_MAP});
} else {
map = new BMap.Map("map", {enableMapClick: false, mapType: BMAP_NORMAL_MAP});
}
map.enableScrollWheelZoom(); //启用滚轮放大缩小,默认禁用
var point = new BMap.Point(o.config.longitude ? o.config.longitude : 116.404, o.config.latitude ? o.config.latitude : 39.915); // 创建点坐标
map.centerAndZoom(point, o.config.zoom);
map.setDefaultCursor("url('" + layui.cache.base + "location/img/location.cur') 17 35,auto"); //设置地图默认的鼠标指针样式
var marker = new BMap.Marker(map.getCenter()); // 创建标注
map.addOverlay(marker); // 将标注添加到地图中
map.addEventListener("click", function (e) {
var tbd = o.transformCoordinate(e.point.lng, e.point.lat);
//显示经纬度
$("#lng").val(tbd.lng);
$("#lat").val(tbd.lat);
o.lng = tbd.lng;
o.lat = tbd.lat;
var point = new BMap.Point(e.point.lng, e.point.lat);
map.removeOverlay(marker);
marker = new BMap.Marker(point);
map.addOverlay(marker);
if (o.config.type==1){
searchNearBy(e.point.lng, e.point.lat);
}
});
// 标记中心点
var markCenter = function (lng, lat){
var tbd = o.transformCoordinate(lng, lat);
//显示经纬度
$("#lng").val(tbd.lng);
$("#lat").val(tbd.lat);
o.lng = tbd.lng;
o.lat = tbd.lat;
var point = new BMap.Point(lng, lat);
map.removeOverlay(marker);
marker = new BMap.Marker(point);
map.addOverlay(marker);
if (o.config.type==1){
searchNearBy(lng, lat);
}
}
// 搜索附近方法
var searchNearBy = function (lng, lat){
var point = new BMap.Point(lng, lat);
var localSearch = new BMap.LocalSearch(point, {
pageCapacity: 10,
onSearchComplete: function (result){
var htmlList = '';
$.each(result,function (i,val){
$.each(val.Hr,function (i,ad){
htmlList += '<div data-lng="' + ad.point.lng + '" data-lat="' + ad.point.lat + '" data-title="'+ ad.title +'" data-address="'+ ad.address +'" class="ew-map-select-search-list-item">';
htmlList += ' <div class="ew-map-select-search-list-item-title">' + ad.title + '</div>';
htmlList += ' <div class="ew-map-select-search-list-item-address">' + ad.address + '</div>';
htmlList += ' <div class="ew-map-select-search-list-item-icon-ok layui-hide"><i class="layui-icon layui-icon-ok-circle"></i></div>';
htmlList += '</div>';
});
});
$('#ew-map-select-poi').html(htmlList);
}
});
localSearch.searchNearby([o.config.searchKey,'镇','街道','店'],point,1000);
}
// 初始化搜索
if (o.config.type==1){
o.initBaiduSearch(map,searchNearBy,markCenter);
}
}
this.initBaiduSearch = function (map,searchNearBy,markCenter){
var o = this;
searchNearBy(o.config.longitude ? o.config.longitude : 116.404, o.config.latitude ? o.config.latitude : 39.915);
// poi列表点击事件
$('#ew-map-select-poi').off('click').on('click', '.ew-map-select-search-list-item', function () {
$('#ew-map-select-tips').addClass('layui-hide');
$('#ew-map-select-poi .ew-map-select-search-list-item-icon-ok').addClass('layui-hide');
$(this).find('.ew-map-select-search-list-item-icon-ok').removeClass('layui-hide');
$('#ew-map-select-center-img').removeClass('bounceInDown');
setTimeout(function () {
$('#ew-map-select-center-img').addClass('bounceInDown');
});
var lng = $(this).data('lng');
var lat = $(this).data('lat');
//
var point = new BMap.Point(lng, lat);
map.centerAndZoom(point, map.getZoom());
markCenter(lng, lat);
var title = $(this).data('title');
var address = $(this).data('address');
o.config.onClickTip({title:title,address:address,lng:lng,lat:lat});
});
// 搜索提示
var $inputSearch = $('#ew-map-select-input-search');
$inputSearch.off('input').on('input', function () {
var keywords = $(this).val();
var $selectTips = $('#ew-map-select-tips');
if (!keywords) {
$selectTips.html('');
$selectTips.addClass('layui-hide');
}
var autoComplete = new BMap.LocalSearch('全国', {
pageCapacity: 10,
onSearchComplete: function (result){
if (undefined == result){
return ;
}
var htmlList = '';
$.each(result.Ir,function (i,ad){
htmlList += '<div data-lng="' + ad.point.lng + '" data-lat="' + ad.point.lat + '" data-title="'+ ad.title +'" data-address="'+ ad.address +'" class="ew-map-select-search-list-item">';
htmlList += ' <div class="ew-map-select-search-list-item-icon-search"><i class="layui-icon layui-icon-search"></i></div>';
htmlList += ' <div class="ew-map-select-search-list-item-title">' + ad.title + '</div>';
htmlList += ' <div class="ew-map-select-search-list-item-address">' + ad.address + '</div>';
htmlList += '</div>';
});
$selectTips.html(htmlList);
if (result.Ir.length === 0) $('#ew-map-select-tips').addClass('layui-hide');
else $('#ew-map-select-tips').removeClass('layui-hide');
}
});
autoComplete.search(keywords);
});
$inputSearch.off('blur').on('blur', function () {
var keywords = $(this).val();
var $selectTips = $('#ew-map-select-tips');
if (!keywords) {
$selectTips.html('');
$selectTips.addClass('layui-hide');
}
});
$inputSearch.off('focus').on('focus', function () {
var keywords = $(this).val();
if (keywords) $('#ew-map-select-tips').removeClass('layui-hide');
});
// tips列表点击事件
$('#ew-map-select-tips').off('click').on('click', '.ew-map-select-search-list-item', function () {
$('#ew-map-select-tips').addClass('layui-hide');
var lng = $(this).data('lng');
var lat = $(this).data('lat');
var point = new BMap.Point(lng, lat);
map.centerAndZoom(point, map.getZoom());
markCenter(lng, lat);
var title = $(this).data('title');
var address = $(this).data('address');
o.config.onClickTip({title:title,address:address,lng:lng,lat:lat});
});
}
this.openTiandiMap = function () {
var o = this;
var map = new T.Map("map"); // 创建地图实例
if (o.config.mapType == 1) {
map.setMapType(TMAP_SATELLITE_MAP);
} else if (o.config.mapType == 2) {
map.setMapType(TMAP_HYBRID_MAP);
} else {
map.setMapType(TMAP_NORMAL_MAP);
}
map.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放
var latLng = new T.LngLat(o.config.longitude ? o.config.longitude : 116.404, o.config.latitude ? o.config.latitude : 39.915);
map.centerAndZoom(latLng, o.config.zoom);
var marker = new T.Marker(latLng); // 创建标注
map.addOverLay(marker);// 将标注添加到地图中
if (undefined === window.T.MarkTool) {
setTimeout(function () {
initMarkerTool();
}, 200);
} else {
initMarkerTool();
}
function initMarkerTool() {
var markerTool = new T.MarkTool(map, {follow: true});
markerTool.open();
/*标注事件*/
var mark = function (e) {
$.each(map.getOverlays(), function (i, marker) {
if (marker != e.currentMarker) {
map.removeOverLay(marker);
}
})
//显示经纬度
var tbd = o.transformCoordinate(e.currentLnglat.getLng(), e.currentLnglat.getLat());
$("#lng").val(tbd.lng);
$("#lat").val(tbd.lat);
o.lng = tbd.lng;
o.lat = tbd.lat;
markerTool = new T.MarkTool(map, {follow: true});
markerTool.open();
markerTool.addEventListener("mouseup", mark);
if (o.config.type==1){
searchNearBy(e.currentLnglat.getLng(), e.currentLnglat.getLat());
}
}
//绑定mouseup事件 在用户每完成一次标注时触发事件。
markerTool.addEventListener("mouseup", mark);
}
// 标记中心点
var markCenter = function (lng, lat) {
$.each(map.getOverlays(), function (i, marker) {
map.removeOverLay(marker);
})
//显示经纬度
var tbd = o.transformCoordinate(lng, lat);
$("#lng").val(tbd.lng);
$("#lat").val(tbd.lat);
o.lng = tbd.lng;
o.lat = tbd.lat;
var latLng = new T.LngLat(lng, lat);
var marker = new T.Marker(latLng); // 创建标注
map.addOverLay(marker);// 将标注添加到地图中
if (o.config.type==1){
searchNearBy(lng, lat);
}
}
// 搜索附近方法
var searchNearBy = function (lng, lat){
var point = new T.LngLat(lng,lat);
var localSearch = new T.LocalSearch(map, {
pageCapacity: 10,
onSearchComplete: function (result){
var htmlList = '';
$.each(result.getPois(),function (i,ad){
var lnglat = ad.lonlat.split(" ");
htmlList += '<div data-lng="' + lnglat[0] + '" data-lat="' + lnglat[1] + '" data-title="'+ ad.name +'" data-address="'+ ad.address +'" class="ew-map-select-search-list-item">';
htmlList += ' <div class="ew-map-select-search-list-item-title">' + ad.name + '</div>';
htmlList += ' <div class="ew-map-select-search-list-item-address">' + ad.address + '</div>';
htmlList += ' <div class="ew-map-select-search-list-item-icon-ok layui-hide"><i class="layui-icon layui-icon-ok-circle"></i></div>';
htmlList += '</div>';
});
$('#ew-map-select-poi').html(htmlList);
}
});
localSearch.setQueryType(1);
localSearch.searchNearby(o.config.searchKey,point,1000);
}
if (o.config.type==1){
o.initTiandiSearch(map,searchNearBy,markCenter);
}
}
this.initTiandiSearch = function (map,searchNearBy,markCenter){
var o = this;
searchNearBy(o.config.longitude ? o.config.longitude : 116.404, o.config.latitude ? o.config.latitude : 39.915);
// poi列表点击事件
$('#ew-map-select-poi').off('click').on('click', '.ew-map-select-search-list-item', function () {
$('#ew-map-select-tips').addClass('layui-hide');
$('#ew-map-select-poi .ew-map-select-search-list-item-icon-ok').addClass('layui-hide');
$(this).find('.ew-map-select-search-list-item-icon-ok').removeClass('layui-hide');
$('#ew-map-select-center-img').removeClass('bounceInDown');
setTimeout(function () {
$('#ew-map-select-center-img').addClass('bounceInDown');
});
var lng = $(this).data('lng');
var lat = $(this).data('lat');
//
var point = new T.LngLat(lng, lat);
map.centerAndZoom(point, map.getZoom());
markCenter(lng, lat);
var title = $(this).data('title');
var address = $(this).data('address');
o.config.onClickTip({title:title,address:address,lng:lng,lat:lat});
});
// 搜索提示
var $inputSearch = $('#ew-map-select-input-search');
$inputSearch.off('input').on('input', function () {
var keywords = $(this).val();
var $selectTips = $('#ew-map-select-tips');
if (!keywords) {
$selectTips.html('');
$selectTips.addClass('layui-hide');
}
var autoComplete = new T.LocalSearch(map, {
pageCapacity: 10,
onSearchComplete: function (result){
if (undefined == result){
return ;
}
var htmlList = '';
$.each(result.getPois(),function (i,ad){
var lnglat = ad.lonlat.split(" ");
htmlList += '<div data-lng="' + lnglat[0] + '" data-lat="' + lnglat[1] + '" data-title="'+ ad.name +'" data-address="'+ ad.address +'" class="ew-map-select-search-list-item">';
htmlList += ' <div class="ew-map-select-search-list-item-title">' + ad.name + '</div>';
htmlList += ' <div class="ew-map-select-search-list-item-address">' + ad.address + '</div>';
htmlList += ' <div class="ew-map-select-search-list-item-icon-ok layui-hide"><i class="layui-icon layui-icon-ok-circle"></i></div>';
htmlList += '</div>';
});
$selectTips.html(htmlList);
if (result.getPois().length === 0) $('#ew-map-select-tips').addClass('layui-hide');
else $('#ew-map-select-tips').removeClass('layui-hide');
}
});
autoComplete.setQueryType(1);
autoComplete.search(keywords);
});
$inputSearch.off('blur').on('blur', function () {
var keywords = $(this).val();
var $selectTips = $('#ew-map-select-tips');
if (!keywords) {
$selectTips.html('');
$selectTips.addClass('layui-hide');
}
});
$inputSearch.off('focus').on('focus', function () {
var keywords = $(this).val();
if (keywords) $('#ew-map-select-tips').removeClass('layui-hide');
});
// tips列表点击事件
$('#ew-map-select-tips').off('click').on('click', '.ew-map-select-search-list-item', function () {
$('#ew-map-select-tips').addClass('layui-hide');
var lng = $(this).data('lng');
var lat = $(this).data('lat');
var point = new T.LngLat(lng, lat);
map.centerAndZoom(point, map.getZoom());
markCenter(lng, lat);
var title = $(this).data('title');
var address = $(this).data('address');
o.config.onClickTip({title:title,address:address,lng:lng,lat:lat});
});
}
this.openGaodeMap = function () {
var o = this;
// 创建地图实例
var layers = [];
if (o.config.mapType == '1') {
var satellite = new AMap.TileLayer.Satellite();
layers.push(satellite);
} else if (o.config.mapType == '2') {
var satellite = new AMap.TileLayer.Satellite();
var roadNet = new AMap.TileLayer.RoadNet();
layers.push(satellite);
layers.push(roadNet);
} else {
var layer = new AMap.TileLayer();
layers.push(layer);
}
var map = new AMap.Map("map",
{
resizeEnable: true,
zoom: o.config.zoom,
center: [o.config.longitude ? o.config.longitude : 116.404, o.config.latitude ? o.config.latitude : 39.915],
layers: layers
});
map.setDefaultCursor("url('" + layui.cache.base + "location/img/location_blue.cur') 17 35,auto");
// 初始化中间点标记
var marker = new AMap.Marker({
icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
position: [o.config.longitude ? o.config.longitude : 116.404, o.config.latitude ? o.config.latitude : 39.915]
});
map.add(marker);
var markCenter = function (e) {
// 标记中心点
map.clearMap();
// alert('您在[ '+e.lnglat.getLng()+','+e.lnglat.getLat()+' ]的位置点击了地图!');
//显示经纬度
var tbd = o.transformCoordinate(e.lng, e.lat);
$("#lng").val(tbd.lng);
$("#lat").val(tbd.lat);
o.lng = tbd.lng;
o.lat = tbd.lat;
var marker = new AMap.Marker({
icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
position: [e.lng, e.lat]
});
map.add(marker);
if (o.config.type == 1) {
searchNearBy(e.lng, e.lat);
}
}
var clickHandler = function (e) {
markCenter({lng: e.lnglat.getLng(), lat: e.lnglat.getLat()});
};
// 绑定事件
map.on('click', clickHandler);
// 附近搜索方法
var searchNearBy = function (lng, lat) {
AMap.service(['AMap.PlaceSearch'], function () {
var placeSearch = new AMap.PlaceSearch({
type: '', pageSize: 10, pageIndex: 1
});
var cpoint = [lng, lat];
placeSearch.searchNearBy('', cpoint, 1000, function (status, result) {
if (status === 'complete') {
var pois = result.poiList.pois;
var htmlList = '';
for (var i = 0; i < pois.length; i++) {
var poiItem = pois[i];
if (poiItem.location !== undefined) {
htmlList += '<div data-lng="' + poiItem.location.lng + '" data-lat="' + poiItem.location.lat + '" data-title="'+ poiItem.name +'" data-address="'+ poiItem.address +'" class="ew-map-select-search-list-item">';
htmlList += ' <div class="ew-map-select-search-list-item-title">' + poiItem.name + '</div>';
htmlList += ' <div class="ew-map-select-search-list-item-address">' + poiItem.address + '</div>';
htmlList += ' <div class="ew-map-select-search-list-item-icon-ok layui-hide"><i class="layui-icon layui-icon-ok-circle"></i></div>';
htmlList += '</div>';
}
}
$('#ew-map-select-poi').html(htmlList);
}
});
});
};
// 初始化search
if (o.config.type == 1) {
o.initGaodeSearch(map, markCenter, searchNearBy);
}
}
this.initGaodeSearch = function (map, markCenter, searchNearBy) {
var o = this;
// poi列表点击事件
$('#ew-map-select-poi').off('click').on('click', '.ew-map-select-search-list-item', function () {
$('#ew-map-select-tips').addClass('layui-hide');
$('#ew-map-select-poi .ew-map-select-search-list-item-icon-ok').addClass('layui-hide');
$(this).find('.ew-map-select-search-list-item-icon-ok').removeClass('layui-hide');
$('#ew-map-select-center-img').removeClass('bounceInDown');
setTimeout(function () {
$('#ew-map-select-center-img').addClass('bounceInDown');
});
var lng = $(this).data('lng');
var lat = $(this).data('lat');
var name = $(this).find('.ew-map-select-search-list-item-title').text();
var address = $(this).find('.ew-map-select-search-list-item-address').text();
//
map.setZoomAndCenter(map.getZoom(), [lng, lat]);
markCenter({lng: lng, lat: lat});
var title = $(this).data('title');
var address = $(this).data('address');
o.config.onClickTip({title:title,address:address,lng:lng,lat:lat});
});
searchNearBy(o.config.longitude ? o.config.longitude : 116.404, o.config.latitude ? o.config.latitude : 39.915);
// 搜索提示
var $inputSearch = $('#ew-map-select-input-search');
$inputSearch.off('input').on('input', function () {
var keywords = $(this).val();
var $selectTips = $('#ew-map-select-tips');
if (!keywords) {
$selectTips.html('');
$selectTips.addClass('layui-hide');
}
AMap.plugin('AMap.Autocomplete', function () {
var autoComplete = new AMap.Autocomplete({city: '全国'});
autoComplete.search(keywords, function (status, result) {
if (result.tips) {
var tips = result.tips;
var htmlList = '';
for (var i = 0; i < tips.length; i++) {
var tipItem = tips[i];
if (tipItem.location !== undefined) {
htmlList += '<div data-lng="' + tipItem.location.lng + '" data-lat="' + tipItem.location.lat + '" data-title="'+ tipItem.name +'" data-address="'+ tipItem.address +'" class="ew-map-select-search-list-item">';
htmlList += ' <div class="ew-map-select-search-list-item-icon-search"><i class="layui-icon layui-icon-search"></i></div>';
htmlList += ' <div class="ew-map-select-search-list-item-title">' + tipItem.name + '</div>';
htmlList += ' <div class="ew-map-select-search-list-item-address">' + tipItem.address + '</div>';
htmlList += '</div>';
}
}
$selectTips.html(htmlList);
if (tips.length === 0) $('#ew-map-select-tips').addClass('layui-hide');
else $('#ew-map-select-tips').removeClass('layui-hide');
} else {
$selectTips.html('');
$selectTips.addClass('layui-hide');
}
});
});
});
$inputSearch.off('blur').on('blur', function () {
var keywords = $(this).val();
var $selectTips = $('#ew-map-select-tips');
if (!keywords) {
$selectTips.html('');
$selectTips.addClass('layui-hide');
}
});
$inputSearch.off('focus').on('focus', function () {
var keywords = $(this).val();
if (keywords) $('#ew-map-select-tips').removeClass('layui-hide');
});
// tips列表点击事件
$('#ew-map-select-tips').off('click').on('click', '.ew-map-select-search-list-item', function () {
$('#ew-map-select-tips').addClass('layui-hide');
var lng = $(this).data('lng');
var lat = $(this).data('lat');
map.setZoomAndCenter(map.getZoom(), [lng, lat]);
markCenter({lng: lng, lat: lat});
var title = $(this).data('title');
var address = $(this).data('address');
o.config.onClickTip({title:title,address:address,lng:lng,lat:lat});
});
}
this.openMap = function () {
var o = this;
if (o.config.apiType == "baiduMap") {
var index = layer.open({
type: 1,
area: ["850px", "600px"],
title: o.config.title,
content: o.config.type == 0 ? tpl0:tpl1,
success: function () {
// 回显数据 中心标记经纬度
$("#lng").val(o.lng);
$("#lat").val(o.lat);
// 渲染地图
if (undefined === window.BMap) {
$.getScript("http://api.map.baidu.com/getscript?v=2.0&ak=tCNPmUfNmy4nTR3VYW71a6IgyWMaOSUb&services=&t=20200824135534", function () {
o.openBaiduMap();
});
} else {
o.openBaiduMap();
}
// 绑定事件
$("#ew-map-select-btn-ok").on("click", function () {
o.config.success({lng: o.lng ? o.lng : 116.404, lat: o.lat ? o.lat : 39.915});
layer.close(index);
})
}
});
} else if (o.config.apiType == "tiandiMap") {
var index = layer.open({
type: 1,
area: ["850px", "600px"],
title: o.config.title,
content: o.config.type == 0 ? tpl0:tpl1,
success: function () {
// 回显数据 中心标记经纬度
$("#lng").val(o.lng);
$("#lat").val(o.lat);
// 渲染地图
if (undefined === window.T) {
$.getScript("http://api.tianditu.gov.cn/api?v=4.0&tk=a8718394c98e9ae85b0d7af352653ce2&callback=init", function () {
o.openTiandiMap();
})
} else {
o.openTiandiMap();
}
// 绑定事件
$("#ew-map-select-btn-ok").on("click", function () {
o.config.success({lng: o.lng ? o.lng : 116.404, lat: o.lat ? o.lat : 39.915});
layer.close(index);
})
}
});
} else if (o.config.apiType == "gaodeMap") {
var index = layer.open({
type: 1,
area: ["850px", "600px"],
title: o.config.title,
content: o.config.type == 0 ? tpl0:tpl1,
success: function () {
// 回显数据 中心标记经纬度
$("#lng").val(o.lng);
$("#lat").val(o.lat);
// 渲染地图
if (undefined === window.AMap) {
$.getScript("https://webapi.amap.com/maps?v=1.4.14&key=006d995d433058322319fa797f2876f5", function () {
o.openGaodeMap();
});
} else {
o.openGaodeMap();
}
// 绑定事件
$("#ew-map-select-btn-ok").on("click", function () {
o.config.success({lng: o.lng ? o.lng : 116.404, lat: o.lat ? o.lat : 39.915});
layer.close(index);
})
}
});
}
}
};
layui.link(layui.cache.base + 'location/location.css'); // 加载css
/*导出模块,用一个location对象来管理obj不需要外部new obj*/
var location = function () {
}
location.prototype.render = function (elem, config) {
$(elem).on("click", function () {
var _this = new obj(config);
_this.openMap();
})
}
var locationObj = new location();
exports(MOD_NAME, locationObj);
})

View File

@ -0,0 +1,168 @@
layui.define(['layer'],function (exports) {
var $ = layui.jquery,
layer=layui.layer,
MOD_NAME = "locationX";
var GPS = {
PI : 3.14159265358979324,
x_pi : 3.14159265358979324 * 3000.0 / 180.0,
delta : function (lat, lon) {
// Krasovsky 1940
//
// a = 6378245.0, 1/f = 298.3
// b = a * (1 - f)
// ee = (a^2 - b^2) / a^2;
var a = 6378245.0; // a: 卫星椭球坐标投影到平面地图坐标系的投影因子。
var ee = 0.00669342162296594323; // ee: 椭球的偏心率。
var dLat = this.transformLat(lon - 105.0, lat - 35.0);
var dLon = this.transformLon(lon - 105.0, lat - 35.0);
var radLat = lat / 180.0 * this.PI;
var magic = Math.sin(radLat);
magic = 1 - ee * magic * magic;
var sqrtMagic = Math.sqrt(magic);
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * this.PI);
dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * this.PI);
return {'lat': dLat, 'lon': dLon};
},
//WGS-84 to GCJ-02
gcj_encrypt : function (wgsLat, wgsLon) {
if (this.outOfChina(wgsLat, wgsLon))
return {'lat': wgsLat, 'lon': wgsLon};
var d = this.delta(wgsLat, wgsLon);
return {'lat' : wgsLat + d.lat,'lon' : wgsLon + d.lon};
},
//GCJ-02 to WGS-84
gcj_decrypt : function (gcjLat, gcjLon) {
if (this.outOfChina(gcjLat, gcjLon))
return {'lat': gcjLat, 'lon': gcjLon};
var d = this.delta(gcjLat, gcjLon);
return {'lat': gcjLat - d.lat, 'lon': gcjLon - d.lon};
},
//GCJ-02 to WGS-84 exactly
gcj_decrypt_exact : function (gcjLat, gcjLon) {
var initDelta = 0.01;
var threshold = 0.000000001;
var dLat = initDelta, dLon = initDelta;
var mLat = gcjLat - dLat, mLon = gcjLon - dLon;
var pLat = gcjLat + dLat, pLon = gcjLon + dLon;
var wgsLat, wgsLon, i = 0;
while (1) {
wgsLat = (mLat + pLat) / 2;
wgsLon = (mLon + pLon) / 2;
var tmp = this.gcj_encrypt(wgsLat, wgsLon)
dLat = tmp.lat - gcjLat;
dLon = tmp.lon - gcjLon;
if ((Math.abs(dLat) < threshold) && (Math.abs(dLon) < threshold))
break;
if (dLat > 0) pLat = wgsLat; else mLat = wgsLat;
if (dLon > 0) pLon = wgsLon; else mLon = wgsLon;
if (++i > 10000) break;
}
//console.log(i);
return {'lat': wgsLat, 'lon': wgsLon};
},
//GCJ-02 to BD-09
bd_encrypt : function (gcjLat, gcjLon) {
var x = gcjLon, y = gcjLat;
var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * this.x_pi);
var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * this.x_pi);
bdLon = z * Math.cos(theta) + 0.0065;
bdLat = z * Math.sin(theta) + 0.006;
return {'lat' : bdLat,'lon' : bdLon};
},
//BD-09 to GCJ-02
bd_decrypt : function (bdLat, bdLon) {
var x = bdLon - 0.0065, y = bdLat - 0.006;
var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * this.x_pi);
var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * this.x_pi);
var gcjLon = z * Math.cos(theta);
var gcjLat = z * Math.sin(theta);
return {'lat' : gcjLat, 'lon' : gcjLon};
},
//
bd_WGS84:function(bdLat, bdLon){
var gcj=GPS.bd_decrypt(bdLat, bdLon);
return GPS.gcj_decrypt(gcj.lat,gcj.lon);
},
// 天地图坐标->百度坐标
WGS84_bd:function(bdLat, bdLon){
var gcj=GPS.gcj_encrypt(bdLat, bdLon);
return GPS.bd_encrypt(gcj.lat,gcj.lon);
},
//WGS-84 to Web mercator
//mercatorLat -> y mercatorLon -> x
mercator_encrypt : function(wgsLat, wgsLon) {
var x = wgsLon * 20037508.34 / 180.;
var y = Math.log(Math.tan((90. + wgsLat) * this.PI / 360.)) / (this.PI / 180.);
y = y * 20037508.34 / 180.;
return {'lat' : y, 'lon' : x};
/*
if ((Math.abs(wgsLon) > 180 || Math.abs(wgsLat) > 90))
return null;
var x = 6378137.0 * wgsLon * 0.017453292519943295;
var a = wgsLat * 0.017453292519943295;
var y = 3189068.5 * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));
return {'lat' : y, 'lon' : x};
//*/
},
// Web mercator to WGS-84
// mercatorLat -> y mercatorLon -> x
mercator_decrypt : function(mercatorLat, mercatorLon) {
var x = mercatorLon / 20037508.34 * 180.;
var y = mercatorLat / 20037508.34 * 180.;
y = 180 / this.PI * (2 * Math.atan(Math.exp(y * this.PI / 180.)) - this.PI / 2);
return {'lat' : y, 'lon' : x};
/*
if (Math.abs(mercatorLon) < 180 && Math.abs(mercatorLat) < 90)
return null;
if ((Math.abs(mercatorLon) > 20037508.3427892) || (Math.abs(mercatorLat) > 20037508.3427892))
return null;
var a = mercatorLon / 6378137.0 * 57.295779513082323;
var x = a - (Math.floor(((a + 180.0) / 360.0)) * 360.0);
var y = (1.5707963267948966 - (2.0 * Math.atan(Math.exp((-1.0 * mercatorLat) / 6378137.0)))) * 57.295779513082323;
return {'lat' : y, 'lon' : x};
//*/
},
// two point's distance
distance : function (latA, lonA, latB, lonB) {
var earthR = 6371000.;
var x = Math.cos(latA * this.PI / 180.) * Math.cos(latB * this.PI / 180.) * Math.cos((lonA - lonB) * this.PI / 180);
var y = Math.sin(latA * this.PI / 180.) * Math.sin(latB * this.PI / 180.);
var s = x + y;
if (s > 1) s = 1;
if (s < -1) s = -1;
var alpha = Math.acos(s);
var distance = alpha * earthR;
return distance;
},
outOfChina : function (lat, lon) {
if (lon < 72.004 || lon > 137.8347)
return true;
if (lat < 0.8293 || lat > 55.8271)
return true;
return false;
},
transformLat : function (x, y) {
var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(y * this.PI) + 40.0 * Math.sin(y / 3.0 * this.PI)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(y / 12.0 * this.PI) + 320 * Math.sin(y * this.PI / 30.0)) * 2.0 / 3.0;
return ret;
},
transformLon : function (x, y) {
var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(x * this.PI) + 40.0 * Math.sin(x / 3.0 * this.PI)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(x / 12.0 * this.PI) + 300.0 * Math.sin(x / 30.0 * this.PI)) * 2.0 / 3.0;
return ret;
}
};
exports(MOD_NAME,GPS);
})

View File

@ -0,0 +1,190 @@
layui.use(['laytpl', 'treeTable','jquery', 'form', 'miniTab', 'xmSelect'], function () {
let $ = layui.jquery,
form = layui.form,
treeTable = layui.treeTable,
layer = layui.layer,
miniTab = layui.miniTab,
xmSelect = layui.xmSelect;
let modifyUrl = $('#row-modify').data('url');
/**** index begin ***/
//index页面
if ($('.location-index-page').length > 0) {
miniTab.listen();
// 渲染表格
let listUrl = $('#menu-table').data('url');
let insTb = treeTable.render({
elem: '#menu-table',
toolbar: '#toolbar-tpl',
defaultToolbar: [],
method: 'POST',
skin: 'line',
url: listUrl,
page: false,
tree: {
iconIndex: 1, // 折叠图标显示在第几列
isPidData: true, // 是否是id、pid形式数据
idName: 'id', // id字段名称
pidName: 'pid' // pid字段名称
},
cols: [[
{type: 'checkbox'},
{field: 'name', minWidth: 200, title: '名称',edit: 'text'},
{field: 'sort', width: 80, align: 'center', title: '排序', edit: 'text'},
{templet: '#menu-operate', width: 150, align: 'center', title: '操作'}
]],
done: function () {
}
});
//监听单元格编辑
treeTable.on('edit(menu-table)', function(obj){
$.post(modifyUrl, {id: obj.data.id, field: obj.field, value: obj.value}, function (res) {
layer.msg(res.msg)
if (res.code === 0) {
insTb.refresh();
}
})
});
//监听工具条 注意区别toolbar和tool toolbar是表头上的工具条 tool是行中的工具条
treeTable.on('toolbar(menu-table)', function (obj) {
let layEvent = obj.event;
if (layEvent === 'expand') {
insTb.expandAll();
return false;
}
if (layEvent === 'refresh') {
insTb.refresh();
return false;
}
if (layEvent === 'fold') {
insTb.foldAll();
return false;
}
if (layEvent === 'del') {
let selected = insTb.checkStatus(false);
let ids = [];
let url = $(obj.elem.context).data('href')
$.each(selected, function (index, val) {
ids.push(val.id);
})
del(url, ids);
return false;
}
if (layEvent === 'add') {
let url = $(obj.elem.context).data('href');
let title = $(obj.elem.context).data('title');
let index = layer.open({
title: title,
type: 2,
shade: 0.2,
maxmin: true,
shadeClose: true,
area: ['100%', '100%'],
content: url,
});
$(window).on("resize", function () {
layer.full(index);
});
return false;
}
});
//删除
function del(url, ids) {
let index = layer.confirm('确认删除吗?', {
btn: ['确认','取消'], //按钮
title: '操作提示',
}, function() {
$.post(url, {ids: ids}, function (res) {
layer.msg(res.msg)
if (res.code === 0) {
insTb.refresh();
}
})
}, function(){
layer.close(index)
return false;
});
}
//监听工具条
treeTable.on('tool(menu-table)', function (obj) {
let data = obj.data;
let layEvent = obj.event;
let url = $(obj.tr.context).data('href');
let title = $(obj.tr.context).data('title');
if (layEvent === 'del') {
let ids = [data.id];
del(url, ids);
return false;
}
if (layEvent === 'edit') {
let index = layer.open({
title: title,
type: 2,
shade: 0.2,
maxmin: true,
shadeClose: true,
area: ['100%', '100%'],
content: url,
});
$(window).on("resize", function () {
layer.full(index);
});
return false;
}
});
}
/*** index end ***/
// add和edit页面
if ($('.location-operate-page').length > 0) {
let parentMenu = $('#parent-menu');
let menuList = parentMenu.data('menu') ? parentMenu.data('menu') : [];
xmSelect.render({
el: '#parent-menu',
paging: false,
autoRow: true,
radio: true,
clickClose: true,
name: 'pid',
tips: '请选择上级分类',
direction: 'auto',
height: 'auto',
model: {
icon: 'hidden',
},
prop: {
name: 'name',
value: 'id',
},
tree: {
show: true,
strict: false,
clickCheck: true,
expandedKeys: true,
clickExpand: false
},
theme: {
color: '#1e84ff',
},
data: menuList
});
}
});

View File

@ -4,57 +4,299 @@
<div class="layui-form layuimini-form">
<div class="layui-form-item">
<label class="layui-form-label">执照</label>
<div class="layui-input-block">
<div class="layui-layer-photos">
<img src="{$item.business_license??''}" layer-src="{$item.business_license??''}" alt="">
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">商家名称</label>
<div class="layui-input-block">
<input type="text" name="user" lay-verify="required" value="{$item.business_name??''}" disabled placeholder="请输入商家名称" class="layui-input">
<input type="text" name="business_name" lay-verify="required" value="{$item.business_name??''}" placeholder="请输入商家名称" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">商家名称</label>
<div class="layui-input-block">
<input type="text" name="business_subtitle" value="{$item.business_subtitle??''}" placeholder="请输入商家简称" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">商家类型</label>
<div class="layui-input-block">
<input type="text" name="user" lay-verify="required" value="{$item.type_name??''}" disabled placeholder="请输入商家类型" class="layui-input">
<select name="type">
<option value="">请选择问题</option>
{foreach $type as $value}
<optgroup label="{$value['name']}">
{if !empty($value['children'])}
{foreach $value['children'] as $ckey => $cvalue}
<option value="{$cvalue['id']}" {if $item['type'] ==$cvalue['id'] } selected {/if}>{$cvalue['name']}</option>
{/foreach}
{/if}
</optgroup>
{/foreach}
</select>
</div>
</div>
<div class="layui-form-item layui-row field-div current-field-cover" >
<label class="layui-form-label">执照:</label>
<div class="layui-inline layui-col-xs12 layui-col-md8">
<div class="layui-row upload-file-div">
<div class=" layui-col-xs12 layui-col-md8">
<input class="layui-input upload-file-value" name="business_license" type="text" value="{$item.business_license??''}">
<div class="layui-form-mid layui-word-aux">图片尺寸:请选择合适尺寸</div>
</div>
<div class="layui-col-xs12 layui-col-md3">
<span>
<button type="button" class="layui-btn layui-btn-danger upload-btn">
<i class="fa fa-upload"></i> 上传
</button>
</span>
</div>
<ul class="layui-row layui-col-xs12 layui-col-md9 preview-list layui-col-space5"></ul>
</div>
</div>
</div>
<!-- 地址 -->
<div class="layui-form-item">
<label class="layui-form-label required">地址</label>
<div class="layui-input-block">
<input type="hidden" id="input-province" name="province" value="{$item.province ?? 0}">
<input type="hidden" id="input-city" name="city" value="{$item.city ?? 0}">
<input type="hidden" id="input-county" name="county" value="{$item.county ?? 0}">
<input type="hidden" id="input-province-text" name="province_text" value="{$item.province_text ?? ''}">
<input type="hidden" id="input-city-text" name="city_text" value="{$item.city_text ?? ''}">
<input type="hidden" id="input-county-text" name="county_text" value="{$item.county_text ?? ''}">
<div id="target" style="z-index: 1111"></div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">商家地址</label>
<label class="layui-form-label required">详细地址</label>
<div class="layui-input-block">
<input type="text" name="user" lay-verify="required" value="{$item.business_address??''}" disabled placeholder="请输入" class="layui-input">
<input type="text" name="business_address" lay-verify="required" value="{$item.business_address??''}" placeholder="请输入" class="layui-input">
</div>
</div>
<!-- 经纬度 -->
<div class="layui-form-item">
<label class="layui-form-label required">经纬度</label>
<div class="layui-input-block">
<div class="layui-input-inline">
<input type="number" name="lng" value="{$item.lng ?? ''}" id="longitude" placeholder="请填写经度" lay-reqtext="经度不能为空" lay-verify="required" autocomplete="off" class="layui-input">
</div>
<div class="layui-input-inline">
<input type="number" name="lat" value="{$item.lat ?? ''}" id="latitude" placeholder="请填写纬度" lay-reqtext="纬度不能为空" lay-verify="required" autocomplete="off" class="layui-input">
</div>
<div class="layui-input-inline"><button class="layui-btn-normal layui-btn" id="locationBtn">定位</button></div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">联系人</label>
<div class="layui-input-block">
<input type="text" name="user" lay-verify="required" value="{$item.contact_name??''}" disabled placeholder="请输入" class="layui-input">
<input type="text" name="contact_name" lay-verify="required" value="{$item.contact_name??''}" placeholder="请输入" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">联系电话</label>
<div class="layui-input-block">
<input type="text" name="user" lay-verify="required" value="{$item.contact_phone??''}" disabled placeholder="请输入" class="layui-input">
<input type="text" name="contact_phone" lay-verify="required" value="{$item.contact_phone??''}" placeholder="请输入" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">审核状态</label>
<div class="layui-input-block">
<input type="radio" disabled {if $item['state']==0 } checked="checked" {/if} name="state" value="0" title="审核中" />
<input type="radio" disabled {if $item['state']==1 } checked="checked" {/if} name="state" value="1" title="审核通过" />
<input type="radio" disabled {if $item['state']==2 } checked="checked" {/if} name="state" value="2" title="拒绝" />
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">启用状态</label>
<div class="layui-input-block">
<input type="radio" {if $item['enable']==0 } checked="checked" {/if} name="enable" value="0" title="正常" />
<input type="radio" {if $item['enable']==1 } checked="checked" {/if} name="enable" value="1" title="禁用" />
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">特色</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="characteristic">{$item['characteristic']}</textarea>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">介绍</label>
<div class="layui-input-block">
<div class="editor"></div>
<textarea class="layui-textarea" name="intro" style="display:none;">{$item['intro']}</textarea>
</div>
</div>
<!-- <div class="layui-form-item">-->
<!-- <div class="layui-input-block">-->
<!-- <button class="layui-btn layui-btn-normal" data-url="/manager/attachment/edit?id={$item.id}" lay-submit lay-filter="saveBtn">确认保存</button>-->
<!-- </div>-->
<!-- </div>-->
<div class="layui-form-item">
<label class="layui-form-label required">商圈</label>
<div class="layui-input-block">
<select name="business_circle_id">
<option value="">请选择</option>
{foreach $businessCircle as $bkey => $bvalue}
<option value="{$bvalue['id']}" {if $item['business_circle_id'] == $bvalue['id'] } selected {/if}>{$bvalue['name']}</option>
{/foreach}
</select>
</div>
</div>
<div class="layui-form-item layui-row field-div current-field-cover" >
<label class="layui-form-label">商家背景图:</label>
<div class="layui-inline layui-col-xs12 layui-col-md8">
<div class="layui-row upload-file-div">
<div class=" layui-col-xs12 layui-col-md8">
<input class="layui-input upload-file-value" name="background" type="text" value="{$item.background??''}">
<div class="layui-form-mid layui-word-aux">图片尺寸:请选择合适尺寸</div>
</div>
<div class="layui-col-xs12 layui-col-md3">
<span>
<button type="button" class="layui-btn layui-btn-danger upload-btn">
<i class="fa fa-upload"></i> 上传
</button>
</span>
</div>
<ul class="layui-row layui-col-xs12 layui-col-md9 preview-list layui-col-space5"></ul>
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">商家评分</label>
<div class="layui-input-block">
<input type="radio" {if $item['score']==1 } checked="checked" {/if} name="score" value="1" title="1星" />
<input type="radio" {if $item['score']==2 } checked="checked" {/if} name="score" value="2" title="2星" />
<input type="radio" {if $item['score']==3 } checked="checked" {/if} name="score" value="3" title="3星" />
<input type="radio" {if $item['score']==4 } checked="checked" {/if} name="score" value="4" title="4星" />
<input type="radio" {if $item['score']==5 } checked="checked" {/if} name="score" value="5" title="5星" />
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn layui-btn-normal" data-url="/manager/business/business-detail?business_code={$item.code}" lay-submit lay-filter="saveBtn">确认保存</button>
</div>
</div>
</div>
</div>
</div>
<script src="__STATIC__/js/iPicker/iPicker.min.js"></script>
<script src="__STATIC__/common/jquery-3.4.1.min.js"></script>
<script>
let province = $('#input-province').val();
let city = $('#input-city').val();
let county = $('#input-county').val();
let _width = 200;
let _height = 34;
province = province ? province : '110000';
city = city ? city : '110100';
county = county ? county : '110101';
if ($('#target').length > 0) {
if ($('#target').data('width') != undefined) {
_width = $('#target').data('width');
}
if ($('#target').data('height') != undefined) {
_height = $('#target').data('height');
}
}
var picker =iPicker.create("#target", {
width: _width,
height: _height,
data: {
// 此处以通过 jquery 库获取本地数据源为例
//source: Promise.resolve($.getJSON("/static/js/iPicker/area.json"))
// 此处以通过 jquery 库获取数据为例
// 示例代码中使用的 "http://www.abcddcba.com/api/area" 是模拟地址,实际应用中替换成真实地址即可
// code 参数值就是相应地区对应的行政区划代码
// ----------------------------------------------------------------------------------------------------------
// 使用自定义数据源时,必须保证 source 属性值是 Function 类型
// iPicker 会自动执行此函数,同时要确保此函数的执行结果返回的是标准的 Promise 对象
// iPicker 会自动调用 then 方法,同时要确保 then 方法的参数就是返回的数据Array 类型)
// ----------------------------------------------------------------------------------------------------------
// 初始状态下iPicker 会自动执行一次 source 函数来获取 “省份” 数据,此时传入的 code 参数值为 null
// 因此,开发者可能需要给 code 参数设置一个默认值来获取 “省份” 数据(如示例代码中 code 为 null 时默认取零)
source: code => $.get( "/api/area/index.html?areaId=" + ( code || 86 ) )
},
onSelect: (code, name, all) => {
// 返回参数均为数组形式
// console.log( code );
// console.log( name );
// console.log( all );
let len = code.length;
if (len === 3) {
$('#input-province').val(code[0]);
$('#input-city').val(code[1]);
$('#input-county').val(code[2]);
$('#input-province-text').val(name[0]);
$('#input-city-text').val(name[1]);
$('#input-county-text').val(name[2]);
}
},
selected: [province, city, county],
})
</script>
<script>
layui.use(['layer','form','jquery','location'],function(){
let $ = layui.jquery;
let form = layui.form;
let location = layui.location;
let lng = $('#longitude').val();
let lat = $('#latitude').val();
lng = lng.length > 0 ? lng : '116.404';
lat = lat.length > 0 ? lat : '39.915';
let locationData = {lng: lng,lat: lat};
location.render("#locationBtn",{
type: 1,
apiType: "gaodeMap",
coordinate: "gaodeMap",
mapType: 0,
zoom: 15,
title: '区域定位',
init: function(){
// 打开地图时 延迟一定时间搜索
$('body').on('click', '#locationBtn', function () {
let address = $("input[name='address']").val();
setTimeout(function () {
$('#ew-map-select-input-search').val(address).trigger('input');
}, 1500)
})
return {longitude: $("#longitude").val()?$("#longitude").val():locationData.lng,latitude: $("#latitude").val()?$("#latitude").val():locationData.lat};
},
success: function (data) {
$("#longitude").val(data.lng);
$("#latitude").val(data.lat);
},
onClickTip: function (data) {
console.log(data);
}
});
});
</script>

View File

@ -0,0 +1,24 @@
{layout name="manager/layout" /}
<style>
.layui-iconpicker-body.layui-iconpicker-body-page .hide {display: none;}
</style>
<div class="layuimini-container location-operate-page">
<div class="layuimini-main">
<div class="layui-form layuimini-form">
<div class="layui-form-item">
<label class="layui-form-label required">标题</label>
<div class="layui-input-block">
<input type="text" name="name" lay-verify="required" lay-reqtext="标题不能为空" placeholder="请输入标题" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn layui-btn-normal" data-url="/manager/business-circle/add" lay-submit lay-filter="saveBtn">确认保存</button>
</div>
</div>
</div>
</div>
</div>
<script src="__MANAGER__/js/business_circle.js?v={:mt_rand()}"></script>

View File

@ -0,0 +1,30 @@
{layout name="manager/layout" /}
<style>
.layui-iconpicker-body.layui-iconpicker-body-page .hide {display: none;}
</style>
<div class="layuimini-container location-operate-page">
<div class="layuimini-main">
<div class="layui-form layuimini-form">
<div class="layui-form-item">
<label class="layui-form-label required">排序</label>
<div class="layui-input-block">
<input type="number" name="sort" lay-verify="required" value="{$item.sort ?? 0}" lay-reqtext="排序不能为空" placeholder="请输入排序" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">标题</label>
<div class="layui-input-block">
<input type="text" name="name" lay-verify="required" value="{$item.name ?? ''}" lay-reqtext="标题不能为空" placeholder="请输入标题" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn layui-btn-normal" data-url="/manager/business-circle/edit?id={$item.id}" lay-submit lay-filter="saveBtn">确认保存</button>
</div>
</div>
</div>
</div>
</div>
<script src="__MANAGER__/js/business_circle.js?v={:mt_rand()}"></script>

View File

@ -0,0 +1,26 @@
{layout name="manager/layout" /}
<div class="layuimini-container location-index-page">
<div class="layuimini-main">
<div>
<table id="menu-table" class="layui-table" data-url="/manager/business-circle" lay-filter="menu-table"></table>
</div>
</div>
</div>
<!-- 隐藏列 -->
<!-- 编辑单元格提交url -->
<input type="hidden" id="row-modify" data-url="/manager/business-circle/modify">
<!-- 操作列 -->
<script type="text/html" id="menu-operate">
<a class="layui-btn layui-btn-primary layui-btn-xs menu-edit" data-href="/manager/business-circle/edit.html?id={{d.id}}" data-title="编辑" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" data-href="/manager/business-circle/del.html" lay-event="del">删除</a>
</script>
<!-- toolbar -->
<script type="text/html" id="toolbar-tpl">
<a class="layui-btn layui-btn-primary layui-btn-sm" data-table-refresh lay-event="refresh"><i class="fa fa-refresh"></i></a>
<a class="layui-btn layui-btn-normal layui-btn-sm" data-href="/manager/business-circle/add.html" data-title="添加" lay-event="add">添加</a>
</script>
<script src="__MANAGER__/js/business_circle.js?v={:mt_rand()}"></script>