index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <view class="py-20rpx">
  3. <view class="bg-white px32rpx py28rpx flex items-center">
  4. <view class="text-[rgba(0,0,0,0.3)]">课程名称:</view>
  5. <view class="flex-1 flex items-center">
  6. <wd-input
  7. type="text"
  8. placeholder="请输入课程名称"
  9. no-border
  10. v-model:model-value="courseItem.name"
  11. readonly
  12. />
  13. </view>
  14. </view>
  15. <view class="mt20rpx bg-white px32rpx py30rpx" v-if="data">
  16. <view class="flex items-center justify-between">
  17. <view class="flex items-center">
  18. <view class="bg-#0074FF w8rpx h28rpx rounded-6rpx"></view>
  19. <view class="font-semibold text-32rpx ml12rpx"> 补课课表 </view>
  20. </view>
  21. <view class="flex items-center">
  22. <commonbtn bg-color="#0074FF" @click="handleAddClass">
  23. 增加课时
  24. </commonbtn>
  25. <view class="ml20rpx flex items-center" @click="handleAllUp">
  26. <view class="text-[rgba(0,0,0,0.3)] mr20rpx"
  27. >{{ isAll ? "全部收起" : "全部展开" }}
  28. </view>
  29. <wd-icon
  30. name="arrow-up"
  31. size="22px"
  32. color="rgba(0,0,0,0.3)"
  33. v-if="isAll"
  34. ></wd-icon>
  35. <wd-icon
  36. name="arrow-down"
  37. size="22px"
  38. color="rgba(0,0,0,0.3)"
  39. v-else
  40. ></wd-icon>
  41. </view>
  42. </view>
  43. </view>
  44. <view
  45. class="mt30rpx bg-#F6F6F6 rounded-32rpx px24rpx py28rpx"
  46. v-for="(item, idx) in makeupClassList"
  47. :key="idx"
  48. >
  49. <view class="flex items-center justify-between">
  50. <view
  51. class="bg-#0074FF text-28rpx rounded-full text-white px14rpx box-border py4rpx"
  52. >
  53. {{ idx + 1 }}</view
  54. >
  55. <view class="flex items-center">
  56. <view
  57. @click="handleDelete(idx)"
  58. class="text-#FB5B5B font-semibold text-28rpx"
  59. v-if="idx > 0"
  60. >删除</view
  61. >
  62. <view
  63. class="ml24rpx flex items-center"
  64. @click="handleItemDown(idx)"
  65. >
  66. <view class="text-[rgba(0,0,0,0.3)] mr20rpx">{{
  67. isActiveItem.includes(idx) ? "收起" : "展开"
  68. }}</view>
  69. <wd-icon
  70. name="arrow-up"
  71. size="22px"
  72. color="rgba(0,0,0,0.3)"
  73. v-if="isActiveItem.includes(idx)"
  74. ></wd-icon>
  75. <wd-icon
  76. name="arrow-down"
  77. size="22px"
  78. color="rgba(0,0,0,0.3)"
  79. v-else
  80. ></wd-icon>
  81. </view>
  82. </view>
  83. </view>
  84. <view v-show="isActiveItem.includes(idx)">
  85. <view class="mt20rpx">
  86. <view class="font-semibold"
  87. ><text class="text-#FB5B5B font-semibold">*</text> 开始时间</view
  88. >
  89. <view class="mt20rpx b-white rounded-16rpx overflow-hidden">
  90. <wd-datetime-picker
  91. placeholder="请选择开始时间"
  92. v-model:model-value="item.startTime"
  93. :minDate="dayjs().valueOf()"
  94. />
  95. </view>
  96. </view>
  97. <view class="mt20rpx">
  98. <view class="font-semibold"
  99. ><text class="text-#FB5B5B font-semibold">*</text> 结束时间</view
  100. >
  101. <view class="mt20rpx b-white rounded-16rpx overflow-hidden">
  102. <wd-datetime-picker
  103. placeholder="请选择结束时间"
  104. v-model:model-value="item.endTime"
  105. :minDate="dayjs().valueOf()"
  106. />
  107. </view>
  108. </view>
  109. <view class="mt20rpx">
  110. <view class="font-semibold"
  111. ><text class="text-#FB5B5B font-semibold">*</text> 课时名称</view
  112. >
  113. <view
  114. class="mt20rpx bg-white rounded-16rpx box-border overflow-hidden px24rpx py18rpx"
  115. >
  116. <wd-input
  117. type="text"
  118. placeholder="请输入课时名称"
  119. no-border
  120. v-model="item.name"
  121. />
  122. </view>
  123. </view>
  124. </view>
  125. <view class="mt3" v-show="!isActiveItem.includes(idx)">
  126. <wd-text
  127. :lines="1"
  128. size="28rpx"
  129. color="#000000"
  130. bold
  131. :text="`${dayjs(item.startTime).format('YYYY-MM-DD HH:mm')} ${dayjs(item.endTime).format('YYYY-MM-DD HH:mm')} ${item.name}`"
  132. ></wd-text>
  133. </view>
  134. </view>
  135. <view class="h150rpx"></view>
  136. </view>
  137. </view>
  138. <fixdbtn block size="large" @click="save">保存</fixdbtn>
  139. </template>
  140. <script setup lang="ts">
  141. import dayjs from "dayjs";
  142. import img1 from "@/subPack/static/del.png";
  143. import img2 from "@/subPack/static/success.png";
  144. import type { webMakeClass } from "@/api/globals";
  145. import { createGlobalLoadingMiddleware } from "@/api/core/middleware";
  146. const isAll = ref(true);
  147. const isActiveItem = ref([0]);
  148. const makeupClassList = ref<
  149. {
  150. startTime: string | number;
  151. endTime: string | number;
  152. name: string;
  153. }[]
  154. >([{ startTime: "", endTime: "", name: "" }]);
  155. const { courseItem } = storeToRefs(useCourseStore());
  156. const { data, send: getData } = useRequest(
  157. (id: string, coursesType: number) =>
  158. Apis.app.queryListByCoursesId({
  159. params: { coursesType, id },
  160. }),
  161. {
  162. immediate: false,
  163. },
  164. );
  165. const { send: saveData } = useRequest(
  166. (fromData: webMakeClass[]) => Apis.app.editPriceRules({ data: fromData }),
  167. {
  168. immediate: false,
  169. middleware: createGlobalLoadingMiddleware({ loadingText: "保存中..." }),
  170. },
  171. );
  172. watch(
  173. () => courseItem.value,
  174. async () => {
  175. await getData(String(courseItem.value.appCourseId), 1);
  176. makeupClassList.value = data.value.map((it) => {
  177. return {
  178. ...it,
  179. startTime: dayjs(it.startTime).valueOf(),
  180. endTime: dayjs(it.endTime).valueOf(),
  181. };
  182. });
  183. },
  184. {
  185. immediate: true,
  186. },
  187. );
  188. function handleAddClass() {
  189. makeupClassList.value.push({
  190. startTime: "",
  191. endTime: "",
  192. name: "",
  193. });
  194. isActiveItem.value.push(makeupClassList.value.length - 1);
  195. }
  196. function handleItemDown(idx: number) {
  197. if (isActiveItem.value.includes(idx)) {
  198. isActiveItem.value = isActiveItem.value.filter((item) => item !== idx);
  199. } else {
  200. isActiveItem.value.push(idx);
  201. }
  202. if (isActiveItem.value.length == makeupClassList.value.length) {
  203. isAll.value = true;
  204. }
  205. if (isActiveItem.value.length == 0) {
  206. isAll.value = false;
  207. }
  208. console.log(isActiveItem.value, "asdasdas");
  209. }
  210. function handleAllUp() {
  211. if (isActiveItem.value.length == makeupClassList.value.length) {
  212. isActiveItem.value = [];
  213. }
  214. isAll.value = !isAll.value;
  215. makeupClassList.value.forEach((item, index) => {
  216. if (isAll.value) {
  217. isActiveItem.value.push(index);
  218. } else {
  219. isActiveItem.value = [];
  220. }
  221. });
  222. }
  223. async function save() {
  224. const form: webMakeClass[] = JSON.parse(
  225. JSON.stringify(makeupClassList.value),
  226. );
  227. if (!areAllItemsAllFieldsFilled(form))
  228. return uni.showToast({
  229. title: "请填写完整",
  230. icon: "error",
  231. duration: 2000,
  232. });
  233. const newObj = form.map((it) => {
  234. return {
  235. ...it,
  236. startTime: dayjs(it.startTime).format("YYYY-MM-DD HH:mm:ss"),
  237. endTime: dayjs(it.endTime).format("YYYY-MM-DD HH:mm:ss"),
  238. coursesId: String(courseItem.value.appCourseId),
  239. };
  240. });
  241. await saveData(newObj);
  242. uni.navigateBack();
  243. }
  244. function handleDelete(idx: number) {
  245. console.log("点击");
  246. uni.showModal({
  247. title: "确认操作",
  248. content: "是否确认删除这条记录?",
  249. success: function (res) {
  250. if (res.confirm) {
  251. makeupClassList.value.splice(idx, 1);
  252. getToast(1);
  253. } else if (res.cancel) {
  254. console.log("用户点击取消");
  255. }
  256. },
  257. });
  258. }
  259. function getToast(type: number) {
  260. uni.showToast({
  261. image: type == 1 ? img1 : img2,
  262. title: type == 1 ? "删除成功" : "保存成功",
  263. });
  264. }
  265. </script>
  266. <style scoped></style>
  267. <route lang="json">
  268. {
  269. "name": "Makeupclass",
  270. "style": {
  271. "navigationBarTitleText": "补课课表"
  272. }
  273. }
  274. </route>