app/views/educode_sales/customers/edit.html.erb in educode_sales-0.6.3 vs app/views/educode_sales/customers/edit.html.erb in educode_sales-0.6.4
- old
+ new
@@ -1,27 +1,26 @@
-<form class="layui-form layuimini-form " action="">
+<form class="layui-form layuimini-form " id="custom_data" data-required="true" action="">
<div class="layui-form-item" style="padding: 25px">
<div class="layui-inline">
<label class="layui-form-label required">客户:</label>
<div class="layui-input-block" style="width: 500px;">
<input type="text" name="name" required lay-verify="required" value="<%=@school.name %>" placeholder="请输入客户" autocomplete="off"
class="layui-input" id="inputFocus">
</div>
</div>
<br>
- <div class="layui-inline">
- <label class="layui-form-label required">省:</label>
- <div class="layui-input-block">
- <%= select_tag "province", options_for_select(EducodeSales::Common.where(clazz: 'area').pluck(:name),@school.province), { include_blank: true } %>
+ <div class="layui-inline city_input">
+ <label class="layui-form-label ">省:</label>
+ <div class="layui-input-block" style="width: 500px;">
+ <select id="province" data-value="<%=@school.province.to_s %>" class="province layui-input"></select>
</div>
</div>
<br>
- <div class="layui-inline">
+ <div class="layui-inline city_input">
<label class="layui-form-label ">市:</label>
- <div class="layui-input-block">
- <input type="text" name="city" value="<%=@school.city %>" autocomplete="off"
- class="layui-input" placeholder="请输入地址" style="width: 223px">
+ <div class="layui-input-block" style="width: 500px;">
+ <select id="city" data-value="<%=@school.city %>" class="city layui-input"></select>
</div>
</div>
<br>
<div class="layui-inline">
<label class="layui-form-label ">地址:</label>
@@ -73,14 +72,275 @@
// 当前弹出层,防止ID被覆盖
var parentIndex = layer.index;
+ var dataCustom = [
+ {
+ "n": "北京",
+ "s": [
+ { "n": "东城" },
+ { "n": "西城" },
+ { "n": "朝阳" },
+ { "n": "丰台" },
+ { "n": "石景山" },
+ { "n": "海淀" },
+ { "n": "门头沟" },
+ { "n": "房山" },
+ { "n": "通州" },
+ { "n": "顺义" },
+ { "n": "昌平" },
+ { "n": "大兴" },
+ { "n": "平谷" },
+ { "n": "怀柔" },
+ { "n": "密云" },
+ { "n": "延庆" }
+ ]
+ },
+ {
+ "n": "上海",
+ "s": [
+ { "n": "崇明" }, { "n": "黄浦" }, { "n": "卢湾" }, { "n": "徐汇" }, { "n": "长宁" }, { "n": "静安" }, { "n": "普陀" }, { "n": "闸北" }, { "n": "虹口" }, { "n": "杨浦" }, { "n": "闵行" },
+ { "n": "宝山" }, { "n": "嘉定" }, { "n": "浦东" }, { "n": "金山" }, { "n": "松江" }, { "n": "青浦" }, { "n": "南汇" }, { "n": "奉贤" }
+ ]
+ },
+ {
+ "n": "广东",
+ "s": [
+ { "n": "广州" }, { "n": "深圳" }, { "n": "珠海" }, { "n": "东莞" }, { "n": "中山" }, { "n": "佛山" }, { "n": "惠州" }, { "n": "河源" }, { "n": "潮州" }, { "n": "江门" }, { "n": "揭阳" }, { "n": "茂名" },
+ { "n": "梅州" }, { "n": "清远" }, { "n": "汕头" }, { "n": "汕尾" }, { "n": "韶关" }, { "n": "顺德" }, { "n": "阳江" }, { "n": "云浮" }, { "n": "湛江" }, { "n": "肇庆" }
+ ]
+ },
+ {
+ "n": "江苏",
+ "s": [
+ { "n": "南京" }, { "n": "常熟" }, { "n": "常州" }, { "n": "海门" }, { "n": "淮安" }, { "n": "江都" }, { "n": "江阴" }, { "n": "昆山" }, { "n": "连云港" }, { "n": "南通" },
+ { "n": "启东" }, { "n": "沭阳" }, { "n": "宿迁" }, { "n": "苏州" }, { "n": "太仓" }, { "n": "泰州" }, { "n": "同里" }, { "n": "无锡" }, { "n": "徐州" }, { "n": "盐城" },
+ { "n": "扬州" }, { "n": "宜兴" }, { "n": "仪征" }, { "n": "张家港" }, { "n": "镇江" }, { "n": "周庄" }
+ ]
+ },
+ {
+ "n": "浙江",
+ "s": [
+ { "n": "杭州" }, { "n": "安吉" }, { "n": "慈溪" }, { "n": "定海" }, { "n": "奉化" }, { "n": "海盐" }, { "n": "黄岩" }, { "n": "湖州" }, { "n": "嘉兴" }, { "n": "金华" }, { "n": "临安" },
+ { "n": "临海" }, { "n": "丽水" }, { "n": "宁波" }, { "n": "瓯海" }, { "n": "平湖" }, { "n": "千岛湖" }, { "n": "衢州" }, { "n": "江山" }, { "n": "瑞安" }, { "n": "绍兴" }, { "n": "嵊州" },
+ { "n": "台州" }, { "n": "温岭" }, { "n": "温州" }, { "n": "余姚" }, { "n": "舟山" }
+ ]
+ },
+ {
+ "n": "重庆",
+ "s": [
+ { "n": "万州" }, { "n": "涪陵" }, { "n": "渝中" }, { "n": "大渡口" }, { "n": "江北" }, { "n": "沙坪坝" }, { "n": "九龙坡" }, { "n": "南岸" }, { "n": "北碚" }, { "n": "万盛" },
+ { "n": "双挢" }, { "n": "渝北" }, { "n": "巴南" }, { "n": "黔江" }, { "n": "长寿" }, { "n": "綦江" }, { "n": "潼南" }, { "n": "铜梁" }, { "n": "大足" }, { "n": "荣昌" }, { "n": "壁山" },
+ { "n": "梁平" }, { "n": "城口" }, { "n": "丰都" }, { "n": "垫江" }, { "n": "武隆" }, { "n": "忠县" }, { "n": "开县" }, { "n": "云阳" }, { "n": "奉节" }, { "n": "巫山" }, { "n": "巫溪" },
+ { "n": "石柱" }, { "n": "秀山" }, { "n": "酉阳" }, { "n": "彭水" }, { "n": "江津" }, { "n": "合川" }, { "n": "永川" }, { "n": "南川" }
+ ]
+ },
+ {
+ "n": "安徽",
+ "s": [
+ { "n": "合肥" }, { "n": "安庆" }, { "n": "蚌埠" }, { "n": "亳州" }, { "n": "巢湖" }, { "n": "滁州" }, { "n": "阜阳" }, { "n": "贵池" }, { "n": "淮北" }, { "n": "淮化" }, { "n": "淮南" },
+ { "n": "黄山" }, { "n": "九华山" }, { "n": "六安" }, { "n": "马鞍山" }, { "n": "宿州" }, { "n": "铜陵" }, { "n": "屯溪" }, { "n": "芜湖" }, { "n": "宣城" }
+ ]
+ },
+ {
+ "n": "福建",
+ "s": [
+ { "n": "福州" }, { "n": "厦门" }, { "n": "泉州" }, { "n": "漳州" }, { "n": "龙岩" }, { "n": "南平" }, { "n": "宁德" }, { "n": "莆田" }, { "n": "三明" }
+ ]
+ },
+ {
+ "n": "甘肃",
+ "s": [
+ { "n": "兰州" }, { "n": "白银" }, { "n": "定西" }, { "n": "敦煌" }, { "n": "甘南" }, { "n": "金昌" }, { "n": "酒泉" }, { "n": "临夏" }, { "n": "平凉" }, { "n": "天水" },
+ { "n": "武都" }, { "n": "武威" }, { "n": "西峰" }, { "n": "张掖" }
+ ]
+ },
+ {
+ "n": "广西",
+ "s": [
+ { "n": "南宁" }, { "n": "百色" }, { "n": "北海" }, { "n": "桂林" }, { "n": "防城港" }, { "n": "贵港" }, { "n": "河池" }, { "n": "贺州" }, { "n": "柳州" }, { "n": "钦州" }, { "n": "梧州" }, { "n": "玉林" }
+ ]
+ },
+ {
+ "n": "贵州",
+ "s": [
+ { "n": "贵阳" }, { "n": "安顺" }, { "n": "毕节" }, { "n": "都匀" }, { "n": "凯里" }, { "n": "六盘水" }, { "n": "铜仁" }, { "n": "兴义" }, { "n": "玉屏" }, { "n": "遵义" }
+ ]
+ },
+ {
+ "n": "海南",
+ "s": [
+ { "n": "海口" }, { "n": "儋县" }, { "n": "陵水" }, { "n": "琼海" }, { "n": "三亚" }, { "n": "通什" }, { "n": "万宁" }
+ ]
+ },
+ {
+ "n": "河北",
+ "s": [
+ { "n": "石家庄" }, { "n": "保定" }, { "n": "北戴河" }, { "n": "沧州" }, { "n": "承德" }, { "n": "丰润" }, { "n": "邯郸" }, { "n": "衡水" }, { "n": "廊坊" }, { "n": "南戴河" }, { "n": "秦皇岛" },
+ { "n": "唐山" }, { "n": "新城" }, { "n": "邢台" }, { "n": "张家口" }
+ ]
+ },
+ {
+ "n": "黑龙江",
+ "s": [
+ { "n": "哈尔滨" }, { "n": "北安" }, { "n": "大庆" }, { "n": "大兴安岭" }, { "n": "鹤岗" }, { "n": "黑河" }, { "n": "佳木斯" }, { "n": "鸡西" }, { "n": "牡丹江" }, { "n": "齐齐哈尔" },
+ { "n": "七台河" }, { "n": "双鸭山" }, { "n": "绥化" }, { "n": "伊春" }
+ ]
+ },
+ {
+ "n": "河南",
+ "s": [
+ { "n": "郑州" }, { "n": "安阳" }, { "n": "鹤壁" }, { "n": "潢川" }, { "n": "焦作" }, { "n": "济源" }, { "n": "开封" }, { "n": "漯河" }, { "n": "洛阳" }, { "n": "南阳" }, { "n": "平顶山" },
+ { "n": "濮阳" }, { "n": "三门峡" }, { "n": "商丘" }, { "n": "新乡" }, { "n": "信阳" }, { "n": "许昌" }, { "n": "周口" }, { "n": "驻马店" }
+ ]
+ },
+ {
+ "n": "湖北",
+ "s": [
+ { "n": "武汉" }, { "n": "恩施" }, { "n": "鄂州" }, { "n": "黄冈" }, { "n": "黄石" }, { "n": "荆门" }, { "n": "荆州" }, { "n": "潜江" }, { "n": "十堰" }, { "n": "随州" }, { "n": "武穴" },
+ { "n": "仙桃" }, { "n": "咸宁" }, { "n": "襄阳" }, { "n": "襄樊" }, { "n": "孝感" }, { "n": "宜昌" }
+ ]
+ },
+ {
+ "n": "湖南",
+ "s": [
+ { "n": "长沙" }, { "n": "常德" }, { "n": "郴州" }, { "n": "衡阳" }, { "n": "怀化" }, { "n": "吉首" }, { "n": "娄底" }, { "n": "邵阳" }, { "n": "湘潭" }, { "n": "益阳" }, { "n": "岳阳" },
+ { "n": "永州" }, { "n": "张家界" }, { "n": "株洲" }
+ ]
+ },
+ {
+ "n": "江西",
+ "s": [
+ { "n": "南昌" }, { "n": "抚州" }, { "n": "赣州" }, { "n": "吉安" }, { "n": "景德镇" }, { "n": "井冈山" }, { "n": "九江" }, { "n": "庐山" }, { "n": "萍乡" },
+ { "n": "上饶" }, { "n": "新余" }, { "n": "宜春" }, { "n": "鹰潭" }
+ ]
+ },
+ {
+ "n": "吉林",
+ "s": [
+ { "n": "长春" }, { "n": "吉林" }, { "n": "白城" }, { "n": "白山" }, { "n": "珲春" }, { "n": "辽源" }, { "n": "梅河" }, { "n": "四平" }, { "n": "松原" }, { "n": "通化" }, { "n": "延吉" }
+ ]
+ },
+ {
+ "n": "辽宁",
+ "s": [
+ { "n": "沈阳" }, { "n": "鞍山" }, { "n": "本溪" }, { "n": "朝阳" }, { "n": "大连" }, { "n": "丹东" }, { "n": "抚顺" }, { "n": "阜新" }, { "n": "葫芦岛" }, { "n": "锦州" },
+ { "n": "辽阳" }, { "n": "盘锦" }, { "n": "铁岭" }, { "n": "营口" }
+ ]
+ },
+ {
+ "n": "内蒙古",
+ "s": [
+ { "n": "呼和浩特" }, { "n": "阿拉善盟" }, { "n": "包头" }, { "n": "赤峰" }, { "n": "东胜" }, { "n": "海拉尔" }, { "n": "集宁" }, { "n": "临河" }, { "n": "通辽" }, { "n": "乌海" },
+ { "n": "乌兰浩特" }, { "n": "锡林浩特" }
+ ]
+ },
+ {
+ "n": "宁夏",
+ "s": [
+ { "n": "银川" }, { "n": "固源" }, { "n": "石嘴山" }, { "n": "吴忠" }
+ ]
+ },
+ {
+ "n": "青海",
+ "s": [
+ { "n": "西宁" }, { "n": "德令哈" }, { "n": "格尔木" }, { "n": "共和" }, { "n": "海东" }, { "n": "海晏" }, { "n": "玛沁" }, { "n": "同仁" }, { "n": "玉树" }
+ ]
+ },
+ {
+ "n": "山东",
+ "s": [
+ { "n": "济南" }, { "n": "滨州" }, { "n": "兖州" }, { "n": "德州" }, { "n": "东营" }, { "n": "菏泽" }, { "n": "济宁" }, { "n": "莱芜" }, { "n": "聊城" }, { "n": "临沂" },
+ { "n": "蓬莱" }, { "n": "青岛" }, { "n": "曲阜" }, { "n": "日照" }, { "n": "泰安" }, { "n": "潍坊" }, { "n": "威海" }, { "n": "烟台" }, { "n": "枣庄" }, { "n": "淄博" }
+ ]
+ },
+ {
+ "n": "山西",
+ "s": [
+ { "n": "太原" }, { "n": "长治" }, { "n": "大同" }, { "n": "候马" }, { "n": "晋城" }, { "n": "离石" }, { "n": "临汾" }, { "n": "宁武" }, { "n": "朔州" }, { "n": "忻州" },
+ { "n": "阳泉" }, { "n": "榆次" }, { "n": "运城" }
+ ]
+ },
+ {
+ "n": "陕西",
+ "s": [
+ { "n": "西安" }, { "n": "安康" }, { "n": "宝鸡" }, { "n": "汉中" }, { "n": "渭南" }, { "n": "商州" }, { "n": "绥德" }, { "n": "铜川" }, { "n": "咸阳" }, { "n": "延安" }, { "n": "榆林" }
+ ]
+ },
+ {
+ "n": "四川",
+ "s": [
+ { "n": "成都" }, { "n": "巴中" }, { "n": "达川" }, { "n": "德阳" }, { "n": "都江堰" }, { "n": "峨眉山" }, { "n": "涪陵" }, { "n": "广安" }, { "n": "广元" }, { "n": "九寨沟" },
+ { "n": "康定" }, { "n": "乐山" }, { "n": "泸州" }, { "n": "马尔康" }, { "n": "绵阳" }, { "n": "眉山" }, { "n": "南充" }, { "n": "内江" }, { "n": "攀枝花" }, { "n": "遂宁" },
+ { "n": "汶川" }, { "n": "西昌" }, { "n": "雅安" }, { "n": "宜宾" }, { "n": "自贡" }, { "n": "资阳" }
+ ]
+ },
+ {
+ "n": "天津",
+ "s": [
+ { "n": "天津" }, { "n": "和平" }, { "n": "东丽" }, { "n": "河东" }, { "n": "西青" }, { "n": "河西" }, { "n": "津南" }, { "n": "南开" }, { "n": "北辰" }, { "n": "河北" }, { "n": "武清" }, { "n": "红挢" },
+ { "n": "塘沽" }, { "n": "汉沽" }, { "n": "大港" }, { "n": "宁河" }, { "n": "静海" }, { "n": "宝坻" }, { "n": "蓟县" }
+ ]
+ },
+ {
+ "n": "新疆",
+ "s": [
+ { "n": "乌鲁木齐" }, { "n": "阿克苏" }, { "n": "阿勒泰" }, { "n": "阿图什" }, { "n": "博乐" }, { "n": "昌吉" }, { "n": "东山" }, { "n": "哈密" }, { "n": "和田" }, { "n": "喀什" },
+ { "n": "克拉玛依" }, { "n": "库车" }, { "n": "库尔勒" }, { "n": "奎屯" }, { "n": "石河子" }, { "n": "塔城" }, { "n": "吐鲁番" }, { "n": "伊宁" }
+ ]
+ },
+ {
+ "n": "西藏",
+ "s": [
+ { "n": "拉萨" }, { "n": "阿里" }, { "n": "昌都" }, { "n": "林芝" }, { "n": "那曲" }, { "n": "日喀则" }, { "n": "山南" }
+ ]
+ },
+ {
+ "n": "云南",
+ "s": [
+ { "n": "昆明" }, { "n": "大理" }, { "n": "保山" }, { "n": "楚雄" }, { "n": "大理" }, { "n": "东川" }, { "n": "个旧" }, { "n": "景洪" }, { "n": "开远" }, { "n": "临沧" }, { "n": "丽江" },
+ { "n": "六库" }, { "n": "潞西" }, { "n": "曲靖" }, { "n": "思茅" }, { "n": "文山" }, { "n": "西双版纳" }, { "n": "玉溪" }, { "n": "中甸" }, { "n": "昭通" }
+ ]
+ },
+ {
+ "n": "香港特别行政区",
+ "s": [
+ { "n": "香港" }, { "n": "九龙" }, { "n": "新界" }
+ ]
+ },
+ {
+ "n": "澳门特别行政区",
+ "s": [
+ { "n": { "n": "澳门" } }
+ ]
+ },
+ {
+ "n": "台湾",
+ "s": [
+ { "n": "台北" }, { "n": "基隆" }, { "n": "台南" }, { "n": "台中" }, { "n": "高雄" }, { "n": "屏东" }, { "n": "南投" }, { "n": "云林" }, { "n": "新竹" }, { "n": "彰化" }, { "n": "苗栗" },
+ { "n": "嘉义" }, { "n": "花莲" }, { "n": "桃园" }, { "n": "宜兰" }, { "n": "台东" }, { "n": "金门" }, { "n": "马祖" }, { "n": "澎湖" }
+ ]
+ },
+ {
+ "n": "海外",
+ "s": [
+ { "n": "美国" }, { "n": "日本" }, { "n": "英国" }, { "n": "法国" }, { "n": "德国" }, { "n": "其他" }
+ ]
+ }
+ ]
+ // 自定义选项
+ $('#custom_data').cxSelect({
+ selects: ['province', 'city'],
+ data: dataCustom
+ });
//监听提交
form.on('submit(data-reset-btn)', function (data) {
+ data.field.province = $("#province option:selected").text(); //获取选中的项
+ data.field.city = $("#city option:selected").text(); //获取选中的项
request.authPut("missions/customers/" + <%= @school.id %>, data.field, function (res) {
if (res.success === false) {
layer.alert(res.msg)
} else {
layer.closeAll(); //关闭所有层
@@ -88,6 +348,423 @@
}
})
return false;
});
});
-</script>
+</script>
+<script type="text/javascript" charset="utf-8">
+ /*!
+ * jQuery cxSelect
+ * @name jquery.cxselect.js
+ * @version 1.4.1
+ * @date 2016-11-02
+ * @author ciaoca
+ * @email ciaoca@gmail.com
+ * @site https://github.com/ciaoca/cxSelect
+ * @license Released under the MIT license
+ */
+ (function(factory) {
+ if (typeof define === 'function' && define.amd) {
+ define(['jquery'], factory);
+ } else {
+ factory(window.jQuery || window.Zepto || window.$);
+ };
+ }(function($) {
+ var cxSelect = function() {
+ var self = this;
+ var dom, settings, callback;
+
+ // 分配参数
+ for (var i = 0, l = arguments.length; i < l; i++) {
+ if (cxSelect.isJquery(arguments[i]) || cxSelect.isZepto(arguments[i])) {
+ dom = arguments[i];
+ } else if (cxSelect.isElement(arguments[i])) {
+ dom = $(arguments[i]);
+ } else if (typeof arguments[i] === 'function') {
+ callback = arguments[i];
+ } else if (typeof arguments[i] === 'object') {
+ settings = arguments[i];
+ };
+ };
+
+ var api = new cxSelect.init(dom, settings);
+
+ if (typeof callback === 'function') {
+ callback(api);
+ };
+
+ return api;
+ };
+
+ cxSelect.isElement = function(o){
+ if (o && (typeof HTMLElement === 'function' || typeof HTMLElement === 'object') && o instanceof HTMLElement) {
+ return true;
+ } else {
+ return (o && o.nodeType && o.nodeType === 1) ? true : false;
+ };
+ };
+
+ cxSelect.isJquery = function(o){
+ return (o && o.length && (typeof jQuery === 'function' || typeof jQuery === 'object') && o instanceof jQuery) ? true : false;
+ };
+
+ cxSelect.isZepto = function(o){
+ return (o && o.length && (typeof Zepto === 'function' || typeof Zepto === 'object') && Zepto.zepto.isZ(o)) ? true : false;
+ };
+
+ cxSelect.getIndex = function(n, required) {
+ return required ? n : n - 1;
+ };
+
+ cxSelect.getData = function(data, space) {
+ if (typeof space === 'string' && space.length) {
+ space = space.split('.');
+ for (var i = 0, l = space.length; i < l; i++) {
+ data = data[space[i]];
+ };
+ };
+ return data;
+ };
+
+ cxSelect.init = function(dom, settings) {
+ var self = this;
+
+ if (!cxSelect.isJquery(dom) && !cxSelect.isZepto(dom)) {return};
+
+ var theSelect = {
+ dom: {
+ box: dom
+ }
+ };
+
+ self.attach = cxSelect.attach.bind(theSelect);
+ self.detach = cxSelect.detach.bind(theSelect);
+ self.setOptions = cxSelect.setOptions.bind(theSelect);
+ self.clear = cxSelect.clear.bind(theSelect);
+
+ theSelect.changeEvent = function() {
+ cxSelect.selectChange.call(theSelect, this.className);
+ };
+
+ theSelect.settings = $.extend({}, $.cxSelect.defaults, settings, {
+ url: theSelect.dom.box.data('url'),
+ emptyStyle: theSelect.dom.box.data('emptyStyle'),
+ required: theSelect.dom.box.data('required'),
+ firstTitle: theSelect.dom.box.data('firstTitle'),
+ firstValue: theSelect.dom.box.data('firstValue'),
+ jsonSpace: theSelect.dom.box.data('jsonSpace'),
+ jsonName: theSelect.dom.box.data('jsonName'),
+ jsonValue: theSelect.dom.box.data('jsonValue'),
+ jsonSub: theSelect.dom.box.data('jsonSub')
+ });
+
+ var _dataSelects = theSelect.dom.box.data('selects');
+
+ if (typeof _dataSelects === 'string' && _dataSelects.length) {
+ theSelect.settings.selects = _dataSelects.split(',');
+ };
+
+ self.setOptions();
+ self.attach();
+
+ // 使用独立接口获取数据
+ if (!theSelect.settings.url && !theSelect.settings.data) {
+ cxSelect.start.apply(theSelect);
+
+ // 设置自定义数据
+ } else if ($.isArray(theSelect.settings.data)) {
+ cxSelect.start.call(theSelect, theSelect.settings.data);
+
+ // 设置 URL,通过 Ajax 获取数据
+ } else if (typeof theSelect.settings.url === 'string' && theSelect.settings.url.length) {
+ $.getJSON(theSelect.settings.url, function(json) {
+ cxSelect.start.call(theSelect, json);
+ });
+ };
+ };
+
+ // 设置参数
+ cxSelect.setOptions = function(opts) {
+ var self = this;
+
+ if (opts) {
+ $.extend(self.settings, opts);
+ };
+
+ // 初次或重设选择器组
+ if (!$.isArray(self.selectArray) || !self.selectArray.length || (opts && opts.selects)) {
+ self.selectArray = [];
+
+ if ($.isArray(self.settings.selects) && self.settings.selects.length) {
+ var _tempSelect;
+
+ for (var i = 0, l = self.settings.selects.length; i < l; i++) {
+ _tempSelect = self.dom.box.find('select.' + self.settings.selects[i]);
+
+ if (!_tempSelect || !_tempSelect.length) {break};
+
+ self.selectArray.push(_tempSelect);
+ };
+ };
+ };
+
+ if (opts) {
+ if (!$.isArray(opts.data) && typeof opts.url === 'string' && opts.url.length) {
+ $.getJSON(self.settings.url, function(json) {
+ cxSelect.start.call(self, json);
+ });
+
+ } else {
+ cxSelect.start.call(self, opts.data);
+ };
+ };
+ };
+
+ // 绑定
+ cxSelect.attach = function() {
+ var self = this;
+
+ if (!self.attachStatus) {
+ self.dom.box.on('change', 'select', self.changeEvent);
+ };
+
+ if (typeof self.attachStatus === 'boolean') {
+ cxSelect.start.call(self);
+ };
+
+ self.attachStatus = true;
+ };
+
+ // 移除绑定
+ cxSelect.detach = function() {
+ var self = this;
+ self.dom.box.off('change', 'select', self.changeEvent);
+ self.attachStatus = false;
+ };
+
+ // 清空选项
+ cxSelect.clear = function(index) {
+ var self = this;
+ var _style = {
+ display: '',
+ visibility: ''
+ };
+
+ index = isNaN(index) ? 0 : index;
+
+ // 清空后面的 select
+ for (var i = index, l = self.selectArray.length; i < l; i++) {
+ self.selectArray[i].empty().prop('disabled', true);
+
+ if (self.settings.emptyStyle === 'none') {
+ _style.display = 'none';
+ } else if (self.settings.emptyStyle === 'hidden') {
+ _style.visibility = 'hidden';
+ };
+
+ self.selectArray[i].css(_style);
+ };
+ };
+
+ cxSelect.start = function(data) {
+ var self = this;
+
+ if ($.isArray(data)) {
+ self.settings.data = cxSelect.getData(data, self.settings.jsonSpace);
+ };
+
+ if (!self.selectArray.length) {return};
+
+ // 保存默认值
+ for (var i = 0, l = self.selectArray.length; i < l; i++) {
+ if (typeof self.selectArray[i].attr('data-value') !== 'string' && self.selectArray[i][0].options.length) {
+ self.selectArray[i].attr('data-value', self.selectArray[i].val());
+ };
+ };
+
+ if (self.settings.data || (typeof self.selectArray[0].data('url') === 'string' && self.selectArray[0].data('url').length)) {
+ cxSelect.getOptionData.call(self, 0);
+ } else {
+ self.selectArray[0].prop('disabled', false).css({
+ 'display': '',
+ 'visibility': ''
+ });
+ };
+ };
+
+ // 获取选项数据
+ cxSelect.getOptionData = function(index) {
+ var self = this;
+
+ if (typeof index !== 'number' || isNaN(index) || index < 0 || index >= self.selectArray.length) {return};
+
+ var _indexPrev = index - 1;
+ var _select = self.selectArray[index];
+ var _selectData;
+ var _valueIndex;
+ var _dataUrl = _select.data('url');
+ var _jsonSpace = typeof _select.data('jsonSpace') === 'undefined' ? self.settings.jsonSpace : _select.data('jsonSpace');
+ var _query = {};
+ var _queryName;
+ var _selectName;
+ var _selectValue;
+
+ cxSelect.clear.call(self, index);
+
+ // 使用独立接口
+ if (typeof _dataUrl === 'string' && _dataUrl.length) {
+ if (index > 0) {
+ for (var i = 0, j = 1; i < index; i++, j++) {
+ _queryName = self.selectArray[j].data('queryName');
+ _selectName = self.selectArray[i].attr('name');
+ _selectValue = self.selectArray[i].val();
+
+ if (typeof _queryName === 'string' && _queryName.length) {
+ _query[_queryName] = _selectValue;
+ } else if (typeof _selectName === 'string' && _selectName.length) {
+ _query[_selectName] = _selectValue;
+ };
+ };
+ };
+
+ $.getJSON(_dataUrl, _query, function(json) {
+ _selectData = cxSelect.getData(json, _jsonSpace);
+
+ cxSelect.buildOption.call(self, index, _selectData);
+ });
+
+ // 使用整合数据
+ } else if (self.settings.data && typeof self.settings.data === 'object') {
+ _selectData = self.settings.data;
+
+ for (var i = 0; i < index; i++) {
+ _valueIndex = cxSelect.getIndex(self.selectArray[i][0].selectedIndex, typeof self.selectArray[i].data('required') === 'boolean' ? self.selectArray[i].data('required') : self.settings.required);
+
+ if (typeof _selectData[_valueIndex] === 'object' && $.isArray(_selectData[_valueIndex][self.settings.jsonSub]) && _selectData[_valueIndex][self.settings.jsonSub].length) {
+ _selectData = _selectData[_valueIndex][self.settings.jsonSub];
+ } else {
+ _selectData = null;
+ break;
+ };
+ };
+
+ cxSelect.buildOption.call(self, index, _selectData);
+ };
+ };
+
+ // 构建选项列表
+ cxSelect.buildOption = function(index, data) {
+ var self = this;
+
+ var _select = self.selectArray[index];
+ var _required = typeof _select.data('required') === 'boolean' ? _select.data('required') : self.settings.required;
+ var _firstTitle = typeof _select.data('firstTitle') === 'undefined' ? self.settings.firstTitle : _select.data('firstTitle');
+ var _firstValue = typeof _select.data('firstValue') === 'undefined' ? self.settings.firstValue : _select.data('firstValue');
+ var _jsonName = typeof _select.data('jsonName') === 'undefined' ? self.settings.jsonName : _select.data('jsonName');
+ var _jsonValue = typeof _select.data('jsonValue') === 'undefined' ? self.settings.jsonValue : _select.data('jsonValue');
+
+ if (!$.isArray(data)) {return};
+
+ var _html = !_required ? '<option value="' + String(_firstValue) + '">' + String(_firstTitle) + '</option>' : '';
+
+ // 区分标题、值的数据
+ if (typeof _jsonName === 'string' && _jsonName.length) {
+ // 无值字段时使用标题作为值
+ if (typeof _jsonValue !== 'string' || !_jsonValue.length) {
+ _jsonValue = _jsonName;
+ };
+
+ for (var i = 0, l = data.length; i < l; i++) {
+ _html += '<option value="' + String(data[i][_jsonValue]) + '">' + String(data[i][_jsonName]) + '</option>';
+ };
+
+ // 数组即为值的数据
+ } else {
+ for (var i = 0, l = data.length; i < l; i++) {
+ _html += '<option value="' + String(data[i]) + '">' + String(data[i]) + '</option>';
+ };
+ };
+
+ _select.html(_html).prop('disabled', false).css({
+ 'display': '',
+ 'visibility': ''
+ });
+
+ // 初次加载设置默认值
+ if (typeof _select.attr('data-value') === 'string') {
+ _select.val(String(_select.attr('data-value'))).removeAttr('data-value');
+
+ if (_select[0].selectedIndex < 0) {
+ _select[0].options[0].selected = true;
+ };
+ };
+
+ if (_required || _select[0].selectedIndex > 0) {
+ _select.trigger('change');
+ };
+
+ };
+
+ // 改变选择时的处理
+ cxSelect.selectChange = function(name) {
+ var self = this;
+
+ if (typeof name !== 'string' || !name.length) {return};
+
+ var index;
+
+ name = name.replace(/\s+/g, ',');
+ name = ',' + name + ',';
+
+ // 获取当前 select 位置
+ for (var i = 0, l = self.selectArray.length; i < l; i++) {
+ if (name.indexOf(',' + self.settings.selects[i] + ',') > -1) {
+ index = i;
+ break;
+ };
+ };
+
+ if (typeof index === 'number' && index > -1) {
+ index += 1;
+ cxSelect.getOptionData.call(self, index);
+ };
+ };
+
+ $.cxSelect = function() {
+ return cxSelect.apply(this, arguments);
+ };
+
+ // 默认值
+ $.cxSelect.defaults = {
+ selects: [], // 下拉选框组
+ url: null, // 列表数据文件路径(URL)或数组数据
+ data: null, // 自定义数据
+ emptyStyle: null, // 无数据状态显示方式
+ required: false, // 是否为必选
+ firstTitle: '请选择', // 第一个选项的标题
+ firstValue: '', // 第一个选项的值
+ jsonSpace: '', // 数据命名空间
+ jsonName: 'n', // 数据标题字段名称
+ jsonValue: '', // 数据值字段名称
+ jsonSub: 's' // 子集数据字段名称
+ };
+
+ $.fn.cxSelect = function(settings, callback) {
+ this.each(function(i) {
+ $.cxSelect(this, settings, callback);
+ });
+ return this;
+ };
+ }));
+
+</script>
+<style>
+ .layui-form .city_input .layui-input {
+ display: none;!important;
+ }
+ .layui-form .city_input .province {
+ display: block;
+ }
+ .layui-form .city_input .city {
+ display: block;
+ }
+</style>
\ No newline at end of file