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.

298 lines
8.1 KiB

  1. const imgurl = require("../../utils/imgurl");
  2. const util = require("../../utils/util");
  3. const Http = require("../../utils/HttpBasics");
  4. const config = require("../../config/config");
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. activityStyle: String,
  11. allFlag: Boolean,
  12. childUrl: String,
  13. },
  14. /**
  15. * 组件的初始数据
  16. */
  17. data: {
  18. week: ['日', '一', '二', '三', '四', '五', '六'],
  19. dateLsit: [],
  20. year: new Date().getFullYear(),
  21. month: new Date().getMonth() + 1,
  22. yearFlgh: new Date().getFullYear(), //当前年
  23. monthFlgh: new Date().getMonth() + 1, //当前月
  24. dey: new Date().getDate(),
  25. thendata: [], //当前这一周的数组
  26. xiala: imgurl.concealBnt.url,
  27. switchFlag: true,
  28. activityDateList: []
  29. },
  30. /**
  31. * 组件的方法列表
  32. */
  33. methods: {
  34. itiActivityLst() { //初始哈活动列表
  35. let tempDateLsit = this.data.dateLsit
  36. let tempThenData = this.data.thendata
  37. this.data.activityDateList.map(item0 => { //初始化当月 标记
  38. tempDateLsit.map(item1 => {
  39. if (item0.yyyy == item1.y && item0.mm == item1.m && item0.dd == item1.value) {
  40. item1.act = 1
  41. }
  42. })
  43. })
  44. this.data.activityDateList.map(item0 => { //初始化 当周标记
  45. tempThenData.map(item1 => {
  46. if (item0.yyyy == item1.y && item0.mm == item1.m && item0.dd == item1.value) {
  47. item1.act = 1
  48. }
  49. })
  50. })
  51. this.setData({
  52. dateLsit: tempDateLsit,
  53. thendata: tempThenData
  54. })
  55. },
  56. getDey() { //查询当月标记日期
  57. let tempMonth = this.data.month
  58. let tempDey = this.getDays(this.data.year, this.data.month) //获取每月有多少天
  59. if (tempMonth < 10) {
  60. tempMonth = '0' + (tempMonth + '')
  61. }
  62. let param = {
  63. startDate: this.data.year + '-' + tempMonth + "-01" + " 00:00:00",
  64. endDate: this.data.year + "-" + tempMonth + "-" + tempDey + " 23:59:59"
  65. }
  66. Http.get({
  67. url: this.data.childUrl,
  68. data: param
  69. }).then(res => {
  70. let {
  71. code,
  72. data
  73. } = res
  74. if (code == 200) {
  75. this.setData({
  76. activityDateList: data
  77. })
  78. this.showDate(this.data.year, this.data.month)
  79. }
  80. })
  81. },
  82. switchs() {
  83. let temp = this.data.switchFlag
  84. this.setData({
  85. switchFlag: !temp
  86. })
  87. },
  88. showDate(year, month) { //刷新日历
  89. let thenDey = this.getThenWeek(year, month) //每个月第一天星期几
  90. let thenMonth = this.getDays(year, month) //获取每月有多少天
  91. let lastMonth = this.getLastMonth(year, month) //上月最后一天是多少天
  92. let tempDey = []
  93. let tmepArr = []
  94. for (let i = 0; i < 42; i++) { //初始化日历数组
  95. tempDey.splice(i, 0, "")
  96. }
  97. for (let i = 0; i < thenMonth; i++) { //获取当前选中月份天数
  98. tmepArr.splice(i, 0, {
  99. style: "0",
  100. value: i + 1,
  101. y: year,
  102. m: month
  103. })
  104. }
  105. tempDey.splice(thenDey, thenMonth, ...tmepArr)
  106. for (let i = 0; i < thenDey; i++) { //添加上一个月的天数
  107. tempDey.splice(i, 1, {
  108. style: "1",
  109. value: lastMonth - (thenDey - 1),
  110. y: year,
  111. m: month - 1
  112. })
  113. lastMonth++
  114. }
  115. for (let i = 0; i < 42 - (thenDey + thenMonth); i++) { //设置下一个月
  116. tempDey.splice(thenDey + thenMonth + i, 1, {
  117. style: "2",
  118. value: i + 1,
  119. y: year,
  120. m: month + 1
  121. })
  122. }
  123. this.setData({
  124. dateLsit: tempDey
  125. })
  126. this.itiActivityLst()
  127. },
  128. handle(e) { //点击号数
  129. let item = e.currentTarget.dataset.item
  130. // if (item.style == '1') {
  131. // this.front()
  132. // } else if (item.style == '2') {
  133. // this.behind()
  134. // }
  135. this.triggerEvent("setDate", {
  136. y: this.data.year,
  137. m: this.data.month,
  138. value:item.value
  139. })
  140. },
  141. getDays(year, month) { //获取每月有多少天
  142. let tempDateArr = []
  143. let thenDate = new Date(year, month, 0).getDate()
  144. return thenDate
  145. },
  146. getLastMonth(year, month) { //上一个月最后一天是多少号
  147. if (month == 1) {
  148. month = 12
  149. year = year - 1
  150. } else {
  151. month = month - 1
  152. }
  153. let tempDateArr = []
  154. let thenDate = new Date(year, month, 0).getDate()
  155. return thenDate
  156. },
  157. getThenWeek(year, month) { //获取每个月第一天是星期几
  158. if (month == 1) {
  159. month = 12
  160. year = year - 1
  161. } else {
  162. month = month - 1
  163. }
  164. let date = new Date()
  165. date.setFullYear(year)
  166. date.setMonth(month)
  167. date.setDate(1)
  168. return date.getDay()
  169. },
  170. getactivityDate(year, month, mode) { //mode == 0 查询当月 mode == 1 查询当天
  171. let tempMonth = month
  172. let tempDey = this.getDays(year, month) //获取每月有多少天
  173. if (tempMonth < 10) {
  174. tempMonth = '0' + (tempMonth + '')
  175. }
  176. let param = {
  177. startDate: year + '-' + tempMonth + "-01" + " 00:00:00",
  178. endDate: year + "-" + tempMonth + "-" + tempDey + " 23:59:59"
  179. }
  180. Http.get({
  181. url: this.data.childUrl,
  182. data: param
  183. }).then(res => {
  184. let {
  185. code,
  186. data
  187. } = res
  188. if (code == 200) {
  189. this.setData({
  190. activityDateList: data
  191. })
  192. }
  193. })
  194. },
  195. front() { //前面
  196. if (this.data.month == 1) {
  197. let temp = this.data.switchFlag
  198. this.setData({
  199. switchFlag: false
  200. })
  201. this.setData({
  202. year: this.data.year - 1,
  203. month: 12
  204. })
  205. } else {
  206. this.setData({
  207. month: this.data.month - 1
  208. })
  209. }
  210. this.triggerEvent("setDate", {
  211. y: this.data.year,
  212. m: this.data.month
  213. }) //第一个是自定义事件名,第二个是要传递的值(可以为空)
  214. this.getDey()
  215. },
  216. behind() { //后面
  217. let temp = this.data.switchFlag
  218. this.setData({
  219. switchFlag: false
  220. })
  221. if (this.data.month == 12) {
  222. this.setData({
  223. year: this.data.year + 1,
  224. month: 1
  225. })
  226. this.showDate(this.data.year, this.data.month)
  227. } else {
  228. this.setData({
  229. month: this.data.month + 1
  230. })
  231. this.showDate(this.data.year, this.data.month)
  232. }
  233. this.getDey()
  234. this.triggerEvent("setDate", {
  235. y: this.data.year,
  236. m: this.data.month
  237. }) //第一个是自定义事件名,第二个是要传递的值(可以为空)
  238. },
  239. },
  240. lifetimes: {
  241. attached: function() {
  242. this.getDey() //查询当月活动
  243. // 设置单周数组
  244. let thenDey = new Date().getDay() //今天是周几
  245. let thenDate = new Date().getDate() //今天是多少号
  246. let tempArr = []
  247. if (thenDey == 0) {
  248. for (let i = 0; i < 7; i++) {
  249. tempArr.splice(i, 1, {
  250. thenFalg: "1",
  251. value: thenDate,
  252. style: "0",
  253. y: this.data.year,
  254. m: this.data.month
  255. })
  256. thenDate++
  257. }
  258. } else {
  259. let temp = new Date().getDay() //今天是周几
  260. let tmpeDey = new Date().getDate() //今天是多少号
  261. for (let i = 0; i <= temp; i++) {
  262. tempArr.splice(i, 0, {
  263. style: "0",
  264. value: thenDate - thenDey,
  265. y: this.data.year,
  266. m: this.data.month
  267. })
  268. thenDey--
  269. }
  270. for (let i = temp + 1; i < 7; i++) {
  271. tmpeDey++
  272. tempArr.splice(i, 0, {
  273. style: "0",
  274. value: tmpeDey,
  275. y: this.data.year,
  276. m: this.data.month
  277. })
  278. }
  279. }
  280. this.setData({
  281. thendata: tempArr
  282. })
  283. // 设置单周数组
  284. // setTimeout(() => {
  285. // this.showDate(this.data.year, this.data.month)
  286. // }, 300)
  287. },
  288. detached: function() {
  289. // 在组件实例被从页面节点树移除时执行
  290. },
  291. },
  292. })