select_times.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. hiddenModel:false,
  18. list:[
  19. ]
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. const {type}=options
  26. wx.setNavigationBarTitle({
  27. title: `${type == 1 ? '选择寒假放假时间' : type == 2 ? '选择五一放假时间' : type == 3 ? '选择暑假放假时间' :'选择国庆放假时间'}`,
  28. })
  29. console.log(options)
  30. this.setData(options)
  31. this.selectDay()
  32. },
  33. /**
  34. * 生命周期函数--监听页面初次渲染完成
  35. */
  36. onReady: function () {
  37. },
  38. /**
  39. * 生命周期函数--监听页面显示
  40. */
  41. onShow: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面隐藏
  45. */
  46. onHide: function () {
  47. console.log('监听页面隐藏')
  48. },
  49. /**
  50. * 生命周期函数--监听页面卸载
  51. */
  52. onUnload: function () {
  53. console.log('监听页面卸载')
  54. },
  55. /**
  56. * 页面相关事件处理函数--监听用户下拉动作
  57. */
  58. onPullDownRefresh: function () {
  59. },
  60. /**
  61. * 页面上拉触底事件的处理函数
  62. */
  63. onReachBottom: function () {
  64. },
  65. /**
  66. * 用户点击右上角分享
  67. */
  68. onShareAppMessage: function () {
  69. },
  70. /**
  71. * 提示框隐藏
  72. */
  73. allShowModel: function () {
  74. this.setData({ hiddenModel: false})
  75. },
  76. /**
  77. * 提示框弹出
  78. */
  79. childShowModel: function () {
  80. this.setData({ hiddenModel: true })
  81. },
  82. /**
  83. * 设置节假日时间
  84. */
  85. sureVacationSetSave: function (cb) {
  86. const continuousFn = { fn: this.sureVacationSetSave, param: { ...arguments } }
  87. const { startDate, endDate, setState,id,type } = this.data;
  88. // 判断不能超出七天
  89. const startTimestamp = new Date(startDate).getTime();
  90. const endTimestamp = new Date(endDate).getTime();
  91. if (type==2||type==4){
  92. if ((endTimestamp - startTimestamp) > 7 * 24 * 60 * 60 * 1000) {
  93. wx.showToast({
  94. title: '假期范围不能超过一周',
  95. icon: 'none'
  96. })
  97. return;
  98. }
  99. }
  100. if ((endTimestamp - startTimestamp) <0){
  101. wx.showToast({
  102. title: '结束时间不能早于开始时间',
  103. icon: 'none'
  104. })
  105. return;
  106. }
  107. console.log(startDate, endDate,setState,id)
  108. VacationSetSave({ data: { startDate, endDate, setState:Number(setState), id }, continuousFn }).then(res => {
  109. wx.showToast({
  110. title: '保存成功',
  111. icon: 'none'
  112. })
  113. wx.navigateBack({})
  114. // this.setData({ isSelectTime:true})
  115. if (isFn(cb)) cb()
  116. }).catch(res => {
  117. if (isFn(cb)) cb()
  118. })
  119. },
  120. /**
  121. * 设置开关
  122. */
  123. selectDay:function(){
  124. const { startDate, endDate,list,btnIndex,id, type, istype,time,index }=this.data;
  125. // var temp = {};
  126. // temp[`startDate`] = list[index].startDate;
  127. // temp[`endDate`] = list[index].endDate;
  128. // this.setData(temp)
  129. const today = new Date().getTime();
  130. if(time){
  131. var start = new Date(time).getTime();
  132. }else{
  133. var start = new Date().getTime();
  134. }
  135. var timestamp = Date.parse(new Date());
  136. var date = new Date(timestamp);
  137. if(btnIndex==1){
  138. var year = date.getFullYear()+1;
  139. }else{
  140. var year = date.getFullYear();
  141. }
  142. if (istype == 1 && (start - today) < 0 || (start - today)==0&&!time){
  143. if(type==1){
  144. this.setData({
  145. star: year + '-' + '01' + '-' +'01',
  146. end: year + '-' + '02' + '-' + 28,
  147. })
  148. } else if (type == 2){
  149. this.setData({
  150. star: year + '-' + '04' + '-' + '01',
  151. end: year + '-' + '05' + '-' + 31,
  152. })
  153. } else if (type == 3) {
  154. this.setData({
  155. star: year + '-' + '07' + '-' + '01',
  156. end: year + '-' + '08' + '-' + 31,
  157. })
  158. } else if (type == 4) {
  159. this.setData({
  160. star: year + '-' + '09' + '-' + '01',
  161. end: year + '-' + 10 + '-' + 31,
  162. })
  163. }
  164. this.setData({setState: istype == 1 ? '2' : '1'})
  165. }else{
  166. this.setData({setState: istype == 1 ? '2' : '1'})
  167. this.sureVacationSetSave()
  168. }
  169. },
  170. /**
  171. * 选择开始时间
  172. */
  173. selectStartDate: function (e) {
  174. const { endDate} = this.data;
  175. const end = new Date(endDate).getTime();
  176. const today = new Date().getTime();
  177. const start = new Date(e.detail.value).getTime();
  178. if ((start - today) < 0) {
  179. wx.showToast({
  180. title: '开始时间不能早于今天',
  181. icon: 'none'
  182. })
  183. return;
  184. }
  185. if ((start-end) >0) {
  186. wx.showToast({
  187. title: '开始时间不能大于结束时间',
  188. icon: 'none'
  189. })
  190. return;
  191. }
  192. this.setData({
  193. startDate: e.detail.value
  194. })
  195. },
  196. /**
  197. * 选择结束时间
  198. */
  199. selectEndDate: function (e) {
  200. const { startDate} = this.data;
  201. const start = new Date(startDate).getTime();
  202. const end = new Date(e.detail.value).getTime();
  203. if ((end - start) < 0) {
  204. wx.showToast({
  205. title: '结束时间不能早于开始时间',
  206. icon: 'none'
  207. })
  208. return;
  209. }
  210. this.setData({
  211. endDate: e.detail.value
  212. })
  213. },
  214. })