猫妈狗爸伴宠师小程序前端代码
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.

236 lines
5.5 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
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 @click="calendarShowEdit = true">
  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
  47. :show="calendarShow" color="#FFBF60" :round="10" :showTitle="false" :mode="mode" @confirm="confirm"
  48. @close="closeCandler"
  49. :maxDate="maxDate"></up-calendar>
  50. <up-calendar
  51. :show="calendarShowEdit" color="#FFBF60"
  52. :defaultDate="selectDateList"
  53. @close="calendarShowEdit = false"
  54. :round="10" :showTitle="false" mode="multiple" @confirm="calendarShowEditConfirm"
  55. :maxDate="maxDate"></up-calendar>
  56. </template>
  57. <script setup>
  58. import {
  59. ref
  60. } from "vue"
  61. import {
  62. onLoad,
  63. onShow
  64. } from '@dcloudio/uni-app'
  65. import {
  66. insertOutDate,
  67. outDateList
  68. } from "@/api/date/index.js"
  69. import dayjs from "dayjs";
  70. onLoad((options) => {
  71. addressId.value = options.addressId
  72. });
  73. onShow(() => {
  74. getOutDateList();
  75. })
  76. const addressId = ref(0)
  77. const list = ref([{
  78. index: 0,
  79. name: '添加不接单日期区间'
  80. },
  81. {
  82. index: 1,
  83. name: '添加不接单日期'
  84. },
  85. {
  86. index: 2,
  87. name: '取消'
  88. }
  89. ]);
  90. const show = ref(false);
  91. const calendarShow = ref(false);
  92. const calendarShowEdit = ref(false);
  93. const mode = ref('range');
  94. const selectDateList = ref([]);
  95. const groupedDates = ref({}); //按月分组
  96. const d = new Date();
  97. const currentYear = d.getFullYear() + 10;
  98. const maxDate = `${currentYear}-12-31`;
  99. // 方法
  100. const selectClick = (selectItem) => {
  101. if (selectItem.index == 0) {
  102. mode.value = 'range';//multiple range
  103. calendarShow.value = true;
  104. } else if (selectItem.index == 1) {
  105. mode.value = 'multiple';
  106. calendarShow.value = true;
  107. }
  108. show.value = false;
  109. };
  110. const confirm = (e) => {
  111. const list = [...selectDateList.value, ...e];
  112. selectDateList.value = [...new Set(list)];
  113. selectDateList.value.sort((a, b) => {
  114. return dayjs(a).valueOf() - dayjs(b).valueOf();
  115. });
  116. gruopDate(selectDateList.value);
  117. calendarShow.value = false;
  118. };
  119. function calendarShowEditConfirm(data){
  120. selectDateList.value = data
  121. calendarShowEdit.value = false
  122. gruopDate(selectDateList.value);
  123. }
  124. const closeCandler = () => {
  125. calendarShow.value = false;
  126. }
  127. // 日期按月分组
  128. const gruopDate = (dateList) => {
  129. groupedDates.value = {}
  130. dateList.forEach(date => {
  131. const [year, month, day] = date.split('-');
  132. const formattedDate = `${parseInt(month)}${parseInt(day)}`;
  133. const monthKey = `${parseInt(month)}`;
  134. if (!groupedDates.value[monthKey]) {
  135. groupedDates.value[monthKey] = [];
  136. }
  137. groupedDates.value[monthKey].push(formattedDate);
  138. });
  139. // 对键进行排序
  140. const sortedKeys = Object.keys(groupedDates.value).sort((a, b) => {
  141. const monthA = parseInt(a.replace('月', ''));
  142. const monthB = parseInt(b.replace('月', ''));
  143. return monthA - monthB;
  144. });
  145. // 根据排序后的键构建新对象
  146. const sortedGroupedDates = {};
  147. sortedKeys.forEach(key => {
  148. sortedGroupedDates[key] = groupedDates.value[key];
  149. });
  150. // 更新 groupedDates 的值
  151. groupedDates.value = sortedGroupedDates;
  152. }
  153. // 清除全部
  154. const cleanDates = () => {
  155. selectDateList.value = [];
  156. gruopDate(selectDateList.value);
  157. }
  158. // 提交
  159. const submit = async () => {
  160. if (!addressId.value) {
  161. return uni.showToast({
  162. title: '地址标识不能为空',
  163. icon: "none"
  164. })
  165. }
  166. let response = await insertOutDate({
  167. addressId: addressId.value,
  168. dataJson : selectDateList.value.toString()
  169. })
  170. if (response.code == 200) {
  171. uni.showToast({
  172. title: response.msg,
  173. icon: "none"
  174. })
  175. uni.navigateBack(-1);
  176. }
  177. }
  178. const getOutDateList = async () => {
  179. let response = await outDateList({
  180. addressId: addressId.value,
  181. });
  182. if (response.code == 200 && response.data) {
  183. let list = response.data.filter(item => item.date !== null && item.date !== undefined);
  184. list = list.map(item => item.date);
  185. // 去除重复日期
  186. selectDateList.value = [...new Set(list)];
  187. gruopDate(selectDateList.value);
  188. }
  189. }
  190. </script>
  191. <style scoped lang="scss">
  192. @import "index";
  193. .line1 {
  194. position: relative;
  195. margin-bottom: 30rpx;
  196. &::before {
  197. position: absolute;
  198. top: 10rpx;
  199. left: 0;
  200. content: "";
  201. width: 718rpx;
  202. height: 0.5rpx;
  203. background-color: #EFEFEF;
  204. // background-color: red;
  205. }
  206. }
  207. </style>