teacher_course_add.vue 14 KB

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