accompanySet.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <template>
  2. <div class="m-container">
  3. <div class="infoWrap">
  4. <el-form :model="accompanyForm"
  5. :inline="true"
  6. label-position="left">
  7. <el-form-item label="每周可预约课次"
  8. style="position: relative"
  9. label-width="130px">
  10. <el-tooltip placement="top"
  11. popper-class="mTooltip">
  12. <div slot="content">不填时,默认不限制上课次数</div>
  13. <!-- <img :src="imageIcon" class="micon el-tooltip" style="width:8px height:8px" alt /> -->
  14. <i class="el-icon-question micon el-tooltip"
  15. style="font-size: 18px; color: #F56C6C"></i>
  16. </el-tooltip>
  17. <el-input type="number"
  18. @mousewheel.native.prevent
  19. v-model.trim="accompanyForm.count"></el-input>
  20. </el-form-item>
  21. <el-form-item label="每周休息的周次">
  22. <el-select v-model="accompanyForm.week"
  23. clearable
  24. @change="setHoliday">
  25. <el-option label="周一"
  26. value="1" />
  27. <el-option label="周二"
  28. value="2" />
  29. <el-option label="周三"
  30. value="3" />
  31. <el-option label="周四"
  32. value="4" />
  33. <el-option label="周五"
  34. value="5" />
  35. </el-select>
  36. </el-form-item>
  37. <!-- <el-form-item>
  38. <el-button type="primary" @click="submitOk" v-permission="'teacherFreeTime/updateSet'">确定</el-button>
  39. </el-form-item>-->
  40. </el-form>
  41. </div>
  42. <!-- 开始布局上课时间段 -->
  43. <div class="timerWrap">
  44. <el-row class="music-title">
  45. <el-col :span="2">周次</el-col>
  46. <el-col :span="18">时间段</el-col>
  47. </el-row>
  48. <el-row v-for="(item,i) in weekList"
  49. :key="i">
  50. <el-col :span="2">{{item.name}}</el-col>
  51. <el-col :span="18">
  52. <el-tag v-for="(s,index) in item.timeList"
  53. :key="index"
  54. :type="item.isHoliday?'info':''"
  55. effect="dark"
  56. :closable="!item.isHoliday"
  57. :disable-transitions="true"
  58. @close="subjectDelete(item,index)">{{s.startTime.substring(0,s.startTime.length - 3)+'-'+s.endTime.substring(0,s.endTime.length - 3)}}</el-tag>
  59. <span style="display: inline-block;">
  60. <el-button v-if="!item.isHoliday"
  61. key="tag"
  62. type="primary"
  63. style="background:#ececec;border:1px solid #ececec;color:#666"
  64. round
  65. icon="el-icon-plus"
  66. @click="subjectAdd(item)">添加</el-button>
  67. </span>
  68. </el-col>
  69. </el-row>
  70. </div>
  71. <el-dialog :visible.sync="timeVisible"
  72. title="添加时间段"
  73. width="600px"
  74. :before-close="closetimeVisible">
  75. <el-form :inline="true"
  76. v-model="timeForm"
  77. ref="timeForm">
  78. <el-form-item label="开始时间">
  79. <el-time-picker v-model="startTime"
  80. @change="changeStartTime"
  81. format="HH:mm"
  82. value-format="HH:mm"
  83. :picker-options="{
  84. selectableRange:`06:00:00 - 21:30:00`
  85. }"
  86. placeholder="选择时间"></el-time-picker>
  87. </el-form-item>
  88. <el-form-item label="结束时间">
  89. <el-time-picker v-model="endTime"
  90. format="HH:mm"
  91. value-format="HH:mm"
  92. :picker-options="{
  93. selectableRange:`${startTime ? startTime+':00' : '06:00:00'}-21:30:00`
  94. }"
  95. placeholder="选择时间"></el-time-picker>
  96. </el-form-item>
  97. </el-form>
  98. <div slot="footer"
  99. class="dialog-footer">
  100. <el-button @click="timeVisible = false">取 消</el-button>
  101. <el-button type="primary"
  102. @click="addTimerSub">确 定</el-button>
  103. </div>
  104. </el-dialog>
  105. <div class="btnWrap">
  106. <auth :auths="pageType == 'create' ? ['/teacherOperationAdd', 'teacherFreeTime/updateSet'] : ['/teacherOperationUpdate', 'teacherFreeTime/updateSet']" mulit>
  107. <el-button type="primary" @click="submitOk">确定</el-button>
  108. </auth>
  109. <el-button type="primary" @click="resetTime">重置</el-button>
  110. <!-- <div class="newBand"
  111. @click="submitOk"
  112. v-permission="'teacherFreeTime/updateSet'">确定</div>
  113. <div class="newBand"
  114. @click="resetTime">重置</div> -->
  115. </div>
  116. </div>
  117. </template>
  118. <script>
  119. import { teacherFreeTime, resetTeacherFreeTime } from "@/api/teacherManager";
  120. export default {
  121. props: ["teacherId"],
  122. data () {
  123. return {
  124. pageType: this.$route.query.type, // 页面类型
  125. accompanyForm: {
  126. count: null,
  127. week: null
  128. },
  129. accompanyId: null,
  130. // imageIcon: require("@/assets/images/base/warning.png"),
  131. weekList: {
  132. monday: {
  133. timeList: [],
  134. name: "周一",
  135. isHoliday: false
  136. },
  137. tuesday: {
  138. timeList: [],
  139. name: "周二",
  140. isHoliday: false
  141. },
  142. wednesday: {
  143. timeList: [],
  144. name: "周三",
  145. isHoliday: false
  146. },
  147. thursday: {
  148. timeList: [],
  149. name: "周四",
  150. isHoliday: false
  151. },
  152. friday: {
  153. timeList: [],
  154. name: "周五",
  155. isHoliday: false
  156. },
  157. saturday: {
  158. timeList: [],
  159. name: "周六",
  160. isHoliday: false
  161. },
  162. sunday: {
  163. timeList: [],
  164. name: "周日",
  165. isHoliday: false
  166. }
  167. },
  168. activeItem: null,
  169. timeVisible: false,
  170. startTime: "",
  171. endTime: "",
  172. timeForm: {}
  173. };
  174. },
  175. created () {
  176. this.init();
  177. },
  178. // activated () {
  179. // this.init();
  180. // },
  181. methods: {
  182. init () {
  183. // this.teacherId = this.$route.query.teacherId ;
  184. if (this.$route.query.search) {
  185. this.Fsearch = this.$route.query.search;
  186. }
  187. if (this.$route.query.rules) {
  188. this.Frules = this.$route.query.rules;
  189. }
  190. if (this.teacherId) {
  191. teacherFreeTime({ id: this.teacherId }).then(res => {
  192. if (res.code == 200 && res.data) {
  193. this.accompanyId = res.data.id;
  194. res.data.totalTimes
  195. ? (this.accompanyForm.count = res.data.totalTimes)
  196. : (this.accompanyForm.count = null);
  197. res.data.holiday
  198. ? (this.accompanyForm.week = res.data.holiday.toString())
  199. : (this.accompanyForm.week = null);
  200. this.setHoliday(res.data.holiday);
  201. // 写入默认数据
  202. res.data.monday
  203. ? (this.weekList.monday.timeList = JSON.parse(res.data.monday))
  204. : (this.weekList.monday.timeList = []);
  205. res.data.tuesday
  206. ? (this.weekList.tuesday.timeList = JSON.parse(res.data.tuesday))
  207. : (this.weekList.tuesday.timeList = []);
  208. res.data.wednesday
  209. ? (this.weekList.wednesday.timeList = JSON.parse(
  210. res.data.wednesday
  211. ))
  212. : (this.weekList.wednesday.timeList = []);
  213. res.data.thursday
  214. ? (this.weekList.thursday.timeList = JSON.parse(
  215. res.data.thursday
  216. ))
  217. : (this.weekList.thursday.timeList = []);
  218. res.data.friday
  219. ? (this.weekList.friday.timeList = JSON.parse(res.data.friday))
  220. : (this.weekList.friday.timeList = []);
  221. res.data.saturday
  222. ? (this.weekList.saturday.timeList = JSON.parse(
  223. res.data.saturday
  224. ))
  225. : (this.weekList.saturday.timeList = []);
  226. res.data.sunday
  227. ? (this.weekList.sunday.timeList = JSON.parse(res.data.sunday))
  228. : (this.weekList.sunday.timeList = []);
  229. }
  230. });
  231. }
  232. },
  233. submitOk () {
  234. this.$confirm("确认保存设置?", "提示", {
  235. confirmButtonText: "确定",
  236. cancelButtonText: "取消",
  237. type: "warning"
  238. }).then(() => {
  239. // 处理数据
  240. if (this.accompanyForm.count) {
  241. let reg = /^\+?[1-9]\d*$/;
  242. if (!reg.test(this.accompanyForm.count)) {
  243. this.$message.error("每周可预约课次可以不填,或大于0的正整数");
  244. return;
  245. }
  246. }
  247. let monday, tuesday, wednesday, thursday, friday, saturday, sunday;
  248. this.weekList.monday.isHoliday
  249. ? (monday = null)
  250. : (monday = this.weekList.monday.timeList);
  251. this.weekList.tuesday.isHoliday
  252. ? (tuesday = null)
  253. : (tuesday = this.weekList.tuesday.timeList);
  254. this.weekList.wednesday.isHoliday
  255. ? (wednesday = null)
  256. : (wednesday = this.weekList.wednesday.timeList);
  257. this.weekList.thursday.isHoliday
  258. ? (thursday = null)
  259. : (thursday = this.weekList.thursday.timeList);
  260. this.weekList.friday.isHoliday
  261. ? (friday = null)
  262. : (friday = this.weekList.friday.timeList);
  263. this.weekList.saturday.isHoliday
  264. ? (saturday = null)
  265. : (saturday = this.weekList.saturday.timeList);
  266. this.weekList.sunday.isHoliday
  267. ? (sunday = null)
  268. : (sunday = this.weekList.sunday.timeList);
  269. resetTeacherFreeTime({
  270. holiday: this.accompanyForm.week,
  271. userId: this.teacherId,
  272. id: this.accompanyId,
  273. totalTimes: this.accompanyForm.count,
  274. monday: monday && monday.length > 0 ? JSON.stringify(monday) : null,
  275. tuesday:
  276. tuesday && tuesday.length > 0 ? JSON.stringify(tuesday) : null,
  277. wednesday:
  278. wednesday && wednesday.length > 0
  279. ? JSON.stringify(wednesday)
  280. : null,
  281. thursday:
  282. thursday && thursday.length > 0 ? JSON.stringify(thursday) : null,
  283. friday: friday && friday.length > 0 ? JSON.stringify(friday) : null,
  284. saturday:
  285. saturday && saturday.length > 0 ? JSON.stringify(saturday) : null,
  286. sunday: sunday && sunday.length > 0 ? JSON.stringify(sunday) : null
  287. }).then(res => {
  288. if (res.code == 200) {
  289. this.$message.success("保存成功");
  290. this.$store.dispatch('delVisitedViews', this.$route)
  291. this.$router.push({
  292. path: "/teacherManager/teacherList",
  293. query: { rules: this.Frules, search: this.Fsearch }
  294. });
  295. }
  296. });
  297. });
  298. },
  299. setHoliday (val) {
  300. // console.log(val)
  301. val = parseInt(val);
  302. // console.log(val)
  303. let arr = [
  304. "monday",
  305. "tuesday",
  306. "wednesday",
  307. "thursday",
  308. "friday",
  309. "saturday",
  310. "sunday"
  311. ];
  312. for (let i = 0; i < arr.length; i++) {
  313. this.weekList[arr[i]].isHoliday = false;
  314. }
  315. if (val) {
  316. this.weekList[arr[val - 1]].isHoliday = true;
  317. }
  318. },
  319. // 删除
  320. subjectDelete (item, index) {
  321. for (let date in this.weekList) {
  322. if (this.weekList[date].name == item.name) {
  323. this.weekList[date].timeList.splice(index, 1);
  324. }
  325. }
  326. },
  327. // 添加
  328. subjectAdd (item) {
  329. this.activeItem = item;
  330. this.timeVisible = true;
  331. // console.log(item)
  332. },
  333. // 提交添加的时间
  334. addTimerSub () {
  335. // this.$refs["timeForm"].validate(res => {
  336. // if (!res) {
  337. // return;
  338. // }
  339. // });
  340. // 判断是否在时间内 开始时间是否在时间段内 结束时间是否在时间段内
  341. if (!this.startTime || !this.endTime) {
  342. this.$message.error("请填写开始时间或结束时间");
  343. return;
  344. }
  345. // 开始时间必须不在所有时段内
  346. let isStartTime = this.activeItem.timeList.some(item => {
  347. return this.timeIsrange(item.startTime, item.endTime, this.startTime);
  348. });
  349. // 结束时间必须不在所有时段内
  350. let isEndTime = this.activeItem.timeList.some(item => {
  351. return this.timeIsrange(item.startTime, item.endTime, this.endTime);
  352. });
  353. // 所有时段的开始时间必须不在新增时段内
  354. let hasStartTime = this.activeItem.timeList.some(item => {
  355. return this.timeIsrange(this.startTime, this.endTime, item.startTime);
  356. });
  357. // 所有时段的结束时间必须不在新增时段内
  358. let hasEndtTime = this.activeItem.timeList.some(item => {
  359. return this.timeIsrange(this.startTime, this.endTime, item.endTime);
  360. });
  361. // 开始时间
  362. if (isStartTime || isEndTime || hasStartTime || hasEndtTime) {
  363. this.$message.error("时间冲突");
  364. return;
  365. }
  366. this.activeItem.timeList.push({
  367. startTime: this.startTime + ":00",
  368. endTime: this.endTime + ":00"
  369. });
  370. // 排序
  371. this.activeItem.timeList.sort((a, b) => {
  372. let ahour = a.startTime.substring(0, 2);
  373. let amin = a.startTime.substring(3, 5);
  374. let bhour = b.startTime.substring(0, 2);
  375. let bmin = b.startTime.substring(3, 5);
  376. let dateA = new Date();
  377. dateA.setHours(ahour);
  378. dateA.setMinutes(amin);
  379. let dateB = new Date();
  380. dateB.setHours(bhour);
  381. dateB.setMinutes(bmin);
  382. return dateA.getTime() - dateB.getTime();
  383. });
  384. this.closetimeVisible();
  385. },
  386. // 判断时间是否在时间段内
  387. timeIsrange (beginTime, endTime, nowTime) {
  388. var strb = beginTime.split(":");
  389. if (strb.length != 2) {
  390. return false;
  391. }
  392. var stre = endTime.split(":");
  393. if (stre.length != 2) {
  394. return false;
  395. }
  396. var strn = nowTime.split(":");
  397. if (stre.length != 2) {
  398. return false;
  399. }
  400. var b = new Date();
  401. var e = new Date();
  402. var n = new Date();
  403. b.setHours(strb[0]);
  404. b.setMinutes(strb[1]);
  405. e.setHours(stre[0]);
  406. e.setMinutes(stre[1]);
  407. n.setHours(strn[0]);
  408. n.setMinutes(strn[1]);
  409. if (n.getTime() - b.getTime() >= 0 && n.getTime() - e.getTime() <= 0) {
  410. // 在时间范围内
  411. return true;
  412. } else {
  413. // 不在时间范围内
  414. return false;
  415. }
  416. },
  417. resetTime () {
  418. this.weekList = {
  419. monday: {
  420. timeList: [],
  421. name: "周一",
  422. isHoliday: false
  423. },
  424. tuesday: {
  425. timeList: [],
  426. name: "周二",
  427. isHoliday: false
  428. },
  429. wednesday: {
  430. timeList: [],
  431. name: "周三",
  432. isHoliday: false
  433. },
  434. thursday: {
  435. timeList: [],
  436. name: "周四",
  437. isHoliday: false
  438. },
  439. friday: {
  440. timeList: [],
  441. name: "周五",
  442. isHoliday: false
  443. },
  444. saturday: {
  445. timeList: [],
  446. name: "周六",
  447. isHoliday: false
  448. },
  449. sunday: {
  450. timeList: [],
  451. name: "周日",
  452. isHoliday: false
  453. }
  454. };
  455. this.accompanyForm.week = null;
  456. },
  457. changeStartTime () {
  458. this.endTime = "";
  459. },
  460. closetimeVisible () {
  461. this.startTime = null;
  462. this.endTime = null;
  463. console.log(111);
  464. this.timeVisible = false;
  465. }
  466. }
  467. };
  468. </script>
  469. <style lang="scss" scoped>
  470. .micon {
  471. position: absolute;
  472. top: 12px;
  473. left: -26px;
  474. z-index: 100;
  475. }
  476. .music-title {
  477. height: 40px;
  478. line-height: 40px;
  479. font-size: 14px;
  480. color: #444;
  481. .el-col {
  482. background-color: #edeef0;
  483. padding-left: 36px;
  484. }
  485. ::v-deep .el-button {
  486. float: right;
  487. margin-top: 10px;
  488. margin-right: 16px;
  489. }
  490. }
  491. ::v-deep .el-row {
  492. margin-bottom: 12px;
  493. font-size: 14px;
  494. .el-col:nth-child(1) {
  495. padding-left: 36px;
  496. }
  497. .el-col {
  498. line-height: 48px;
  499. }
  500. .el-col-18 {
  501. width: calc(90% - 20px);
  502. margin-left: 20px;
  503. }
  504. }
  505. .el-tag + .el-tag {
  506. margin-left: 10px;
  507. }
  508. .button-new-tag {
  509. margin-left: 10px;
  510. height: 32px;
  511. line-height: 30px;
  512. padding-top: 0;
  513. padding-bottom: 0;
  514. }
  515. .input-new-tag {
  516. width: 90px;
  517. // margin-left: 10px;
  518. vertical-align: bottom;
  519. }
  520. .el-tag--dark.el-tag--info {
  521. background-color: #f0f2f5;
  522. border-color: #f0f2f5;
  523. color: #5a5e66;
  524. ::v-deep .el-tag__close {
  525. background-color: #c0c4cc;
  526. }
  527. }
  528. // var(--color-primary)
  529. .el-tag--dark {
  530. background-color: var(--color-primary);
  531. border-color: var(--color-primary);
  532. }
  533. </style>