From 423acb0329fd75f593c9a5ddc074316d43b5763b Mon Sep 17 00:00:00 2001 From: augushong Date: Sat, 9 Jul 2022 18:27:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84table=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=BB=86=E8=8A=82=EF=BC=9B=E5=BC=80=E5=A7=8B=E6=8E=A5=E5=85=A5?= =?UTF-8?q?=E5=9F=8E=E5=B8=82=E9=80=89=E6=8B=A9=E5=99=A8=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/test/Goods.php | 65 + app/admin/model/TestGoods.php | 31 + .../curd/templates/view/module/table.code | 1 + app/admin/view/test/goods/add.html | 161 + app/admin/view/test/goods/edit.html | 169 + app/admin/view/test/goods/index.html | 10 + public/static/admin/css/public.css | 27 + public/static/admin/js/test/goods.js | 34 + public/static/config-admin.js | 2 + public/static/plugs/easy-admin/easy-admin.js | 16 +- .../jq-module/city-picker/css/city-picker.css | 162 + .../city-picker/images/drop-arrow.png | Bin 0 -> 314 bytes .../city-picker/js/city-picker.data.js | 4067 +++++++++++++++++ .../city-picker/js/city-picker.data.min.js | 11 + .../jq-module/city-picker/js/city-picker.js | 647 +++ .../city-picker/js/city-picker.min.js | 10 + 16 files changed, 5412 insertions(+), 1 deletion(-) create mode 100644 app/admin/controller/test/Goods.php create mode 100644 app/admin/model/TestGoods.php create mode 100644 app/admin/view/test/goods/add.html create mode 100644 app/admin/view/test/goods/edit.html create mode 100644 app/admin/view/test/goods/index.html create mode 100644 public/static/admin/js/test/goods.js create mode 100644 public/static/plugs/jq-module/city-picker/css/city-picker.css create mode 100644 public/static/plugs/jq-module/city-picker/images/drop-arrow.png create mode 100644 public/static/plugs/jq-module/city-picker/js/city-picker.data.js create mode 100644 public/static/plugs/jq-module/city-picker/js/city-picker.data.min.js create mode 100644 public/static/plugs/jq-module/city-picker/js/city-picker.js create mode 100644 public/static/plugs/jq-module/city-picker/js/city-picker.min.js diff --git a/app/admin/controller/test/Goods.php b/app/admin/controller/test/Goods.php new file mode 100644 index 0000000..53e2082 --- /dev/null +++ b/app/admin/controller/test/Goods.php @@ -0,0 +1,65 @@ +model = new \app\admin\model\TestGoods(); + + $this->assign('select_list_status', $this->model::SELECT_LIST_STATUS, true); + + $this->assign('select_list_time_status', $this->model::SELECT_LIST_TIME_STATUS, true); + + $this->assign('select_list_is_recommend', $this->model::SELECT_LIST_IS_RECOMMEND, true); + + $this->assign('select_list_shop_type', $this->model::SELECT_LIST_SHOP_TYPE, true); + + } + + + /** + * @NodeAnotation(title="列表") + */ + public function index() + { + if ($this->request->isAjax()) { + if (input('selectFields')) { + return $this->selectList(); + } + list($page, $limit, $where) = $this->buildTableParames(); + $count = $this->model + ->withJoin('mallCate', 'LEFT') + ->where($where) + ->count(); + $list = $this->model + ->withJoin('mallCate', 'LEFT') + ->where($where) + ->page($page, $limit) + ->order($this->sort) + ->select(); + $data = [ + 'code' => 0, + 'msg' => '', + 'count' => $count, + 'data' => $list, + ]; + return json($data); + } + return $this->fetch(); + } +} \ No newline at end of file diff --git a/app/admin/model/TestGoods.php b/app/admin/model/TestGoods.php new file mode 100644 index 0000000..cd1ed50 --- /dev/null +++ b/app/admin/model/TestGoods.php @@ -0,0 +1,31 @@ +'正常','1'=>'禁用',]; + + public const SELECT_LIST_TIME_STATUS = ['0'=>'未参加','1'=>'已开始','3'=>'已结束',]; + + public const SELECT_LIST_IS_RECOMMEND = ['0'=>'不推荐','1'=>'推荐',]; + + public const SELECT_LIST_SHOP_TYPE = ['taobao'=>'淘宝','jd'=>'京东',]; + + + + public function mallCate() + { + return $this->belongsTo('\app\admin\model\MallCate', 'cate_id', 'id'); + } + + +} \ No newline at end of file diff --git a/app/admin/service/curd/templates/view/module/table.code b/app/admin/service/curd/templates/view/module/table.code index 502d8da..24ec507 100644 --- a/app/admin/service/curd/templates/view/module/table.code +++ b/app/admin/service/curd/templates/view/module/table.code @@ -1,3 +1,4 @@ +
diff --git a/app/admin/view/test/goods/add.html b/app/admin/view/test/goods/add.html new file mode 100644 index 0000000..c4e79d7 --- /dev/null +++ b/app/admin/view/test/goods/add.html @@ -0,0 +1,161 @@ +
+
+ +
+ +
+
+ +
+
+
+
+ +
+ +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ {foreach $select_list_status as $k=>$v} + + {/foreach} +
+
+ +
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ {foreach $select_list_is_recommend as $k=>$v} + + {/foreach} +
+
+ +
+ +
+ {foreach $select_list_shop_type as $k=>$v} + + {/foreach} +
+
+ +
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+
+ + +
+ +
+
\ No newline at end of file diff --git a/app/admin/view/test/goods/edit.html b/app/admin/view/test/goods/edit.html new file mode 100644 index 0000000..efc6be2 --- /dev/null +++ b/app/admin/view/test/goods/edit.html @@ -0,0 +1,169 @@ +
+
+ +
+ +
+
+ +
+
+
+
+ +
+ +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ {foreach $select_list_status as $k=>$v} + + {/foreach} +
+
+ +
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ {foreach $select_list_is_recommend as $k=>$v} + + {/foreach} +
+
+ +
+ +
+ {foreach $select_list_shop_type as $k=>$v} + + {/foreach} +
+
+ +
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+ + + +
+
+
+
+ + +
+ +
+
\ No newline at end of file diff --git a/app/admin/view/test/goods/index.html b/app/admin/view/test/goods/index.html new file mode 100644 index 0000000..da5508a --- /dev/null +++ b/app/admin/view/test/goods/index.html @@ -0,0 +1,10 @@ +
+
+ +
+
+
\ No newline at end of file diff --git a/public/static/admin/css/public.css b/public/static/admin/css/public.css index 4190d03..e19bdf6 100644 --- a/public/static/admin/css/public.css +++ b/public/static/admin/css/public.css @@ -1,6 +1,7 @@ @import url("../../plugs/layui-v2.7.2/css/layui.css"); @import url("../../plugs/font-awesome-4.7.0/css/font-awesome.min.css"); @import url("../css/iconfont.css"); +@import url('../../plugs/jq-module/city-picker/css/city-picker.css'); html, body { @@ -620,6 +621,32 @@ table样式 display: flex; width : 274px; } + .form-item-number-limit .layui-input-inline { display: flex; +} + +/* 重写地区选择器的样式 */ + +.city-picker-span { + height : 38px; + border-width : 1px; + border-style : solid; + background-color: #fff; + color : rgba(0, 0, 0, .85); + border-radius : 2px; + border-color : #eee; +} + +.city-picker-span:hover { + border-color: #eee !important; +} + +.city-picker-span>.placeholder { + padding-left: 10px; +} + +.city-picker-span.focus, +.city-picker-span.open { + border-color: #d2d2d2 !important; } \ No newline at end of file diff --git a/public/static/admin/js/test/goods.js b/public/static/admin/js/test/goods.js new file mode 100644 index 0000000..e65d676 --- /dev/null +++ b/public/static/admin/js/test/goods.js @@ -0,0 +1,34 @@ +define(["jquery", "easy-admin"], function ($, ea) { + + var init = { + table_elem: '#currentTable', + table_render_id: 'currentTableRenderId', + index_url: 'test.goods/index', + add_url: 'test.goods/add', + edit_url: 'test.goods/edit', + delete_url: 'test.goods/delete', + export_url: 'test.goods/export', + modify_url: 'test.goods/modify', + }; + + var Controller = { + + index: function () { + ea.table.render({ + init: init, + cols: [[ + {type: 'checkbox'}, {field: 'id', title: 'id'}, {field: 'cate_id', title: '分类ID'}, {field: 'title', title: '商品名称'}, {field: 'logo', title: '商品logo', templet: ea.table.image}, {field: 'total_stock', title: '总库存'}, {field: 'sort', title: '排序', edit: 'text'}, {field: 'status', search: 'select', selectList: ea.getDataBrage('select_list_status'), title: '状态', templet: ea.table.switch}, {field: 'cert_file', title: '合格证', templet: ea.table.url}, {field: 'remark', title: '备注说明', templet: ea.table.text}, {field: 'create_time', title: 'create_time'}, {field: 'publish_time', title: '发布日期'}, {field: 'sale_time', title: '售卖日期'}, {field: 'intro', title: '简介'}, {field: 'time_status', search: 'select', selectList: ea.getDataBrage('select_list_time_status'), title: '秒杀状态'}, {field: 'is_recommend', search: 'select', selectList: ea.getDataBrage('select_list_is_recommend'), title: '是否推荐'}, {field: 'shop_type', search: 'select', selectList: ea.getDataBrage('select_list_shop_type'), title: '商品类型'}, {field: 'mallCate.id', title: ''}, {field: 'mallCate.title', title: '分类名'}, {field: 'mallCate.image', title: '分类图片', templet: ea.table.image}, {field: 'mallCate.sort', title: '排序', edit: 'text'}, {field: 'mallCate.status', title: '状态', templet: ea.table.switch}, {field: 'mallCate.remark', title: '备注说明', templet: ea.table.text}, {field: 'mallCate.create_time', title: '创建时间'}, {width: 250, title: '操作', templet: ea.table.tool}, + ]], + }); + + ea.listen(); + }, + add: function () { + ea.listen(); + }, + edit: function () { + ea.listen(); + }, + }; + return Controller; +}); \ No newline at end of file diff --git a/public/static/config-admin.js b/public/static/config-admin.js index f8ecc2f..beb60b0 100644 --- a/public/static/config-admin.js +++ b/public/static/config-admin.js @@ -22,6 +22,8 @@ require.config({ "autocomplete": ["plugs/lay-module/autocomplete/autocomplete"], "vue": ["plugs/vue-2.6.10/vue.min"], "ckeditor": ["plugs/ckeditor4/ckeditor"], + 'citypicker': ['plugs/jq-module/city-picker/js/city-picker.min'], + 'ChineseDistricts': ['plugs/jq-module/city-picker/js/city-picker.data.min'], } }); diff --git a/public/static/plugs/easy-admin/easy-admin.js b/public/static/plugs/easy-admin/easy-admin.js index efdbfca..940b8bd 100644 --- a/public/static/plugs/easy-admin/easy-admin.js +++ b/public/static/plugs/easy-admin/easy-admin.js @@ -1,4 +1,4 @@ -define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData'], function ($, tableSelect, undefined, miniTheme, tableData) { +define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData','citypicker'], function ($, tableSelect, undefined, miniTheme, tableData) { window.onInitElemStyle = function () { miniTheme.renderElemStyle() @@ -1708,6 +1708,20 @@ define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData'], function }); } + var cityList= $(v).closest('.layui-form').find('[data-toggle="city-picker"]'); + + if(cityList.length > 0){ + $.each(cityList, function (i, v) { + console.log(i); + console.log(v); + var code = $(v).data('citypicker').getCode(type); + var text = $(v).data('citypicker').getVal(type); + + console.log(code); + console.log(text); + }) + } + if (typeof preposeCallback === 'function') { dataField = preposeCallback(dataField); } diff --git a/public/static/plugs/jq-module/city-picker/css/city-picker.css b/public/static/plugs/jq-module/city-picker/css/city-picker.css new file mode 100644 index 0000000..4a0d82e --- /dev/null +++ b/public/static/plugs/jq-module/city-picker/css/city-picker.css @@ -0,0 +1,162 @@ +.city-picker-input { + opacity: 0 !important; + top: -9999px; + left: -9999px; + position: absolute; +} + +.city-picker-span { + position: relative; + display: block; + outline: 0; + -webkit-tap-highlight-color: rgba(0, 0, 0, 0); + border-bottom: 1px solid #ccc; + background-color: #fff; + color: #ccc; + cursor: pointer; +} + +.city-picker-span > .placeholder { + color: #aaa; +} + +.city-picker-span > .arrow { + position: absolute; + top: 50%; + right: 8px; + width: 10px; + margin-top: -3px; + height: 5px; + background: url(../images/drop-arrow.png) -10px -25px no-repeat; +} + +.city-picker-span.focus, +.city-picker-span.open { + border-bottom-color: #46A4FF; +} + +.city-picker-span.open > .arrow { + background-position: -10px -10px; +} + +.city-picker-span > .title > span { + color: #333; + padding: 5px; + border-radius: 3px; +} + +.city-picker-span > .title > span:hover { + background-color: #f1f8ff; +} + +.city-picker-dropdown { + position: absolute; + width: 315px; + left: -9999px; + top: -9999px; + outline: 0; + -webkit-tap-highlight-color: rgba(0, 0, 0, 0); + z-index: 999999; + display: none; + min-width: 330px; + margin-bottom: 20px; +} + +.city-select-wrap { + box-shadow: 0 1px 5px rgba(0, 0, 0, 0.5); +} + +.city-select-tab { + border-bottom: 1px solid #ccc; + background: #f0f0f0; + font-size: 13px; +} + +.city-select-tab > a { + display: inline-block; + padding: 8px 22px; + border-left: 1px solid #ccc; + border-bottom: 1px solid transparent; + color: #4D4D4D; + text-align: center; + outline: 0; + text-decoration: none; + cursor: pointer; + font-size: 14px; + margin-bottom: -1px; +} + +.city-select-tab > a.active { + background: #fff; + border-bottom: 1px solid #fff; + color: #46A4FF; +} + +.city-select-tab > a:first-child { + border-left: none; +} + +.city-select-tab > a:last-child.active { + border-right: 1px solid #ccc; +} + +.city-select-content { + width: 100%; + min-height: 10px; + background-color: #fff; + padding: 10px 15px; + box-sizing: border-box; +} + +.city-select { + font-size: 13px; +} + +.city-select dl { + line-height: 2; + clear: both; + padding: 3px 0; + margin: 0; +} + +.city-select dt { + position: absolute; + width: 2.5em; + font-weight: 500; + text-align: right; + line-height: 2; +} + +.city-select dd { + margin-left: 0; + line-height: 2; +} + +.city-select.province dd { + margin-left: 3em; +} + +.city-select a { + display: inline-block; + padding: 0 10px; + outline: 0; + text-decoration: none; + white-space: nowrap; + margin-right: 2px; + text-decoration: none; + color: #333; + cursor: pointer; +} + +.city-select a:hover, +.city-select a:focus { + background-color: #f1f8ff; + border-radius: 2px; + color: #46A4FF; +} + +.city-select a.active { + background-color: #46A4FF; + color: #fff; + border-radius: 2px; +} diff --git a/public/static/plugs/jq-module/city-picker/images/drop-arrow.png b/public/static/plugs/jq-module/city-picker/images/drop-arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..308dae5f492f8f5e39ee9175ced7004da80fddad GIT binary patch literal 314 zcmeAS@N?(olHy`uVBq!ia0vp^azL!X!3HE>3VR6wDVAa<&kznEsNqQI0P;BtJR*x3 z7`TCQ+(L|(?$-SQ3d)qYMwA5Srw3Rh2f^iH#&WX8cf&rrj~(=@db54F@YuJ5~dxl34(!QtG^Z%ZdmZ&h2j zqW0SqX*<8D<-HH|c9iZ7tdV$Eb6H@XM0X3P@IM(FnQo;;4%MmCil=-|Pu{q_zqcw+!EqMR8am%M0(LJt*S~%' + + (placeholder ? '' + placeholder + '' : '') + + '
' + '', + + dropdown = '
' + + '
' + + '
' + + '省份' + + (this.includeDem('city') ? '城市' : '') + + (this.includeDem('district') ? '区县' : '') + '
' + + '
' + + '
' + + (this.includeDem('city') ? '
' : '') + + (this.includeDem('district') ? '
' : '') + + '
'; + + this.$element.addClass('city-picker-input'); + this.$textspan = $(textspan).insertAfter(this.$element); + this.$dropdown = $(dropdown).insertAfter(this.$textspan); + var $select = this.$dropdown.find('.city-select'); + + // setup this.$province, this.$city and/or this.$district object + $.each(this.dems, $.proxy(function (i, type) { + this['$' + type] = $select.filter('.' + type + ''); + }, this)); + + this.refresh(); + }, + + refresh: function (force) { + // clean the data-item for each $select + var $select = this.$dropdown.find('.city-select'); + $select.data('item', null); + // parse value from value of the target $element + var val = this.$element.val() || ''; + val = val.split('/'); + $.each(this.dems, $.proxy(function (i, type) { + if (val[i] && i < val.length) { + this.options[type] = val[i]; + } else if (force) { + this.options[type] = ''; + } + this.output(type); + }, this)); + this.tab(PROVINCE); + this.feedText(); + this.feedVal(); + }, + + defineDems: function () { + var stop = false; + $.each([PROVINCE, CITY, DISTRICT], $.proxy(function (i, type) { + if (!stop) { + this.dems.push(type); + } + if (type === this.options.level) { + stop = true; + } + }, this)); + }, + + includeDem: function (type) { + return $.inArray(type, this.dems) !== -1; + }, + + getPosition: function () { + var p, h, w, s, pw; + p = this.$element.position(); + s = this.getSize(this.$element); + h = s.height; + w = s.width; + if (this.options.responsive) { + pw = this.$element.offsetParent().width(); + if (pw) { + w = w / pw; + if (w > 0.99) { + w = 1; + } + w = w * 100 + '%'; + } + } + + return { + top: p.top || 0, + left: p.left || 0, + height: h, + width: w + }; + }, + + getSize: function ($dom) { + var $wrap, $clone, sizes; + if (!$dom.is(':visible')) { + $wrap = $("
").appendTo($("body")); + $wrap.css({ + "position": "absolute !important", + "visibility": "hidden !important", + "display": "block !important" + }); + + $clone = $dom.clone().appendTo($wrap); + + sizes = { + width: $clone.outerWidth(), + height: $clone.outerHeight() + }; + + $wrap.remove(); + } else { + sizes = { + width: $dom.outerWidth(), + height: $dom.outerHeight() + }; + } + + return sizes; + }, + + getWidthStyle: function (w, dropdown) { + if (this.options.responsive && !$.isNumeric(w)) { + return 'width:' + w + ';'; + } else { + return 'width:' + (dropdown ? Math.max(320, w) : w) + 'px;'; + } + }, + + bind: function () { + var $this = this; + + $(document).on('click', (this._mouteclick = function (e) { + var $target = $(e.target); + var $dropdown, $span, $input; + if ($target.is('.city-picker-span')) { + $span = $target; + } else if ($target.is('.city-picker-span *')) { + $span = $target.parents('.city-picker-span'); + } + if ($target.is('.city-picker-input')) { + $input = $target; + } + if ($target.is('.city-picker-dropdown')) { + $dropdown = $target; + } else if ($target.is('.city-picker-dropdown *')) { + $dropdown = $target.parents('.city-picker-dropdown'); + } + if ((!$input && !$span && !$dropdown) || + ($span && $span.get(0) !== $this.$textspan.get(0)) || + ($input && $input.get(0) !== $this.$element.get(0)) || + ($dropdown && $dropdown.get(0) !== $this.$dropdown.get(0))) { + $this.close(true); + } + + })); + + this.$element.on('change', (this._changeElement = $.proxy(function () { + this.close(true); + this.refresh(true); + }, this))).on('focus', (this._focusElement = $.proxy(function () { + this.needBlur = true; + this.open(); + }, this))).on('blur', (this._blurElement = $.proxy(function () { + if (this.needBlur) { + this.needBlur = false; + this.close(true); + } + }, this))); + + this.$textspan.on('click', function (e) { + var $target = $(e.target), type; + $this.needBlur = false; + if ($target.is('.select-item')) { + type = $target.data('count'); + $this.open(type); + } else { + if ($this.$dropdown.is(':visible')) { + $this.close(); + } else { + $this.open(); + } + } + }).on('mousedown', function () { + $this.needBlur = false; + }); + + this.$dropdown.on('click', '.city-select a', function () { + var $select = $(this).parents('.city-select'); + var $active = $select.find('a.active'); + var last = $select.next().length === 0; + $active.removeClass('active'); + $(this).addClass('active'); + if ($active.data('code') !== $(this).data('code')) { + $select.data('item', { + address: $(this).attr('title'), code: $(this).data('code') + }); + $(this).trigger(EVENT_CHANGE); + $this.feedText(); + $this.feedVal(true); + if (last) { + $this.close(); + } + } + }).on('click', '.city-select-tab a', function () { + if (!$(this).hasClass('active')) { + var type = $(this).data('count'); + $this.tab(type); + } + }).on('mousedown', function () { + $this.needBlur = false; + }); + + if (this.$province) { + this.$province.on(EVENT_CHANGE, (this._changeProvince = $.proxy(function () { + this.output(CITY); + this.output(DISTRICT); + this.tab(CITY); + }, this))); + } + + if (this.$city) { + this.$city.on(EVENT_CHANGE, (this._changeCity = $.proxy(function () { + this.output(DISTRICT); + this.tab(DISTRICT); + }, this))); + } + }, + + open: function (type) { + type = type || PROVINCE; + this.$dropdown.show(); + this.$textspan.addClass('open').addClass('focus'); + this.tab(type); + }, + + close: function (blur) { + this.$dropdown.hide(); + this.$textspan.removeClass('open'); + if (blur) { + this.$textspan.removeClass('focus'); + } + }, + + unbind: function () { + + $(document).off('click', this._mouteclick); + + this.$element.off('change', this._changeElement); + this.$element.off('focus', this._focusElement); + this.$element.off('blur', this._blurElement); + + this.$textspan.off('click'); + this.$textspan.off('mousedown'); + + this.$dropdown.off('click'); + this.$dropdown.off('mousedown'); + + if (this.$province) { + this.$province.off(EVENT_CHANGE, this._changeProvince); + } + + if (this.$city) { + this.$city.off(EVENT_CHANGE, this._changeCity); + } + }, + + getText: function () { + var text = ''; + this.$dropdown.find('.city-select') + .each(function () { + var item = $(this).data('item'), + type = $(this).data('count'); + if (item) { + text += ($(this).hasClass('province') ? '' : '/') + '' + item.address + ''; + } + }); + return text; + }, + + getPlaceHolder: function () { + return this.$element.attr('placeholder') || this.options.placeholder; + }, + + feedText: function () { + var text = this.getText(); + if (text) { + this.$textspan.find('>.placeholder').hide(); + this.$textspan.find('>.title').html(this.getText()).show(); + } else { + this.$textspan.find('>.placeholder').text(this.getPlaceHolder()).show(); + this.$textspan.find('>.title').html('').hide(); + } + }, + + getCode: function (count) { + var obj = {}, arr = []; + this.$textspan.find('.select-item') + .each(function () { + var code = $(this).data('code'); + var count = $(this).data('count'); + obj[count] = code; + arr.push(code); + }); + return count ? obj[count] : arr.join('/'); + }, + + getVal: function () { + var text = ''; + this.$dropdown.find('.city-select') + .each(function () { + var item = $(this).data('item'); + if (item) { + text += ($(this).hasClass('province') ? '' : '/') + item.address; + } + }); + return text; + }, + + feedVal: function (trigger) { + this.$element.val(this.getVal()); + if(trigger) { + this.$element.trigger('cp:updated'); + } + }, + + output: function (type) { + var options = this.options; + //var placeholders = this.placeholders; + var $select = this['$' + type]; + var data = type === PROVINCE ? {} : []; + var item; + var districts; + var code; + var matched = null; + var value; + + if (!$select || !$select.length) { + return; + } + + item = $select.data('item'); + + value = (item ? item.address : null) || options[type]; + + code = ( + type === PROVINCE ? 86 : + type === CITY ? this.$province && this.$province.find('.active').data('code') : + type === DISTRICT ? this.$city && this.$city.find('.active').data('code') : code + ); + + districts = $.isNumeric(code) ? ChineseDistricts[code] : null; + + if ($.isPlainObject(districts)) { + $.each(districts, function (code, address) { + var provs; + if (type === PROVINCE) { + provs = []; + for (var i = 0; i < address.length; i++) { + if (address[i].address === value) { + matched = { + code: address[i].code, + address: address[i].address + }; + } + provs.push({ + code: address[i].code, + address: address[i].address, + selected: address[i].address === value + }); + } + data[code] = provs; + } else { + if (address === value) { + matched = { + code: code, + address: address + }; + } + data.push({ + code: code, + address: address, + selected: address === value + }); + } + }); + } + + $select.html(type === PROVINCE ? this.getProvinceList(data) : + this.getList(data, type)); + $select.data('item', matched); + }, + + getProvinceList: function (data) { + var list = [], + $this = this, + simple = this.options.simple; + + $.each(data, function (i, n) { + list.push('
'); + list.push('
' + i + '
'); + $.each(n, function (j, m) { + list.push( + '' + + ( simple ? $this.simplize(m.address, PROVINCE) : m.address) + + ''); + }); + list.push('
'); + }); + + return list.join(''); + }, + + getList: function (data, type) { + var list = [], + $this = this, + simple = this.options.simple; + list.push('
'); + + $.each(data, function (i, n) { + list.push( + '' + + ( simple ? $this.simplize(n.address, type) : n.address) + + ''); + }); + list.push('
'); + + return list.join(''); + }, + + simplize: function (address, type) { + address = address || ''; + if (type === PROVINCE) { + return address.replace(/[省,市,自治区,壮族,回族,维吾尔]/g, ''); + } else if (type === CITY) { + return address.replace(/[市,地区,回族,蒙古,苗族,白族,傣族,景颇族,藏族,彝族,壮族,傈僳族,布依族,侗族]/g, '') + .replace('哈萨克', '').replace('自治州', '').replace(/自治县/, ''); + } else if (type === DISTRICT) { + return address.length > 2 ? address.replace(/[市,区,县,旗]/g, '') : address; + } + }, + + tab: function (type) { + var $selects = this.$dropdown.find('.city-select'); + var $tabs = this.$dropdown.find('.city-select-tab > a'); + var $select = this['$' + type]; + var $tab = this.$dropdown.find('.city-select-tab > a[data-count="' + type + '"]'); + if ($select) { + $selects.hide(); + $select.show(); + $tabs.removeClass('active'); + $tab.addClass('active'); + } + }, + + reset: function () { + this.$element.val(null).trigger('change'); + }, + + destroy: function () { + this.unbind(); + this.$element.removeData(NAMESPACE).removeClass('city-picker-input'); + this.$textspan.remove(); + this.$dropdown.remove(); + } + }; + + CityPicker.DEFAULTS = { + simple: false, + responsive: false, + placeholder: '请选择省/市/区', + level: 'district', + province: '', + city: '', + district: '' + }; + + CityPicker.setDefaults = function (options) { + $.extend(CityPicker.DEFAULTS, options); + }; + + // Save the other citypicker + CityPicker.other = $.fn.citypicker; + + // Register as jQuery plugin + $.fn.citypicker = function (option) { + var args = [].slice.call(arguments, 1); + + return this.each(function () { + var $this = $(this); + var data = $this.data(NAMESPACE); + var options; + var fn; + + if (!data) { + if (/destroy/.test(option)) { + return; + } + + options = $.extend({}, $this.data(), $.isPlainObject(option) && option); + $this.data(NAMESPACE, (data = new CityPicker(this, options))); + } + + if (typeof option === 'string' && $.isFunction(fn = data[option])) { + fn.apply(data, args); + } + }); + }; + + $.fn.citypicker.Constructor = CityPicker; + $.fn.citypicker.setDefaults = CityPicker.setDefaults; + + // No conflict + $.fn.citypicker.noConflict = function () { + $.fn.citypicker = CityPicker.other; + return this; + }; + + // 根据code查询地址 + $.fn.citypicker.getAddressbyCodeId = function(code_id){ + var city = ChineseDistricts; + var code = city[''+code_id]; + var addr = ''; + var province = ''; + var province_code = ''; + var city_str = ''; + var county = ''; + if(code_id.substring(0,2)==='44'){ + province = '广东省'; + province_code = '440000'; + }else{ + $.each(city['86'], function(i,item) { + $.each(item, function(j,index) { + if(index['code']===code_id.substring(0,2)+'0000'){ + province = index['address']; + province_code = index['code']; + return false; + } + }); + }); + } + if(code_id.substring(2,4).indexOf('00')==-1){ + var city_code = code_id.substring(0,4)+'00'; + city_str = city[province_code][city_code]; + } + if(code===undefined){ + //440103 + code = code_id.substring(0,4)+"00"; + if(city[code] == null) return; + addr = city[code][code_id]; + return addr = province+'/'+city_str+'/'+addr; + }else{ + if(code_id.substring(2,4).indexOf('00')!=-1){ + //440000 + return addr = province; + }else{ + //440100 + var city_city = city[code_id.substring(0,2)+'0000']; + return addr = province +'/'+city_city[code_id]; + } + } + } + + $(function () { + $('[data-toggle="city-picker"]').citypicker(); + }); +}); \ No newline at end of file diff --git a/public/static/plugs/jq-module/city-picker/js/city-picker.min.js b/public/static/plugs/jq-module/city-picker/js/city-picker.min.js new file mode 100644 index 0000000..fc665f5 --- /dev/null +++ b/public/static/plugs/jq-module/city-picker/js/city-picker.min.js @@ -0,0 +1,10 @@ +/*! + * CityPicker v1.2.0 + * https://github.com/tshi0912/citypicker + * + * Copyright (c) 2015-2018 Tao Shi + * Released under the MIT license + * + * Date: 2018-04-12T04:27:10.483Z + */ +!function(t){"function"==typeof define&&define.amd?define(["jquery","ChineseDistricts"],t):"object"==typeof exports?t(require("jquery"),require("ChineseDistricts")):t(jQuery,ChineseDistricts)}(function(t,e){"use strict";function i(e,s){this.$element=t(e),this.$dropdown=null,this.options=t.extend({},i.DEFAULTS,t.isPlainObject(s)&&s),this.active=!1,this.dems=[],this.needBlur=!1,this.init()}if("undefined"==typeof e)throw new Error('The file "city-picker.data.js" must be included first!');var s="citypicker",n="change."+s,c="province",o="city",d="district";i.prototype={constructor:i,init:function(){this.codeRender(),this.defineDems(),this.render(),this.bind(),this.active=!0},codeRender:function(){var e=this.$element.attr("code");void 0===e||""===e||isNaN(Number(e))||this.$element.val(t.fn.citypicker.getAddressbyCodeId(e))},render:function(){var e=this.getPosition(),i=this.$element.attr("placeholder")||this.options.placeholder,s=''+(i?''+i+"":"")+'
',n='
省份'+(this.includeDem("city")?'城市':"")+(this.includeDem("district")?'区县':"")+'
'+(this.includeDem("city")?'
':"")+(this.includeDem("district")?'
':"")+"
";this.$element.addClass("city-picker-input"),this.$textspan=t(s).insertAfter(this.$element),this.$dropdown=t(n).insertAfter(this.$textspan);var c=this.$dropdown.find(".city-select");t.each(this.dems,t.proxy(function(t,e){this["$"+e]=c.filter("."+e)},this)),this.refresh()},refresh:function(e){var i=this.$dropdown.find(".city-select");i.data("item",null);var s=this.$element.val()||"";s=s.split("/"),t.each(this.dems,t.proxy(function(t,i){s[t]&&t.99&&(i=1),i=100*i+"%")),{top:t.top||0,left:t.left||0,height:e,width:i}},getSize:function(e){var i,s,n;return e.is(":visible")?n={width:e.outerWidth(),height:e.outerHeight()}:(i=t("
").appendTo(t("body")),i.css({position:"absolute !important",visibility:"hidden !important",display:"block !important"}),s=e.clone().appendTo(i),n={width:s.outerWidth(),height:s.outerHeight()},i.remove()),n},getWidthStyle:function(e,i){return this.options.responsive&&!t.isNumeric(e)?"width:"+e+";":"width:"+(i?Math.max(320,e):e)+"px;"},bind:function(){var e=this;t(document).on("click",this._mouteclick=function(i){var s,n,c,o=t(i.target);o.is(".city-picker-span")?n=o:o.is(".city-picker-span *")&&(n=o.parents(".city-picker-span")),o.is(".city-picker-input")&&(c=o),o.is(".city-picker-dropdown")?s=o:o.is(".city-picker-dropdown *")&&(s=o.parents(".city-picker-dropdown")),(!c&&!n&&!s||n&&n.get(0)!==e.$textspan.get(0)||c&&c.get(0)!==e.$element.get(0)||s&&s.get(0)!==e.$dropdown.get(0))&&e.close(!0)}),this.$element.on("change",this._changeElement=t.proxy(function(){this.close(!0),this.refresh(!0)},this)).on("focus",this._focusElement=t.proxy(function(){this.needBlur=!0,this.open()},this)).on("blur",this._blurElement=t.proxy(function(){this.needBlur&&(this.needBlur=!1,this.close(!0))},this)),this.$textspan.on("click",function(i){var s,n=t(i.target);e.needBlur=!1,n.is(".select-item")?(s=n.data("count"),e.open(s)):e.$dropdown.is(":visible")?e.close():e.open()}).on("mousedown",function(){e.needBlur=!1}),this.$dropdown.on("click",".city-select a",function(){var i=t(this).parents(".city-select"),s=i.find("a.active"),c=0===i.next().length;s.removeClass("active"),t(this).addClass("active"),s.data("code")!==t(this).data("code")&&(i.data("item",{address:t(this).attr("title"),code:t(this).data("code")}),t(this).trigger(n),e.feedText(),e.feedVal(!0),c&&e.close())}).on("click",".city-select-tab a",function(){if(!t(this).hasClass("active")){var i=t(this).data("count");e.tab(i)}}).on("mousedown",function(){e.needBlur=!1}),this.$province&&this.$province.on(n,this._changeProvince=t.proxy(function(){this.output(o),this.output(d),this.tab(o)},this)),this.$city&&this.$city.on(n,this._changeCity=t.proxy(function(){this.output(d),this.tab(d)},this))},open:function(t){t=t||c,this.$dropdown.show(),this.$textspan.addClass("open").addClass("focus"),this.tab(t)},close:function(t){this.$dropdown.hide(),this.$textspan.removeClass("open"),t&&this.$textspan.removeClass("focus")},unbind:function(){t(document).off("click",this._mouteclick),this.$element.off("change",this._changeElement),this.$element.off("focus",this._focusElement),this.$element.off("blur",this._blurElement),this.$textspan.off("click"),this.$textspan.off("mousedown"),this.$dropdown.off("click"),this.$dropdown.off("mousedown"),this.$province&&this.$province.off(n,this._changeProvince),this.$city&&this.$city.off(n,this._changeCity)},getText:function(){var e="";return this.$dropdown.find(".city-select").each(function(){var i=t(this).data("item"),s=t(this).data("count");i&&(e+=(t(this).hasClass("province")?"":"/")+''+i.address+"")}),e},getPlaceHolder:function(){return this.$element.attr("placeholder")||this.options.placeholder},feedText:function(){var t=this.getText();t?(this.$textspan.find(">.placeholder").hide(),this.$textspan.find(">.title").html(this.getText()).show()):(this.$textspan.find(">.placeholder").text(this.getPlaceHolder()).show(),this.$textspan.find(">.title").html("").hide())},getCode:function(e){var i={},s=[];return this.$textspan.find(".select-item").each(function(){var e=t(this).data("code"),n=t(this).data("count");i[n]=e,s.push(e)}),e?i[e]:s.join("/")},getVal:function(){var e="";return this.$dropdown.find(".city-select").each(function(){var i=t(this).data("item");i&&(e+=(t(this).hasClass("province")?"":"/")+i.address)}),e},feedVal:function(t){this.$element.val(this.getVal()),t&&this.$element.trigger("cp:updated")},output:function(i){var s,n,a,r,h=this.options,l=this["$"+i],p=i===c?{}:[],u=null;l&&l.length&&(s=l.data("item"),r=(s?s.address:null)||h[i],a=i===c?86:i===o?this.$province&&this.$province.find(".active").data("code"):i===d?this.$city&&this.$city.find(".active").data("code"):a,n=t.isNumeric(a)?e[a]:null,t.isPlainObject(n)&&t.each(n,function(t,e){var s;if(i===c){s=[];for(var n=0;n'),i.push("
"+e+"
"),t.each(o,function(t,e){i.push(''+(n?s.simplize(e.address,c):e.address)+"")}),i.push("
")}),i.join("")},getList:function(e,i){var s=[],n=this,c=this.options.simple;return s.push('
'),t.each(e,function(t,e){s.push(''+(c?n.simplize(e.address,i):e.address)+"")}),s.push("
"),s.join("")},simplize:function(t,e){return t=t||"",e===c?t.replace(/[省,市,自治区,壮族,回族,维吾尔]/g,""):e===o?t.replace(/[市,地区,回族,蒙古,苗族,白族,傣族,景颇族,藏族,彝族,壮族,傈僳族,布依族,侗族]/g,"").replace("哈萨克","").replace("自治州","").replace(/自治县/,""):e===d?t.length>2?t.replace(/[市,区,县,旗]/g,""):t:void 0},tab:function(t){var e=this.$dropdown.find(".city-select"),i=this.$dropdown.find(".city-select-tab > a"),s=this["$"+t],n=this.$dropdown.find('.city-select-tab > a[data-count="'+t+'"]');s&&(e.hide(),s.show(),i.removeClass("active"),n.addClass("active"))},reset:function(){this.$element.val(null).trigger("change")},destroy:function(){this.unbind(),this.$element.removeData(s).removeClass("city-picker-input"),this.$textspan.remove(),this.$dropdown.remove()}},i.DEFAULTS={simple:!1,responsive:!1,placeholder:"请选择省/市/区",level:"district",province:"",city:"",district:""},i.setDefaults=function(e){t.extend(i.DEFAULTS,e)},i.other=t.fn.citypicker,t.fn.citypicker=function(e){var n=[].slice.call(arguments,1);return this.each(function(){var c,o,d=t(this),a=d.data(s);if(!a){if(/destroy/.test(e))return;c=t.extend({},d.data(),t.isPlainObject(e)&&e),d.data(s,a=new i(this,c))}"string"==typeof e&&t.isFunction(o=a[e])&&o.apply(a,n)})},t.fn.citypicker.Constructor=i,t.fn.citypicker.setDefaults=i.setDefaults,t.fn.citypicker.noConflict=function(){return t.fn.citypicker=i.other,this},t.fn.citypicker.getAddressbyCodeId=function(i){var s=e,n=s[""+i],c="",o="",d="",a="";if("44"===i.substring(0,2)?(o="广东省",d="440000"):t.each(s[86],function(e,s){t.each(s,function(t,e){if(e.code===i.substring(0,2)+"0000")return o=e.address,d=e.code,!1})}),i.substring(2,4).indexOf("00")==-1){var r=i.substring(0,4)+"00";a=s[d][r]}if(void 0===n){if(n=i.substring(0,4)+"00",null==s[n])return;return c=s[n][i],c=o+"/"+a+"/"+c}if(i.substring(2,4).indexOf("00")!=-1)return c=o;var h=s[i.substring(0,2)+"0000"];return c=o+"/"+h[i]},t(function(){t('[data-toggle="city-picker"]').citypicker()})}); \ No newline at end of file