course_publish.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <view>
  3. <view v-for="(item, index) in requirement" :key="index">
  4. <view class="requires" @click="requireDetail(item)">
  5. <uni-row class="demo-uni-row">
  6. <uni-col offset="1">
  7. <view class="requires-col1">课程号:{{item.courseId}}</view>
  8. </uni-col>
  9. </uni-row>
  10. <uni-row class="demo-uni-row">
  11. <uni-col offset="1" :span="16">
  12. <view class="requires-col2">科目:{{item.subject}}</view>
  13. </uni-col>
  14. <uni-col :span="7">
  15. <view>
  16. <button @click.stop="open(item)" size="mini" :type="item.buttonType">{{item.display}}</button>
  17. </view>
  18. </uni-col>
  19. </uni-row>
  20. <view class="requires-col3">
  21. <uni-row class="demo-uni-row">
  22. <uni-col :span="4" offset="12">
  23. <view style="color: red;">{{item.verifyStatus}}</view>
  24. </uni-col>
  25. <uni-col :span="4" >
  26. <view style="color: red;">{{item.deal}}</view>
  27. </uni-col>
  28. <uni-col :span="4" >
  29. <view style="color: red;">{{item.locked}}</view>
  30. </uni-col>
  31. </uni-row>
  32. </view>
  33. </view>
  34. </view>
  35. <uni-popup ref="popup" type="message">
  36. <uni-popup-message :type="popupType" :message="showMessage" :duration="1000"></uni-popup-message>
  37. </uni-popup>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data() {
  43. return {
  44. requirement: [],
  45. // 分页对象
  46. queryObj: {
  47. pageNum: 1,
  48. pageSize: 8
  49. },
  50. isloading: false,
  51. count: 0, // 总数量
  52. publishCount: 0, // 上架数量
  53. showMessage: '上架成功',
  54. popupType: 'success'
  55. }
  56. },
  57. created() {
  58. this.getPublishCounts()
  59. },
  60. methods: {
  61. // 查询个人上架了多少课程
  62. async getPublishCounts(cb) {
  63. // 打开节流阀
  64. this.isloading = true
  65. const { data: result } = await uni.$http.get('/education/teacher-courses/showPersonCourse', this.queryObj)
  66. this.isloading = false
  67. cb && cb()
  68. // console.log(result.data.list)
  69. this.publishCount = result.data.publishCounts
  70. this.count = result.data.count
  71. let courses = []
  72. courses = result.data.list
  73. for (let i = 0; i < courses.length; i++) {
  74. if (courses[i].display === '上架') {
  75. courses[i].display = '下架'
  76. courses[i].buttonType = 'warn'
  77. } else {
  78. courses[i].display = '上架'
  79. courses[i].buttonType = 'primary'
  80. }
  81. }
  82. this.requirement = [...this.requirement, ...courses]
  83. console.log(this.requirement)
  84. },
  85. // 下拉刷新的事件
  86. onPullDownRefresh() {
  87. if (this.isloading) return
  88. // 1.重置数据
  89. this.queryObj.pageNum = 1
  90. this.publishCount = 0
  91. this.requirement = []
  92. this.isloading = false
  93. // 2.重新发请求
  94. this.getPublishCounts(() => uni.stopPullDownRefresh())
  95. },
  96. // 触底的事件
  97. onReachBottom() {
  98. // 判断是否有下一页的数据
  99. if (this.queryObj.pageNum * this.queryObj.pageSize >= this.count)
  100. return uni.$showMsg('数据加载完毕!')
  101. // 是否有其他正在请求数据
  102. if (this.isloading) return
  103. // 页码自增
  104. this.queryObj.pageNum += 1
  105. this.getPublishCounts()
  106. },
  107. async open(item) {
  108. console.log(item.display)
  109. if (item.display === '上架') {
  110. if (item.verifyStatus !== '已通过') return uni.$showMsg('审核通过才能上架')
  111. if (item.deal === '已成交') return uni.$showMsg('已成交的课程不能上架')
  112. if (this.publishCount >= 4) return uni.$showMsg('最多上架4个课程')
  113. }
  114. const queryObj = {
  115. display: item.display,
  116. courseId: item.courseId
  117. }
  118. const { data: result } = await uni.$http.get('/education/teacher-courses/updatePersonDisplay', queryObj)
  119. if (result.code === 20000) {
  120. if (item.display === '上架') {
  121. item.display = '下架'
  122. this.showMessage = '上架成功'
  123. this.popupType = 'success'
  124. item.buttonType = 'warn'
  125. this.publishCount += 1
  126. } else if (item.display === '下架') {
  127. item.display = '上架'
  128. this.showMessage = '下架成功'
  129. this.popupType = 'error'
  130. item.buttonType = 'primary'
  131. this.publishCount -= 1
  132. }
  133. this.$refs.popup.open('top')
  134. }
  135. },
  136. requireDetail(item) {
  137. uni.navigateTo({
  138. url: '/subpkg/course_detail/course_detail?item=' + encodeURIComponent(JSON.stringify(item))
  139. })
  140. },
  141. }
  142. }
  143. </script>
  144. <style scoped lang="scss">
  145. .requires {
  146. background-color: #FFF2CC;
  147. border: 1px solid #41719C;
  148. .requires-col1 {
  149. margin-top: 15rpx;
  150. }
  151. .requires-col2 {
  152. margin: 15rpx 0;
  153. }
  154. .requires-col3 {
  155. padding-bottom: 15rpx;
  156. }
  157. }
  158. </style>