add_course.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. countNoDeal: 1,
  47. confirmText: '',
  48. // 表单数据
  49. baseFormData: {
  50. subject: {
  51. 1: '1',
  52. 2: '1',
  53. 3: '1',
  54. 4: '1'
  55. },
  56. mode: [],
  57. teachTime: '',
  58. teachAge: 1,
  59. location: ''
  60. },
  61. dynamicsLists: [],
  62. count: 1, // 选择课程计数
  63. // 选择课程
  64. courseTree: [{
  65. text: '一年级',
  66. value: '1-0',
  67. children: [{
  68. text: '1.1班',
  69. value: '1'
  70. }
  71. ]
  72. }
  73. ],
  74. // 多选授课方式数据源
  75. modes: [{
  76. text: '老师上门',
  77. value: '老师上门'
  78. }, {
  79. text: '学员上门',
  80. value: '学员上门'
  81. }, {
  82. text: '线上辅导',
  83. value: '线上辅导'
  84. }],
  85. rules: {
  86. subject: {
  87. rules: [{
  88. required: true,
  89. errorMessage: '授课科目不能为空',
  90. }]
  91. },
  92. mode: {
  93. rules: [{
  94. required: true,
  95. errorMessage: '授课方式不能为空',
  96. }]
  97. },
  98. teachTime: {
  99. rules: [{
  100. required: true,
  101. errorMessage: '授课时间不能为空',
  102. }]
  103. },
  104. location: {
  105. rules: [{
  106. require: true,
  107. errorMessage: '地理位置不能为空',
  108. }]
  109. },
  110. experience: {
  111. rules: [{
  112. required: true,
  113. errorMessage: '成功经验不能为空',
  114. }]
  115. },
  116. introduce: {
  117. rules: [{
  118. required: true,
  119. errorMessage: '自我介绍不能为空',
  120. }]
  121. }
  122. }
  123. };
  124. },
  125. created() {
  126. this.getPriceAndTree(),
  127. this.queryNoDealCourse()
  128. },
  129. mounted() {
  130. this.openDialog()
  131. },
  132. methods: {
  133. ...mapMutations('m_user', ['updateAuthentication']),
  134. // 查询未成交的课程
  135. async queryNoDealCourse() {
  136. const {
  137. data: result1
  138. } = await uni.$http.get('/education/teacher-courses/queryPersonNoDeal')
  139. this.countNoDeal = result1.data.count
  140. },
  141. // 打开对话框
  142. openDialog() {
  143. if (this.authentication === '正在审核中…') {
  144. this.confirmText = '再等等'
  145. this.$refs.alertDialog.open()
  146. } else if (this.authentication !== '认证成功,点击前往课程发布' && this.authentication !== '正在审核中…') {
  147. this.confirmText = '去认证'
  148. this.$refs.alertDialog.open()
  149. }
  150. },
  151. // 取消按钮
  152. dialogClose() {
  153. this.$refs.alertDialog.close()
  154. uni.navigateBack()
  155. },
  156. // 确定按钮
  157. dialogConfirm() {
  158. this.$refs.alertDialog.close()
  159. if (this.authentication === '正在审核中…') {
  160. uni.navigateBack()
  161. } else {
  162. this.updateAuthentication('')
  163. uni.redirectTo({
  164. url: '/subpkg/teacher_authorize/teacher_authorize'
  165. })
  166. }
  167. },
  168. // 获取老师地理位置
  169. getLocation() {
  170. wx.choosePoi({
  171. success: res => {
  172. // console.log(res)
  173. if (res.type === 0) {
  174. // 不显示位置
  175. this.baseFormData.location = ''
  176. } else if (res.type === 2) {
  177. // 详细位置
  178. this.baseFormData.location = res.address
  179. } else if (res.type === 1) {
  180. // 概要位置
  181. this.baseFormData.location = res.city
  182. }
  183. }
  184. })
  185. },
  186. add() {
  187. this.count++
  188. if (this.dynamicsLists.length > 2) return uni.$showMsg('新增授权科目过多!')
  189. this.dynamicsLists.push({
  190. label: '授课科目',
  191. id: this.count
  192. })
  193. },
  194. del(id) {
  195. let index = this.dynamicsLists.findIndex(v => v.id === id)
  196. this.dynamicsLists.splice(index, 1)
  197. },
  198. // 树形结构的课程和价格表
  199. async getPriceAndTree() {
  200. const {
  201. data: result
  202. } = await uni.$http.get('/education/course-price/treeAndPrice')
  203. this.courseTree = result.data.treeCourse
  204. },
  205. submit(ref) {
  206. const remain = 4 - this.countNoDeal
  207. if (this.dynamicsLists.length > remain - 1) {
  208. return uni.$showMsg(`还剩${remain}门课程可以发布`, 2000)
  209. }
  210. for (let i = 1; i <= this.dynamicsLists.length + 1; i++) {
  211. if (this.baseFormData.subject[i] === '1') {
  212. return uni.$showMsg('请选择授课科目' + i)
  213. }
  214. }
  215. if (this.baseFormData.location === '') return uni.$showMsg('请输入位置!')
  216. this.$refs[ref].validate().then(res => {
  217. console.log(this.baseFormData)
  218. uni.request({
  219. url: 'http://192.168.0.207:8222/education/teacher-courses/publishCourse',
  220. data: JSON.stringify(this.baseFormData),
  221. header: {
  222. token: uni.getStorageSync('token')
  223. },
  224. method: 'POST',
  225. success: res => {
  226. // this.isLoading = false
  227. console.log(res)
  228. uni.$showMsg(res.data.message)
  229. setTimeout(() => {
  230. uni.navigateBack()
  231. }, 1000)
  232. }
  233. })
  234. }).catch(err => {
  235. console.log('err', err);
  236. })
  237. }
  238. }
  239. }
  240. </script>
  241. <style lang="scss" scoped>
  242. .button-group {
  243. margin-top: 15px;
  244. display: flex;
  245. justify-content: space-around;
  246. }
  247. </style>