|
|
- <template>
- <!-- <div>不接单日期</div> -->
- <view class="box box-size">
- <view class="top box-size level">
- <view>
- <view class="text">
- 添加不接单日期
- </view>
- 您不会再接收到选择日期内的订单
- </view>
- <view @click="show = true" class="buttom level" :style="{borderRadius:'31rpx'}">
- 添加不接单日期
- </view>
- </view>
-
- <view v-if="selectDateList.length" class="level center">
- <view class="">
- <view class="text1" :style="{ textAlign: 'right' }">
- {{ selectDateList.length }}天
- </view>
- 共不接单时间
- </view>
- <view class="level center_item">
- <!-- <view class="">
- <up-icon name="edit-pen" color="#2979ff" size="22"></up-icon>
- 修改
- </view> -->
- <view @click="cleanDates" class="">
- <!-- <up-icon name="trash" color="#2979ff" size="22"></up-icon> -->
- 清空
- </view>
- </view>
- </view>
-
- <view v-if="selectDateList.length" v-for="(dates,month) in groupedDates" :key="month" class="item box-size"
- :style="{borderRadius:'16rpx'}">
- {{ month }}不接单
- <view class="text2">
- 共{{ dates.length }}天:<text v-for="(item,index) in dates"
- :key="index">{{ item + (index != dates.length - 1 ? "," : "") }}</text>
- </view>
- </view>
- <view @click="submit" class="buttom_ level" :style="{borderRadius:'41rpx'}">
- 保存
- </view>
- </view>
-
- <up-action-sheet :actions="list" @select="selectClick" :show="show" :round="10"></up-action-sheet>
- <up-calendar :show="calendarShow" color="#FFBF60" :round="10" :showTitle="false" :mode="mode" @confirm="confirm"
- @close="closeCandler" :minDate="minDate" :maxDate="maxDate"></up-calendar>
- </template>
-
- <script setup>
- import {
- ref
- } from "vue"
-
- import {
- onLoad,
- onShow
- } from '@dcloudio/uni-app'
- import {
- insertOutDate,
- outDateList
- } from "@/api/date/index.js"
-
- onLoad((options) => {
- addressId.value = options.addressId
- });
-
- onShow(() => {
- let response = outDateList();
- console.log("返回数据",response)
- })
-
- const addressId = ref(0)
- const list = ref([{
- index: 0,
- name: '添加不接单日期区间'
- },
- {
- index: 1,
- name: '添加不接单日期'
- },
- {
- index: 2,
- name: '取消'
- }
- ]);
-
- const show = ref(false);
- const calendarShow = ref(false);
- const mode = ref('range');
- const selectDateList = ref([]);
- const groupedDates = ref({}); //按月分组
- const d = new Date();
- const currentYear = d.getFullYear();
- const minDate = `${currentYear}-01-01`;
- const maxDate = `${currentYear}-12-31`;
-
- // 方法
- const selectClick = (selectItem) => {
- if (selectItem.index == 0) {
- mode.value = 'range';
- calendarShow.value = true;
- } else if (selectItem.index == 1) {
- mode.value = 'single';
- calendarShow.value = true;
- }
- show.value = false;
- };
-
- const confirm = (e) => {
- const list = [...selectDateList.value, ...e];
- selectDateList.value = [...new Set(list)];
- gruopDate(selectDateList.value);
- calendarShow.value = false;
- };
-
- const closeCandler = () => {
- calendarShow.value = false;
- }
-
-
- // 日期按月分组
- const gruopDate = (dateList) => {
- groupedDates.value = {}
- dateList.forEach(date => {
- const [year, month, day] = date.split('-');
- const formattedDate = `${parseInt(month)}月${parseInt(day)}日`;
- const monthKey = `${parseInt(month)}月`;
-
- if (!groupedDates.value[monthKey]) {
- groupedDates.value[monthKey] = [];
- }
- groupedDates.value[monthKey].push(formattedDate);
- });
-
- // 对键进行排序
- const sortedKeys = Object.keys(groupedDates.value).sort((a, b) => {
- const monthA = parseInt(a.replace('月', ''));
- const monthB = parseInt(b.replace('月', ''));
- return monthA - monthB;
- });
-
- // 根据排序后的键构建新对象
- const sortedGroupedDates = {};
- sortedKeys.forEach(key => {
- sortedGroupedDates[key] = groupedDates.value[key];
- });
-
- // 更新 groupedDates 的值
- groupedDates.value = sortedGroupedDates;
- }
-
- const cleanDates = () => {
- selectDateList.value = [];
- gruopDate(selectDateList.value);
- }
-
- const submit = async () => {
- if (!selectDateList.value.length) {
- return uni.showToast({
- title: '请选择日期',
- icon: "none"
- })
- } else if (!addressId.value) {
- return uni.showToast({
- title: '地址标识不能为空',
- icon: "none"
- })
- }
- let response = await insertOutDate({
- addressId: addressId.value,
- date: selectDateList.value.toString()
- })
- if (response.code == 200) {
- uni.showToast({
- title: response.msg,
- icon: "none"
- })
- uni.navigateBack(-1);
- }
- }
- </script>
-
- <style scoped lang="scss">
- @import "index";
-
- .line1 {
- position: relative;
- margin-bottom: 30rpx;
-
- &::before {
- position: absolute;
- top: 10rpx;
- left: 0;
- content: "";
- width: 718rpx;
- height: 0.5rpx;
- background-color: #EFEFEF;
- // background-color: red;
- }
- }
- </style>
|