Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

u-picker.vue 21 KiB

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