index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="daily_practice">
  3. <nav-bar title="每日一练"></nav-bar>
  4. <view class="contents">
  5. <view class="remind">
  6. <view>订阅</view>
  7. </view>
  8. <view class="insist">
  9. <view>坚持打卡{{ dayExamDetail.recordCount }} 天</view>
  10. </view>
  11. <view class="names">
  12. <view class="name_title">{{ dayExamDetail.examName || ''}}</view>
  13. <view class="percentage">
  14. <text v-if=" dayExamDetail.examRecord == 1">恭喜你,今天的打卡已完成~</text>
  15. <text v-else>打卡进度超过了{{ dayExamDetail.recordPercentage || '0%' }}的学员,快来打卡呀~</text>
  16. </view>
  17. </view>
  18. <view class="toPractice" @click="goPractice()">
  19. {{ dayExamDetail.examRecord == 1 ? '今日已完成' : '快来做题' }}
  20. </view>
  21. <view class="punch_calendar">
  22. <view class="card_box">
  23. {{ curMonth + '月'}}
  24. </view>
  25. <u-line color="#EEEEEE" />
  26. <view class="weeks">
  27. <view v-for="(item, index) in weekLists" :key="index" class="card_date">{{ item }}</view>
  28. </view>
  29. <view class="day_dailys">
  30. <view v-for="(item, index) in date_num" :key="index" class="date_num">
  31. <view class="items">
  32. {{ item.date }}
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data() {
  43. return {
  44. weekLists: ['日','一','二','三','四','五','六'],
  45. date_num: [],
  46. curMonth: 0, // 当前月份
  47. goodsId: '',
  48. orderGoodsId: '',
  49. dayExamDetail: {}, // 每日一练当天信息试卷
  50. dayRecordList: [], // 每日一练试卷日历打卡记录
  51. }
  52. },
  53. onLoad(option) {
  54. this.goodsId = option.goodsId
  55. this.orderGoodsId = option.orderGoodsId
  56. },
  57. onShow() {
  58. this.initCalendar()
  59. this.getToDayExam()
  60. },
  61. methods: {
  62. // 初始化当月日历
  63. initCalendar() {
  64. let date = new Date()
  65. let year = date.getFullYear() //获取当前年份
  66. this.curMonth = date.getMonth() + 1 //获取当前月份
  67. let dd = new Date(year, this.curMonth, 0) //获取当月总天数
  68. let current_month = []
  69. // let weekList = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]
  70. for (let i = 1; i <= dd.getDate(); i++) {
  71. current_month.push({
  72. date: i,
  73. week: new Date(date.setDate(i)).getDay(),//获取对应日期的星期
  74. });
  75. }
  76. if (current_month[0].week != 0) {
  77. for (let index = 0; index < 2; index++) {
  78. let item = {
  79. date: '',
  80. week: index
  81. }
  82. current_month.splice(index, 0, item)
  83. }
  84. }
  85. this.date_num = current_month
  86. this.getDailyRecord()
  87. },
  88. // 获取每日一练当天的试卷信息
  89. getToDayExam() {
  90. // ${this.goodsId || 990}
  91. this.$http({
  92. url: `/bank/question/getToDayExam/${this.goodsId}`,
  93. method: 'get',
  94. }).then((res) => {
  95. if (res.data.code == 200) {
  96. this.dayExamDetail = res.data.data || {}
  97. }
  98. })
  99. },
  100. // 获取每日一练试卷日历打卡记录
  101. getDailyRecord() {
  102. this.$http({
  103. url: '/bank/question/get/special/record',
  104. method: 'get',
  105. data: {
  106. goodsId: this.goodsId,
  107. // chapterExamId: this.dayExamDetail.chapterExamId || 0,
  108. // moduleExamId: this.dayExamDetail.moduleExamId || 0,
  109. // examId: this.dayExamDetail.examId,
  110. }
  111. }).then((res) => {
  112. if (res.data.code == 200) {
  113. let data = res.data.data || []
  114. this.dayRecordList = data.map((item) => {
  115. let day = 0
  116. if (item.recordTime) {
  117. day = new Date(item.recordTime * 1000).getDate()
  118. }
  119. return {
  120. ...item,
  121. day: day
  122. }
  123. })
  124. if (this.dayRecordList.length) {
  125. this.date_num.forEach((item, index) => {
  126. let findV = this.dayRecordList.find(e => e.day == item.date)
  127. if (findV) {
  128. this.$set(this.date_num[index], 'sign', true)
  129. } else {
  130. this.$set(this.date_num[index], 'sign', false)
  131. }
  132. })
  133. }
  134. console.log('this.dayRecordList', this.dayRecordList, this.date_num);
  135. }
  136. })
  137. },
  138. goPractice() {
  139. const { examId, moduleExamId = 0, chapterExamId = 0 } = this.dayExamDetail
  140. uni.navigateTo({
  141. url:'/pages2/bank/questionBank?orderGoodsId='+ this.orderGoodsId + '&id=' + examId + '&goodsid=' + this.goodsId
  142. +'&moduleId=' + moduleExamId + '&chapterId=' + chapterExamId + '&entryType=daily'
  143. })
  144. },
  145. },
  146. }
  147. </script>
  148. <style lang="scss">
  149. .daily_practice {
  150. width: 100%;
  151. padding: 32rpx;
  152. }
  153. .contents {
  154. .toPractice {
  155. width: 600rpx;
  156. height: 100rpx;
  157. line-height: 100rpx;
  158. text-align: center;
  159. font-size: 32rpx;
  160. color: #222;
  161. border: 2rpx solid #666;
  162. }
  163. }
  164. .punch_calendar {
  165. width: 100%;
  166. background: #ffffff;
  167. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(47, 67, 121, 0.1);
  168. border-radius: 22rpx;
  169. margin-top: 16rpx;
  170. padding-bottom: 15rpx;
  171. .card_box {
  172. height: 60rpx;
  173. line-height: 60rpx;
  174. // margin-left: 20rpx;
  175. text-align: center;
  176. }
  177. .t1 {
  178. color: #007AFF;
  179. font-size: 24rpx;
  180. }
  181. .weeks {
  182. width: 100%;
  183. display: flex;
  184. justify-content:center;
  185. margin-top: 20rpx;
  186. }
  187. .card_date {
  188. width: 14%;
  189. text-align: center;
  190. color: #7f8caf;
  191. }
  192. .day_dailys {
  193. width: 100%;
  194. display: flex;
  195. margin-top: 40rpx;
  196. flex-wrap: wrap;
  197. }
  198. .date_num {
  199. width: 14%;
  200. text-align: center;
  201. position: relative;
  202. display: inline-block;
  203. margin-top: 20rpx;
  204. .items {
  205. width: 100%;
  206. }
  207. }
  208. }
  209. </style>