运维小程序
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.

index.js 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. // pages/scheduling/index.js
  2. const api = require('../../api/index.js');
  3. const timestamp = require("../../utils/util.js")
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. visible:false,
  10. current: [],
  11. options: [],
  12. userdata:[],
  13. value:'',
  14. minDate: new Date(2022, 0, 10).getTime(),
  15. maxDate: new Date(2027, 10, 27).getTime(),
  16. format(day) {
  17. const { date } = day;
  18. const year = date.getFullYear();
  19. const month = date.getMonth() + 1;
  20. const curDate = date.getDate();
  21. // 农历月份名称
  22. const lunarMonths = ['正月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '冬月', '腊月'];
  23. // 农历日期名称
  24. const lunarDays = [
  25. '初一', '初二', '初三', '初四', '初五', '初六', '初七', '初八', '初九', '初十',
  26. '十一', '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九', '二十',
  27. '廿一', '廿二', '廿三', '廿四', '廿五', '廿六', '廿七', '廿八', '廿九', '三十'
  28. ];
  29. // 阳历节日映射
  30. const solarFestivals = {
  31. '1-1': '元旦',
  32. '2-14': '情人节',
  33. '3-8': '妇女节',
  34. '4-1': '愚人节',
  35. '5-1': '劳动节',
  36. '6-1': '儿童节',
  37. '9-10': '教师节',
  38. '10-1': '国庆节',
  39. '12-24': '平安夜',
  40. '12-25': '圣诞节'
  41. };
  42. // 农历节日映射(需要根据具体年份计算,这里简化处理)
  43. const lunarFestivals = {
  44. '正月-初一': '春节',
  45. '正月-十五': '元宵',
  46. '五月-初五': '端午',
  47. '七月-初七': '七夕',
  48. '八月-十五': '中秋',
  49. '九月-初九': '重阳',
  50. '腊月-三十': '除夕'
  51. };
  52. // 节气映射(简化版)
  53. const solarTerms = {
  54. '2-4': '立春', '2-19': '雨水',
  55. '3-5': '惊蛰', '3-20': '春分',
  56. '4-5': '清明', '4-20': '谷雨',
  57. '5-5': '立夏', '5-21': '小满',
  58. '6-6': '芒种', '6-21': '夏至',
  59. '7-7': '小暑', '7-23': '大暑',
  60. '8-8': '立秋', '8-23': '处暑',
  61. '9-8': '白露', '9-23': '秋分',
  62. '10-8': '寒露', '10-23': '霜降',
  63. '11-7': '立冬', '11-22': '小雪',
  64. '12-7': '大雪', '12-22': '冬至'
  65. };
  66. // 计算农历日期(简化算法)
  67. const lunarMonthIndex = (month - 1 + Math.floor(curDate / 15)) % 12;
  68. const lunarDayIndex = (curDate - 1) % 30;
  69. let lunarDate = lunarDays[lunarDayIndex];
  70. const lunarMonth = lunarMonths[lunarMonthIndex];
  71. // 如果是初一,显示月份
  72. if (lunarDayIndex === 0) {
  73. lunarDate = lunarMonth;
  74. }
  75. // 设置农历显示
  76. day.prefix = lunarDate;
  77. // 检查阳历节日
  78. const solarFestivalKey = `${month}-${curDate}`;
  79. if (solarFestivalKey in solarFestivals) {
  80. day.suffix = solarFestivals[solarFestivalKey];
  81. day.className = 'is-solar-festival';
  82. }
  83. // 检查农历节日
  84. const lunarFestivalKey = `${lunarMonth}-${lunarDays[lunarDayIndex]}`;
  85. if (lunarFestivalKey in lunarFestivals) {
  86. day.suffix = lunarFestivals[lunarFestivalKey];
  87. day.className = 'is-lunar-festival';
  88. }
  89. // 检查节气
  90. if (solarFestivalKey in solarTerms) {
  91. day.suffix = solarTerms[solarFestivalKey];
  92. day.className = 'is-solar-term';
  93. }
  94. // 周末样式
  95. if (date.getDay() === 0 || date.getDay() === 6) {
  96. day.className = (day.className || '') + ' is-weekend';
  97. }
  98. // 今天日期样式
  99. const today = new Date();
  100. if (year === today.getFullYear() &&
  101. month === today.getMonth() + 1 &&
  102. curDate === today.getDate()) {
  103. day.className = (day.className || '') + ' is-today';
  104. }
  105. return day;
  106. },
  107. selectschedudata:[],
  108. partnerPosition:wx.getStorageSync('partnerPosition').partnerPosition
  109. },
  110. // day.suffix = '¥100';
  111. /**
  112. * 生命周期函数--监听页面加载
  113. */
  114. onLoad(options) {
  115. this.getuser()
  116. const currentTimestamp = Date.now();
  117. this.setData({
  118. value:currentTimestamp,
  119. valuename:timestamp.timestamp(currentTimestamp)
  120. })
  121. this.getdatetime()
  122. },
  123. // 查询人员
  124. getuser(){
  125. let data = {
  126. partnerName:'',
  127. partnerPhone:'',
  128. partnerType:''
  129. }
  130. api.request(`/partner/selectinformationall`, 'POST',data)
  131. .then((res) => {
  132. console.log(res);
  133. const positionMap = { 1: '值班员', 2: '值长', 3: '站长', 4: '董事长' };
  134. const transformedData = res.data.map(item => ({
  135. label: item.partnerName,
  136. value: item.partnerId,
  137. content: positionMap[item.partnerPosition] || item.partnerPosition,
  138. ...item
  139. }));
  140. console.log(transformedData);
  141. this.setData({
  142. options:transformedData
  143. })
  144. })
  145. .catch((err) => {
  146. console.error('请求失败:', err);
  147. // 在这里处理请求失败的情况
  148. });
  149. },
  150. handleSelect(e) {
  151. const { value } = e.detail;
  152. this.setData({
  153. value:value,
  154. valuename:timestamp.timestamp(value)
  155. })
  156. console.log(value);
  157. this.getdatetime()
  158. },
  159. handleConfirm(e) {
  160. this.setData({ value: e.detail.value });
  161. console.log(e.detail.value);
  162. },
  163. handlePanelChange(e) {
  164. const { year, month } = e.detail;
  165. console.log('year: ', year, 'month: ', month);
  166. },
  167. ondutyadd(){
  168. this.setData({
  169. visible:true
  170. })
  171. },
  172. onVisibleChange(){
  173. this.setData({
  174. visible:false
  175. })
  176. },
  177. handleGroupChange(event) {
  178. console.log('group', event.detail.value);
  179. this.setData({
  180. current: event.detail.value,
  181. });
  182. },
  183. // 查询日期
  184. getdatetime(){
  185. let data = {
  186. startdate:this.data.valuename,
  187. enddate:this.data.valuename,
  188. }
  189. api.request(`/scheduling/selectscheduling`, 'POST',data)
  190. .then((res) => {
  191. console.log(res);
  192. this.setData({
  193. selectschedudata:res.data
  194. })
  195. })
  196. .catch((err) => {
  197. console.error('请求失败:', err);
  198. // 在这里处理请求失败的情况
  199. });
  200. },
  201. onworkorder(){
  202. let data ={
  203. schedulingId:this.data.selectschedudata[0].id,
  204. partnerId:this.data.current.toString()
  205. }
  206. api.request(`/scheduling`, 'POST',data)
  207. .then((res) => {
  208. console.log(res);
  209. this.setData({
  210. visible:false
  211. })
  212. this.getdatetime()
  213. })
  214. .catch((err) => {
  215. console.error('请求失败:', err);
  216. // 在这里处理请求失败的情况
  217. });
  218. },
  219. /**
  220. * 生命周期函数--监听页面初次渲染完成
  221. */
  222. onReady() {
  223. },
  224. /**
  225. * 生命周期函数--监听页面显示
  226. */
  227. onShow() {
  228. },
  229. /**
  230. * 生命周期函数--监听页面隐藏
  231. */
  232. onHide() {
  233. },
  234. /**
  235. * 生命周期函数--监听页面卸载
  236. */
  237. onUnload() {
  238. },
  239. /**
  240. * 页面相关事件处理函数--监听用户下拉动作
  241. */
  242. onPullDownRefresh() {
  243. },
  244. /**
  245. * 页面上拉触底事件的处理函数
  246. */
  247. onReachBottom() {
  248. },
  249. /**
  250. * 用户点击右上角分享
  251. */
  252. onShareAppMessage() {
  253. }
  254. })