C端小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

366 Zeilen
9.8 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. activiyFalg:"",
  31. context: -1 ,//-1表示取一周下标 1表示取一个月的下标
  32. },
  33. /**
  34. * 组件的方法列表
  35. */
  36. methods: {
  37. itiActivityLst() { //初始哈活动列表
  38. let tempDateLsit = this.data.dateLsit
  39. let tempThenData = this.data.thendata
  40. this.data.activityDateList.map(item0 => { //初始化当月 标记
  41. tempDateLsit.map(item1 => {
  42. if (item0.yyyy == item1.y && item0.mm == item1.m && item0.dd == item1.value) {
  43. item1.act = 1
  44. }
  45. })
  46. })
  47. this.data.activityDateList.map(item0 => { //初始化 当周标记
  48. tempThenData.map(item1 => {
  49. if (item0.yyyy == item1.y && item0.mm == item1.m && item0.dd == item1.value) {
  50. item1.act = 1
  51. }
  52. })
  53. })
  54. this.setData({
  55. dateLsit: tempDateLsit,
  56. thendata: tempThenData
  57. })
  58. this.setThenDye(0)
  59. },
  60. getDey() { //查询当月标记日期
  61. let tempMonth = this.data.month
  62. let tempDey = this.getDays(this.data.year, this.data.month) //获取每月有多少天
  63. if (tempMonth < 10) {
  64. tempMonth = '0' + (tempMonth + '')
  65. }
  66. let param = {
  67. startDate: this.data.year + '-' + tempMonth + "-01" + " 00:00:00",
  68. endDate: this.data.year + "-" + tempMonth + "-" + tempDey + " 23:59:59"
  69. }
  70. Http.get({
  71. url: this.data.childUrl,
  72. data: param
  73. }).then(res => {
  74. let {
  75. code,
  76. data
  77. } = res
  78. if (code == 200) {
  79. this.setData({
  80. activityDateList: data
  81. })
  82. this.showDate(this.data.year, this.data.month)
  83. }
  84. })
  85. },
  86. switchs() {
  87. let temp = this.data.switchFlag
  88. this.setData({
  89. switchFlag: !temp
  90. })
  91. if(this.data.switchFlag){
  92. this.setData({
  93. context:-1
  94. })
  95. this.setThenDye()
  96. }else{
  97. this.setData({
  98. context: 1
  99. })
  100. this.setThenDye()
  101. }
  102. // console.log(this.data.switchFlag)
  103. },
  104. showDate(year, month) { //刷新日历
  105. let thenDey = this.getThenWeek(year, month) //每个月第一天星期几
  106. let thenMonth = this.getDays(year, month) //获取每月有多少天
  107. let lastMonth = this.getLastMonth(year, month) //上月最后一天是多少天
  108. let tempDey = []
  109. let tmepArr = []
  110. for (let i = 0; i < 42; i++) { //初始化日历数组
  111. tempDey.splice(i, 0, "")
  112. }
  113. for (let i = 0; i < thenMonth; i++) { //获取当前选中月份天数
  114. tmepArr.splice(i, 0, {
  115. style: "0",
  116. value: i + 1,
  117. y: year,
  118. m: month
  119. })
  120. }
  121. tempDey.splice(thenDey, thenMonth, ...tmepArr)
  122. for (let i = 0; i < thenDey; i++) { //添加上一个月的天数
  123. tempDey.splice(i, 1, {
  124. style: "1",
  125. value: lastMonth - (thenDey - 1),
  126. y: year,
  127. m: month==1?12:month-1
  128. })
  129. lastMonth++
  130. }
  131. for (let i = 0; i < 42 - (thenDey + thenMonth); i++) { //设置下一个月
  132. tempDey.splice(thenDey + thenMonth + i, 1, {
  133. style: "2",
  134. value: i + 1,
  135. y: year,
  136. m: month == 12 ? 1 : month + 1
  137. })
  138. }
  139. this.setData({
  140. dateLsit: tempDey
  141. })
  142. this.itiActivityLst()
  143. this.setThenDye()
  144. },
  145. setThenDye(){//设置当天index
  146. if (this.data.context==-1){//-1表示一周
  147. console.log(this.data.thendata,this.data.dey,this.data.monthFlgh,this.data.yearFlgh,"this.data.thendata")
  148. let index_ = ""
  149. this.data.thendata.map((item,index)=>{
  150. if(item.value == this.data.dey && this.data.monthFlgh == item.m && item.y == this.data.yearFlgh){
  151. index_ = index
  152. this.setData({
  153. activiyFalg: index_
  154. })
  155. return
  156. }
  157. })
  158. }else{
  159. let index_ = ""
  160. if(this.data.year==this.data.yearFlgh&&this.data.month==this.data.monthFlgh){
  161. this.data.dateLsit.map((item, index) => {
  162. if (item.value == this.data.dey && this.data.monthFlgh == item.m && item.y == this.data.yearFlgh) {
  163. console.log(index, "index")
  164. index_ = index
  165. this.setData({
  166. activiyFalg: index_
  167. })
  168. return
  169. }
  170. })
  171. }else{
  172. this.setData({
  173. activiyFalg: -1
  174. })
  175. }
  176. }
  177. },
  178. handle(e) { //点击号数
  179. let item = e.currentTarget.dataset.item
  180. let index = e.currentTarget.dataset.index
  181. if (this.data.allFlag){
  182. this.setData({
  183. activiyFalg:index
  184. })
  185. }
  186. if (item.style==0){
  187. this.triggerEvent("setDate", {
  188. y: this.data.year,
  189. m: this.data.month,
  190. value: item.value
  191. })
  192. }else{
  193. return
  194. }
  195. },
  196. getDays(year, month) { //获取每月有多少天
  197. let tempDateArr = []
  198. let thenDate = new Date(year, month, 0).getDate()
  199. return thenDate
  200. },
  201. getLastMonth(year, month) { //上一个月最后一天是多少号
  202. if (month == 1) {
  203. month = 12
  204. year = year - 1
  205. } else {
  206. month = month - 1
  207. }
  208. let tempDateArr = []
  209. let thenDate = new Date(year, month, 0).getDate()
  210. return thenDate
  211. },
  212. getThenWeek(year, month) { //获取每个月第一天是星期几
  213. if (month == 1) {
  214. month = 12
  215. year = year - 1
  216. } else {
  217. month = month - 1
  218. }
  219. let date = new Date()
  220. date.setFullYear(year)
  221. date.setMonth(month)
  222. date.setDate(1)
  223. return date.getDay()
  224. },
  225. getactivityDate(year, month, mode) { //mode == 0 查询当月 mode == 1 查询当天
  226. let tempMonth = month
  227. let tempDey = this.getDays(year, month) //获取每月有多少天
  228. if (tempMonth < 10) {
  229. tempMonth = '0' + (tempMonth + '')
  230. }
  231. let param = {
  232. startDate: year + '-' + tempMonth + "-01" + " 00:00:00",
  233. endDate: year + "-" + tempMonth + "-" + tempDey + " 23:59:59"
  234. }
  235. Http.get({
  236. url: this.data.childUrl,
  237. data: param
  238. }).then(res => {
  239. let {
  240. code,
  241. data
  242. } = res
  243. if (code == 200) {
  244. this.setData({
  245. activityDateList: data
  246. })
  247. }
  248. })
  249. },
  250. front() { //前面
  251. this.setData({
  252. context:1
  253. })
  254. if (this.data.month == 1) {
  255. let temp = this.data.switchFlag
  256. this.setData({
  257. switchFlag: false
  258. })
  259. this.setData({
  260. year: this.data.year - 1,
  261. month: 12
  262. })
  263. } else {
  264. this.setData({
  265. month: this.data.month - 1
  266. })
  267. }
  268. this.triggerEvent("setDate", {
  269. y: this.data.year,
  270. m: this.data.month
  271. }) //第一个是自定义事件名,第二个是要传递的值(可以为空)
  272. this.getDey()
  273. },
  274. behind() { //后面
  275. this.setData({
  276. context: 1
  277. })
  278. let temp = this.data.switchFlag
  279. this.setData({
  280. switchFlag: false
  281. })
  282. if (this.data.month == 12) {
  283. this.setData({
  284. year: this.data.year + 1,
  285. month: 1
  286. })
  287. this.showDate(this.data.year, this.data.month)
  288. } else {
  289. this.setData({
  290. month: this.data.month + 1
  291. })
  292. this.showDate(this.data.year, this.data.month)
  293. }
  294. this.getDey()
  295. this.triggerEvent("setDate", {
  296. y: this.data.year,
  297. m: this.data.month
  298. })
  299. },
  300. },
  301. lifetimes: {
  302. attached: function() {
  303. this.getDey() //查询当月活动
  304. // 设置单周数组
  305. let thenDey = new Date().getDay() //今天是周几
  306. let thenDate = new Date().getDate() //今天是多少号
  307. let tempArr = []
  308. if (thenDey == 0) {
  309. for (let i = 0; i < 7; i++) {
  310. tempArr.splice(i, 1, {
  311. thenFalg: "1",
  312. value: thenDate,
  313. style: "0",
  314. y: this.data.year,
  315. m: this.data.month
  316. })
  317. thenDate++
  318. }
  319. } else {
  320. let temp = new Date().getDay() //今天是周几
  321. let tmpeDey = new Date().getDate() //今天是多少号
  322. for (let i = 0; i <= temp; i++) {
  323. tempArr.splice(i, 0, {
  324. style: "0",
  325. value: thenDate - thenDey,
  326. y: this.data.year,
  327. m: this.data.month
  328. })
  329. thenDey--
  330. }
  331. for (let i = temp + 1; i < 7; i++) {
  332. tmpeDey++
  333. tempArr.splice(i, 0, {
  334. style: "0",
  335. value: tmpeDey,
  336. y: this.data.year,
  337. m: this.data.month
  338. })
  339. }
  340. }
  341. this.setData({
  342. thendata: tempArr,
  343. context:this.data.allFlag ? -1 : 1
  344. })
  345. // 设置单周数组
  346. // setTimeout(() => {
  347. // this.showDate(this.data.year, this.data.month)
  348. // }, 300)
  349. },
  350. detached: function() {
  351. // 在组件实例被从页面节点树移除时执行
  352. },
  353. },
  354. })