酷炫直播运营系统小程序版本

editPlanTime.vue 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="mask" @touchmove.stop.prevent="moveStop" @click="cancelEvent">
  3. <view class="mask-container" @click.stop="moveStop">
  4. <view class="operationBox">
  5. <view class="cancel" @click="cancelEvent">取消</view>
  6. <view class="define" @click="submitEvent">确定</view>
  7. </view>
  8. <view class="timeBox">
  9. <view :class="['timeBoxItem',type==1?'timeBoxItem1_active':'']" @click="timeClick(1)">
  10. <view class="time">{{editTime.startLiveTime.time}}</view>
  11. <view class="date">{{editTime.startLiveTime.date}}</view>
  12. </view>
  13. <view :class="['timeBoxItem',type==2?'timeBoxItem2_active':'']" @click="timeClick(2)">
  14. <view class="time">{{editTime.endLiveTime.time}}</view>
  15. <view class="date">{{editTime.endLiveTime.date}}</view>
  16. </view>
  17. </view>
  18. <picker-view v-if="visible" :indicator-style="indicatorStyle" :value="value" @change="bindChange">
  19. <picker-view-column>
  20. <view class="item" v-for="(item,index) in dates" :key="index">{{item}}</view>
  21. </picker-view-column>
  22. <picker-view-column>
  23. <view class="item" v-for="(item,index) in hours" :key="index">{{item}}</view>
  24. </picker-view-column>
  25. <picker-view-column>
  26. <view class="item" v-for="(item,index) in minutes" :key="index">{{item}}</view>
  27. </picker-view-column>
  28. </picker-view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. props: ['editTimeData'],
  35. data () {
  36. const hours = []
  37. const minutes = []
  38. for (let i = 0; i <= 23; i++) {
  39. hours.push((i < 10 ? '0' + i : i))
  40. }
  41. for (let i = 0; i <= 60; i += 5) {
  42. minutes.push((i < 10 ? '0' + i : i))
  43. }
  44. return {
  45. type: 1,
  46. editTime: this.editTimeData,
  47. indicatorStyle: `height: 50px;`,
  48. value: [0, 0, 0],
  49. minutes,
  50. hours,
  51. dates: [],
  52. visible: false
  53. }
  54. },
  55. created () {
  56. for (let i = -30; i <= 30; i++) {
  57. this.dates.push(this.$getDay(i))
  58. }
  59. this.timeInit()
  60. },
  61. methods: {
  62. timeInit () {
  63. let date_index = 0;
  64. let hour_index = 0;
  65. let minute_index = 0;
  66. this.dates.filter((v, index) => {
  67. if (new Date(v).getTime() == new Date((this.type == 1 ? this.editTimeData.startLiveTime.date :
  68. this.editTimeData.endLiveTime.date)).getTime()) {
  69. date_index = index
  70. return v
  71. }
  72. })
  73. let h = 0;
  74. let m = 0;
  75. if (this.type == 1) {
  76. if (this.editTimeData.startLiveTime.time) {
  77. h = this.editTimeData.startLiveTime.time.split(':')[0];
  78. m = this.editTimeData.startLiveTime.time.split(':')[1];
  79. }
  80. } else {
  81. if (this.editTimeData.endLiveTime.time) {
  82. h = this.editTimeData.endLiveTime.time.split(':')[0];
  83. m = this.editTimeData.endLiveTime.time.split(':')[1];
  84. }
  85. }
  86. for (var i in this.hours) {
  87. if (this.hours[i] >= h) {
  88. hour_index = i;
  89. break;
  90. }
  91. }
  92. for (var i in this.minutes) {
  93. if (this.minutes[i] >= m) {
  94. minute_index = i;
  95. break;
  96. }
  97. }
  98. this.value = [date_index, hour_index, minute_index]
  99. this.visible = true
  100. },
  101. timeClick (type) {
  102. this.type = type
  103. this.timeInit()
  104. },
  105. bindChange (e) { //picker 改变
  106. const val = e.detail.value
  107. if (this.type == 1) {
  108. this.editTime.startLiveTime.date = this.dates[val[0]];
  109. this.editTime.startLiveTime.time = this.hours[val[1]] + ':' + this.minutes[val[2]]
  110. } else {
  111. this.editTime.endLiveTime.date = this.dates[val[0]];
  112. this.editTime.endLiveTime.time = this.hours[val[1]] + ':' + this.minutes[val[2]]
  113. }
  114. },
  115. submitEvent () {
  116. this.$emit('changeTime', this.editTime)
  117. },
  118. cancelEvent () {
  119. this.$emit('closeEvent')
  120. },
  121. moveStop () { }
  122. }
  123. }
  124. </script>
  125. <style scoped lang="scss">
  126. .mask {
  127. width: 100%;
  128. height: 100vh;
  129. background: rgba(0, 0, 0, 0.5);
  130. position: fixed;
  131. bottom: 0;
  132. left: 0;
  133. z-index: 3;
  134. .mask-container {
  135. position: absolute;
  136. left: 0;
  137. bottom: 0;
  138. background: #ffffff;
  139. width: 100%;
  140. height: 700rpx;
  141. border-top-left-radius: 38rpx;
  142. border-top-right-radius: 38rpx;
  143. .operationBox {
  144. display: flex;
  145. align-items: center;
  146. justify-content: space-between;
  147. padding: 36rpx;
  148. .cancel,
  149. .define {
  150. font-size: 28rpx;
  151. line-height: 40rpx;
  152. }
  153. .cancel {
  154. color: #747474;
  155. }
  156. .define {
  157. color: #1f2126;
  158. }
  159. }
  160. .timeBox {
  161. display: flex;
  162. align-items: center;
  163. height: 124rpx;
  164. border-top: 2rpx solid #e8e8e8;
  165. border-bottom: 2rpx solid #e8e8e8;
  166. .timeBoxItem {
  167. flex: 1;
  168. padding-left: 78rpx;
  169. height: 100%;
  170. display: flex;
  171. flex-direction: column;
  172. justify-content: center;
  173. .time {
  174. color: #000000;
  175. font-size: 32rpx;
  176. line-height: 44rpx;
  177. font-weight: 500;
  178. }
  179. .date {
  180. color: #34383a;
  181. font-size: 32rpx;
  182. line-height: 44rpx;
  183. }
  184. &.timeBoxItem1_active {
  185. background: url(../../static/img/editTime1.png) no-repeat;
  186. background-size: 100% 100%;
  187. opacity: 0.7;
  188. .time,
  189. .date {
  190. color: #ffffff;
  191. }
  192. }
  193. &.timeBoxItem2_active {
  194. background: url(../../static/img/editTime2.png) no-repeat;
  195. background-size: 100% 100%;
  196. opacity: 0.7;
  197. .time,
  198. .date {
  199. color: #ffffff;
  200. }
  201. }
  202. }
  203. }
  204. }
  205. }
  206. picker-view {
  207. width: 100%;
  208. height: 400rpx;
  209. margin-top: 20rpx;
  210. }
  211. .item {
  212. line-height: 100rpx;
  213. text-align: center;
  214. color: #000000;
  215. font-weight: bold;
  216. }
  217. </style>