tm-pickersDate.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view class="tm-pickersDate d-inline-block fulled">
  3. <view @click.stop.prevent="openPoup"><slot></slot></view>
  4. <tm-poup @change="toogle" ref="pop" v-model="showpop" :height="750" :bg-color="black_tmeme?'grey-darken-5':bgColor">
  5. <view class="tm-pickersDate-title pa-32 pb-16">
  6. <view class="text-size-n text-align-center" style="min-height: 48rpx;">{{title}}</view>
  7. <view class="tm-pickersDate-close rounded flex-center " :class="black_tmeme?'grey-darken-3':'grey-lighten-3'">
  8. <tm-icons @click="close" name="icon-times" size="24" :color="black_tmeme?'white':'grey'"></tm-icons>
  9. </view>
  10. </view>
  11. <tm-pickersDateView ref="gg"
  12. @aniStart="aniisTrue=false" @aniEnd="aniisTrue=true"
  13. :modeValue="modeValue"
  14. :black="black_tmeme"
  15. :start="start"
  16. :end="end"
  17. :defaultValue="dataValue"
  18. :itemHeight="itemHeight"
  19. :disabled="disabled"
  20. :bgColor="bgColor"
  21. :showDetail="showDetail"
  22. :mode="mode"
  23. :fullNumber="fullNumber"
  24. ></tm-pickersDateView>
  25. <view class="pa-32">
  26. <tm-button :black="black_tmeme" @click="confirm" block itemeClass="round-24" :theme="btnColor" fontSize="32">{{btnText}}</tm-button>
  27. </view>
  28. </tm-poup>
  29. </view>
  30. </template>
  31. <script>
  32. /**
  33. * 日期下拉选择器(弹层)
  34. * @description 日期下拉选择器(弹层)
  35. * @property {Array} default-value = [] 默认:当前的时间,初始显示的时间
  36. * @property {String|Number} item-height = [34|42|50|58|62] 项目的高度单位px
  37. * @property {String|Boolean} black = [true|false] 是否开启暗黑模式。
  38. * @property {String|Boolean} disabled = [true|false] 是否禁用
  39. * @property {String} bg-color = [white|blue] 默认:white,白色背景;请填写背景的主题色名称。
  40. * @property {Object} show-detail = [{year:true,month:true,day:true,hour:false,min:false,sec:false}] 默认:{year:true,month:true,day:true,hour:false,min:false,sec:false}
  41. * @property {String} start = [1900-1-1 00:00:00] 默认:1900-1-1 00:00:00,开始的时间
  42. * @property {String} end = [] 默认:当前,结束的时间
  43. * @property {String|Boolean} mode = [true|false] 默认:true,是否显示中文年,月后缀
  44. * @property {String|Boolean} full-number = [true|false] 默认:true,是否把个位数补齐双位数
  45. * @property {String} title = [] 弹层层标题
  46. * @property {String} btn-text = [] 底部按钮确认的文字
  47. * @property {String} btn-color = [primary|green|orange|red|blue|bg-gradient-blue-lighten] 默认:bg-gradient-blue-lighten底部按钮确认的背景颜色仅支持主题色名称
  48. * @property {Function} confirm 返回当前选中的数据
  49. */
  50. import tmButton from "@/tm-vuetify/components/tm-button/tm-button.vue"
  51. import tmPoup from "@/tm-vuetify/components/tm-poup/tm-poup.vue"
  52. import tmIcons from "@/tm-vuetify/components/tm-icons/tm-icons.vue"
  53. import tmPickersDateView from "@/tm-vuetify/components/tm-pickersDateView/tm-pickersDateView.vue"
  54. export default {
  55. components:{tmButton,tmPoup,tmIcons,tmPickersDateView},
  56. name:"tm-pickersDate",
  57. model:{
  58. prop:'value',
  59. event:'input'
  60. },
  61. mounted() {
  62. this.showpop = this.value;
  63. },
  64. props: {
  65. // 行高。
  66. itemHeight: {
  67. type: String | Number,
  68. default: 40
  69. },
  70. // 等同v-model,或者value.sync
  71. value: {
  72. type: String | Number,
  73. default: false
  74. },
  75. black:{
  76. type:String|Boolean,
  77. default:null
  78. },
  79. // 是否禁用
  80. disabled:{
  81. type:String|Boolean,
  82. default:false
  83. },
  84. // 背景颜色,主题色名称。
  85. bgColor:{
  86. type:String,
  87. default:'white'
  88. },
  89. //要展示的时间。
  90. showDetail:{
  91. type:Object,
  92. default:()=>{
  93. return {
  94. year:true,//年
  95. month:true,//月
  96. day:true,//天
  97. hour:false,//小时
  98. min:false,//分
  99. sec:false//秒
  100. }
  101. }
  102. },
  103. start:{
  104. type:String,
  105. default:'1949-1-1 00:00:00'
  106. },
  107. end:{
  108. type:String,
  109. default:''
  110. },
  111. defaultValue:'',
  112. // 是否显示中文年,月后缀
  113. mode:{
  114. type:String|Boolean,
  115. default:true
  116. },
  117. // 是否把个位数补齐双位数
  118. fullNumber:{
  119. type:String|Boolean,
  120. default:true
  121. },
  122. // 顶部标题。
  123. title:{
  124. type:String,
  125. default:'请选择时间'
  126. },
  127. // 底部按钮文件
  128. btnText:{
  129. type:String,
  130. default:'确认'
  131. },
  132. // 底部按钮背景主题色名称
  133. btnColor:{
  134. type:String,
  135. default:'primary'
  136. },
  137. //要展示的时间。
  138. modeValue:{
  139. type:Object,
  140. default:()=>{
  141. return {
  142. year:'年',//年
  143. month:'月',//月
  144. day:'日',//天
  145. hour:'时',//小时
  146. min:'分',//分
  147. sec:'秒'//秒
  148. }
  149. }
  150. },
  151. },
  152. data() {
  153. return {
  154. showpop:false,
  155. dataValue:'1949',
  156. aniisTrue:true,
  157. };
  158. },
  159. computed: {
  160. black_tmeme: function() {
  161. if (this.black !== null) return this.black;
  162. return this.$tm.vx.state().tmVuetify.black;
  163. }
  164. },
  165. watch:{
  166. value:function(val){
  167. this.showpop = val;
  168. if(val){
  169. this.$nextTick(function(){
  170. setTimeout(function() {
  171. uni.hideKeyboard();
  172. }, 20);
  173. })
  174. }
  175. }
  176. },
  177. mounted() {
  178. this.$nextTick(function(){
  179. this.$refs.gg.resetVal(this.dataValue)
  180. })
  181. },
  182. methods: {
  183. confirm() {
  184. if(!this.aniisTrue){
  185. console.log('no');
  186. return ;
  187. }
  188. let value = this.$refs.gg.getSelectedValue();
  189. this.$emit('confirm',value)
  190. // this.$emit('update:defaultValue',this.$refs.gg.getSelectedValue())
  191. this.$refs.pop.close();
  192. },
  193. close(){
  194. this.$refs.pop.close();
  195. },
  196. openPoup(){
  197. if(this.disabled==true) return;
  198. this.showpop=!this.showpop
  199. },
  200. toogle(e){
  201. let t = this;
  202. if(e){
  203. if(this.dataValue != this.defaultValue){
  204. t.dataValue = t.defaultValue;
  205. }
  206. // #ifdef APP-VUE
  207. this.$nextTick(function(){
  208. setTimeout(function(){
  209. t.$refs.gg.resetVal(t.dataValue)
  210. },500)
  211. })
  212. // #endif
  213. // #ifndef APP-VUE
  214. t.$refs.gg.resetVal(t.dataValue)
  215. // #endif
  216. }
  217. this.$emit('input',e);
  218. this.$emit('update:value',e);
  219. }
  220. },
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. .tm-pickersDate-title {
  225. position: relative;
  226. .tm-pickersDate-close {
  227. position: absolute;
  228. top: 32upx;
  229. right: 32upx;
  230. width: 50upx;
  231. height: 50upx;
  232. }
  233. }
  234. </style>