setOrderTime.uvue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <!-- 设置时间 -->
  2. <template>
  3. <view class="body" :style="'padding-top:' + bottomHeight">
  4. <view style="width: 100%;height: 48rpx;"></view>
  5. <view class="head-box" @click="allTime">全部可接单</view>
  6. <scroll-view scroll-y="true" class="list">
  7. <view class="ss-flex-2 div-time-flag-box">
  8. <view :class="item?.isSelect ? 'conter-xz' : 'conter-xx'" v-for="item in timeArr"
  9. @click.stop="chooseTime(item)" :key="item.start_time">
  10. <view :class="item?.isSelect ? 'kjd-time' : 'xx-time'">{{ item.start_time }}</view>
  11. <view :class="item?.isSelect ? 'kjd-text' : 'xx-text'">{{ item?.isSelect ? '可接单' : '休息' }}</view>
  12. </view>
  13. </view>
  14. </scroll-view>
  15. <view class="save-box" @click="handleSave">保存设置</view>
  16. </view>
  17. </template>
  18. <script setup>
  19. import {
  20. ref
  21. } from 'vue';
  22. import {
  23. onShow
  24. } from '@dcloudio/uni-app';
  25. //接口
  26. import workbenchesInfoApi from '@/sheep/api/masterProject/workbenches';
  27. const allIndex = ref(1)
  28. const timeArr = ref(Array.from({ length: 48 }, (_, i) => ({
  29. start_time: `${Math.floor(i / 2) < 10 ? '0' : ''}${Math.floor(i / 2)}:${i % 2 === 0 ? '00' : '30'}`,
  30. end_time: `${Math.floor((i + 1) / 2) < 10 ? '0' : ''}${Math.floor((i + 1) / 2)}:${(i + 1) % 2 === 0 ? '00' : '30'}`,
  31. isSelect: false
  32. })))
  33. onShow(() => {
  34. allIndex.value = 1
  35. getCoachTime()
  36. })
  37. //获取技师的时间设置
  38. const getCoachTime = async () => {
  39. // 先全部置为未选中
  40. timeArr.value.forEach(item => item.isSelect = false);
  41. const res = await workbenchesInfoApi.getWorkTimeSetting();
  42. const timeRanges = res.data?.time_ranges || [];
  43. // 全部可接单
  44. if (
  45. timeRanges.length === 1 &&
  46. timeRanges[0].start_time === '00:00' &&
  47. timeRanges[0].end_time === '24:00'
  48. ) {
  49. allTime();
  50. return;
  51. }
  52. // 遍历所有时间段,判断是否在任一 time_range 内
  53. timeArr.value.forEach(item => {
  54. const itemTime = item.start_time;
  55. for (const range of timeRanges) {
  56. if (
  57. compareTime(itemTime, range.start_time) >= 0 &&
  58. compareTime(itemTime, range.end_time) < 0
  59. ) {
  60. item.isSelect = true;
  61. break;
  62. }
  63. }
  64. });
  65. };
  66. // 时间字符串比较函数,返回 1/0/-1
  67. function compareTime(t1, t2) {
  68. // t1, t2: "09:00"
  69. const [h1, m1] = t1.split(':').map(Number);
  70. const [h2, m2] = t2.split(':').map(Number);
  71. if (h1 > h2) return 1;
  72. if (h1 < h2) return -1;
  73. if (m1 > m2) return 1;
  74. if (m1 < m2) return -1;
  75. return 0;
  76. }
  77. //点击单个时间
  78. const chooseTime = async (item) => {
  79. if (item.isSelect) {
  80. item.isSelect = false
  81. } else {
  82. item.isSelect = true
  83. }
  84. }
  85. //全部可接单
  86. const allTime = async () => {
  87. timeArr.value.forEach(item => {
  88. item.isSelect = true;
  89. });
  90. allIndex.value = 2
  91. }
  92. /**
  93. * 保存排班设置
  94. * @returns {Promise<void>}
  95. */
  96. const handleSave = async () => {
  97. //获取可接单时间段
  98. const kjTime = []
  99. for (let i = 0; i < timeArr.value.length; i++) {
  100. const item = timeArr.value[i]
  101. if (item?.isSelect) {
  102. kjTime.push(item)
  103. }
  104. }
  105. if (kjTime.length === 0) {
  106. uni.showToast({
  107. title: '请至少选择一个可接单时间段',
  108. icon: 'none',
  109. duration: 2000
  110. })
  111. return
  112. }
  113. try {
  114. const scheduleData = {
  115. time_ranges: kjTime.filter(range => range.isSelect).map(range => ({
  116. start_time: range.start_time,
  117. end_time: range.end_time
  118. }))
  119. };
  120. await workbenchesInfoApi.editWorkTimeSetting(scheduleData);
  121. uni.showToast({
  122. title: '保存成功',
  123. icon: 'success',
  124. duration: 2000
  125. });
  126. setTimeout(() => {
  127. uni.reLaunch({
  128. url: '/pages/masterProject/homePage/index'
  129. })
  130. }, 2300);
  131. } catch (error) {
  132. uni.showToast({
  133. title: '保存失败,请重试',
  134. icon: 'none'
  135. });
  136. }
  137. };
  138. const bottomHeight = ref('0rpx');
  139. // #ifdef APP-PlUS
  140. //获取顶部安全距离
  141. const app = uni.getSystemInfoSync();
  142. const bottomHeightOne = app.statusBarHeight + 'rpx';
  143. bottomHeight.value = bottomHeightOne
  144. // #endif
  145. </script>
  146. <style scoped lang="scss">
  147. //设置时间样式
  148. .head-box {
  149. width: 184rpx;
  150. height: 66rpx;
  151. line-height: 66rpx;
  152. text-align: center;
  153. border-radius: 16rpx;
  154. background-color: #FFDA59;
  155. color: #3D444E;
  156. font-size: 28rpx;
  157. font-weight: 550;
  158. letter-spacing: 3rpx;
  159. margin-left: 32rpx;
  160. box-sizing: border-box;
  161. }
  162. .div-time-flag-box {
  163. width: 96%;
  164. margin-left: 3%;
  165. flex-wrap: wrap;
  166. box-sizing: border-box;
  167. }
  168. .conter-xz {
  169. width: 158rpx;
  170. height: 90rpx;
  171. background-color: #FFFBEF;
  172. border: 2rpx solid #FFDB5F;
  173. border-radius: 16rpx;
  174. margin-bottom: 22rpx;
  175. margin-right: 22rpx;
  176. box-sizing: border-box;
  177. }
  178. .kjd-time {
  179. font-size: 28rpx;
  180. color: #3A3330;
  181. font-weight: 500;
  182. margin-top: 10rpx;
  183. text-align: center;
  184. }
  185. .kjd-text {
  186. font-size: 26rpx;
  187. color: #3A3330;
  188. font-weight: 500;
  189. letter-spacing: 2rpx;
  190. text-align: center;
  191. }
  192. .conter-xx {
  193. width: 158rpx;
  194. height: 94rpx;
  195. background-color: #F3F3F3;
  196. border-radius: 16rpx;
  197. margin-bottom: 22rpx;
  198. margin-right: 22rpx;
  199. box-sizing: border-box;
  200. }
  201. .xx-time {
  202. font-size: 28rpx;
  203. color: #9B9B9B;
  204. margin-top: 10rpx;
  205. text-align: center;
  206. }
  207. .xx-text {
  208. font-size: 26rpx;
  209. color: #9B9B9B;
  210. letter-spacing: 2rpx;
  211. text-align: center;
  212. }
  213. .save-box {
  214. position: absolute;
  215. bottom: 30rpx;
  216. left: 0;
  217. width: 78%;
  218. margin-left: 11%;
  219. height: 100rpx;
  220. line-height: 100rpx;
  221. text-align: center;
  222. background-color: #FFDA59;
  223. border-radius: 24rpx;
  224. font-size: 34rpx;
  225. color: #3A3330;
  226. font-weight: 550;
  227. letter-spacing: 3rpx;
  228. box-sizing: border-box;
  229. }
  230. //old样式
  231. .icon-navigation {
  232. font-size: 32rpx;
  233. color: #3D444E;
  234. font-weight: 700;
  235. }
  236. // 上中下布局样式
  237. // .body {
  238. // position: relative;
  239. // width: 100vw;
  240. // height: 100vh;
  241. // background-color: #FFFFFF;
  242. // box-sizing: border-box;
  243. // }
  244. .list {
  245. position: absolute;
  246. top: 180rpx;
  247. left: 0;
  248. bottom: 150rpx;
  249. box-sizing: border-box;
  250. }
  251. </style>