/*! * iPicker v4.0.2 * Copyright (C) 2020-2021, ZG * Released under the MIT license. */ !((e,i)=>{typeof exports==="object"&&typeof module!=="undefined"?module.exports=i():typeof define==="function"&&define.amd?define(i):(e=e||self,e.iPicker=i())})(typeof window!=="undefined"?window:this,e=>{"use strict";const i={type:e=>Object.prototype.toString.call(e).slice(8,-1).toLowerCase(),isCorrectObject:e=>!!(i.type(e)==="object"&&Object.keys(e).length),isCorrectNumber:(e,i)=>!!(Number.isSafeInteger(e)&&(!i?e>0:e>=0)),isFunction:e=>i.type(e)==="function",uid(e){const i=Math.random().toString(36).substr(2,10);return e?Symbol(i):i},delayTimer(e=0){return new Promise(i=>{const t=window.setTimeout(()=>{window.clearTimeout(t);i()},e)})},mergeParam(e={},t){const r={};for(const s in t){const n=e[s];if(i.type(n)==="object"){r[s]=i.mergeParam(n,t[s])}else{r[s]=n===0?n:n||t[s]}}return r}};const t=(()=>{function e(e){const i=e[0]?e.length:0;this.length=i;for(let t=0;t0&&i[0]&&i[0].nodeType){for(let e=0,r=i.length;e{},placeholder:["省","市","区"],separator:"/",clearable:false,strict:false,onlyShowLastLevel:false,icon:"arrow",onClear:()=>{},onSelect:()=>{}};const s={originalElem:new WeakMap,options:new WeakMap,value:new WeakMap,id:new WeakMap,target:new Map};const n=new Map;const c="__iPicker-default-style__";const a={createFrame(e,{theme:i,level:t,icon:r,clearable:s,disabled:n},c){let a=`\n
\n
\n\n\n${s?'':""}\n
\n
___
\n
\n`;switch(i){case"select":a=a.replace("___","").repeat(t);break;case"cascader":a=a.replace("___","".repeat(t));break;case"panel":a=a.replace("___",`\n
\n
省份
\n${t>1?"
城市
":""}\n${t>2?"
区县
":""}\n
\n
${"
    ".repeat(t)}
    \n`);break}e.addClass("iPicker-target").html(a).data({theme:i,id:c.toString().replace(/(\(|\))/g,"")})},createList(e,i,t){return new Promise(r=>{let s="";const n=i.theme==="cascader";if(!t){const{code:t,name:r}=i.data.props||{};e.forEach(e=>{s+=`\n
  • \n${e[r]}\n${n?"":""}\n
  • \n`})}else{for(const i in e){s+=`\n
  • \n${e[i]}\n${n?"":""}\n
  • \n`}}r(s)})},getData(e,t,r,s){return new Promise(c=>{function a(e,t){if(i.isFunction(r.data.when)){return r.data.when(e,t)}else{return e}}if(!s){const i=n.get(e);if(i){c(a(i,t))}else{r.data.source(e,t).then(i=>{n.set(e,i);c(a(i,t))})}}else{r.data.source.then(i=>{c(a(i[e],t))})}})},getSelected(e){const i=e.find(".iPicker-list-active");const r=i.length;const[s,n,c]=[[],[],[]];if(r){i.each(function(){const e=t(this).data("code");const i=t(this).data("name");s.push(e);n.push(i);c.push({code:e,name:i})})}return[s,n,c]},cacheSelected(e,i){s.value.set(e,i)}};const l=(e,n)=>{if(!e||!n||typeof e!=="string"||!e.trim()||!i.isCorrectObject(n)||!i.isCorrectObject(n.data)||!n.data.source||!i.isFunction(n.data.source)&&i.type(n.data.source)!=="promise"){return}const o=t(e);const d=o.get();if(!d){return}const u=i.mergeParam(n,r);if(!i.isCorrectNumber(u.level)||u.level<1||u.level>3){u.level=3}const h=u.theme==="select";const f=u.theme==="cascader";const p=u.theme==="panel";const g=i.type(u.data.source)==="promise";const b=i.isFunction(u.data.source);const k=i.isFunction(u.onClear);const M=i.isFunction(u.onSelect);const m=d._iPicker_uid_||i.uid(true);s.originalElem.set(d,e);s.options.set(d,u);s.target.set(m,d);s.id.set(d,m);d._iPicker_uid_=m;if(!document.getElementById(c)){document.head.insertAdjacentHTML("afterbegin",`\n\n`)}a.createFrame(o,u,m);const P=o.find(".iPicker-container");const v=o.find(".iPicker-result");const y=o.find(".iPicker-input");const x=o.find(".iPicker-list");const w=x.find("ul");w.each(function(e){t(this).data("level",++e)});if(i.isCorrectNumber(u.maxHeight)&&u.maxHeight>=100){x.css("maxHeight",`${u.maxHeight}px`);if(f){w.css("maxHeight",`${u.maxHeight}px`)}if(p){x.find(".iPicker-panel-content").css("height",`${u.maxHeight-38}px`)}}if(i.isCorrectNumber(u.width)&&u.width>=100){v.css("width",`${u.width}px`);if(h){x.css("width",`${u.width}px`)}}if(typeof u.width==="string"&&u.width.trim().endsWith("%")){v.css("width",u.width);if(h){x.css("width",u.width)}else{P.css("width",u.width)}}if(i.isCorrectNumber(u.height)&&u.height>=20){v.css("height",`${u.height}px`);y.css("height",`${u.height-2}px`);y.next().css("height",`${u.height-2}px`)}if(u.disabledItem===true){new MutationObserver(()=>{o.find("li").addClass("iPicker-list-disabled")}).observe(d,{childList:true,subtree:true})}if(Array.isArray(u.disabledItem)&&u.disabledItem.length){for(const e of[...new Set(u.disabledItem)]){new MutationObserver(()=>{const i=d.querySelector(`[data-code="${e}"]:not(.iPicker-list-disabled)`);if(i){i.classList.add("iPicker-list-disabled")}}).observe(d,{childList:true,subtree:true})}}if(u.disabled===true){u.disabled=[1,2,3].slice(0,u.level)}if(i.isCorrectNumber(u.disabled)){u.disabled=[u.disabled]}if(Array.isArray(u.disabled)&&u.disabled.length){for(const e of[...new Set(u.disabled)]){if(i.isCorrectNumber(e)&&e>=1&&e<=3){v.eq(e-1).addClass("iPicker-disabled")}}}if(h&&Array.isArray(u.placeholder)){u.placeholder.forEach((e,i)=>{const t=y.eq(i).get();if(t){t.setAttribute("placeholder",u.placeholder[i]||r.placeholder[i])}})}if(f||p){if(typeof u.placeholder!=="string"||!u.placeholder.trim()){u.placeholder="请选择地区"}y.eq(0).get().setAttribute("placeholder",u.placeholder)}if(i.isCorrectNumber(u.radius,true)){v.add(y).css("borderRadius",`${u.radius}px`)}v.find(".clear-icon").hide();v.each(function(){const e=t(this).get();e.addEventListener("mouseenter",()=>{const i=e.querySelector("input");if(i){if(i.value&&!e.classList.contains("iPicker-disabled")){t(this).find(".clear-icon").show().prev().hide()}}});e.addEventListener("mouseleave",()=>{t(this).find(".clear-icon").hide().prev().show()})});const N=o.find(".clear-icon");if(!h){N.click(()=>{N.hide().prev().show();l.clear(m);if(k){u.onClear()}})}else{N.each(function(){const e=t(this);e.click(function(){e.hide().prev().show();const i=e.parent();const t=i.next().find("ul");const r=+t.data("index");i.find("input").val("");t.find(".iPicker-list-active").removeClass("iPicker-list-active");i.parent().nextAll().find("input").val("").parent().next().find("ul").html("");L();z(i.next());if(k){u.onClear()}})})}v.each(function(){t(this).find("input, .arrow-icon").click(function(){const e=t(this).parent();const i=e.next();const r=e.parent().parent().data("id");const s=t(`.iPicker-target:not([data-id="${r}"]) .iPicker-list`);if(s.length){z(s)}if(!e.hasClass("iPicker-disabled")){if(!i.find("li").length){return}e.toggleClass("iPicker-result-active");if(i.hasClass("iPicker-list-show")){z(i)}else{if(p){o.find(".iPicker-panel-tab > div:first-child").addClass("iPicker-panel-tab-active").siblings().removeClass("iPicker-panel-tab-active");o.find(".iPicker-panel-content > ul:first-child").show().siblings().hide()}let t=false;const r=parseInt(e.css("height"));function n(){if(t){return}t=true;i.addClass("iPicker-list-show-temporary");const s=document.documentElement.clientHeight-e.get().getBoundingClientRect().bottom;const n=parseInt(i.css("height"));if(s{e.get().style.removeProperty("display")});if(!h){L()}const r=e.parent().parent();const n=s.options.get(r.get());if(n.strict){i.delayTimer(200).then(()=>{const[e]=s.value.get(r.get());const i=e.length;if(i&&i!==n.level){function c(){return new Promise(e=>{if(i===1){if(n.level===2){e()}else{j(w.eq(1).find("li:first-child").data("code"),3).then(()=>{e()})}}else{e()}})}c().then(()=>{w.each(function(){if(!t(this).find(".iPicker-list-active").length){t(this).find("li:first-child").addClass("iPicker-list-active")}});L()})}})}}}function j(e,i){return new Promise(t=>{a.getData(e,i,u,g).then(e=>{a.createList(e,u,g).then(e=>{const r=w.eq(i-1);r.html(e).nextAll().html("");if(h){r.parent().parent().nextAll().find("ul").html("")}if(f){let e=0;w.each(function(){if(this.innerHTML){e++}});x.css("width",`${200*e}px`);w.eq(i-1).show().nextAll().hide()}if(p){w.eq(i-1).show().siblings().hide();o.find(`.iPicker-panel-tab > div:nth-child(${i})`).addClass("iPicker-panel-tab-active").siblings().removeClass("iPicker-panel-tab-active")}L();t()})})})}function L(){const e=a.getSelected(o);a.cacheSelected(d,e);const i=u.separator.trim().charAt(0);function t(e){if(e){if(f||p){if(u.onlyShowLastLevel){e=e.split(i).slice(-1)[0].trim()}}}return e}if(h){e[1].forEach((e,i)=>{y.eq(i).val(t(e))})}else{const r=e[1].join(` ${i} `);y.eq(0).val(t(r))}if(M){if(e[1].length){u.onSelect(...s.value.get(d))}}}j(g?"86":null,1).then(()=>{d.dataset.promise="true";if(Array.isArray(u.selected)&&u.selected.length){u.selected=[...new Set(u.selected)];for(const e of u.selected){if(u.disabledItem.includes(e)){return}}!function e(t){j(u.selected[t-1],t+1).then(()=>{t++;if(t{o.find(`li[data-code="${e}"]`).addClass("iPicker-list-active")});L();if(i.isFunction(u.selectedCallback)){u.selectedCallback()}}})}(1)}});o.click(e=>{if(e.target.nodeName.toLowerCase()!=="li"){return}const i=t(e.target);const r=i.parent();if(i.hasClass("iPicker-list-disabled")){return}i.addClass("iPicker-list-active").siblings().removeClass("iPicker-list-active");j(i.data("code"),+r.data("level")+1);if(h){z(r.parent());r.parent().parent().nextAll().find(".iPicker-result input").val("")}if(r.index()===u.level-1){if(f){z(r.parent())}if(p){z(r.parent().parent())}}});if(f){w.css({minHeight:`${u.maxHeight}px`,maxHeight:`${u.maxHeight}px`})}if(p){o.find(".iPicker-panel-tab > div").click(function(){const e=t(this).index();if(!t(this).parent().next().find("ul").eq(e).find("li").length){return}t(this).addClass("iPicker-panel-tab-active").siblings().removeClass("iPicker-panel-tab-active");o.find(".iPicker-panel-content ul").eq(t(this).index()).show().siblings().hide()})}t(document).click(function(e){P.each(function(i){if(e.target!==this&&!this.contains(e.target)){z(x.eq(i))}})});return m};l.create=((e,i)=>{return l(e,i)});l.set=((e,i)=>{const t=s.target.get(e);if(!e||!t||!i||!Array.isArray(i)||!i.length){return}l.clear(e);if(t.dataset.promise){r()}else{new MutationObserver(()=>{r()}).observe(t,{attributes:true})}function r(){const e=t.querySelectorAll("ul");!function r(s){const n=t.querySelector(`[data-code="${i[s]}"]`);if(e[s+1]){new MutationObserver(()=>{++s;if(s{const t=s.target.get(e);if(!e||!t){return}const r=s.value.get(t);if(i==="code"||i===undefined){return r[0]}if(i==="name"){return r[1]}if(i==="all"){return r[2]}});l.clear=(e=>{const i=s.target.get(e);if(!e||!i){return}const r=t(i);const n=s.options.get(i);s.value.set(i,[[],[],[]]);r.find("input").val("");r.find("li").removeClass("iPicker-list-active");r.find("ul").each(function(e){const i=t(this);if(e){i.html("");if(n.theme==="cascader"){i.parent().css("width","200px");i.get().style.removeProperty("display")}}});if(n.theme==="panel"){r.find(".iPicker-panel-tab > div").eq(0).addClass("iPicker-panel-tab-active").siblings().removeClass("iPicker-panel-tab-active");r.find(".iPicker-panel-content > ul").eq(0).show().siblings().hide()}r.find(".iPicker-list").get().scrollTop=0;r.find("ul").get().scrollTop=0;return e});l.reset=(e=>{const i=s.target.get(e);if(!e||!i){return}return l(s.originalElem.get(i),s.options.get(i))});l.destroy=(e=>{const i=s.target.get(e);if(!e||!i){return}s.originalElem.delete(i);s.value.delete(i);s.options.delete(i);s.id.delete(i);s.target.delete(i._iPicker_uid_);delete i._iPicker_uid_;i.innerHTML="";if(!document.querySelector(".iPicker-container")){t(`#${c}`).remove()}});l.enabled=((e,r)=>{const n=s.target.get(e);if(!e||!n||!r){return}const c=t(n);const a=c.find(".iPicker-result");if(r===true){a.removeClass("iPicker-disabled")}if(i.isCorrectNumber(r)){r=[r]}if(Array.isArray(r)&&r.length){r.forEach(e=>{if(i.isCorrectNumber(e)&&e>=1&&e<=3){a.eq(e-1).removeClass("iPicker-disabled")}})}return e});l.disabled=((e,r)=>{const n=s.target.get(e);if(!e||!n||!r){return}const c=t(n);const a=c.find(".iPicker-result");if(r===true){a.addClass("iPicker-disabled")}if(i.isCorrectNumber(r)){r=[r]}if(Array.isArray(r)&&r.length){r.forEach(e=>{if(i.isCorrectNumber(e)&&e>=1&&e<=3){a.eq(e-1).addClass("iPicker-disabled")}})}return e});const o=e=>e.filter(e=>typeof e==="string"&&e.match(/^\d{6,12}$/));l.enabledItem=((e,i)=>{const r=s.target.get(e);if(!e||!r||!i){return}const n={childList:true,subtree:true};if(i===true){new MutationObserver(()=>{t(r).find("li").removeClass("iPicker-list-disabled")}).observe(r,n)}if(Array.isArray(i)&&i.length){i=o([...new Set(i)]);const e=i.length;new MutationObserver(()=>{for(let t=0;t{const r=s.target.get(e);if(!e||!r||!i){return}const n={childList:true,subtree:true};if(i===true){new MutationObserver(()=>{t(r).find("li").addClass("iPicker-list-disabled")}).observe(r,n)}if(Array.isArray(i)&&i.length){i=o([...new Set(i)]);const e=i.length;new MutationObserver(()=>{for(let t=0;t