preference.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view class="preference">
  3. <uni-nav-bar left-icon="back" :statusBar="true" fixed="true" title="课程内容选择"
  4. @clickLeft="clickLeft"></uni-nav-bar>
  5. <view class="header">
  6. 已选学时:{{ chapterClassHours(chapterIdListAllNum)}} / {{options.minClassHour}}
  7. </view>
  8. <view class="dis_flex">
  9. <u-button type="success" :plain="true" size="medium" @click="autoGet" v-if="firstChoiceStatusBtn">一键选课</u-button>
  10. <u-button type="success" size="medium" @click="submit">保存</u-button>
  11. </view>
  12. <view class="fgx"></view>
  13. <view class="contents">
  14. <u-checkbox-group>
  15. <u-checkbox class="u_checkbox" v-for="(item, index) in courseMenu" :key="index" v-model="item.checked"
  16. shape="circle" :disabled="item.disabled" :name="item.menuId">{{item.menuName}}<text
  17. v-if="item.type == 2"
  18. style="color:red">(学时:{{ chapterClassHours(item.totalTime) }})</text></u-checkbox>
  19. </u-checkbox-group>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. data() {
  26. return {
  27. options: {},
  28. courseMenu: [],
  29. chapterIdListAllNum: 0,
  30. firstChoiceStatusBtn: false,
  31. };
  32. },
  33. onLoad(options) {
  34. options.minClassHour = parseFloat(options.minClassHour)
  35. this.options = options
  36. this.init()
  37. },
  38. watch: {
  39. courseMenu: {
  40. handler(newVal, oldVal) {
  41. let A = 0
  42. this.courseMenu.forEach(i => {
  43. if (i.checked == true) {
  44. A += i.totalTime || 0
  45. }
  46. })
  47. this.chapterIdListAllNum = A
  48. },
  49. // 深度监听 属性的变化
  50. deep: true
  51. }
  52. },
  53. methods: {
  54. autoGet() {
  55. this.courseMenu.forEach((i, k) => {
  56. this.$set(this.courseMenu[k], 'checked', i.firstChoiceStatus == 1)
  57. })
  58. },
  59. chapterClassHours(num) {
  60. return num ? (parseInt(num) / 60 / 45).toFixed(1) : 0;
  61. },
  62. init() {
  63. this.firstChoiceStatusBtn = false
  64. this.$api
  65. .reMenuList({
  66. courseId: this.options.courseId,
  67. gradeId: this.options.gradeId,
  68. orderGoodsId: this.options.orderGoodsId,
  69. getHours: 1
  70. })
  71. .then(res => {
  72. res.data.rows.forEach(i => {
  73. i.checked = false
  74. i.disabled = i.type == 2 ? false : true;
  75. if (i.firstChoiceStatus) {
  76. this.firstChoiceStatusBtn = true
  77. }
  78. });
  79. this.courseMenu = res.data.rows;
  80. }); //获取课程内容
  81. },
  82. clickLeft() {
  83. uni.navigateBack({
  84. delta: 1
  85. });
  86. },
  87. submit() {
  88. if (
  89. this.chapterClassHours(this.chapterIdListAllNum) < this.options.minClassHour
  90. ) {
  91. uni.showModal({
  92. showCancel: false,
  93. content: "未选够" + this.options.minClassHour + "学时"
  94. })
  95. return;
  96. }
  97. if (
  98. this.chapterClassHours(this.chapterIdListAllNum) >
  99. this.options.minClassHour + 3
  100. ) {
  101. uni.showModal({
  102. showCancel: false,
  103. content: `学时范围(${this.options.minClassHour}~${this.options
  104. .minClassHour + 3} ),已超出,请重新选择`
  105. })
  106. return;
  107. }
  108. let array = []
  109. this.courseMenu.forEach(i => {
  110. if (i.checked == true) {
  111. array.push(i.menuId)
  112. }
  113. })
  114. let ary = {
  115. chapterIdList: array,
  116. courseId: this.options.courseId,
  117. goodsId: this.options.goodsId,
  118. gradeId: this.options.gradeId,
  119. orderGoodsId: this.options.orderGoodsId
  120. };
  121. this.$api.orderfirstChoiceGoods(ary).then(res => {
  122. uni.redirectTo({
  123. url: `/pages3/polyv/detail?id=${
  124. res.data.data.courseId
  125. }&goodsId=${res.data.data.goodsId}&orderGoodsId=${
  126. res.data.data.orderGoodsId
  127. }&gradeId=${res.data.data.gradeId}&periodWaitTime=${
  128. this.options.periodWaitTime
  129. }&isQ=${this.options.isQ}`,
  130. });
  131. });
  132. },
  133. },
  134. };
  135. </script>
  136. <style scoped lang="scss">
  137. .header {
  138. padding: 16rpx 0rpx;
  139. background-color: rgb(88, 190, 238);
  140. color: #fff;
  141. text-align: center;
  142. }
  143. .dis_flex {
  144. display: flex;
  145. align-items: center;
  146. height: 100rpx;
  147. justify-content: space-around;
  148. }
  149. ::v-deep .u-size-medium {
  150. width: 150rpx !important;
  151. }
  152. .fgx {
  153. height: 1rpx;
  154. background-color: #dedede;
  155. margin: 20rpx 0rpx 20rpx;
  156. }
  157. .contents {
  158. background-color: #fff;
  159. }
  160. ::v-deep .u-checkbox-group {
  161. display: flex;
  162. flex-direction: column;
  163. padding: 0rpx 20rpx;
  164. }
  165. ::v-deep .u_checkbox {
  166. padding: 10rpx 0rpx;
  167. border-bottom: 1rpx solid #dedede;
  168. }
  169. </style>