add_course.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view>
  3. <uni-forms ref="baseForm" :model="baseFormData" labelWidth="80px" :rules="rules" labelPosition="top">
  4. <uni-forms-item label="授课科目1:" required>
  5. <uni-data-picker placeholder="选择授课" popup-title="课程大纲-具体课程" v-model="baseFormData.subject[1]" :clearIcon="false" :localdata="courseTree" />
  6. </uni-forms-item>
  7. <uni-forms-item v-for="(item, index) in dynamicsLists" :key="item.id" :label="item.label+''+(index+2)+':'" :name="'baseFormData.subject[' + item.id + ']'" >
  8. <uni-data-picker class="publish-course" placeholder="选择授课" popup-title="课程大纲-具体课程" v-model="baseFormData.subject[item.id]" :clearIcon="false" :localdata="courseTree" />
  9. </uni-forms-item>
  10. <uni-forms-item label="授课方式:" name="mode" required>
  11. <uni-data-checkbox v-model="baseFormData.mode" multiple :localdata="modes" />
  12. </uni-forms-item>
  13. <uni-forms-item label="授课时间:" name="teachTime" required>
  14. <uni-datetime-picker v-model="baseFormData.teachTime" type="datetimerange" rangeSeparator="至" />
  15. </uni-forms-item>
  16. <uni-forms-item label="教龄:" name="teachAge" required>
  17. <uni-number-box v-model="baseFormData.teachAge" :min="1" ></uni-number-box>
  18. </uni-forms-item>
  19. <uni-forms-item label="老师位置:" name="location" required>
  20. <uni-easyinput type="text" v-model="baseFormData.location" @focus="getLocation" maxlength="250" trim="both" />
  21. </uni-forms-item>
  22. <uni-forms-item label="成功经验:" name="experience" required>
  23. <uni-easyinput type="textarea" v-model="baseFormData.experience" maxlength="250" trim="both" />
  24. </uni-forms-item>
  25. <uni-forms-item label="自我介绍:" name="introduce" required>
  26. <uni-easyinput type="textarea" v-model="baseFormData.introduce" maxlength="250" trim="both" />
  27. </uni-forms-item>
  28. </uni-forms>
  29. <view class="button-group">
  30. <button type="warn" size="mini" @click="add">新增授课科目</button>
  31. <button type="primary" size="mini" @click="submit('baseForm')">发布课程</button>
  32. </view>
  33. <uni-popup ref="alertDialog" type="dialog">
  34. <uni-popup-dialog type="info" :confirmText="confirmText" title="温馨提示" :content="authentication" @close="dialogClose" @confirm="dialogConfirm"></uni-popup-dialog>
  35. </uni-popup>
  36. </view>
  37. </template>
  38. <script>
  39. import { mapState, mapMutations } from 'vuex'
  40. export default {
  41. computed: {
  42. ...mapState('m_user', ['authentication'])
  43. },
  44. data() {
  45. return {
  46. confirmText: '',
  47. // 表单数据
  48. baseFormData: {
  49. subject: {
  50. 1: '1',
  51. 2: '1',
  52. 3: '1',
  53. 4: '1'
  54. },
  55. mode: [],
  56. teachTime: '',
  57. teachAge: 1,
  58. location: ''
  59. },
  60. dynamicsLists: [],
  61. count: 1, // 选择课程计数
  62. // 选择课程
  63. courseTree: [{
  64. text: '一年级',
  65. value: '1-0',
  66. children: [{
  67. text: '1.1班',
  68. value: '1'
  69. }
  70. ]
  71. }
  72. ],
  73. // 多选授课方式数据源
  74. modes: [{
  75. text: '老师上门',
  76. value: '老师上门'
  77. }, {
  78. text: '学员上门',
  79. value: '学员上门'
  80. }, {
  81. text: '线上辅导',
  82. value: '线上辅导'
  83. }],
  84. rules: {
  85. subject: {
  86. rules: [{
  87. required: true,
  88. errorMessage: '授课科目不能为空',
  89. }]
  90. },
  91. mode: {
  92. rules: [{
  93. required: true,
  94. errorMessage: '授课方式不能为空',
  95. }]
  96. },
  97. teachTime: {
  98. rules: [{
  99. required: true,
  100. errorMessage: '授课时间不能为空',
  101. }]
  102. },
  103. location: {
  104. rules: [{
  105. require: true,
  106. errorMessage: '地理位置不能为空',
  107. }]
  108. },
  109. experience: {
  110. rules: [{
  111. required: true,
  112. errorMessage: '成功经验不能为空',
  113. }]
  114. },
  115. introduce: {
  116. rules: [{
  117. required: true,
  118. errorMessage: '自我介绍不能为空',
  119. }]
  120. }
  121. }
  122. };
  123. },
  124. created() {
  125. this.getPriceAndTree()
  126. },
  127. mounted() {
  128. this.openDialog()
  129. },
  130. methods: {
  131. ...mapMutations('m_user', ['updateAuthentication']),
  132. // 打开对话框
  133. openDialog() {
  134. if (this.authentication === '正在审核中…') {
  135. this.confirmText = '再等等'
  136. this.$refs.alertDialog.open()
  137. } else if (this.authentication !== '认证成功,点击前往课程发布' && this.authentication !== '正在审核中…') {
  138. this.confirmText = '去认证'
  139. this.$refs.alertDialog.open()
  140. }
  141. },
  142. // 取消按钮
  143. dialogClose() {
  144. this.$refs.alertDialog.close()
  145. uni.navigateBack()
  146. },
  147. // 确定按钮
  148. dialogConfirm() {
  149. this.$refs.alertDialog.close()
  150. if (this.authentication === '正在审核中…') {
  151. uni.navigateBack()
  152. } else {
  153. this.updateAuthentication('')
  154. uni.redirectTo({
  155. url: '/subpkg/teacher_authorize/teacher_authorize'
  156. })
  157. }
  158. },
  159. // 获取老师地理位置
  160. getLocation() {
  161. wx.choosePoi({
  162. success: res => {
  163. console.log(res)
  164. if (res.type === 0) {
  165. // 不显示位置
  166. this.baseFormData.location = ''
  167. } else if (res.type === 2) {
  168. // 详细位置
  169. this.baseFormData.location = res.address
  170. } else if (res.type === 1) {
  171. // 概要位置
  172. this.baseFormData.location = res.city
  173. }
  174. }
  175. })
  176. },
  177. add() {
  178. this.count++
  179. if (this.dynamicsLists.length > 2) return uni.$showMsg('新增授权科目过多!')
  180. this.dynamicsLists.push({
  181. label: '授课科目',
  182. id: this.count
  183. })
  184. },
  185. del(id) {
  186. let index = this.dynamicsLists.findIndex(v => v.id === id)
  187. this.dynamicsLists.splice(index, 1)
  188. },
  189. // 树形结构的课程和价格表
  190. async getPriceAndTree() {
  191. const {
  192. data: result
  193. } = await uni.$http.get('/education/course-price/treeAndPrice')
  194. this.courseTree = result.data.treeCourse
  195. },
  196. submit(ref) {
  197. for (let i = 1; i <= this.dynamicsLists.length + 1; i++) {
  198. if (this.baseFormData.subject[i] === '1') {
  199. return uni.$showMsg('请选择授课科目' + i)
  200. }
  201. }
  202. if (this.baseFormData.location === '') return uni.$showMsg('请输入位置!')
  203. this.$refs[ref].validate().then(res => {
  204. console.log(this.baseFormData)
  205. uni.request({
  206. url: 'http://192.168.0.207:8222/education/teacher-courses/publishCourse',
  207. data: JSON.stringify(this.baseFormData),
  208. header: {
  209. token: uni.getStorageSync('token')
  210. },
  211. method: 'POST',
  212. success: res => {
  213. // this.isLoading = false
  214. console.log(res)
  215. uni.$showMsg(res.data.message)
  216. setTimeout(() => {
  217. uni.navigateBack()
  218. }, 1000)
  219. }
  220. })
  221. }).catch(err => {
  222. console.log('err', err);
  223. })
  224. }
  225. }
  226. }
  227. </script>
  228. <style lang="scss" scoped>
  229. .button-group {
  230. margin-top: 15px;
  231. display: flex;
  232. justify-content: space-around;
  233. }
  234. </style>