''
liukangdong
2024-06-17 e8e0e31be5f27e657de6f07f57a20fdf70e9bb9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<template>
  <view class="main_app">
    <view class="app_header">
      <view class="item" @click="isShowCar = true">
        <text v-if="param.carCode">{{ param.carCode }}</text>
        <text v-else class="placeholder9">选择车辆</text>
        <u-icon name="arrow-down" color="#999999" />
      </view>
      <view class="item" @click="isShowDate = true">
        <text v-if="param.queryDate">{{ param.queryDate }}</text>
        <text v-else class="placeholder9">选择日期</text>
        <u-icon name="arrow-down" color="#999999" />
      </view>
    </view>
    <!--  -->
    <view class="time_list">
      <view
        class="item"
        :class="{ disable: item.isUse == 1, active: item.checked == '1' }"
        @click="datetimeClick(item, i)"
        v-for="(item, i) in timeList"
        :key="i"
        >{{ item.startHours }}-{{ item.endHours }}</view
      >
    </view>
    <!--  -->
    <view class="main_footer">
      <view class="df_ac">
        <view>已选择:</view>
        <view class="sel_time">{{ selDatetime }}</view>
      </view>
      <view class="btns">
        <view class="left">
          <view class="item" v-for="item in colorOptions" :key="item.name">
            <view class="box" :style="{ background: item.color }"></view>
            <view class="">{{ item.name }}</view>
          </view>
        </view>
        <view class="sub" @click="onSubmit">确认预约</view>
      </view>
    </view>
    <!--  -->
    <!-- 选择车辆 -->
    <u-picker
      keyName="code"
      :show="isShowCar"
      :columns="carsList"
      @confirm="seletedCar"
      @cancel="isShowCar = false"
    ></u-picker>
    <!-- 日期 -->
    <u-datetime-picker
      :show="isShowDate"
      :minDate="minDate"
      @confirm="confirmDate"
      @cancel="isShowDate = false"
      mode="date"
    ></u-datetime-picker>
  </view>
</template>
 
