u-picker.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. <template>
  2. <u-popup :maskCloseAble="maskCloseAble" mode="bottom" :popup="false" v-model="value" length="auto"
  3. :safeAreaInsetBottom="safeAreaInsetBottom" @close="close" :z-index="uZIndex">
  4. <view class="u-datetime-picker">
  5. <view class="u-picker-header" @touchmove.stop.prevent="">
  6. <view class="u-btn-picker u-btn-picker--tips" :style="{ color: cancelColor }" hover-class="u-opacity"
  7. :hover-stay-time="150" @tap="getResult('cancel')">{{cancelText}}</view>
  8. <view class="u-picker__title">{{ title }}</view>
  9. <view class="u-btn-picker u-btn-picker--primary" :style="{ color: moving ? cancelColor : confirmColor }"
  10. hover-class="u-opacity" :hover-stay-time="150" @touchmove.stop="" @tap.stop="getResult('confirm')">
  11. {{confirmText}}
  12. </view>
  13. </view>
  14. <view class="u-picker-body">
  15. <picker-view v-if="mode == 'region'" :value="valueArr" @change="change" class="u-picker-view"
  16. @pickstart="pickstart" @pickend="pickend">
  17. <picker-view-column v-if="!reset && params.province">
  18. <view class="u-column-item" v-for="(item, index) in provinces" :key="index">
  19. <view class="u-line-1">{{ item.label }}</view>
  20. </view>
  21. </picker-view-column>
  22. <picker-view-column v-if="!reset && params.city">
  23. <view class="u-column-item" v-for="(item, index) in citys" :key="index">
  24. <view class="u-line-1">{{ item.label }}</view>
  25. </view>
  26. </picker-view-column>
  27. <picker-view-column v-if="!reset && params.area">
  28. <view class="u-column-item" v-for="(item, index) in areas" :key="index">
  29. <view class="u-line-1">{{ item.label }}</view>
  30. </view>
  31. </picker-view-column>
  32. </picker-view>
  33. <picker-view v-else-if="mode == 'time'" :value="valueArr" @change="change" class="u-picker-view"
  34. @pickstart="pickstart" @pickend="pickend">
  35. <picker-view-column v-if="!reset && params.year">
  36. <view class="u-column-item" v-for="(item, index) in years" :key="index">
  37. {{ item }}
  38. <text class="u-text" v-if="showTimeTag">年</text>
  39. </view>
  40. </picker-view-column>
  41. <picker-view-column v-if="!reset && params.month">
  42. <view class="u-column-item" v-for="(item, index) in months" :key="index">
  43. {{ formatNumber(item) }}
  44. <text class="u-text" v-if="showTimeTag">月</text>
  45. </view>
  46. </picker-view-column>
  47. <picker-view-column v-if="!reset && params.day">
  48. <view class="u-column-item" v-for="(item, index) in days" :key="index">
  49. {{ formatNumber(item) }}
  50. <text class="u-text" v-if="showTimeTag">日</text>
  51. </view>
  52. </picker-view-column>
  53. <picker-view-column v-if="!reset && params.hour">
  54. <view class="u-column-item" v-for="(item, index) in hours" :key="index">
  55. {{ formatNumber(item) }}
  56. <text class="u-text" v-if="showTimeTag">时</text>
  57. </view>
  58. </picker-view-column>
  59. <picker-view-column v-if="!reset && params.minute">
  60. <view class="u-column-item" v-for="(item, index) in minutes" :key="index">
  61. {{ formatNumber(item) }}
  62. <text class="u-text" v-if="showTimeTag">分</text>
  63. </view>
  64. </picker-view-column>
  65. <picker-view-column v-if="!reset && params.second">
  66. <view class="u-column-item" v-for="(item, index) in seconds" :key="index">
  67. {{ formatNumber(item) }}
  68. <text class="u-text" v-if="showTimeTag">秒</text>
  69. </view>
  70. </picker-view-column>
  71. </picker-view>
  72. <picker-view v-else-if="mode == 'selector'" :value="valueArr" @change="change" class="u-picker-view"
  73. @pickstart="pickstart" @pickend="pickend">
  74. <picker-view-column v-if="!reset">
  75. <view class="u-column-item" v-for="(item, index) in range" :key="index">
  76. <view class="u-line-1">{{ getItemValue(item, 'selector') }}</view>
  77. </view>
  78. </picker-view-column>
  79. </picker-view>
  80. <picker-view v-else-if="mode == 'multiSelector'" :value="valueArr" @change="change"
  81. class="u-picker-view" @pickstart="pickstart" @pickend="pickend">
  82. <picker-view-column v-if="!reset" v-for="(item, index) in range" :key="index">
  83. <view class="u-column-item" v-for="(item1, index1) in item" :key="index1">
  84. <view class="u-line-1">{{ getItemValue(item1, 'multiSelector') }}</view>
  85. </view>
  86. </picker-view-column>
  87. </picker-view>
  88. </view>
  89. </view>
  90. </u-popup>
  91. </template>
  92. <script>
  93. import provinces from '../../libs/util/province.js';
  94. import citys from '../../libs/util/city.js';
  95. import areas from '../../libs/util/area.js';
  96. /**
  97. * picker picker弹出选择器
  98. * @description 此选择器有两种弹出模式:一是时间模式,可以配置年,日,月,时,分,秒参数 二是地区模式,可以配置省,市,区参数
  99. * @tutorial https://www.uviewui.com/components/picker.html
  100. * @property {Object} params 需要显示的参数,见官网说明
  101. * @property {String} mode 模式选择,region-地区类型,time-时间类型(默认time)
  102. * @property {String Number} start-year 可选的开始年份,mode=time时有效(默认1950)
  103. * @property {String Number} end-year 可选的结束年份,mode=time时有效(默认2050)
  104. * @property {Boolean} safe-area-inset-bottom 是否开启底部安全区适配(默认false)
  105. * @property {Boolean} show-time-tag 时间模式时,是否显示后面的年月日中文提示
  106. * @property {String} cancel-color 取消按钮的颜色(默认#606266)
  107. * @property {String} confirm-color 确认按钮的颜色(默认#2979ff)
  108. * @property {String} default-time 默认选中的时间,mode=time时有效
  109. * @property {String} confirm-text 确认按钮的文字
  110. * @property {String} cancel-text 取消按钮的文字
  111. * @property {String} default-region 默认选中的地区,中文形式,mode=region时有效
  112. * @property {String} default-code 默认选中的地区,编号形式,mode=region时有效
  113. * @property {Boolean} mask-close-able 是否允许通过点击遮罩关闭Picker(默认true)
  114. * @property {String Number} z-index 弹出时的z-index值(默认1075)
  115. * @property {Array} default-selector 数组形式,其中每一项表示选择了range对应项中的第几个
  116. * @property {Array} range 自定义选择的数据,mode=selector或mode=multiSelector时有效
  117. * @property {String} range-key 当range参数的元素为对象时,指定Object中的哪个key的值作为选择器显示内容
  118. * @event {Function} confirm 点击确定按钮,返回当前选择的值
  119. * @event {Function} cancel 点击取消按钮,返回当前选择的值
  120. * @example <u-picker v-model="show" mode="time"></u-picker>
  121. */
  122. export default {
  123. name: 'u-picker',
  124. props: {
  125. // picker中需要显示的参数
  126. params: {
  127. type: Object,
  128. default () {
  129. return {
  130. year: true,
  131. month: true,
  132. day: true,
  133. hour: false,
  134. minute: false,
  135. second: false,
  136. province: true,
  137. city: true,
  138. area: true,
  139. timestamp: true,
  140. };
  141. }
  142. },
  143. // 当mode=selector或者mode=multiSelector时,提供的数组
  144. range: {
  145. type: Array,
  146. default () {
  147. return [];
  148. }
  149. },
  150. // 当mode=selector或者mode=multiSelector时,提供的默认选中的下标
  151. defaultSelector: {
  152. type: Array,
  153. default () {
  154. return [0];
  155. }
  156. },
  157. // 当 range 是一个 Array<Object> 时,通过 range-key 来指定 Object 中 key 的值作为选择器显示内容
  158. rangeKey: {
  159. type: String,
  160. default: ''
  161. },
  162. // 模式选择,region-地区类型,time-时间类型,selector-单列模式,multiSelector-多列模式
  163. mode: {
  164. type: String,
  165. default: 'time'
  166. },
  167. // 年份开始时间
  168. startYear: {
  169. type: [String, Number],
  170. default: 1950
  171. },
  172. // 年份结束时间
  173. endYear: {
  174. type: [String, Number],
  175. default: 2050
  176. },
  177. // "取消"按钮的颜色
  178. cancelColor: {
  179. type: String,
  180. default: '#606266'
  181. },
  182. // "确定"按钮的颜色
  183. confirmColor: {
  184. type: String,
  185. default: '#2979ff'
  186. },
  187. // 默认显示的时间,2025-07-02 || 2025-07-02 13:01:00 || 2025/07/02
  188. defaultTime: {
  189. type: String,
  190. default: ''
  191. },
  192. // 默认显示的地区,可传类似["河北省", "秦皇岛市", "北戴河区"]
  193. defaultRegion: {
  194. type: Array,
  195. default () {
  196. return [];
  197. }
  198. },
  199. // 时间模式时,是否显示后面的年月日中文提示
  200. showTimeTag: {
  201. type: Boolean,
  202. default: true
  203. },
  204. // 默认显示地区的编码,defaultRegion和areaCode同时存在,areaCode优先,可传类似["13", "1303", "130304"]
  205. areaCode: {
  206. type: Array,
  207. default () {
  208. return [];
  209. }
  210. },
  211. safeAreaInsetBottom: {
  212. type: Boolean,
  213. default: false
  214. },
  215. // 是否允许通过点击遮罩关闭Picker
  216. maskCloseAble: {
  217. type: Boolean,
  218. default: true
  219. },
  220. // 通过双向绑定控制组件的弹出与收起
  221. value: {
  222. type: Boolean,
  223. default: false
  224. },
  225. // 弹出的z-index值
  226. zIndex: {
  227. type: [String, Number],
  228. default: 0
  229. },
  230. // 顶部标题
  231. title: {
  232. type: String,
  233. default: ''
  234. },
  235. // 取消按钮的文字
  236. cancelText: {
  237. type: String,
  238. default: '取消'
  239. },
  240. // 确认按钮的文字
  241. confirmText: {
  242. type: String,
  243. default: '确认'
  244. }
  245. },
  246. data() {
  247. return {
  248. years: [],
  249. months: [],
  250. days: [],
  251. hours: [],
  252. minutes: [],
  253. seconds: [],
  254. year: 0,
  255. month: 0,
  256. day: 0,
  257. hour: 0,
  258. minute: 0,
  259. second: 0,
  260. reset: false,
  261. startDate: '',
  262. endDate: '',
  263. valueArr: [],
  264. provinces: provinces,
  265. citys: citys[0],
  266. areas: areas[0][0],
  267. province: 0,
  268. city: 0,
  269. area: 0,
  270. moving: false // 列是否还在滑动中,微信小程序如果在滑动中就点确定,结果可能不准确
  271. };
  272. },
  273. mounted() {
  274. this.init();
  275. },
  276. computed: {
  277. propsChange() {
  278. // 引用这几个变量,是为了监听其变化
  279. return `${this.mode}-${this.defaultTime}-${this.startYear}-${this.endYear}-${this.defaultRegion}-${this.areaCode}`;
  280. },
  281. regionChange() {
  282. // 引用这几个变量,是为了监听其变化
  283. return `${this.province}-${this.city}`;
  284. },
  285. yearAndMonth() {
  286. return `${this.year}-${this.month}`;
  287. },
  288. uZIndex() {
  289. // 如果用户有传递z-index值,优先使用
  290. return this.zIndex ? this.zIndex : this.$u.zIndex.popup;
  291. }
  292. },
  293. watch: {
  294. propsChange() {
  295. this.reset = true;
  296. setTimeout(() => this.init(), 10);
  297. },
  298. // 如果地区发生变化,为了让picker联动起来,必须重置this.citys和this.areas
  299. regionChange(val) {
  300. this.citys = citys[this.province];
  301. this.areas = areas[this.province][this.city];
  302. },
  303. // watch监听月份的变化,实时变更日的天数,因为不同月份,天数不一样
  304. // 一个月可能有30,31天,甚至闰年2月的29天,平年2月28天
  305. yearAndMonth(val) {
  306. if (this.params.year) this.setDays();
  307. },
  308. // 微信和QQ小程序由于一些奇怪的原因(故同时对所有平台均初始化一遍),需要重新初始化才能显示正确的值
  309. value(n) {
  310. if (n) {
  311. this.reset = true;
  312. setTimeout(() => this.init(), 10);
  313. }
  314. }
  315. },
  316. methods: {
  317. // 标识滑动开始,只有微信小程序才有这样的事件
  318. pickstart() {
  319. // #ifdef MP-WEIXIN
  320. this.moving = true;
  321. // #endif
  322. },
  323. // 标识滑动结束
  324. pickend() {
  325. // #ifdef MP-WEIXIN
  326. this.moving = false;
  327. // #endif
  328. },
  329. // 对单列和多列形式的判断是否有传入变量的情况
  330. getItemValue(item, mode) {
  331. // 目前(2020-05-25)uni-app对微信小程序编译有错误,导致v-if为false中的内容也执行,错误导致
  332. // 单列模式或者多列模式中的getItemValue同时被执行,故在这里再加一层判断
  333. if (this.mode == mode) {
  334. return typeof item == 'object' ? item[this.rangeKey] : item;
  335. }
  336. },
  337. // 小于10前面补0,用于月份,日期,时分秒等
  338. formatNumber(num) {
  339. return +num < 10 ? '0' + num : String(num);
  340. },
  341. // 生成递进的数组
  342. generateArray: function(start, end) {
  343. // 转为数值格式,否则用户给end-year等传递字符串值时,下面的end+1会导致字符串拼接,而不是相加
  344. start = Number(start);
  345. end = Number(end);
  346. end = end > start ? end : start;
  347. // 生成数组,获取其中的索引,并剪出来
  348. return [...Array(end + 1).keys()].slice(start);
  349. },
  350. getIndex: function(arr, val) {
  351. let index = arr.indexOf(val);
  352. // 如果index为-1(即找不到index值),~(-1)=-(-1)-1=0,导致条件不成立
  353. return ~index ? index : 0;
  354. },
  355. //日期时间处理
  356. initTimeValue() {
  357. // 格式化时间,在IE浏览器(uni不存在此情况),无法识别日期间的"-"间隔符号
  358. let fdate = this.defaultTime.replace(/\-/g, '/');
  359. fdate = fdate && fdate.indexOf('/') == -1 ? `2020/01/01 ${fdate}` : fdate;
  360. let time = null;
  361. if (fdate) time = new Date(fdate);
  362. else time = new Date();
  363. // 获取年日月时分秒
  364. this.year = time.getFullYear();
  365. this.month = Number(time.getMonth()) + 1;
  366. this.day = time.getDate();
  367. this.hour = time.getHours();
  368. this.minute = time.getMinutes();
  369. this.second = time.getSeconds();
  370. },
  371. init() {
  372. this.valueArr = [];
  373. this.reset = false;
  374. if (this.mode == 'time') {
  375. this.initTimeValue();
  376. if (this.params.year) {
  377. this.valueArr.push(0);
  378. this.setYears();
  379. }
  380. if (this.params.month) {
  381. this.valueArr.push(0);
  382. this.setMonths();
  383. }
  384. if (this.params.day) {
  385. this.valueArr.push(0);
  386. this.setDays();
  387. }
  388. if (this.params.hour) {
  389. this.valueArr.push(0);
  390. this.setHours();
  391. }
  392. if (this.params.minute) {
  393. this.valueArr.push(0);
  394. this.setMinutes();
  395. }
  396. if (this.params.second) {
  397. this.valueArr.push(0);
  398. this.setSeconds();
  399. }
  400. } else if (this.mode == 'region') {
  401. if (this.params.province) {
  402. this.valueArr.push(0);
  403. this.setProvinces();
  404. }
  405. if (this.params.city) {
  406. this.valueArr.push(0);
  407. this.setCitys();
  408. }
  409. if (this.params.area) {
  410. this.valueArr.push(0);
  411. this.setAreas();
  412. }
  413. } else if (this.mode == 'selector') {
  414. this.valueArr = this.defaultSelector;
  415. } else if (this.mode == 'multiSelector') {
  416. this.valueArr = this.defaultSelector;
  417. this.multiSelectorValue = this.defaultSelector;
  418. }
  419. this.$forceUpdate();
  420. },
  421. // 设置picker的某一列值
  422. setYears() {
  423. // 获取年份集合
  424. this.years = this.generateArray(this.startYear, this.endYear);
  425. // 设置this.valueArr某一项的值,是为了让picker预选中某一个值
  426. this.valueArr.splice(this.valueArr.length - 1, 1, this.getIndex(this.years, this.year));
  427. },
  428. setMonths() {
  429. this.months = this.generateArray(1, 12);
  430. this.valueArr.splice(this.valueArr.length - 1, 1, this.getIndex(this.months, this.month));
  431. },
  432. setDays() {
  433. let totalDays = new Date(this.year, this.month, 0).getDate();
  434. this.days = this.generateArray(1, totalDays);
  435. let index = 0;
  436. // 这里不能使用类似setMonths()中的this.valueArr.splice(this.valueArr.length - 1, xxx)做法
  437. // 因为this.month和this.year变化时,会触发watch中的this.setDays(),导致this.valueArr.length计算有误
  438. if (this.params.year && this.params.month) index = 2;
  439. else if (this.params.month) index = 1;
  440. else if (this.params.year) index = 1;
  441. else index = 0;
  442. // 当月份变化时,会导致日期的天数也会变化,如果原来选的天数大于变化后的天数,则重置为变化后的最大值
  443. // 比如原来选中3月31日,调整为2月后,日期变为最大29,这时如果day值继续为31显然不合理,于是将其置为29(picker-column从1开始)
  444. if (this.day > this.days.length) this.day = this.days.length;
  445. this.valueArr.splice(index, 1, this.getIndex(this.days, this.day));
  446. },
  447. setHours() {
  448. this.hours = this.generateArray(0, 23);
  449. this.valueArr.splice(this.valueArr.length - 1, 1, this.getIndex(this.hours, this.hour));
  450. },
  451. setMinutes() {
  452. this.minutes = this.generateArray(0, 59);
  453. this.valueArr.splice(this.valueArr.length - 1, 1, this.getIndex(this.minutes, this.minute));
  454. },
  455. setSeconds() {
  456. this.seconds = this.generateArray(0, 59);
  457. this.valueArr.splice(this.valueArr.length - 1, 1, this.getIndex(this.seconds, this.second));
  458. },
  459. setProvinces() {
  460. // 判断是否需要province参数
  461. if (!this.params.province) return;
  462. let tmp = '';
  463. let useCode = false;
  464. // 如果同时配置了defaultRegion和areaCode,优先使用areaCode参数
  465. if (this.areaCode.length) {
  466. tmp = this.areaCode[0];
  467. useCode = true;
  468. } else if (this.defaultRegion.length) tmp = this.defaultRegion[0];
  469. else tmp = 0;
  470. // 历遍省份数组匹配
  471. provinces.map((v, k) => {
  472. if (useCode ? v.value == tmp : v.label == tmp) {
  473. tmp = k;
  474. }
  475. });
  476. this.province = tmp;
  477. this.provinces = provinces;
  478. // 设置默认省份的值
  479. this.valueArr.splice(0, 1, this.province);
  480. },
  481. setCitys() {
  482. if (!this.params.city) return;
  483. let tmp = '';
  484. let useCode = false;
  485. if (this.areaCode.length) {
  486. tmp = this.areaCode[1];
  487. useCode = true;
  488. } else if (this.defaultRegion.length) tmp = this.defaultRegion[1];
  489. else tmp = 0;
  490. citys[this.province].map((v, k) => {
  491. if (useCode ? v.value == tmp : v.label == tmp) {
  492. tmp = k;
  493. }
  494. });
  495. this.city = tmp;
  496. this.citys = citys[this.province];
  497. this.valueArr.splice(1, 1, this.city);
  498. },
  499. setAreas() {
  500. if (!this.params.area) return;
  501. let tmp = '';
  502. let useCode = false;
  503. if (this.areaCode.length) {
  504. tmp = this.areaCode[2];
  505. useCode = true;
  506. } else if (this.defaultRegion.length) tmp = this.defaultRegion[2];
  507. else tmp = 0;
  508. areas[this.province][this.city].map((v, k) => {
  509. if (useCode ? v.value == tmp : v.label == tmp) {
  510. tmp = k;
  511. }
  512. });
  513. this.area = tmp;
  514. this.areas = areas[this.province][this.city];
  515. this.valueArr.splice(2, 1, this.area);
  516. },
  517. close() {
  518. this.$emit('input', false);
  519. },
  520. // 用户更改picker的列选项
  521. change(e) {
  522. this.valueArr = e.detail.value;
  523. let i = 0;
  524. if (this.mode == 'time') {
  525. // 这里使用i++,是因为this.valueArr数组的长度是不确定长度的,它根据this.params的值来配置长度
  526. // 进入if规则,i会加1,保证了能获取准确的值
  527. if (this.params.year) this.year = this.years[this.valueArr[i++]];
  528. if (this.params.month) this.month = this.months[this.valueArr[i++]];
  529. if (this.params.day) this.day = this.days[this.valueArr[i++]];
  530. if (this.params.hour) this.hour = this.hours[this.valueArr[i++]];
  531. if (this.params.minute) this.minute = this.minutes[this.valueArr[i++]];
  532. if (this.params.second) this.second = this.seconds[this.valueArr[i++]];
  533. } else if (this.mode == 'region') {
  534. if (this.params.province) this.province = this.valueArr[i++];
  535. if (this.params.city) this.city = this.valueArr[i++];
  536. if (this.params.area) this.area = this.valueArr[i++];
  537. } else if (this.mode == 'multiSelector') {
  538. let index = null;
  539. // 对比前后两个数组,寻找变更的是哪一列,如果某一个元素不同,即可判定该列发生了变化
  540. this.defaultSelector.map((val, idx) => {
  541. if (val != e.detail.value[idx]) index = idx;
  542. });
  543. // 为了让用户对多列变化时,对动态设置其他列的变更
  544. if (index != null) {
  545. this.$emit('columnchange', {
  546. column: index,
  547. index: e.detail.value[index]
  548. });
  549. }
  550. }
  551. },
  552. // 用户点击确定按钮
  553. getResult(event = null) {
  554. // #ifdef MP-WEIXIN
  555. if (this.moving) return;
  556. // #endif
  557. let result = {};
  558. // 只返回用户在this.params中配置了为true的字段
  559. if (this.mode == 'time') {
  560. if (this.params.year) result.year = this.formatNumber(this.year || 0);
  561. if (this.params.month) result.month = this.formatNumber(this.month || 0);
  562. if (this.params.day) result.day = this.formatNumber(this.day || 0);
  563. if (this.params.hour) result.hour = this.formatNumber(this.hour || 0);
  564. if (this.params.minute) result.minute = this.formatNumber(this.minute || 0);
  565. if (this.params.second) result.second = this.formatNumber(this.second || 0);
  566. if (this.params.timestamp) result.timestamp = this.getTimestamp();
  567. } else if (this.mode == 'region') {
  568. if (this.params.province) result.province = provinces[this.province];
  569. if (this.params.city) result.city = citys[this.province][this.city];
  570. if (this.params.area) result.area = areas[this.province][this.city][this.area];
  571. } else if (this.mode == 'selector') {
  572. result = this.valueArr;
  573. } else if (this.mode == 'multiSelector') {
  574. result = this.valueArr;
  575. }
  576. if (event) this.$emit(event, result);
  577. this.close();
  578. },
  579. // 获取时间戳
  580. getTimestamp() {
  581. // yyyy-mm-dd为安卓写法,不支持iOS,需要使用"/"分隔,才能二者兼容
  582. let time = this.year + '/' + this.month + '/' + this.day + ' ' + this.hour + ':' + this.minute + ':' + this
  583. .second;
  584. return new Date(time).getTime() / 1000;
  585. }
  586. }
  587. };
  588. </script>
  589. <style lang="scss" scoped>
  590. @import '../../libs/css/style.components.scss';
  591. .u-datetime-picker {
  592. position: relative;
  593. z-index: 999;
  594. }
  595. .u-picker-view {
  596. height: 100%;
  597. box-sizing: border-box;
  598. }
  599. .u-picker-header {
  600. width: 100%;
  601. height: 90rpx;
  602. padding: 0 40rpx;
  603. @include vue-flex;
  604. justify-content: space-between;
  605. align-items: center;
  606. box-sizing: border-box;
  607. font-size: 30rpx;
  608. background: #fff;
  609. position: relative;
  610. }
  611. .u-picker-header::after {
  612. content: '';
  613. position: absolute;
  614. border-bottom: 1rpx solid #eaeef1;
  615. -webkit-transform: scaleY(0.5);
  616. transform: scaleY(0.5);
  617. bottom: 0;
  618. right: 0;
  619. left: 0;
  620. }
  621. .u-picker__title {
  622. color: $u-content-color;
  623. }
  624. .u-picker-body {
  625. width: 100%;
  626. height: 500rpx;
  627. overflow: hidden;
  628. background-color: #fff;
  629. }
  630. .u-column-item {
  631. @include vue-flex;
  632. align-items: center;
  633. justify-content: center;
  634. font-size: 32rpx;
  635. color: $u-main-color;
  636. padding: 0 8rpx;
  637. }
  638. .u-text {
  639. font-size: 24rpx;
  640. padding-left: 8rpx;
  641. }
  642. .u-btn-picker {
  643. padding: 16rpx;
  644. box-sizing: border-box;
  645. text-align: center;
  646. text-decoration: none;
  647. }
  648. .u-opacity {
  649. opacity: 0.5;
  650. }
  651. .u-btn-picker--primary {
  652. color: $u-type-primary;
  653. }
  654. .u-btn-picker--tips {
  655. color: $u-tips-color;
  656. }
  657. </style>