C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
5.3 KiB

  1. const imgurl = require("../../utils/imgurl");
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. activityStyle: String,
  8. allFlag:Boolean,
  9. },
  10. /**
  11. * 组件的初始数据
  12. */
  13. data: {
  14. week: ['日', '一', '二', '三', '四', '五', '六'],
  15. dateLsit: [],
  16. year: new Date().getFullYear(),
  17. month: new Date().getMonth() + 1,
  18. yearFlgh: new Date().getFullYear(),//当前年
  19. monthFlgh: new Date().getMonth() + 1,//当前月
  20. dey: new Date().getDate(),
  21. thendata: [], //当前这一周的数组
  22. xiala: imgurl.concealBnt.url,
  23. switchFlag:true,
  24. },
  25. /**
  26. * 组件的方法列表
  27. */
  28. methods: {
  29. switchs(){
  30. let temp = this.data.switchFlag
  31. this.setData({
  32. switchFlag:!temp
  33. })
  34. console.log(this.data.switchFlag)
  35. },
  36. showDate(year, month) { //刷新日历
  37. let thenDey = this.getThenWeek(year, month) //每个月第一天星期几
  38. let thenMonth = this.getDays(year, month) //获取每月有多少天
  39. let lastMonth = this.getLastMonth(year, month) //上月最后一天是多少天
  40. let tempDey = []
  41. let tmepArr = []
  42. for (let i = 0; i < 42; i++) { //初始化日历数组
  43. tempDey.splice(i, 0, "")
  44. }
  45. for (let i = 0; i < thenMonth; i++) { //获取当前选中月份天数
  46. tmepArr.splice(i, 0, {
  47. style: "0",
  48. value: i + 1,
  49. y:year,
  50. m: month
  51. })
  52. }
  53. tempDey.splice(thenDey, thenMonth, ...tmepArr)
  54. for (let i = 0; i < thenDey; i++) { //添加上一个月的天数
  55. tempDey.splice(i, 1, {
  56. style: "1",
  57. value: lastMonth - (thenDey - 1),
  58. y: year,
  59. m: month-1
  60. })
  61. lastMonth++
  62. }
  63. for (let i = 0; i < 42 - (thenDey + thenMonth); i++) { //设置下一个月
  64. tempDey.splice(thenDey + thenMonth + i, 1, {
  65. style: "2",
  66. value: i + 1,
  67. y: year,
  68. m: month+1
  69. })
  70. }
  71. this.setData({
  72. dateLsit: tempDey
  73. })
  74. console.log(tempDey,"?")
  75. },
  76. handle(e) { //点击号数
  77. let item = e.currentTarget.dataset.item
  78. console.log(item)
  79. if (item.style == '1') {
  80. this.front()
  81. } else if (item.style == '2') {
  82. this.behind()
  83. }
  84. },
  85. getDays(year, month) { //获取每月有多少天
  86. let tempDateArr = []
  87. let thenDate = new Date(year, month, 0).getDate()
  88. return thenDate
  89. },
  90. getLastMonth(year, month) { //上一个月最后一天是多少号
  91. if (month == 1) {
  92. month = 12
  93. year = year - 1
  94. } else {
  95. month = month - 1
  96. }
  97. let tempDateArr = []
  98. let thenDate = new Date(year, month, 0).getDate()
  99. return thenDate
  100. },
  101. getThenWeek(year, month) { //获取每个月第一天是星期几
  102. if (month == 1) {
  103. month = 12
  104. year = year - 1
  105. } else {
  106. month = month - 1
  107. }
  108. let date = new Date()
  109. date.setFullYear(year)
  110. date.setMonth(month)
  111. date.setDate(1)
  112. return date.getDay()
  113. },
  114. front() { //前面
  115. if (this.data.month == 1) {
  116. let temp = this.data.switchFlag
  117. this.setData({
  118. switchFlag: false
  119. })
  120. this.setData({
  121. year: this.data.year - 1,
  122. month: 12
  123. })
  124. this.showDate(this.data.year, this.data.month)
  125. } else {
  126. this.setData({
  127. month: this.data.month - 1
  128. })
  129. this.showDate(this.data.year, this.data.month)
  130. }
  131. },
  132. behind() { //后面
  133. let temp = this.data.switchFlag
  134. this.setData({
  135. switchFlag: false
  136. })
  137. if (this.data.month == 12) {
  138. this.setData({
  139. year: this.data.year + 1,
  140. month: 1
  141. })
  142. this.showDate(this.data.year, this.data.month)
  143. } else {
  144. this.setData({
  145. month: this.data.month + 1
  146. })
  147. this.showDate(this.data.year, this.data.month)
  148. }
  149. },
  150. },
  151. lifetimes: {
  152. attached: function() {
  153. // 在组件实例进入页面节点树时执行
  154. let thenDey = new Date().getDay() //今天是周几
  155. let thenDate = new Date().getDate() //今天是多少号
  156. let tempArr = []
  157. if (thenDey == 0) {
  158. for (let i = 0; i < 7; i++) {
  159. tempArr.splice(i, 1, {
  160. thenFalg: "1",
  161. value: thenDate,
  162. style:"0",
  163. y: this.data.year,
  164. m:this.data.month
  165. })
  166. thenDate++
  167. }
  168. } else {
  169. let temp = new Date().getDay() //今天是周几
  170. let tmpeDey = new Date().getDate() //今天是多少号
  171. for (let i = 0; i <= temp; i++) {
  172. tempArr.splice(i, 0, {
  173. style: "0", value: thenDate - thenDey, y: this.data.year,
  174. m: this.data.month} )
  175. thenDey--
  176. }
  177. for (let i = temp + 1; i < 7; i++) {
  178. tmpeDey++
  179. tempArr.splice(i, 0, {
  180. style: "0", value: tmpeDey, y: this.data.year,
  181. m: this.data.month} )
  182. }
  183. }
  184. this.setData({
  185. thendata: tempArr
  186. })
  187. console.log(this.data.thendata, "?????")
  188. this.showDate(this.data.year, this.data.month)
  189. },
  190. detached: function() {
  191. // 在组件实例被从页面节点树移除时执行
  192. },
  193. },
  194. })