<script>
import dayjs from 'dayjs'
import { getCarsList, carCanReservationDate } from '@/api'
export default {
  data() {
    return {
      isShowCar: false,
      isShowDate: false,
      param: {},
 
      minDate: '',
      carsList: [[{ name: 'aa', value: '11' }]],
      timeList: [],
      selDatetime: '',
 
      colorOptions: [
        { color: this.$store.state.primaryColor, name: '已选择' },
        { color: '#F7F7F7', name: '可预约' },
        { color: '#cccccc', name: '不可预约' },
      ]
    }
  },
  onLoad() {
    this.minDate = new Date().getTime()
    this.initData()
  },
  methods: {
    onSubmit() {
            const { param } = this
      const selTimeList = this.timeList.filter(i => i.checked == '1')
      if (selTimeList.length == 0) {
        return uni.showToast({
          title: '请先选择用车时间段',
          icon: 'none'
        })
      }
            const obj = {
                carCode: param.carCode,
                carId: param.carId ,
                startTime: selTimeList[0].startTime,
                endTime: selTimeList[selTimeList.length - 1].endTime,
                dateDay: param.queryDate,
        type: '0'
            }
            uni.navigateTo({
                url: `/pages/staff/vehicle/apply?carCode=${obj.carCode}&carId=${obj.carId}&startTime=${obj.startTime}&endTime=${obj.endTime}&dateDay=${obj.dateDay}&type=${obj.type}`
            })
      // this.$jump('/pages/staff/vehicle/apply')
    },
    datetimeClick(item, index) {
      if(item.isUse == '1') return
      const { timeList } = this
      const selTimeList = timeList.filter(i => i.checked == '1')
      if (selTimeList.length === 0) {
        this.timeList.forEach((ite, i) => {
          if (i === index) {
            ite.checked = '1'
            this.$forceUpdate()
          }
        })
      } else {
        const findIndex = selTimeList.findIndex(i => i.index === index)
        console.log('findIndex', findIndex)
        if (findIndex === -1) {
          const startNum = index - selTimeList[0].index
          const endNum = index - selTimeList[selTimeList.length - 1].index
          if (startNum == 1 || startNum == -1 || endNum == 1 || endNum == -1) {
            console.log('相邻')
            item.checked = true
            this.$forceUpdate()
          } else {
            return uni.showToast({
              title: '请选择相邻的时间段',
              icon: 'none'
            })
          }
        } else {
          if (index === selTimeList[0].index || index === selTimeList[selTimeList.length - 1].index) {
            item.checked = false
            this.$forceUpdate()
          } else {
            return uni.showToast({
              title: '请先取消最外层的时间段',
              icon: 'none'
            })
          }
 
        }
      }
      const selTimeLists = this.timeList.filter(i => i.checked == '1')
      // console.log('selTimeList', selTimeList);
      if (selTimeLists.length === 0) {
        this.selDatetime = ''
      } else {
        this.selDatetime = this.param.queryDate.slice(5) + ' ' + selTimeLists[0].startHours + '-' + selTimeLists[selTimeLists.length - 1].endHours
      }
    },
    confirmDate(e) {
      this.param.queryDate = dayjs(e.value).format('YYYY-MM-DD')
      this.isShowDate = false
      if(this.param.carId && this.param.queryDate){
                this.gettimes()
            }
    },
    initData() {
      getCarsList({
         type: 1
      }).then(res => {
        this.carsList = [res.data]
      })
    },
    gettimes() {
      const { param } = this
      carCanReservationDate({
        dateDay: param.queryDate,
        carId: param.carId
      }).then(res => {
        if (res.code === 200) {
          this.timeList = res.data || []
          this.timeList.forEach((i, j) => {
            i.checked = '0',
              i.index = j
          })
        }
      })
    },
    seletedCar(e) {
      const item = e.value[0]
      this.$set(this.param, 'carCode', item.code)
      this.$set(this.param, 'carId', item.id)
            if(this.param.carId && this.param.queryDate){
                this.gettimes()
            }
      this.isShowCar = false
    }
  }
};
</script>
 
<style lang="scss">
.main_app {
  .app_header {
    display: flex;
    align-items: center;
    margin: 0 -15rpx;
    .item {
      width: 330rpx;
      height: 72rpx;
      margin: 15rpx;
      padding: 0 30rpx;
      border-radius: 36rpx;
      border: 1rpx solid #e5e5e5;
      display: flex;
      align-items: center;
      justify-content: space-between;
      align-items: center;
    }
  }
  .main_footer {
    position: absolute;
    width: 100%;
    left: 0;
    bottom: 0;
    padding: 20rpx 30rpx 84rpx;
    box-shadow: 0rpx -3rpx 6rpx 0rpx #eeeeee;
    .sel_time {
      color: $uni-color-primary;
    }
    .btns {
      margin-top: 10rpx;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .left {
        display: flex;
        .item {
          display: flex;
          align-items: center;
          margin-right: 20rpx;
          .box {
            margin-right: 10rpx;
            width: 32rpx;
            height: 32rpx;
          }
        }
      }
      .sub {
        width: 184rpx;
        height: 72rpx;
        line-height: 72rpx;
        text-align: center;
        background: $uni-color-primary;
        box-shadow: 0rpx -1rpx 0rpx 0rpx #eeeeee;
        border-radius: 36rpx;
        font-size: 30rpx;
        color: #ffffff;
      }
    }
  }
  .time_list {
    display: flex;
    justify-content: space-between;
    padding: 30rpx 0;
    flex-wrap: wrap;
    .item {
      width: 220rpx;
      height: 80rpx;
      line-height: 80rpx;
      text-align: center;
      background: #f7f7f7;
      border-radius: 4rpx;
      margin-bottom: 24rpx;
      font-size: 30rpx;
    }
    .active {
      background-color: $uni-color-primary;
      color: #fff;
    }
    .disable {
      background-color: #cccccc;
      color: #999999;
    }
  }
}
</style>