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.

297 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. xiangshang: imgurl.xiangshang.url,
  28. switchFlag: true,
  29. activityDateList: []
  30. },
  31. /**
  32. * 组件的方法列表
  33. */
  34. methods: {
  35. itiActivityLst() { //初始哈活动列表
  36. let tempDateLsit = this.data.dateLsit
  37. let tempThenData = this.data.thendata
  38. this.data.activityDateList.map(item0 => { //初始化当月 标记
  39. tempDateLsit.map(item1 => {
  40. if (item0.yyyy == item1.y && item0.mm == item1.m && item0.dd == item1.value) {
  41. item1.act = 1
  42. }
  43. })
  44. })
  45. this.data.activityDateList.map(item0 => { //初始化 当周标记
  46. tempThenData.map(item1 => {
  47. if (item0.yyyy == item1.y && item0.mm == item1.m && item0.dd == item1.value) {
  48. item1.act = 1
  49. }
  50. })
  51. })
  52. this.setData({
  53. dateLsit: tempDateLsit,
  54. thendata: tempThenData
  55. })
  56. },
  57. getDey() { //查询当月标记日期
  58. let tempMonth = this.data.month
  59. let tempDey = this.getDays(this.data.year, this.data.month) //获取每月有多少天
  60. if (tempMonth < 10) {
  61. tempMonth = '0' + (tempMonth + '')
  62. }
  63. let param = {
  64. startDate: this.data.year + '-' + tempMonth + "-01" + " 00:00:00",
  65. endDate: this.data.year + "-" + tempMonth + "-" + tempDey + " 23:59:59"
  66. }
  67. Http.get({
  68. url: this.data.childUrl,
  69. data: param
  70. }).then(res => {
  71. let {
  72. code,
  73. data
  74. } = res
  75. if (code == 200) {
  76. this.setData({
  77. activityDateList: data
  78. })
  79. this.showDate(this.data.year, this.data.month)
  80. }
  81. })
  82. },
  83. switchs() {
  84. let temp = this.data.switchFlag
  85. this.setData({
  86. switchFlag: !temp
  87. })
  88. },
  89. showDate(year, month) { //刷新日历
  90. let thenDey = this.getThenWeek(year, month) //每个月第一天星期几
  91. let thenMonth = this.getDays(year, month) //获取每月有多少天
  92. let lastMonth = this.getLastMonth(year, month) //上月最后一天是多少天
  93. let tempDey = []
  94. let tmepArr = []
  95. for (let i = 0; i < 42; i++) { //初始化日历数组
  96. tempDey.splice(i, 0, "")
  97. }
  98. for (let i = 0; i < thenMonth; i++) { //获取当前选中月份天数
  99. tmepArr.splice(i, 0, {
  100. style: "0",
  101. value: i + 1,
  102. y: year,
  103. m: month
  104. })
  105. }
  106. tempDey.splice(thenDey, thenMonth, ...tmepArr)
  107. for (let i = 0; i < thenDey; i++) { //添加上一个月的天数
  108. tempDey.splice(i, 1, {
  109. style: "1",
  110. value: lastMonth - (thenDey - 1),
  111. y: year,
  112. m: month - 1
  113. })
  114. lastMonth++
  115. }
  116. for (let i = 0; i < 42 - (thenDey + thenMonth); i++) { //设置下一个月
  117. tempDey.splice(thenDey + thenMonth + i, 1, {
  118. style: "2",
  119. value: i + 1,
  120. y: year,
  121. m: month + 1
  122. })
  123. }
  124. this.setData({
  125. dateLsit: tempDey
  126. })
  127. this.itiActivityLst()
  128. },
  129. handle(e) { //点击号数
  130. let item = e.currentTarget.dataset.item
  131. if (item.style==0){
  132. this.triggerEvent("setDate", {
  133. y: this.data.year,
  134. m: this.data.month,
  135. value: item.value
  136. })
  137. }else{
  138. return
  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. })