popoPicker.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  1. /*!
  2. * popoPicker.js v1.0
  3. * https://po-po.github.io/popoPicker
  4. * Released under the MIT License.
  5. */
  6. ;(function (window,document) {
  7. 'use strict';
  8. function extend() {
  9. var name, options, src, copy;
  10. var length = arguments.length;
  11. var target = arguments[0];
  12. for (var i = 1; i < length; i++) {
  13. options = arguments[i];
  14. if (options != null) {
  15. for (name in options) {
  16. src = target[name];
  17. copy = options[name];
  18. if (copy !== undefined) {
  19. target[name] = copy;
  20. }
  21. }
  22. }
  23. }
  24. return target;
  25. }
  26. var popoPicker = function (el, option) {
  27. //触摸移动
  28. var self = this;
  29. var option = extend({
  30. wheels: [],
  31. container:'body',
  32. scrollType: '3d',
  33. background: 'light',
  34. display: "bottom",
  35. headTitle: '',
  36. init: function () {},
  37. getResult: function () {},
  38. save: function () {},
  39. cancel: function () {}
  40. }, option);
  41. var clickTarget = document.querySelectorAll(el);
  42. var rows = 5;
  43. var itemHeight = 34;
  44. var itemSize2d = 9;
  45. var itemSize3d = 9;
  46. var scroll3dAngle = 360 / (itemSize3d * 2);
  47. var rs = {
  48. result: [],
  49. scrollIdx: null,
  50. scrollEvt: []
  51. };
  52. function getselectedIdx(wheel) {
  53. var index = 0;
  54. for (var i = 0; i < wheel.data.length; i++) {
  55. if (wheel.data[i].value == wheel.selected) {
  56. index = i;
  57. break;
  58. } else {
  59. index = 0;
  60. }
  61. }
  62. return index;
  63. }
  64. function generateItems(wheel, start, end, is3d) {
  65. var data = wheel.data;
  66. var html = '',
  67. value,
  68. display,
  69. len = data.length,
  70. infinite = wheel.infinite,
  71. selectedIdx = getselectedIdx(wheel);
  72. //选中的位置
  73. start += selectedIdx;
  74. end += selectedIdx;
  75. for (var i = start; i <= end; i++) {
  76. var idx = (i < 0 ? len + (i % len) : i) % len;
  77. value = data[idx].value;
  78. display = data[idx].display;
  79. if (is3d) {
  80. var deg = 0;
  81. var show = "list-item";
  82. deg = -(i - selectedIdx) * scroll3dAngle % 360;
  83. if (!infinite) {
  84. if (i < 0 || i > (len - 1)) {
  85. show = "none"
  86. } else {
  87. show = "list-item"
  88. }
  89. }
  90. html += '<li data-index="' + i + '" data-val="' + value + '" style="transform:rotateX(' + deg + 'deg) translateZ(' + (itemHeight * rows / 2) + 'px); display: ' + show + '">' + display + '</li>';
  91. } else {
  92. var opacity = 1;
  93. if (!infinite) {
  94. if (i < 0 || i > (len - 1)) {
  95. opacity = 0
  96. } else {
  97. opacity = 1
  98. }
  99. }
  100. html += '<li data-index="' + i + '" data-val="' + value + '" style="opacity: ' + opacity + '">' + display + '</li>';
  101. }
  102. }
  103. return html;
  104. }
  105. function createEl(wheels) {
  106. var html = '';
  107. html += '<div class="p-select-wrap '+ (option.scrollType == '3d' ? 'p-3d' : '') + (option.display == 'center' ? ' p-center' : '') +(option.background == 'dark' ? ' dark' : '')+'">';
  108. html += '<div class="p-select-main">';
  109. html += '<div class="p-select-head">';
  110. if (option.display != 'center') {
  111. html += '<a href="javascript:void(0)" class="p-select-cancel-btn">取消</a>';
  112. }
  113. if (option.headTitle != '') {
  114. html += '<div class="p-select-title">' + option.headTitle + '</div>';
  115. }
  116. if (option.display != 'center') {
  117. html += '<a href="javascript:void(0)" class="p-select-submit-btn">确认</a>';
  118. }
  119. html += '</div>';
  120. html += '<div class="p-select-body">';
  121. html += '<div class="p-select-line" '+ (option.scrollType=='3d' ? 'style="transform: translateZ(' + (itemHeight * rows / 2 + 4) + 'px)"':'') +'></div>';
  122. for (var i = 0; i < wheels.length; i++) {
  123. var label = wheels[i].label;
  124. html += '<div class="p-select-item">';
  125. html += '<div class="p-select-col">';
  126. html += '<div class="p-select-list" '+ (option.scrollType=='3d' ? 'style="transform: translateZ(' + (itemHeight * rows / 2 +3) + 'px)"':'') +'>';
  127. html += '<ul class="p-select-ul">';
  128. html += generateItems(wheels[i], -itemSize2d, itemSize2d, false);
  129. html += '</ul>';
  130. html += '</div>';
  131. if (option.scrollType == '3d') {
  132. html += '<ul class="p-select-wheel">';
  133. html += generateItems(wheels[i], -itemSize3d, itemSize3d, true);
  134. html += '</ul>';
  135. }
  136. html += '</div>';
  137. if (label) {
  138. html += '<div class="p-select-col p-select-label" '+ (option.scrollType=='3d' ? 'style="transform: translateZ(' + (itemHeight * rows / 2 + 4) + 'px)"':'') +'>' + label + '</div>';
  139. }
  140. html += '</div>';
  141. }
  142. html += '</div>';
  143. if (option.display == 'center') {
  144. html += '<div class="p-select-foot">';
  145. html += '<a href="javascript:void(0)" class="p-select-cancel-btn">取消</a>';
  146. html += '<a href="javascript:void(0)" class="p-select-submit-btn">确认</a>';
  147. html += '</div>';
  148. }
  149. html += '</div>';
  150. html += '<div class="p-select-mask"></div>';
  151. html += '</div>';
  152. var node = document.createElement("div");
  153. node.className = "p-scroll";
  154. node.innerHTML = html;
  155. document.querySelector(option.container).appendChild(node)
  156. }
  157. function snap(pos) {
  158. var pos = Math.round(pos),
  159. n1 = Math.round(pos % itemHeight),
  160. n2 = itemHeight / 2;
  161. if (Math.abs(n1) < n2) {
  162. return pos - n1;
  163. } else {
  164. return pos - n1 + (pos > 0 ? itemHeight : -itemHeight);
  165. }
  166. }
  167. function getVal(pos, data, infinite, selectedIdx) {
  168. var len = data.length,
  169. index = (Math.round(-pos / itemHeight) - itemSize2d + selectedIdx) % len,
  170. index = index < 0 ? len + index : index,
  171. dataIndex = Math.round(-pos / itemHeight) - itemSize2d + selectedIdx,
  172. result = {
  173. value: data[index].value,
  174. display: data[index].display,
  175. dataIndex: dataIndex
  176. };
  177. return result;
  178. }
  179. function getPosition(el) {
  180. var style = getComputedStyle(el),
  181. matrix,
  182. pref = ['t', 'webkitT', 'MozT', 'OT', 'msT'],
  183. px;
  184. for (var i = 0; i < pref.length; i++) {
  185. var v = pref[i];
  186. if (style[v + 'ransform'] !== undefined) {
  187. matrix = style[v + 'ransform'];
  188. break;
  189. }
  190. }
  191. matrix = matrix.split(')')[0].split(', ');
  192. px = Number(matrix[13] || matrix[5]);
  193. return px;
  194. }
  195. function isPC() {
  196. var userAgentInfo = navigator.userAgent;
  197. var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
  198. var flag = true;
  199. for (var i = 0; i < Agents.length; i++) {
  200. if (userAgentInfo.indexOf(Agents[i]) > 0) {
  201. flag = false;
  202. break;
  203. }
  204. }
  205. return flag;
  206. }
  207. function destroy() {
  208. rs = {
  209. result: [],
  210. scrollIdx: 0,
  211. scrollEvt :[],
  212. };
  213. var box = document.querySelector('.p-scroll');
  214. box.className += ' hide';
  215. setTimeout(function () {
  216. box.remove();
  217. }, 300)
  218. }
  219. this.Scroll = function (el, wheel, index, opt) {
  220. this.el = el;
  221. this.wheel = wheel;
  222. this.index = index;
  223. this.opt = extend({
  224. data: this.wheel.data,
  225. scrollEl2d: el.querySelector('.p-select-ul'),
  226. item2d: el.querySelectorAll('.p-select-ul li'),
  227. scrollY: -itemHeight * itemSize2d,
  228. marginTop: 0,
  229. dataLen: this.wheel.data.length,
  230. lastY: 1,
  231. moveY: 0,
  232. current: 0,
  233. infinite: this.wheel.infinite,
  234. rotateX: 0,
  235. selectedIdx: getselectedIdx(wheel),
  236. transTimer: null,
  237. scrollTimer: null,
  238. clickDown: false,
  239. inertia: true
  240. }, opt);
  241. if (option.scrollType == "3d") {
  242. this.opt.scrollEl3d = el.querySelector('.p-select-wheel');
  243. this.opt.item3d = el.querySelectorAll('.p-select-wheel li');
  244. }
  245. this.defaultScrollY = this.opt.scrollY;
  246. this.init();
  247. };
  248. this.Scroll.prototype = {
  249. init: function () {
  250. this.Run(0, this.opt.scrollY);
  251. if (isPC()) {
  252. this.el.addEventListener('mousedown', this.touchStart.bind(this), false);
  253. document.addEventListener('mousemove', this.touchMove.bind(this), false);
  254. document.addEventListener('mouseup', this.touchEnd.bind(this), false);
  255. } else {
  256. this.el.addEventListener('touchstart', this.touchStart.bind(this), false);
  257. this.el.addEventListener('touchmove', this.touchMove.bind(this), false);
  258. this.el.addEventListener('touchend', this.touchEnd.bind(this), false);
  259. this.el.addEventListener('touchcancel', this.touchEnd.bind(this), false);
  260. }
  261. var self = this;
  262. if (option.scrollType == '3d') {
  263. //3d点击事件
  264. this.itemClick(this.opt.item3d);
  265. } else {
  266. //2d点击事件
  267. this.itemClick(this.opt.item2d);
  268. }
  269. },
  270. itemClick: function (itemObj) {
  271. var self = this;
  272. for (var i = 0; i < itemObj.length; i++) {
  273. itemObj[i].addEventListener('click', function (e) {
  274. self.opt.inertia = false;
  275. var curIdx = Number(e.target.dataset.index);
  276. var lastIdx = rs.result[self.index].dataIndex;
  277. var diff = curIdx - lastIdx;
  278. self.cusTouch(diff);
  279. }, false)
  280. }
  281. },
  282. Run: function (interval, pos) {
  283. if (interval == 0) {
  284. this.opt.scrollEl2d.style.webkitTransition = "none";
  285. if (option.scrollType == "3d") {
  286. this.opt.scrollEl3d.style.webkitTransition = "none";
  287. }
  288. } else {
  289. this.opt.scrollEl2d.style.webkitTransition = "transform cubic-bezier(0.190, 1.000, 0.220, 1.000) " + interval + "ms";
  290. if (option.scrollType == "3d") {
  291. this.opt.scrollEl3d.style.webkitTransition = "transform cubic-bezier(0.190, 1.000, 0.220, 1.000) " + interval + "ms";
  292. }
  293. }
  294. this.opt.scrollEl2d.style.webkitTransform = "translate3d(0," + pos + "px, 0)";
  295. if (option.scrollType == "3d") {
  296. pos = Math.round(-(pos * (scroll3dAngle / itemHeight)) - 180);
  297. this.opt.scrollEl3d.style.webkitTransform = "rotateX(" + pos + "deg) translate3d(0,0,0)";
  298. }
  299. },
  300. scrollDone: function () {
  301. clearInterval(this.opt.scrollTimer);
  302. clearTimeout(this.opt.transTimer);
  303. },
  304. onMove: function (pos, cusDiff) {
  305. var self = this,
  306. pos = pos || getPosition(this.opt.scrollEl2d),
  307. index = Math.round(-pos / itemHeight) - itemSize2d,
  308. diff = index - this.opt.current;
  309. if (cusDiff != undefined || diff) {
  310. this.opt.current = index;
  311. //2D
  312. for (var i = 0; i < this.opt.item2d.length; i++) {
  313. var item = this.opt.item2d[i];
  314. var index = Number(item.getAttribute("data-index")) + diff,
  315. len = self.opt.dataLen,
  316. idx = (index < 0 ? len + (index % len) : index) % len,
  317. val = self.opt.data[idx].value,
  318. display = self.opt.data[idx].display;
  319. if (!self.opt.infinite) {
  320. if (index < 0 || index > (len - 1)) {
  321. item.style.opacity = "0"
  322. } else {
  323. item.style.opacity = "1"
  324. }
  325. }
  326. item.setAttribute("data-index", index);
  327. item.setAttribute("data-val", val);
  328. item.innerText = display;
  329. }
  330. if (option.scrollType == "3d") {
  331. //3D
  332. for (var i = 0; i < this.opt.item3d.length; i++) {
  333. var item = this.opt.item3d[i];
  334. var index = Number(item.getAttribute("data-index")) + diff,
  335. len = self.opt.dataLen,
  336. idx = (index < 0 ? len + (index % len) : index) % len,
  337. val = self.opt.data[idx].value,
  338. deg = -(index - self.opt.selectedIdx) * scroll3dAngle,
  339. display = self.opt.data[idx].display;
  340. if (!self.opt.infinite) {
  341. if (index < 0 || index > (len - 1)) {
  342. item.style.display = "none"
  343. } else {
  344. item.style.display = "list-item"
  345. }
  346. }
  347. item.setAttribute("data-index", index);
  348. item.setAttribute("data-val", val);
  349. item.setAttribute("data-idx", idx);
  350. item.innerText = display;
  351. item.style.webkitTransform = "rotateX(" + deg + "deg) translateZ(" + (itemHeight * rows / 2) + "px)";
  352. }
  353. }
  354. //2d margin-top
  355. this.opt.marginTop += diff * itemHeight;
  356. this.opt.scrollEl2d.style.marginTop = this.opt.marginTop + "px";
  357. }
  358. },
  359. touchStart: function (e) {
  360. if (e.type == 'touchstart') {
  361. this.opt.startY = e.targetTouches["0"].clientY;
  362. } else {
  363. this.opt.startY = e.clientY;
  364. this.opt.clickDown = true;
  365. }
  366. this.opt.startTime = new Date();
  367. },
  368. touchMove: function (e) {
  369. if (e.type == 'touchmove') {
  370. e.preventDefault();
  371. for (var i = 0; i < e.targetTouches.length; i++) {
  372. this.opt.curY = e.targetTouches[i].clientY;
  373. }
  374. } else {
  375. if (this.opt.clickDown) {
  376. this.opt.curY = e.clientY;
  377. } else {
  378. return false;
  379. }
  380. }
  381. this.opt.moveY = this.opt.curY - this.opt.startY;
  382. this.opt.distance = this.opt.scrollY + this.opt.moveY;
  383. if (this.opt.curY < this.opt.lastY) {
  384. //move up
  385. this.opt.direction = 1;
  386. } else if (this.opt.curY > this.opt.lastY) {
  387. //move down
  388. this.opt.direction = -1;
  389. }
  390. if (this.opt.direction) {
  391. this.onMove();
  392. this.opt.lastY = this.opt.curY;
  393. this.Run(0, this.opt.distance);
  394. }
  395. },
  396. touchEnd: function (e) {
  397. if (e.type == 'touchend') {
  398. this.opt.lastY = e.changedTouches["0"].clientY;
  399. } else {
  400. if (this.opt.clickDown) {
  401. this.opt.lastY = e.clientY;
  402. this.opt.clickDown = false;
  403. } else {
  404. return false;
  405. }
  406. }
  407. this.opt.endTime = new Date();
  408. var self = this,
  409. interval = this.opt.endTime - this.opt.startTime,
  410. speed = 500,
  411. addPos = 0;
  412. //模拟惯性
  413. if (this.opt.inertia && interval < 300) {
  414. speed = Math.abs(this.opt.moveY / interval);
  415. speed = Math.round(speed * 1000);
  416. addPos = speed / 3 * (this.opt.moveY < 0 ? -1 : 1);
  417. speed = speed < 500 ? 500 : speed;
  418. } else {
  419. addPos = this.opt.moveY;
  420. this.opt.inertia = true
  421. }
  422. this.opt.scrollY += snap(addPos);
  423. this.opt.moveY = 0;
  424. clearInterval(this.opt.scrollTimer);
  425. this.opt.scrollTimer = setInterval(function () {
  426. self.onMove();
  427. }, 100);
  428. clearTimeout(this.opt.transTimer);
  429. this.opt.transTimer = setTimeout(function () {
  430. self.onMove();
  431. self.scrollDone();
  432. }, speed);
  433. //非无限滚动阈值
  434. if (!this.opt.infinite) {
  435. var maxScroll = this.opt.selectedIdx * itemHeight - itemHeight * itemSize2d;
  436. var minScroll = this.opt.selectedIdx * itemHeight - itemHeight * (this.opt.dataLen - 1) - itemHeight * itemSize2d;
  437. if (this.opt.scrollY > maxScroll) {
  438. this.opt.scrollY = maxScroll;
  439. } else if (this.opt.scrollY < minScroll) {
  440. this.opt.scrollY = minScroll;
  441. }
  442. }
  443. this.Run(speed, this.opt.scrollY);
  444. var res = getVal(this.opt.scrollY, this.opt.data, this.opt.infinite, this.opt.selectedIdx);
  445. rs.result[this.index] = res;
  446. rs.scrollIdx = this.index;
  447. option.getResult(rs);
  448. },
  449. cusTouch: function (diff) {
  450. var e1 = {
  451. clientY: 0,
  452. targetTouches: [{clientY: 0}],
  453. type: "click"
  454. };
  455. var e2 = {
  456. clientY: -itemHeight * diff,
  457. targetTouches: [{clientY: -itemHeight * diff}],
  458. type: "click"
  459. };
  460. var e3 = {
  461. clientY: -itemHeight * diff,
  462. changedTouches: [{clientY: -itemHeight * diff}],
  463. type: "click"
  464. };
  465. this.touchStart(e1)
  466. this.touchMove(e2);
  467. this.touchEnd(e3);
  468. },
  469. scrollTo: function (val, interval) {
  470. this.wheel.selected = val;
  471. var selectedIdx = getselectedIdx(this.wheel);
  472. var diff = this.opt.selectedIdx - selectedIdx;
  473. this.opt.scrollY = this.defaultScrollY + diff * itemHeight;
  474. this.Run(interval, this.opt.scrollY);
  475. this.onMove(this.opt.scrollY, true);
  476. },
  477. removeItem: function (valArr) {
  478. var data = this.opt.data,
  479. resultVal = rs.result[this.index].value,
  480. removeLen = 0,
  481. moveEnd = false;
  482. for (var i = 0; i < data.length; i++) {
  483. for (var j = 0; j < valArr.length; j++) {
  484. if (data[i].value == valArr[j]) {
  485. //移除
  486. data.splice(i--, 1);
  487. removeLen++;
  488. } else {
  489. if (valArr[j] == resultVal) {
  490. moveEnd = true;
  491. }
  492. }
  493. }
  494. }
  495. if (moveEnd) {
  496. rs.result[this.index] = {
  497. value: data[data.length - 1].value,
  498. display: data[data.length - 1].display
  499. }
  500. }
  501. this.opt.dataLen = data.length;
  502. this.scrollTo(rs.result[this.index].value, 0);
  503. },
  504. appendItem: function (valArr) {
  505. var data = this.opt.data;
  506. //去重
  507. for (var i = 0; i < data.length; i++) {
  508. for (var j = 0; j < valArr.length; j++) {
  509. if (data[i].value == valArr[j].value) {
  510. valArr.splice(j--, 1)
  511. }
  512. }
  513. }
  514. //添加
  515. for (var i = 0; i < valArr.length; i++) {
  516. data.push(valArr[i]);
  517. }
  518. this.opt.dataLen = data.length;
  519. this.scrollTo(rs.result[this.index].value, 0);
  520. }
  521. };
  522. function init(wheels, target) {
  523. //创建DOM
  524. createEl(wheels);
  525. var el = document.querySelectorAll(".p-select-item");
  526. for (var i = 0; i < el.length; i++) {
  527. //滚动事件
  528. var scroll = new self.Scroll(el[i], wheels[i], i);
  529. //初始结果
  530. var res = getVal(scroll.opt.scrollY, scroll.opt.data, scroll.opt.infinite, scroll.opt.selectedIdx);
  531. rs.result.push(res);
  532. rs.scrollEvt.push(scroll);
  533. rs.scrollIdx = 0;
  534. }
  535. //传出初始结果
  536. option.init(rs);
  537. var submitBtn = document.querySelector('.p-select-submit-btn'),
  538. cancelBtn = document.querySelector('.p-select-cancel-btn'),
  539. mask = document.querySelector('.p-select-mask');
  540. submitBtn.addEventListener('click', function () {
  541. var attr_rs = [],
  542. display = [];
  543. for (var i = 0; i < rs.result.length; i++) {
  544. attr_rs.push(rs.result[i].value);
  545. display.push(rs.result[i].display)
  546. }
  547. target.setAttribute('data-value', attr_rs);
  548. if(target.isInput){
  549. target.value = display;
  550. }else{
  551. target.innerText = display;
  552. }
  553. option.getResult(rs);
  554. option.save(rs, target);
  555. self.target = target;
  556. destroy()
  557. }, false);
  558. cancelBtn.addEventListener('click', function () {
  559. option.cancel();
  560. destroy()
  561. }, false);
  562. mask.addEventListener('click', function () {
  563. option.cancel();
  564. destroy()
  565. }, false);
  566. document.querySelector('.p-scroll').addEventListener('touchmove', function (e) {
  567. e.preventDefault()
  568. }, false);
  569. }
  570. for (var i = 0; i < clickTarget.length; i++) {
  571. var item = clickTarget[i],
  572. wheels = option.wheels,
  573. isInput = item.localName == 'input' || item.localName == 'textarea',
  574. attr_rs = item.getAttribute('data-value');
  575. if(attr_rs){
  576. attr_rs = attr_rs.split(',');
  577. var display = [];
  578. for (var j=0;j<attr_rs.length;j++){
  579. wheels[j].selected = attr_rs[j];
  580. var idx = getselectedIdx(wheels[j])
  581. display.push(wheels[j].data[idx].display)
  582. }
  583. if(isInput){
  584. item.value = display;
  585. }else{
  586. item.innerText = display;
  587. }
  588. }
  589. if(isInput){
  590. item.setAttribute('readonly',"readonly");
  591. item.setAttribute('unselectable','on');
  592. }
  593. item.addEventListener('click', function () {
  594. var target = this,
  595. wheelsCopy = JSON.parse(JSON.stringify(wheels)),
  596. attr_rs = target.getAttribute('data-value');
  597. target.isInput = isInput;
  598. if(isInput){
  599. target.blur();
  600. }
  601. if (attr_rs) {
  602. attr_rs = attr_rs.split(',');
  603. for (var j = 0; j < attr_rs.length; j++) {
  604. wheelsCopy[j].selected = attr_rs[j];
  605. }
  606. init(wheelsCopy, target ,isInput);
  607. }else{
  608. init(wheels, target, isInput);
  609. }
  610. }, false)
  611. }
  612. };
  613. var popoDateTime = function(el,opt){
  614. var opt = extend({
  615. container:'body',
  616. scrollType: "3d",
  617. background:'light',
  618. showLabel: true, //显示label
  619. labelType:'symbol', //symbol符号 text文字 split分割(需date和time同时存在)
  620. display:"bottom",
  621. headResult: false,
  622. date:true,
  623. time:true,
  624. beginYear: new Date().getFullYear()-100,
  625. endYear:new Date().getFullYear()+100,
  626. startDate: '',
  627. save:function(){},
  628. cancel:function(){}
  629. },opt);
  630. function addZero(num){
  631. return num<10?"0"+num:String(num);
  632. }
  633. var d = new Date(),
  634. year = d.getFullYear(),
  635. month = d.getMonth() + 1,
  636. day = d.getDate(),
  637. hour = d.getHours(),
  638. minute = d.getMinutes(),
  639. beginYear = opt.beginYear,
  640. endYear = opt.endYear,
  641. yearData = [],
  642. monthData = [],
  643. dayData = [],
  644. hourData = [],
  645. minuteData = [],
  646. lastValue = '',
  647. wheels = [
  648. {
  649. infinite: false,
  650. selected: addZero(year),
  651. label:"<span>-</span>",
  652. data: yearData
  653. },
  654. {
  655. infinite: true,
  656. selected: addZero(month),
  657. label:"<span>-</span>",
  658. data: monthData
  659. },
  660. {
  661. infinite: true,
  662. selected: addZero(day),
  663. label:"",
  664. data: dayData
  665. },
  666. {
  667. infinite: true,
  668. selected: addZero(hour),
  669. label:"<span>:</span>",
  670. data: hourData
  671. },
  672. {
  673. infinite: true,
  674. selected: addZero(minute),
  675. label:"",
  676. data: minuteData
  677. },
  678. ];
  679. for(var i=beginYear;i<=endYear;i++){
  680. yearData.push({value:addZero(i),display:addZero(i)});
  681. }
  682. //月
  683. for(var i=1;i<=12;i++){
  684. monthData.push({value:addZero(i),display:addZero(i)});
  685. }
  686. //日
  687. for(var i=1;i<=31;i++){
  688. dayData.push({value:addZero(i),display:addZero(i)});
  689. }
  690. //时
  691. for(var i=0;i<=23;i++){
  692. hourData.push({value:addZero(i),display:addZero(i)});
  693. }
  694. //分
  695. for(var i=0;i<=59;i++){
  696. minuteData.push({value:addZero(i),display:addZero(i)});
  697. }
  698. //判断显示日期/时间
  699. if(!opt.date){
  700. wheels.splice(0,3);
  701. }
  702. if(!opt.time){
  703. wheels.splice(3,5);
  704. wheels[2].label = " ";
  705. }
  706. //Label控制
  707. if(!opt.showLabel){
  708. for(var i=0;i<wheels.length;i++){
  709. delete wheels[i].label;
  710. }
  711. }else{
  712. if(opt.labelType == 'text'){
  713. var text = ['年','月','日','时','分','秒']
  714. for(var i=0;i<wheels.length;i++){
  715. wheels[i].label = text[i];
  716. }
  717. }
  718. if(opt.labelType == 'split' && opt.date && opt.time){
  719. for(var i=0;i<wheels.length;i++){
  720. delete wheels[i].label;
  721. }
  722. wheels[2].label='<div class="p-select-time-split-1"></div>';
  723. }
  724. }
  725. //判断闰年
  726. function isLeapYear(year) {
  727. if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
  728. return true;
  729. } else {
  730. return false;
  731. }
  732. }
  733. //判断大小月
  734. function bigSmallMonth(dayObj,year,month){
  735. var smallMonth = (month=="04" || month=="06" || month=="09" || month=="11");
  736. dayObj.appendItem(
  737. [
  738. {value:"29",display:"29"},
  739. {value:"30",display:"30"},
  740. {value:"31",display:"31"}
  741. ]
  742. );
  743. if(smallMonth){
  744. dayObj.removeItem(["31"]);
  745. }else if(month=="02"){
  746. if(isLeapYear(year)){
  747. dayObj.removeItem(["30","31"]);
  748. }else{
  749. dayObj.removeItem(["29","30","31"]);
  750. }
  751. }
  752. }
  753. //获取结果
  754. function getLastVal(result) {
  755. if(result.length==5){
  756. lastValue = result[0].display+'-'+result[1].display+'-'+result[2].display+' '+result[3].display+':'+result[4].display;
  757. }else if (result.length==3){
  758. lastValue = result[0].display+'-'+result[1].display+'-'+result[2].display;
  759. } else{
  760. lastValue = result[0].display+':'+result[1].display;
  761. }
  762. if(opt.headResult){
  763. var title = document.querySelector('.p-select-title');
  764. title.innerText = lastValue;
  765. }
  766. }
  767. //日期滚轮
  768. var p = new popoPicker(el,{
  769. wheels: wheels,
  770. scrollType:opt.scrollType,
  771. background: opt.background,
  772. display:opt.display,
  773. headTitle:opt.headResult?1:'',
  774. container:opt.container,
  775. init:function(rs){
  776. if(opt.date){
  777. var year = rs.result[0].value;
  778. var month = rs.result[1].value;
  779. bigSmallMonth(rs.scrollEvt[2],year,month);
  780. }
  781. getLastVal(rs.result)
  782. },
  783. getResult:function(rs){
  784. var n1 = opt.date && (rs.scrollIdx== 0 || rs.scrollIdx== 1);
  785. year = rs.result[0].value,
  786. month = rs.result[1].value;
  787. if(n1){
  788. bigSmallMonth(rs.scrollEvt[2],year,month);
  789. }
  790. getLastVal(rs.result)
  791. },
  792. save:function(rs, target){
  793. if(target.isInput){
  794. target.value = lastValue;
  795. }else{
  796. target.innerText = lastValue;
  797. }
  798. opt.save(lastValue, target);
  799. },
  800. cancel:function(){
  801. opt.cancel();
  802. }
  803. });
  804. //判断是否有自定义初始值
  805. var target = document.querySelectorAll(el);
  806. for(var i=0;i<target.length;i++){
  807. var item = target[i],
  808. isInput = item.localName == 'input' || item.localName == 'textarea',
  809. val = isInput?item.value:item.innerText;
  810. if(val){
  811. val = val.match(/\d+/g);
  812. item.setAttribute('data-value',val);
  813. }
  814. }
  815. };
  816. var popoDateT = function(el,opt){
  817. var opt = extend({
  818. container:'body',
  819. scrollType: "3d",
  820. background:'light',
  821. showLabel: true, //显示label
  822. labelType:'symbol', //symbol符号 text文字 split分割(需date和time同时存在)
  823. display:"bottom",
  824. headResult: false,
  825. date:true,
  826. time:true,
  827. beginYear: new Date().getFullYear()-100,
  828. endYear:new Date().getFullYear()+100,
  829. startDate: '',
  830. save:function(){},
  831. cancel:function(){}
  832. },opt);
  833. function addZero(num){
  834. return num<10?"0"+num:String(num);
  835. }
  836. var d = new Date(),
  837. year = d.getFullYear(),
  838. month = d.getMonth() + 1,
  839. day = d.getDate(),
  840. hour = d.getHours(),
  841. minute = d.getMinutes(),
  842. beginYear = opt.beginYear,
  843. endYear = opt.endYear,
  844. yearData = [],
  845. monthData = [],
  846. dayData = [],
  847. // hourData = [],
  848. // minuteData = [],
  849. lastValue = '',
  850. wheels = [
  851. {
  852. infinite: false,
  853. selected: addZero(year),
  854. label:"<span>-</span>",
  855. data: yearData
  856. },
  857. {
  858. infinite: true,
  859. selected: addZero(month),
  860. label:"<span>-</span>",
  861. data: monthData
  862. },
  863. {
  864. infinite: true,
  865. selected: addZero(day),
  866. label:"",
  867. data: dayData
  868. }
  869. ];
  870. for(var i=beginYear;i<=endYear;i++){
  871. yearData.push({value:addZero(i),display:addZero(i)});
  872. }
  873. //月
  874. for(var i=1;i<=12;i++){
  875. monthData.push({value:addZero(i),display:addZero(i)});
  876. }
  877. //日
  878. for(var i=1;i<=31;i++){
  879. dayData.push({value:addZero(i),display:addZero(i)});
  880. }
  881. //Label控制
  882. if(!opt.showLabel){
  883. for(var i=0;i<wheels.length;i++){
  884. delete wheels[i].label;
  885. }
  886. }else{
  887. if(opt.labelType == 'text'){
  888. var text = ['年','月','日','时','分','秒']
  889. for(var i=0;i<wheels.length;i++){
  890. wheels[i].label = text[i];
  891. }
  892. }
  893. if(opt.labelType == 'split' && opt.date && opt.time){
  894. for(var i=0;i<wheels.length;i++){
  895. delete wheels[i].label;
  896. }
  897. wheels[2].label='<div class="p-select-time-split-1"></div>';
  898. }
  899. }
  900. //判断闰年
  901. function isLeapYear(year) {
  902. if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
  903. return true;
  904. } else {
  905. return false;
  906. }
  907. }
  908. //判断大小月
  909. function bigSmallMonth(dayObj,year,month){
  910. var smallMonth = (month=="04" || month=="06" || month=="09" || month=="11");
  911. dayObj.appendItem(
  912. [
  913. {value:"29",display:"29"},
  914. {value:"30",display:"30"},
  915. {value:"31",display:"31"}
  916. ]
  917. );
  918. if(smallMonth){
  919. dayObj.removeItem(["31"]);
  920. }else if(month=="02"){
  921. if(isLeapYear(year)){
  922. dayObj.removeItem(["30","31"]);
  923. }else{
  924. dayObj.removeItem(["29","30","31"]);
  925. }
  926. }
  927. }
  928. //获取结果
  929. function getLastVal(result) {
  930. if(result.length==5){
  931. lastValue = result[0].display+'-'+result[1].display+'-'+result[2].display+' '+result[3].display+':'+result[4].display;
  932. }else if (result.length==3){
  933. lastValue = result[0].display+'-'+result[1].display+'-'+result[2].display;
  934. } else{
  935. lastValue = result[0].display+':'+result[1].display;
  936. }
  937. if(opt.headResult){
  938. var title = document.querySelector('.p-select-title');
  939. title.innerText = lastValue;
  940. }
  941. }
  942. //日期滚轮
  943. var p = new popoPicker(el,{
  944. wheels: wheels,
  945. scrollType:opt.scrollType,
  946. background: opt.background,
  947. display:opt.display,
  948. headTitle:opt.headResult?1:'',
  949. container:opt.container,
  950. init:function(rs){
  951. if(opt.date){
  952. var year = rs.result[0].value;
  953. var month = rs.result[1].value;
  954. bigSmallMonth(rs.scrollEvt[2],year,month);
  955. }
  956. getLastVal(rs.result)
  957. },
  958. getResult:function(rs){
  959. var n1 = opt.date && (rs.scrollIdx== 0 || rs.scrollIdx== 1);
  960. year = rs.result[0].value,
  961. month = rs.result[1].value;
  962. if(n1){
  963. bigSmallMonth(rs.scrollEvt[2],year,month);
  964. }
  965. getLastVal(rs.result)
  966. },
  967. save:function(rs, target){
  968. if(target.isInput){
  969. target.value = lastValue;
  970. }else{
  971. target.innerText = lastValue;
  972. }
  973. opt.save(lastValue, target);
  974. },
  975. cancel:function(){
  976. opt.cancel();
  977. }
  978. });
  979. //判断是否有自定义初始值
  980. var target = document.querySelectorAll(el);
  981. for(var i=0;i<target.length;i++){
  982. var item = target[i],
  983. isInput = item.localName == 'input' || item.localName == 'textarea',
  984. val = isInput?item.value:item.innerText;
  985. if(val){
  986. val = val.match(/\d+/g);
  987. item.setAttribute('data-value',val);
  988. }
  989. }
  990. };
  991. var popoDate = function(el,opt){
  992. var opt = extend({
  993. container:'body',
  994. scrollType: "3d",
  995. background:'light',
  996. showLabel: true, //显示label
  997. labelType:'symbol', //symbol符号 text文字 split分割(需date和time同时存在)
  998. display:"bottom",
  999. headResult: false,
  1000. // date:true,
  1001. // time:true,
  1002. beginYear: new Date().getFullYear()-100,
  1003. endYear:new Date().getFullYear()+100,
  1004. startDate: '',
  1005. save:function(){},
  1006. cancel:function(){}
  1007. },opt);
  1008. function addZero(num){
  1009. return num<10?"0"+num:String(num);
  1010. }
  1011. var d = new Date(),
  1012. year = d.getFullYear(),
  1013. month = d.getMonth() + 1,
  1014. day = d.getDate(),
  1015. hour = d.getHours(),
  1016. minute = d.getMinutes(),
  1017. beginYear = opt.beginYear,
  1018. endYear = opt.endYear,
  1019. yearData = [],
  1020. monthData = [],
  1021. // dayData = [],
  1022. // hourData = [],
  1023. // minuteData = [],
  1024. lastValue = '',
  1025. wheels = [
  1026. {
  1027. infinite: false,
  1028. selected: addZero(year),
  1029. label:"<span>-</span>",
  1030. data: yearData
  1031. },
  1032. {
  1033. infinite: true,
  1034. selected: addZero(month),
  1035. label:"<span></span>",
  1036. data: monthData
  1037. },
  1038. ];
  1039. for(var i=beginYear;i<=endYear;i++){
  1040. yearData.push({value:addZero(i),display:addZero(i)});
  1041. }
  1042. //月
  1043. for(var i=1;i<=12;i++){
  1044. monthData.push({value:addZero(i),display:addZero(i)});
  1045. }
  1046. //Label控制
  1047. if(!opt.showLabel){
  1048. for(var i=0;i<wheels.length;i++){
  1049. delete wheels[i].label;
  1050. }
  1051. }else{
  1052. if(opt.labelType == 'text'){
  1053. var text = ['年','月','日','时','分','秒']
  1054. for(var i=0;i<wheels.length;i++){
  1055. wheels[i].label = text[i];
  1056. }
  1057. }
  1058. if(opt.labelType == 'split' && opt.date && opt.time){
  1059. for(var i=0;i<wheels.length;i++){
  1060. delete wheels[i].label;
  1061. }
  1062. wheels[2].label='<div class="p-select-time-split-1"></div>';
  1063. }
  1064. }
  1065. //判断闰年
  1066. function isLeapYear(year) {
  1067. if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
  1068. return true;
  1069. } else {
  1070. return false;
  1071. }
  1072. }
  1073. //判断大小月
  1074. function bigSmallMonth(dayObj,year,month){
  1075. var smallMonth = (month=="04" || month=="06" || month=="09" || month=="11");
  1076. dayObj.appendItem(
  1077. [
  1078. {value:"29",display:"29"},
  1079. {value:"30",display:"30"},
  1080. {value:"31",display:"31"}
  1081. ]
  1082. );
  1083. if(smallMonth){
  1084. dayObj.removeItem(["31"]);
  1085. }else if(month=="02"){
  1086. if(isLeapYear(year)){
  1087. dayObj.removeItem(["30","31"]);
  1088. }else{
  1089. dayObj.removeItem(["29","30","31"]);
  1090. }
  1091. }
  1092. }
  1093. //获取结果
  1094. function getLastVal(result) {
  1095. if(result.length==5){
  1096. lastValue = result[0].display+'-'+result[1].display+'-'+result[2].display+' '+result[3].display+':'+result[4].display;
  1097. }else if (result.length==3){
  1098. lastValue = result[0].display+'-'+result[1].display+'-'+result[2].display;
  1099. } else{
  1100. lastValue = result[0].display+'-'+result[1].display;
  1101. }
  1102. if(opt.headResult){
  1103. var title = document.querySelector('.p-select-title');
  1104. title.innerText = lastValue;
  1105. }
  1106. }
  1107. //日期滚轮
  1108. var p = new popoPicker(el,{
  1109. wheels: wheels,
  1110. scrollType:opt.scrollType,
  1111. background: opt.background,
  1112. display:opt.display,
  1113. headTitle:opt.headResult?1:'',
  1114. container:opt.container,
  1115. init:function(rs){
  1116. if(opt.date){
  1117. var year = rs.result[0].value;
  1118. var month = rs.result[1].value;
  1119. bigSmallMonth(rs.scrollEvt[2],year,month);
  1120. }
  1121. getLastVal(rs.result)
  1122. },
  1123. getResult:function(rs){
  1124. var n1 = opt.date && (rs.scrollIdx== 0 || rs.scrollIdx== 1);
  1125. year = rs.result[0].value,
  1126. month = rs.result[1].value;
  1127. if(n1){
  1128. bigSmallMonth(rs.scrollEvt[2],year,month);
  1129. }
  1130. getLastVal(rs.result)
  1131. },
  1132. save:function(rs, target){
  1133. if(target.isInput){
  1134. target.value = lastValue;
  1135. }else{
  1136. target.innerText = lastValue;
  1137. }
  1138. opt.save(lastValue, target);
  1139. },
  1140. cancel:function(){
  1141. opt.cancel();
  1142. }
  1143. });
  1144. //判断是否有自定义初始值
  1145. var target = document.querySelectorAll(el);
  1146. for(var i=0;i<target.length;i++){
  1147. var item = target[i],
  1148. isInput = item.localName == 'input' || item.localName == 'textarea',
  1149. val = isInput?item.value:item.innerText;
  1150. if(val){
  1151. val = val.match(/\d+/g);
  1152. item.setAttribute('data-value',val);
  1153. }
  1154. }
  1155. };
  1156. var popoYear = function(el,opt){
  1157. var opt = extend({
  1158. container:'body',
  1159. scrollType: "3d",
  1160. background:'light',
  1161. showLabel: true, //显示label
  1162. labelType:'symbol', //symbol符号 text文字 split分割(需date和time同时存在)
  1163. display:"bottom",
  1164. headResult: false,
  1165. // date:true,
  1166. // time:true,
  1167. beginYear: new Date().getFullYear()-100,
  1168. endYear:new Date().getFullYear()+100,
  1169. startDate: '',
  1170. save:function(){},
  1171. cancel:function(){}
  1172. },opt);
  1173. function addZero(num){
  1174. return num<10?"0"+num:String(num);
  1175. }
  1176. var d = new Date(),
  1177. year = d.getFullYear(),
  1178. month = d.getMonth() + 1,
  1179. day = d.getDate(),
  1180. hour = d.getHours(),
  1181. minute = d.getMinutes(),
  1182. beginYear = opt.beginYear,
  1183. endYear = opt.endYear,
  1184. yearData = [],
  1185. monthData = [],
  1186. // dayData = [],
  1187. // hourData = [],
  1188. // minuteData = [],
  1189. lastValue = '',
  1190. wheels = [
  1191. {
  1192. infinite: false,
  1193. selected: addZero(year),
  1194. label:"<span></span>",
  1195. data: yearData
  1196. }
  1197. ];
  1198. for(var i=beginYear;i<=endYear;i++){
  1199. yearData.push({value:addZero(i),display:addZero(i)});
  1200. }
  1201. //月
  1202. for(var i=1;i<=12;i++){
  1203. monthData.push({value:addZero(i),display:addZero(i)});
  1204. }
  1205. //Label控制
  1206. if(!opt.showLabel){
  1207. for(var i=0;i<wheels.length;i++){
  1208. delete wheels[i].label;
  1209. }
  1210. }else{
  1211. if(opt.labelType == 'text'){
  1212. var text = ['年','月','日','时','分','秒']
  1213. for(var i=0;i<wheels.length;i++){
  1214. wheels[i].label = text[i];
  1215. }
  1216. }
  1217. if(opt.labelType == 'split' && opt.date && opt.time){
  1218. for(var i=0;i<wheels.length;i++){
  1219. delete wheels[i].label;
  1220. }
  1221. wheels[2].label='<div class="p-select-time-split-1"></div>';
  1222. }
  1223. }
  1224. //判断闰年
  1225. function isLeapYear(year) {
  1226. if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
  1227. return true;
  1228. } else {
  1229. return false;
  1230. }
  1231. }
  1232. //判断大小月
  1233. function bigSmallMonth(dayObj,year,month){
  1234. var smallMonth = (month=="04" || month=="06" || month=="09" || month=="11");
  1235. dayObj.appendItem(
  1236. [
  1237. {value:"29",display:"29"},
  1238. {value:"30",display:"30"},
  1239. {value:"31",display:"31"}
  1240. ]
  1241. );
  1242. if(smallMonth){
  1243. dayObj.removeItem(["31"]);
  1244. }else if(month=="02"){
  1245. if(isLeapYear(year)){
  1246. dayObj.removeItem(["30","31"]);
  1247. }else{
  1248. dayObj.removeItem(["29","30","31"]);
  1249. }
  1250. }
  1251. }
  1252. //获取结果
  1253. function getLastVal(result) {
  1254. if(result.length==5){
  1255. lastValue = result[0].display+'-'+result[1].display+'-'+result[2].display+' '+result[3].display+':'+result[4].display;
  1256. }else if (result.length==3){
  1257. lastValue = result[0].display+'-'+result[1].display+'-'+result[2].display;
  1258. } else{
  1259. lastValue = result[0].display;
  1260. }
  1261. if(opt.headResult){
  1262. var title = document.querySelector('.p-select-title');
  1263. title.innerText = lastValue;
  1264. }
  1265. }
  1266. //日期滚轮
  1267. var p = new popoPicker(el,{
  1268. wheels: wheels,
  1269. scrollType:opt.scrollType,
  1270. background: opt.background,
  1271. display:opt.display,
  1272. headTitle:opt.headResult?1:'',
  1273. container:opt.container,
  1274. init:function(rs){
  1275. if(opt.date){
  1276. var year = rs.result[0].value;
  1277. bigSmallMonth(rs.scrollEvt[2],year);
  1278. }
  1279. getLastVal(rs.result)
  1280. },
  1281. getResult:function(rs){
  1282. var n1 = opt.date && (rs.scrollIdx== 0 || rs.scrollIdx== 1);
  1283. year = rs.result[0].value
  1284. if(n1){
  1285. bigSmallMonth(rs.scrollEvt[2],year);
  1286. }
  1287. getLastVal(rs.result)
  1288. },
  1289. save:function(rs, target){
  1290. if(target.isInput){
  1291. target.value = lastValue;
  1292. }else{
  1293. target.innerText = lastValue;
  1294. }
  1295. opt.save(lastValue, target);
  1296. },
  1297. cancel:function(){
  1298. opt.cancel();
  1299. }
  1300. });
  1301. //判断是否有自定义初始值
  1302. var target = document.querySelectorAll(el);
  1303. for(var i=0;i<target.length;i++){
  1304. var item = target[i],
  1305. isInput = item.localName == 'input' || item.localName == 'textarea',
  1306. val = isInput?item.value:item.innerText;
  1307. if(val){
  1308. val = val.match(/\d+/g);
  1309. item.setAttribute('data-value',val);
  1310. }
  1311. }
  1312. };
  1313. window.popoPicker = popoPicker;
  1314. window.popoDateTime = popoDateTime;
  1315. window.popoDateT = popoDateT;
  1316. window.popoDate = popoDate;
  1317. window.popoYear = popoYear;
  1318. })(window,document);