teacher_course_add.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. <template>
  2. <view class="course-add-container" style="background-color: #F0F0F0;">
  3. <uni-forms ref="baseForm" :model="baseFormData" labelWidth="80px" :rules="rules" labelPosition="top">
  4. <uni-forms-item label="授课科目:" required>
  5. <uni-data-picker placeholder="选择授课" popup-title="课程大纲-具体课程" v-model="baseFormData.subject" :clearIcon="false" :localdata="courseTree">
  6. </uni-data-picker>
  7. </uni-forms-item>
  8. <uni-forms-item label="授课方式:" name="mode" required>
  9. <uni-data-checkbox v-model="baseFormData.mode" :localdata="modes" />
  10. </uni-forms-item>
  11. <uni-forms-item label="授课时间" required>
  12. </uni-forms-item>
  13. <view class="tr-container">
  14. <view class="tr_1">
  15. <text class="th_0" decode="true">&ensp;&ensp;&ensp;&ensp;</text>
  16. <text class="th_1">周一</text>
  17. <text class="th_1">周二</text>
  18. <text class="th_1">周三</text>
  19. <text class="th_1">周四</text>
  20. <text class="th_1">周五</text>
  21. <text class="th_1">周六</text>
  22. <text class="th_1">周日</text>
  23. </view>
  24. <view class="tr_2">
  25. <checkbox-group @change="chechboxChangeAM">
  26. <view class="th2_0">上午</view>
  27. <label v-for="item in timeAM" :key="item.value">
  28. <checkbox class="th2_1" :value="item.value" :checked="item.checked"></checkbox>
  29. </label>
  30. </checkbox-group>
  31. </view>
  32. <view class="tr_2">
  33. <checkbox-group @change="chechboxChangePM">
  34. <view class="th2_0">下午</view>
  35. <label v-for="item in timePM" :key="item.value">
  36. <checkbox class="th2_1" :value="item.value" :checked="item.checked"></checkbox>
  37. </label>
  38. </checkbox-group>
  39. </view>
  40. <view class="tr_2">
  41. <checkbox-group @change="chechboxChangeEvening">
  42. <view class="th2_0">晚上</view>
  43. <label v-for="item in timeEvening" :key="item.value">
  44. <checkbox class="th2_1" :value="item.value" :checked="item.checked"></checkbox>
  45. </label>
  46. </checkbox-group>
  47. </view>
  48. </view>
  49. <uni-forms-item label="教龄:" name="teachAge" required>
  50. <uni-number-box v-model="baseFormData.teachAge" :min="1" ></uni-number-box>
  51. </uni-forms-item>
  52. <uni-forms-item label="教员位置:" name="location" required>
  53. <uni-easyinput type="text" v-model="baseFormData.location" @focus="getLocation" maxlength="250" trim="both" />
  54. </uni-forms-item>
  55. <uni-forms-item label="成功经验:" name="experience" required>
  56. <uni-easyinput type="textarea" v-model="baseFormData.experience" maxlength="250" trim="both" />
  57. </uni-forms-item>
  58. <uni-forms-item label="自我介绍:" name="introduce" required>
  59. <uni-easyinput type="textarea" v-model="baseFormData.introduce" maxlength="250" trim="both" />
  60. </uni-forms-item>
  61. </uni-forms>
  62. <view class="button-group">
  63. <button class="submitBtn" type="primary" @click="submit('baseForm')" :disabled="addflag">提交发布</button>
  64. </view>
  65. <uni-popup ref="alertDialog" type="dialog">
  66. <uni-popup-dialog type="info" :confirmText="confirmText" title="温馨提示" :content="authentication" @close="dialogClose" @confirm="dialogConfirm"></uni-popup-dialog>
  67. </uni-popup>
  68. </view>
  69. </template>
  70. <script>
  71. import { mapState, mapMutations } from 'vuex'
  72. export default {
  73. computed: {
  74. ...mapState('m_user', ['authentication'])
  75. },
  76. data() {
  77. return {
  78. addflag: false,
  79. courseWeekday: [],
  80. introduce: '',
  81. courseAM: [],
  82. coursePM: [],
  83. courseEV: [],
  84. confirmText: '',
  85. // 表单数据
  86. baseFormData: {
  87. subject: '',
  88. mode: [],
  89. teachTime: [],
  90. teachAge: 1,
  91. location: '',
  92. experience: '',
  93. introduce: '',
  94. subjectBig: ''
  95. },
  96. // 选择课程
  97. courseTree: [{
  98. text: '一年级',
  99. value: '1-0',
  100. children: [{
  101. text: '1.1班',
  102. value: '1'
  103. }
  104. ]
  105. }
  106. ],
  107. // 单选授课方式数据源
  108. modes: [{
  109. text: '教员上门',
  110. value: '教员上门'
  111. }, {
  112. text: '学员上门',
  113. value: '学员上门'
  114. }, {
  115. text: '线上辅导',
  116. value: '线上辅导'
  117. }],
  118. // 上课时间
  119. // 上午
  120. timeAM: [{
  121. value: 'A1',
  122. name: '1',
  123. checked: false
  124. },
  125. {
  126. name: '2',
  127. value: 'A2',
  128. checked: false
  129. },
  130. {
  131. name: '3',
  132. value: 'A3',
  133. checked: false
  134. },
  135. {
  136. name: '4',
  137. value: 'A4',
  138. checked: false
  139. },
  140. {
  141. name: '5',
  142. value: 'A5',
  143. checked: false
  144. },
  145. {
  146. name: '6',
  147. value: 'A6',
  148. checked: false
  149. },
  150. {
  151. name: '7',
  152. value: 'A7',
  153. checked: false
  154. }
  155. ],
  156. // 下午
  157. timePM: [{
  158. value: 'P1',
  159. name: '1',
  160. checked: false
  161. },
  162. {
  163. name: '2',
  164. value: 'P2',
  165. checked: false
  166. },
  167. {
  168. name: '3',
  169. value: 'P3',
  170. checked: false
  171. },
  172. {
  173. name: '4',
  174. value: 'P4',
  175. checked: false
  176. },
  177. {
  178. name: '5',
  179. value: 'P5',
  180. checked: false
  181. },
  182. {
  183. name: '6',
  184. value: 'P6',
  185. checked: false
  186. },
  187. {
  188. name: '7',
  189. value: 'P7',
  190. checked: false
  191. }
  192. ],
  193. // 晚上
  194. timeEvening: [{
  195. name: '1',
  196. value: 'E1',
  197. checked: false
  198. },
  199. {
  200. name: '2',
  201. value: 'E2',
  202. checked: false
  203. },
  204. {
  205. name: '3',
  206. value: 'E3',
  207. checked: false
  208. },
  209. {
  210. name: '4',
  211. value: 'E4',
  212. checked: false
  213. },
  214. {
  215. name: '5',
  216. value: 'E5',
  217. checked: false
  218. },
  219. {
  220. name: '6',
  221. value: 'E6',
  222. checked: false
  223. },
  224. {
  225. name: '7',
  226. value: 'E7',
  227. checked: false
  228. }
  229. ],
  230. rules: {
  231. subject: {
  232. rules: [{
  233. required: true,
  234. errorMessage: '授课科目不能为空',
  235. }]
  236. },
  237. mode: {
  238. rules: [{
  239. required: true,
  240. errorMessage: '授课方式不能为空',
  241. }]
  242. },
  243. location: {
  244. rules: [{
  245. required: true,
  246. errorMessage: '地理位置不能为空',
  247. }]
  248. },
  249. introduce: {
  250. rules: [{
  251. required: true,
  252. errorMessage: '自我介绍不能为空',
  253. }],
  254. },
  255. teachTime: {
  256. rules: [{
  257. required: true,
  258. errorMessage: '授课时间不能为空',
  259. }]
  260. },
  261. experience: {
  262. rules: [{
  263. required: true,
  264. errorMessage: '成功经验不能为空',
  265. }]
  266. },
  267. }
  268. };
  269. },
  270. onLoad(option) {
  271. this.getPriceAndTree(),
  272. this.getPersonAuthorize()
  273. if (option.item !== undefined) {
  274. let item = JSON.parse(decodeURIComponent(option.item))
  275. this.formatCourse(item)
  276. }
  277. },
  278. methods: {
  279. ...mapMutations('m_user', ['updateAuthentication']),
  280. // 格式化传递过来的course信息
  281. formatCourse(item) {
  282. const arr = item.subject.split("/")
  283. this.baseFormData.subject = arr[1]
  284. this.baseFormData.subjectBig = arr[0]
  285. this.baseFormData.mode = item.mode
  286. this.baseFormData.teachAge = item.teachAge
  287. this.baseFormData.location = item.location
  288. this.baseFormData.locationAl = item.locationAl
  289. this.baseFormData.experience = item.experience
  290. this.baseFormData.introduce = item.introduce
  291. this.courseWeekday = item.teachTime.split(",")
  292. this.baseFormData.teachTime = this.courseWeekday
  293. for (let i = 0; i < this.courseWeekday.length; i++) {
  294. for (let x = 0; x < this.timeAM.length; x++) {
  295. if (this.courseWeekday[i] == this.timeAM[x].value) {
  296. this.timeAM[x].checked = true
  297. this.courseAM.push(this.courseWeekday[i])
  298. }
  299. }
  300. for (let y = 0; y < this.timePM.length; y++) {
  301. if (this.courseWeekday[i] == this.timePM[y].value) {
  302. this.timePM[y].checked = true
  303. this.coursePM.push(this.courseWeekday[i])
  304. }
  305. }
  306. for (let z = 0; z < this.timeEvening.length; z++) {
  307. if (this.courseWeekday[i] == this.timeEvening[z].value) {
  308. this.timeEvening[z].checked = true
  309. this.courseEV.push(this.courseWeekday[i])
  310. }
  311. }
  312. }
  313. if (this.courseAM.length > 0) {
  314. this.courseAM.push(this.courseAM.join().split(','))
  315. }
  316. if (this.coursePM.length > 0) {
  317. this.coursePM.push(this.coursePM.join().split(','))
  318. }
  319. if (this.courseEV.length > 0) {
  320. this.courseEV.push(this.courseEV.join().split(','))
  321. }
  322. },
  323. // 获取认证信息
  324. async getPersonAuthorize() {
  325. const { data: result } = await uni.$http.get('/education/teacher-certifications/findVerifyStatus')
  326. const auth = result.message
  327. this.updateAuthentication(auth)
  328. if (auth === '审核中') {
  329. this.confirmText = '请耐心等待'
  330. this.$refs.alertDialog.open()
  331. } else if (auth !== '已通过') {
  332. this.confirmText = '去认证'
  333. this.$refs.alertDialog.open()
  334. }
  335. },
  336. // 取消按钮
  337. dialogClose() {
  338. this.$refs.alertDialog.close()
  339. uni.navigateBack()
  340. },
  341. // 确定按钮
  342. dialogConfirm() {
  343. this.$refs.alertDialog.close()
  344. if (this.authentication === '审核中') {
  345. uni.navigateBack()
  346. } else if (this.authentication !== '已通过'){
  347. uni.redirectTo({
  348. url: '/subpkg/teacher/authentication/teacher_authentication'
  349. })
  350. }
  351. },
  352. // 获取老师地理位置
  353. getLocation() {
  354. wx.chooseLocation({
  355. success: res => {
  356. if (res.errMsg === 'chooseLocation:ok') {
  357. this.baseFormData.location = res.address + res.name
  358. this.baseFormData.locationAl = res.latitude + ',' + res.longitude
  359. }
  360. }
  361. })
  362. },
  363. // 树形结构的课程和价格表
  364. async getPriceAndTree() {
  365. const {
  366. data: result
  367. } = await uni.$http.get('/education/course-price/treeAndPrice')
  368. this.courseTree = result.data.treeCourse
  369. },
  370. // 上午复选框
  371. chechboxChangeAM(e) {
  372. this.courseAM.push(e.detail.value)
  373. },
  374. // 下午复选框
  375. chechboxChangePM(e) {
  376. this.coursePM.push(e.detail.value)
  377. },
  378. // 晚上复选框
  379. chechboxChangeEvening(e) {
  380. this.courseEV.push(e.detail.value)
  381. },
  382. submit(ref) {
  383. this.baseFormData.teachTime = []
  384. if (this.courseAM.length === 0 && this.coursePM.length === 0 && this.courseEV.length === 0 ) return uni.$showMsg('请选择授课时间!')
  385. if (this.courseAM[this.courseAM.length - 1] == '' && this.coursePM.length === 0 && this.courseEV.length === 0 ) return uni.$showMsg('请选择授课时间!')
  386. if (this.courseAM.length === 0 && this.coursePM[this.coursePM.length - 1] == '' && this.courseEV.length === 0 ) return uni.$showMsg('请选择授课时间!')
  387. if (this.courseAM.length === 0 && this.coursePM.length === 0 && this.courseEV[this.courseEV.length - 1] == '' ) return uni.$showMsg('请选择授课时间!')
  388. if (this.courseAM[this.courseAM.length - 1] == '' && this.coursePM[this.coursePM.length - 1] == '' && this.courseEV.length === 0 ) return uni.$showMsg('请选择授课时间!')
  389. if (this.courseAM[this.courseAM.length - 1] == '' && this.coursePM.length === 0 && this.courseEV[this.courseEV.length - 1] == '' ) return uni.$showMsg('请选择授课时间!')
  390. if (this.courseAM.length === 0 && this.coursePM[this.coursePM.length - 1] == '' && this.courseEV[this.courseEV.length - 1] == '' ) return uni.$showMsg('请选择授课时间!')
  391. if (this.courseAM[this.courseAM.length - 1] == '' && this.coursePM[this.coursePM.length - 1] == '' && this.courseEV[this.courseEV.length - 1] == '' ) return uni.$showMsg('请选择授课时间!')
  392. if (this.courseAM.length > 0) {
  393. this.baseFormData.teachTime.push(this.courseAM[this.courseAM.length - 1])
  394. }
  395. if (this.coursePM.length > 0) {
  396. this.baseFormData.teachTime.push(this.coursePM[this.coursePM.length - 1])
  397. }
  398. if (this.courseEV.length > 0) {
  399. this.baseFormData.teachTime.push(this.courseEV[this.courseEV.length - 1])
  400. }
  401. // 上课时间
  402. this.baseFormData.teachTime = this.baseFormData.teachTime.join()
  403. // 末尾为,
  404. if (this.baseFormData.teachTime.slice(-1) === ',') {
  405. this.baseFormData.teachTime = this.baseFormData.teachTime.substring(0, this.baseFormData.teachTime.length - 1)
  406. }
  407. // 开始为,
  408. if (this.baseFormData.teachTime.slice(0,1) === ',') {
  409. let temp = this.baseFormData.teachTime.substring(1, this.baseFormData.teachTime.length )
  410. this.baseFormData.teachTime = temp
  411. }
  412. if (this.baseFormData.subject === '') {
  413. return uni.$showMsg('请选择授课科目')
  414. }
  415. // 授课科目
  416. for (let x = 0; x < this.courseTree.length; x++) {
  417. for (let y = 0; y < this.courseTree[x].children.length; y++) {
  418. if (this.courseTree[x].children[y].value === this.baseFormData.subject) {
  419. this.baseFormData.subjectBig = this.courseTree[x].value + '/' + this.baseFormData.subject
  420. }
  421. }
  422. }
  423. if (this.baseFormData.location === '') return uni.$showMsg('请输入位置!')
  424. this.addflag = true
  425. this.$refs[ref].validate().then(res => {
  426. uni.showLoading({
  427. title: '数据加载中'
  428. })
  429. uni.request({
  430. url: `${uni.$http.baseUrl}/education/teacher-courses/publishCourse`,
  431. data: JSON.stringify(this.baseFormData),
  432. header: {
  433. token: uni.getStorageSync('token')
  434. },
  435. method: 'POST',
  436. success: res => {
  437. uni.hideLoading()
  438. uni.$showMsg(res.data.message)
  439. setTimeout(() => {
  440. uni.redirectTo({
  441. url: '/subpkg/teacher/course/teacher_course_pattern'
  442. })
  443. }, 1000)
  444. },
  445. complete: () => {
  446. setTimeout(() => {
  447. this.addflag = false
  448. }, 1000)
  449. }
  450. })
  451. }).catch(err =>{
  452. return
  453. })
  454. }
  455. }
  456. }
  457. </script>
  458. <!-- 设置页面背景 -->
  459. <style lang="scss">
  460. page{
  461. height: 100%;
  462. //background-color: #D4F5E9;
  463. }
  464. </style>
  465. <style lang="scss" scoped>
  466. .course-add-container{
  467. width: 96%;
  468. padding-left: 20rpx;
  469. }
  470. .tr-container{
  471. display: flex;
  472. position: relative;
  473. width: 96%;
  474. flex-direction: column;
  475. /* border: 1rpx solid gray; */
  476. margin: -10px 20rpx;
  477. margin-bottom: 20px;
  478. }
  479. .tr_1 {
  480. display: flex;
  481. position: relative;
  482. height: 80rpx;
  483. line-height: 80rpx;
  484. }
  485. .tr_2{
  486. display: block;
  487. height: 80rpx;
  488. line-height: 80rpx;
  489. }
  490. .th_0,
  491. .th_1,
  492. .th_2,
  493. .th2_0,
  494. .th2_1,
  495. .th2_2{
  496. width: 12%;
  497. height: 80rpx;
  498. line-height: 80rpx;
  499. border-right: 1rpx solid gray;
  500. border-bottom: 1rpx solid gray;
  501. text-align: center;
  502. }
  503. .th_0,
  504. .th_1,
  505. .th_2{
  506. border-top: 1rpx solid gray;
  507. }
  508. .th_0,
  509. .th2_0{
  510. border-left: 1rpx solid gray;
  511. }
  512. .th2_0{
  513. float: left;
  514. width: 12%;
  515. height: 80rpx;
  516. line-height: 80rpx;
  517. text-align: center;
  518. /* background-color: greenyellow; */
  519. }
  520. .button-group{
  521. padding-left: -20rpx;
  522. margin-bottom: 40rpx;
  523. height: 140rpx;
  524. }
  525. // 发布课程按钮
  526. .publishBtn{
  527. width: 260rpx;
  528. border-radius: 50rpx;
  529. background-color: #35b882;
  530. }
  531. // 提交按钮样式
  532. .submitBtnWrapper{
  533. margin-top: 30rpx;
  534. height: 140rpx;
  535. align-items: center;
  536. }
  537. .submitBtn{
  538. width: 300rpx;
  539. border-radius: 50rpx;
  540. // margin-bottom: 40rpx;
  541. background-color: #35b882;
  542. font-size: 30rpx;
  543. }
  544. </style>