add_course.vue 14 KB

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