index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. }
  108. }).then((res) => {
  109. if (res.data.code == 200) {
  110. let data = res.data.data || []
  111. this.dayRecordList = data.map((item) => {
  112. let day = 0
  113. if (item.recordTime) {
  114. day = new Date(item.recordTime * 1000).getDate()
  115. }
  116. return {
  117. ...item,
  118. day: day
  119. }
  120. })
  121. if (this.dayRecordList.length) {
  122. this.date_num.forEach((item, index) => {
  123. let findV = this.dayRecordList.find(e => e.day == item.date)
  124. if (findV) {
  125. this.$set(this.date_num[index], 'sign', true)
  126. } else {
  127. this.$set(this.date_num[index], 'sign', false)
  128. }
  129. })
  130. }
  131. console.log('this.dayRecordList', this.dayRecordList, this.date_num);
  132. }
  133. })
  134. },
  135. goPractice() {
  136. const { examId, moduleExamId = 0, chapterExamId = 0 } = this.dayExamDetail
  137. uni.navigateTo({
  138. url:'/pages2/bank/questionBank?orderGoodsId='+ this.orderGoodsId + '&id=' + examId + '&goodsid=' + this.goodsId
  139. +'&moduleId=' + moduleExamId + '&chapterId=' + chapterExamId + '&entryType=daily'
  140. })
  141. },
  142. },
  143. }
  144. </script>
  145. <style lang="scss">
  146. .daily_practice {
  147. width: 100%;
  148. padding: 32rpx;
  149. }
  150. .contents {
  151. .toPractice {
  152. width: 600rpx;
  153. height: 100rpx;
  154. line-height: 100rpx;
  155. text-align: center;
  156. font-size: 32rpx;
  157. color: #222;
  158. border: 2rpx solid #666;
  159. }
  160. }
  161. .punch_calendar {
  162. width: 100%;
  163. background: #ffffff;
  164. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(47, 67, 121, 0.1);
  165. border-radius: 22rpx;
  166. margin-top: 16rpx;
  167. padding-bottom: 15rpx;
  168. .card_box {
  169. height: 60rpx;
  170. line-height: 60rpx;
  171. // margin-left: 20rpx;
  172. text-align: center;
  173. }
  174. .t1 {
  175. color: #007AFF;
  176. font-size: 24rpx;
  177. }
  178. .weeks {
  179. width: 100%;
  180. display: flex;
  181. justify-content:center;
  182. margin-top: 20rpx;
  183. }
  184. .card_date {
  185. width: 14%;
  186. text-align: center;
  187. color: #7f8caf;
  188. }
  189. .day_dailys {
  190. width: 100%;
  191. display: flex;
  192. margin-top: 40rpx;
  193. flex-wrap: wrap;
  194. }
  195. .date_num {
  196. width: 14%;
  197. text-align: center;
  198. position: relative;
  199. display: inline-block;
  200. margin-top: 20rpx;
  201. .items {
  202. width: 100%;
  203. }
  204. }
  205. }
  206. </style>