猫妈狗爸伴宠师小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

212 lines
5.0 KiB

3 months ago
3 months ago
2 months ago
3 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
3 months ago
  1. <template>
  2. <!-- <div>不接单日期</div> -->
  3. <view class="box box-size">
  4. <view class="top box-size level">
  5. <view>
  6. <view class="text">
  7. 添加不接单日期
  8. </view>
  9. 您不会再接收到选择日期内的订单
  10. </view>
  11. <view @click="show = true" class="buttom level" :style="{borderRadius:'31rpx'}">
  12. 添加不接单日期
  13. </view>
  14. </view>
  15. <view v-if="selectDateList.length" class="level center">
  16. <view >
  17. <view class="text1" :style="{ textAlign: 'right' }">
  18. {{ selectDateList.length }}
  19. </view>
  20. 共不接单时间
  21. </view>
  22. <view class="level center_item">
  23. <view >
  24. <!-- <up-icon name="edit-pen" color="#2979ff" size="22"></up-icon> -->
  25. 修改
  26. </view>
  27. <view @click="cleanDates" >
  28. <!-- <up-icon name="trash" color="#2979ff" size="22"></up-icon> -->
  29. 清空
  30. </view>
  31. </view>
  32. </view>
  33. <view v-if="selectDateList.length" v-for="(dates,month) in groupedDates" :key="month" class="item box-size"
  34. :style="{borderRadius:'16rpx'}">
  35. {{ month }}不接单
  36. <view class="text2">
  37. {{ dates.length }}:<text v-for="(item,index) in dates"
  38. :key="index">{{ item + (index != dates.length - 1 ? "," : "") }}</text>
  39. </view>
  40. </view>
  41. <view @click="submit" class="buttom_ level" :style="{borderRadius:'41rpx'}">
  42. 保存
  43. </view>
  44. </view>
  45. <up-action-sheet :actions="list" @select="selectClick" :show="show" :round="10"></up-action-sheet>
  46. <up-calendar :show="calendarShow" color="#FFBF60" :round="10" :showTitle="false" :mode="mode" @confirm="confirm"
  47. @close="closeCandler" :minDate="minDate" :maxDate="maxDate"></up-calendar>
  48. </template>
  49. <script setup>
  50. import {
  51. ref
  52. } from "vue"
  53. import {
  54. onLoad,
  55. onShow
  56. } from '@dcloudio/uni-app'
  57. import {
  58. insertOutDate,
  59. outDateList
  60. } from "@/api/date/index.js"
  61. onLoad((options) => {
  62. addressId.value = options.addressId
  63. });
  64. onShow(() => {
  65. getOutDateList();
  66. })
  67. const addressId = ref(0)
  68. const list = ref([{
  69. index: 0,
  70. name: '添加不接单日期区间'
  71. },
  72. {
  73. index: 1,
  74. name: '添加不接单日期'
  75. },
  76. {
  77. index: 2,
  78. name: '取消'
  79. }
  80. ]);
  81. const show = ref(false);
  82. const calendarShow = ref(false);
  83. const mode = ref('range');
  84. const selectDateList = ref([]);
  85. const groupedDates = ref({}); //按月分组
  86. const d = new Date();
  87. const currentYear = d.getFullYear();
  88. const minDate = `${currentYear}-01-01`;
  89. const maxDate = `${currentYear}-12-31`;
  90. // 方法
  91. const selectClick = (selectItem) => {
  92. if (selectItem.index == 0) {
  93. mode.value = 'range';
  94. calendarShow.value = true;
  95. } else if (selectItem.index == 1) {
  96. mode.value = 'single';
  97. calendarShow.value = true;
  98. }
  99. show.value = false;
  100. };
  101. const confirm = (e) => {
  102. const list = [...selectDateList.value, ...e];
  103. selectDateList.value = [...new Set(list)];
  104. gruopDate(selectDateList.value);
  105. calendarShow.value = false;
  106. };
  107. const closeCandler = () => {
  108. calendarShow.value = false;
  109. }
  110. // 日期按月分组
  111. const gruopDate = (dateList) => {
  112. groupedDates.value = {}
  113. dateList.forEach(date => {
  114. const [year, month, day] = date.split('-');
  115. const formattedDate = `${parseInt(month)}${parseInt(day)}`;
  116. const monthKey = `${parseInt(month)}`;
  117. if (!groupedDates.value[monthKey]) {
  118. groupedDates.value[monthKey] = [];
  119. }
  120. groupedDates.value[monthKey].push(formattedDate);
  121. });
  122. // 对键进行排序
  123. const sortedKeys = Object.keys(groupedDates.value).sort((a, b) => {
  124. const monthA = parseInt(a.replace('月', ''));
  125. const monthB = parseInt(b.replace('月', ''));
  126. return monthA - monthB;
  127. });
  128. // 根据排序后的键构建新对象
  129. const sortedGroupedDates = {};
  130. sortedKeys.forEach(key => {
  131. sortedGroupedDates[key] = groupedDates.value[key];
  132. });
  133. // 更新 groupedDates 的值
  134. groupedDates.value = sortedGroupedDates;
  135. }
  136. // 清除全部
  137. const cleanDates = () => {
  138. selectDateList.value = [];
  139. gruopDate(selectDateList.value);
  140. }
  141. // 提交
  142. const submit = async () => {
  143. if (!addressId.value) {
  144. return uni.showToast({
  145. title: '地址标识不能为空',
  146. icon: "none"
  147. })
  148. }
  149. let response = await insertOutDate({
  150. addressId: addressId.value,
  151. date: selectDateList.value.toString()
  152. })
  153. if (response.code == 200) {
  154. uni.showToast({
  155. title: response.msg,
  156. icon: "none"
  157. })
  158. uni.navigateBack(-1);
  159. }
  160. }
  161. const getOutDateList = async () => {
  162. let response = await outDateList();
  163. if (response.code == 200 && response.data) {
  164. let list = response.data.filter(item => item.date !== null && item.date !== undefined);
  165. list = list.map(item => item.date);
  166. // 去除重复日期
  167. selectDateList.value = [...new Set(list)];
  168. console.log(selectDateList)
  169. gruopDate(selectDateList.value);
  170. }
  171. }
  172. </script>
  173. <style scoped lang="scss">
  174. @import "index";
  175. .line1 {
  176. position: relative;
  177. margin-bottom: 30rpx;
  178. &::before {
  179. position: absolute;
  180. top: 10rpx;
  181. left: 0;
  182. content: "";
  183. width: 718rpx;
  184. height: 0.5rpx;
  185. background-color: #EFEFEF;
  186. // background-color: red;
  187. }
  188. }
  189. </style>