云链智安app
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

time-picker-popup.vue 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <!-- 时间选择器弹窗 -->
  3. <uni-popup ref="popup" type="bottom" :safe-area="false">
  4. <view class="custom-picker">
  5. <view class="custom-picker__header">
  6. <view class="cancel" :style="{ color: canceColor }" @tap="onCancel">{{ cancelText }}</view>
  7. <view class="title">{{ title }}</view>
  8. <view class="confirm" :style="{ color: confirmColor }" @tap="onConfirm">{{ confirmText }}</view>
  9. </view>
  10. <picker-view :indicator-class="indicatorClass" :indicator-style="indicatorStyle" class="picker-view"
  11. :value="value.data" @change="bindChange" @pickstart="pickstart" @pickend="pickend">
  12. <picker-view-column>
  13. <view class="picker-view__item" v-for="(item,index) in rangeList[0]" :key="index">{{item}}</view>
  14. </picker-view-column>
  15. <picker-view-column>
  16. <view class="picker-view__item" v-for="(item,index) in rangeList[1]" :key="index">{{item}}</view>
  17. </picker-view-column>
  18. <picker-view-column>
  19. <view class="picker-view__item" v-for="(item,index) in rangeList[2]" :key="index">{{item}}</view>
  20. </picker-view-column>
  21. <picker-view-column>
  22. <view class="picker-view__item" v-for="(item,index) in rangeList[3]" :key="index">{{item}}</view>
  23. </picker-view-column>
  24. <view class="horizontal-line1">:</view>
  25. <view class="horizontal-line2">-</view>
  26. <view class="horizontal-line3">:</view>
  27. </picker-view>
  28. <view class="nav-view">
  29. <view class="popup-content" :class="{ 'popup-height': devicetype === 'left' || devicetype === 'right' }">
  30. <view class="popuptext">
  31. <view class="popuptext_left">
  32. 方向:
  33. </view>
  34. <l-switch v-model="defaultValue" :placeholder="['充电', '静置']" dotSize="14px" height="22px" width="32px" @change="onswitch"></l-switch>
  35. </view>
  36. <view class="popuptext">
  37. <view class="popuptext_left">
  38. 功率:
  39. </view>
  40. <uni-number-box :value="numberValue" @change="changeValue" />
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </uni-popup>
  46. </template>
  47. <!-- -->
  48. <script>
  49. import {
  50. props,
  51. range
  52. } from './utils.js';
  53. export default {
  54. name: 'TimePickerPopup',
  55. props: props,
  56. data() {
  57. return {
  58. rangeList: range,
  59. pickerValue: [0, 0, 0, 0],
  60. isScoll: false, // 是否正在滚动
  61. numberValue:'',
  62. defaultValue:true,
  63. devicetype:''
  64. }
  65. },
  66. methods: {
  67. /**
  68. * 开启弹窗
  69. */
  70. open() {
  71. // 判断是否传入props -> value
  72. console.log(this.value);
  73. console.log(this.rangeList);
  74. this.numberValue = this.value.numberValue;
  75. this.defaultValue = this.value.defaultValue;
  76. if (Array.isArray(this.value.data) && this.value.data.length) {
  77. this.pickerValue = this.value.data.map((item, index) => this.rangeList[index].findIndex(child =>
  78. child == this.value.data[index]));
  79. } else {
  80. this.pickerValue = [0, 0, 0, 0];
  81. }
  82. console.log(this.pickerValue);
  83. this.$refs.popup.open();
  84. },
  85. /**
  86. * 关闭弹窗
  87. */
  88. close() {
  89. this.$refs.popup.close();
  90. // 重置选中数据
  91. this.pickerValue = [0, 0, 0, 0];
  92. },
  93. /**
  94. * 点击确定
  95. */
  96. onConfirm() {
  97. if(this.numberValue!=''){
  98. return
  99. uni.showToast({
  100. title:'请输入功率!'
  101. })
  102. }
  103. if (!this.isScoll) {
  104. let data = this.value || ['00', '00', '00', '00'];
  105. if (this.pickerValue && this.pickerValue.length) {
  106. data = this.pickerValue.map((item, index) => String(this.rangeList[index][item]));
  107. }
  108. console.log(data);
  109. let obj = {
  110. numberValue:this.numberValue,
  111. defaultValue:this.defaultValue,
  112. data:data
  113. }
  114. this.$emit('confirm', obj);
  115. this.close();
  116. }
  117. },
  118. /**
  119. * 点击取消
  120. */
  121. onCancel() {
  122. this.close();
  123. },
  124. /**
  125. * 滚动开始
  126. */
  127. pickstart() {
  128. this.isScoll = true;
  129. },
  130. /**
  131. * 滚动结束
  132. */
  133. pickend() {
  134. this.isScoll = false;
  135. },
  136. /**
  137. * 选择器改变
  138. * @param {Object} e
  139. */
  140. bindChange(e) {
  141. this.pickerValue = e.detail.value;
  142. },
  143. changeValue(e){
  144. console.log(e);
  145. this.numberValue = e;
  146. },
  147. onswitch(e){
  148. console.log(e);
  149. this.defaultValue = e;
  150. }
  151. }
  152. }
  153. </script>
  154. <style lang="scss" scoped>
  155. .custom-picker {
  156. width: 100%;
  157. height: 800rpx;
  158. background-color: #fff;
  159. padding-bottom: 0;
  160. padding-bottom: constant(safe-area-inset-bottom);
  161. padding-bottom: env(safe-area-inset-bottom);
  162. .custom-picker__header {
  163. display: flex;
  164. align-items: center;
  165. justify-content: space-between;
  166. padding: 30rpx 40rpx;
  167. .cancel {
  168. color: #666;
  169. }
  170. .title {
  171. font-size: 32rpx;
  172. color: #333;
  173. }
  174. .confirm {
  175. color: #2bb781;
  176. }
  177. }
  178. }
  179. .picker-view {
  180. width: 100%;
  181. height: 400rpx;
  182. position: relative; /* 使横线相对于 picker-view 定位 */
  183. &__item {
  184. line-height: 100rpx;
  185. text-align: center;
  186. }
  187. // 使用 ::v-deep 替代 /deep/
  188. ::v-deep .picker-view__indicator {
  189. height: 100rpx;
  190. color: #2bb781;
  191. }
  192. &__segmentation {
  193. display: flex;
  194. align-items: center;
  195. }
  196. }
  197. .picker-view::before{
  198. &::before { content: attr(data-segmentation); display: block; position: absolute; left: 50%; top: 50%; }
  199. }
  200. .horizontal-line1 {
  201. position: absolute;
  202. top: 46%; /* 将横线垂直居中 */
  203. left: 25%;
  204. z-index: 1; /* 确保横线在内容之上 */
  205. }
  206. .horizontal-line2 {
  207. position: absolute;
  208. top: 46%; /* 将横线垂直居中 */
  209. left: 50%;
  210. z-index: 1; /* 确保横线在内容之上 */
  211. }
  212. .horizontal-line3 {
  213. position: absolute;
  214. top: 46%; /* 将横线垂直居中 */
  215. left: 75%;
  216. z-index: 1; /* 确保横线在内容之上 */
  217. }
  218. /* 弹出层内容样式 */
  219. .popup-content {
  220. padding: 30px;
  221. display: flex;
  222. margin-top: 40rpx;
  223. justify-content: space-around;
  224. // justify-content: space-between;
  225. text-align: center;
  226. border-radius: 20rpx;
  227. box-sizing: border-box;
  228. }
  229. /* 文本样式 */
  230. .popuptext {
  231. display: flex;
  232. align-items: center;
  233. font-size: 26rpx;
  234. color: #333;
  235. margin-bottom: 60rpx;
  236. }
  237. .popuptext_left{
  238. margin-right: 20rpx;
  239. }
  240. /* 取消按钮样式 */
  241. .cancel-button {
  242. margin-top: 20rpx;
  243. font-size: 24rpx;
  244. color: #333;
  245. border: 0px solid rgba(0, 0, 0, 0) !important;
  246. background-color: #fff;
  247. }
  248. .uni-button:after{
  249. border: 0px solid rgba(0, 0, 0, 0) !important;
  250. }
  251. /* 确认按钮样式 */
  252. .confirm-button {
  253. width: 120rpx;
  254. height: 60rpx;
  255. margin-top: 10rpx;
  256. font-size: 24rpx;
  257. background-color: #007aff;
  258. color: #fff;
  259. }
  260. /* 根据设备类型调整高度 */
  261. .popup-height {
  262. height: 200px;
  263. }
  264. .popupbutton{
  265. display: flex;
  266. justify-content: center;
  267. }
  268. .l-switch{
  269. overflow: hidden;
  270. }
  271. .l-switch__rail-placeholder{
  272. height: 100%;
  273. }
  274. </style>