set_time.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. // pages/set_time/set_time.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber } from '../../utils/util.js'
  3. import { VacationSetSave, VacationList } from '../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, saveUserInfo, getWxloginCode, checkStatus } = getApp()
  6. const { baseImgUrl, thumbnail } = globalData
  7. const app = getApp()
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. isSelectTime:true,
  14. startDate:'',
  15. endDate:'',
  16. btnIndex:0,
  17. btnList:['今年','明年'],
  18. list:[
  19. // {
  20. // libId: "xxxxx",
  21. // id: "sssss",
  22. // type: 1,
  23. // endDate: "2020--01-24",
  24. // startDate: "2020--02-24",
  25. // setState: 1,
  26. // limitMsg:'5555'
  27. // },
  28. // {
  29. // libId: "xxxxx",
  30. // id: "sssss",
  31. // type: 2,
  32. // endDate: "2020--01-24",
  33. // startDate: "2020--02-24",
  34. // setState: 2,
  35. // limitMsg: '5555'
  36. // },
  37. // {
  38. // libId: "xxxxx",
  39. // id: "sssss",
  40. // type: 3,
  41. // endDate: "2020--01-24",
  42. // startDate: "2020--02-24",
  43. // setState: 1,
  44. // limitMsg: '5555'
  45. // },
  46. // {
  47. // libId: "xxxxx",
  48. // id: "sssss",
  49. // type: 4,
  50. // endDate: "2020--01-24",
  51. // startDate: "2020--02-24",
  52. // setState: 2,
  53. // limitMsg: '5555'
  54. // },
  55. ]
  56. },
  57. /**
  58. * 生命周期函数--监听页面加载
  59. */
  60. onLoad: function (options) {
  61. this.setData(options)
  62. },
  63. /**
  64. * 生命周期函数--监听页面初次渲染完成
  65. */
  66. onReady: function () {
  67. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  68. for (const i in obj) {
  69. this[i] = obj[i]
  70. }
  71. },
  72. /**
  73. * 生命周期函数--监听页面显示
  74. */
  75. onShow: function () {
  76. this.sureVacationList()
  77. },
  78. /**
  79. * 生命周期函数--监听页面隐藏
  80. */
  81. onHide: function () {
  82. },
  83. /**
  84. * 生命周期函数--监听页面卸载
  85. */
  86. onUnload: function () {
  87. },
  88. /**
  89. * 页面相关事件处理函数--监听用户下拉动作
  90. */
  91. onPullDownRefresh: function () {
  92. },
  93. /**
  94. * 页面上拉触底事件的处理函数
  95. */
  96. onReachBottom: function () {
  97. },
  98. /**
  99. * 用户点击右上角分享
  100. */
  101. onShareAppMessage: function () {
  102. },
  103. /**
  104. * 选择年份
  105. */
  106. selectYear:function(e){
  107. const { idx } = e.currentTarget.dataset;
  108. this.setData({btnIndex:idx})
  109. this.sureVacationList()
  110. },
  111. /**
  112. * 获取假期
  113. */
  114. sureVacationList: function (cb) {
  115. const continuousFn = { fn: this.sureVacationList, param: { ...arguments } }
  116. const { libId,btnIndex} = this.data;
  117. console.log(btnIndex)
  118. VacationList({ data: { libId,type:btnIndex}, continuousFn }).then(res => {
  119. const {list}=res.data;
  120. this.setData({list})
  121. if (isFn(cb)) cb()
  122. }).catch(res => {
  123. if (isFn(cb)) cb()
  124. })
  125. },
  126. /**
  127. * 设置节假日时间
  128. */
  129. sureVacationSetSave: function (cb) {
  130. const continuousFn = { fn: this.sureVacationSetSave, param: { ...arguments } }
  131. const { startDate, endDate, setState,id,type } = this.data;
  132. // 判断不能超出七天
  133. const startTimestamp = new Date(startDate).getTime();
  134. const endTimestamp = new Date(endDate).getTime();
  135. if (type==2||type==4){
  136. if ((endTimestamp - startTimestamp) > 7 * 24 * 60 * 60 * 1000) {
  137. wx.showToast({
  138. title: '查询范围不能超过一周',
  139. icon: 'none'
  140. })
  141. return;
  142. }
  143. }
  144. if ((endTimestamp - startTimestamp) <0){
  145. wx.showToast({
  146. title: '结束时间不能早于开始时间',
  147. icon: 'none'
  148. })
  149. return;
  150. }
  151. console.log(startDate, endDate,setState,id)
  152. VacationSetSave({ data: { startDate, endDate, setState:Number(setState), id }, continuousFn }).then(res => {
  153. wx.showToast({
  154. title: '保存成功',
  155. icon: 'none'
  156. })
  157. this.sureVacationList()
  158. // this.setData({ isSelectTime:true})
  159. if (isFn(cb)) cb()
  160. }).catch(res => {
  161. if (isFn(cb)) cb()
  162. })
  163. },
  164. /**
  165. * 设置开关
  166. */
  167. selectDay:function(e){
  168. const { startDate, endDate,list,btnIndex}=this.data;
  169. console.log(e)
  170. const { id, type, istype,time,index } = e.currentTarget.dataset.paras;
  171. var temp = {};
  172. temp[`startDate`] = list[index].startDate;
  173. temp[`endDate`] = list[index].endDate;
  174. this.setData(temp)
  175. const today = new Date().getTime();
  176. if(time){
  177. var start = new Date(time).getTime();
  178. }else{
  179. var start = new Date().getTime();
  180. }
  181. var timestamp = Date.parse(new Date());
  182. var date = new Date(timestamp);
  183. if(btnIndex==1){
  184. var year = date.getFullYear()+1;
  185. }else{
  186. var year = date.getFullYear();
  187. }
  188. if (istype == 1 && (start - today) < 0 || (start - today)==0&&!time){
  189. if(type==1){
  190. this.setData({
  191. star: year + '-' + '01' + '-' +'01',
  192. end: year + '-' + '02' + '-' + 28,
  193. })
  194. } else if (type == 2){
  195. this.setData({
  196. star: year + '-' + '04' + '-' + '01',
  197. end: year + '-' + '05' + '-' + 31,
  198. })
  199. } else if (type == 3) {
  200. this.setData({
  201. star: year + '-' + '07' + '-' + '01',
  202. end: year + '-' + '08' + '-' + 31,
  203. })
  204. } else if (type == 4) {
  205. this.setData({
  206. star: year + '-' + '09' + '-' + '01',
  207. end: year + '-' + 10 + '-' + 31,
  208. })
  209. }
  210. this.setData({setState: istype == 1 ? '2' : '1',id, type,})
  211. }else{
  212. this.setData({setState: istype == 1 ? '2' : '1',id, type,})
  213. this.sureVacationSetSave()
  214. }
  215. },
  216. /**
  217. * 选择开始时间
  218. */
  219. selectStartDate: function (e) {
  220. const { endDate} = this.data;
  221. const end = new Date(endDate).getTime();
  222. const today = new Date().getTime();
  223. const start = new Date(e.detail.value).getTime();
  224. if ((start - today) < 0) {
  225. wx.showToast({
  226. title: '开始时间不能早于今天',
  227. icon: 'none'
  228. })
  229. return;
  230. }
  231. if ((start-end) >0) {
  232. wx.showToast({
  233. title: '开始时间不能大于结束时间',
  234. icon: 'none'
  235. })
  236. return;
  237. }
  238. this.setData({
  239. startDate: e.detail.value
  240. })
  241. },
  242. /**
  243. * 选择结束时间
  244. */
  245. selectEndDate: function (e) {
  246. const { startDate} = this.data;
  247. const start = new Date(startDate).getTime();
  248. const end = new Date(e.detail.value).getTime();
  249. if ((end - start) < 0) {
  250. wx.showToast({
  251. title: '结束时间不能早于开始时间',
  252. icon: 'none'
  253. })
  254. return;
  255. }
  256. this.setData({
  257. endDate: e.detail.value
  258. })
  259. },
  260. })