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

204 lines
4.7 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 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 class="">
  17. <view class="text1" :style="{ textAlign: 'right' }">
  18. {{ selectDateList.length }}
  19. </view>
  20. 共不接单时间
  21. </view>
  22. <view class="level center_item">
  23. <!-- <view class="">
  24. <up-icon name="edit-pen" color="#2979ff" size="22"></up-icon>
  25. 修改
  26. </view> -->
  27. <view @click="cleanDates" class="">
  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. let response = outDateList();
  66. console.log("返回数据",response)
  67. })
  68. const addressId = ref(0)
  69. const list = ref([{
  70. index: 0,
  71. name: '添加不接单日期区间'
  72. },
  73. {
  74. index: 1,
  75. name: '添加不接单日期'
  76. },
  77. {
  78. index: 2,
  79. name: '取消'
  80. }
  81. ]);
  82. const show = ref(false);
  83. const calendarShow = ref(false);
  84. const mode = ref('range');
  85. const selectDateList = ref([]);
  86. const groupedDates = ref({}); //按月分组
  87. const d = new Date();
  88. const currentYear = d.getFullYear();
  89. const minDate = `${currentYear}-01-01`;
  90. const maxDate = `${currentYear}-12-31`;
  91. // 方法
  92. const selectClick = (selectItem) => {
  93. if (selectItem.index == 0) {
  94. mode.value = 'range';
  95. calendarShow.value = true;
  96. } else if (selectItem.index == 1) {
  97. mode.value = 'single';
  98. calendarShow.value = true;
  99. }
  100. show.value = false;
  101. };
  102. const confirm = (e) => {
  103. const list = [...selectDateList.value, ...e];
  104. selectDateList.value = [...new Set(list)];
  105. gruopDate(selectDateList.value);
  106. calendarShow.value = false;
  107. };
  108. const closeCandler = () => {
  109. calendarShow.value = false;
  110. }
  111. // 日期按月分组
  112. const gruopDate = (dateList) => {
  113. groupedDates.value = {}
  114. dateList.forEach(date => {
  115. const [year, month, day] = date.split('-');
  116. const formattedDate = `${parseInt(month)}${parseInt(day)}`;
  117. const monthKey = `${parseInt(month)}`;
  118. if (!groupedDates.value[monthKey]) {
  119. groupedDates.value[monthKey] = [];
  120. }
  121. groupedDates.value[monthKey].push(formattedDate);
  122. });
  123. // 对键进行排序
  124. const sortedKeys = Object.keys(groupedDates.value).sort((a, b) => {
  125. const monthA = parseInt(a.replace('月', ''));
  126. const monthB = parseInt(b.replace('月', ''));
  127. return monthA - monthB;
  128. });
  129. // 根据排序后的键构建新对象
  130. const sortedGroupedDates = {};
  131. sortedKeys.forEach(key => {
  132. sortedGroupedDates[key] = groupedDates.value[key];
  133. });
  134. // 更新 groupedDates 的值
  135. groupedDates.value = sortedGroupedDates;
  136. }
  137. const cleanDates = () => {
  138. selectDateList.value = [];
  139. gruopDate(selectDateList.value);
  140. }
  141. const submit = async () => {
  142. if (!selectDateList.value.length) {
  143. return uni.showToast({
  144. title: '请选择日期',
  145. icon: "none"
  146. })
  147. } else if (!addressId.value) {
  148. return uni.showToast({
  149. title: '地址标识不能为空',
  150. icon: "none"
  151. })
  152. }
  153. let response = await insertOutDate({
  154. addressId: addressId.value,
  155. date: selectDateList.value.toString()
  156. })
  157. if (response.code == 200) {
  158. uni.showToast({
  159. title: response.msg,
  160. icon: "none"
  161. })
  162. uni.navigateBack(-1);
  163. }
  164. }
  165. </script>
  166. <style scoped lang="scss">
  167. @import "index";
  168. .line1 {
  169. position: relative;
  170. margin-bottom: 30rpx;
  171. &::before {
  172. position: absolute;
  173. top: 10rpx;
  174. left: 0;
  175. content: "";
  176. width: 718rpx;
  177. height: 0.5rpx;
  178. background-color: #EFEFEF;
  179. // background-color: red;
  180. }
  181. }
  182. </style>