index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. let date = new Date()
  2. let times = []
  3. for (let i = 0 ; i < 15; i++) {
  4. let stamp = date.setDate(date.getDate()+ (i == 0 ? 0 : 1))
  5. let year = new Date(stamp).getFullYear()
  6. let month = new Date(stamp).getMonth()+1 < 10 ? '0'+(new Date(stamp).getMonth()+1) : new Date(stamp).getMonth()+1
  7. let day = new Date(stamp).getDate() < 10 ? '0'+new Date(stamp).getDate() : new Date(stamp).getDate()
  8. times.push(`${year+'-'+month+'-'+day}`)
  9. }
  10. import {
  11. get,
  12. } from '../../../../utils/http';
  13. Component({
  14. /**
  15. * 组件的属性列表
  16. */
  17. properties: {
  18. projectData: {
  19. type: Object,
  20. value: {},
  21. observer(newVal,oldVal) {
  22. if(newVal) {
  23. this.getTime().then(res => {
  24. this.triggerEvent("change",this.data.hours[0])
  25. })
  26. }
  27. }
  28. }
  29. },
  30. lifetimes: {
  31. attached: function() {
  32. },
  33. detached: function() {
  34. // 在组件实例被从页面节点树移除时执行
  35. },
  36. },
  37. /**
  38. * 组件的初始数据
  39. */
  40. data: {
  41. hours: [],
  42. times,
  43. day: 2,
  44. current: 0,
  45. value: [0,0],
  46. },
  47. /**
  48. * 组件的方法列表
  49. */
  50. methods: {
  51. bindChange: function (e) {
  52. const value = e.detail.value
  53. if(e.currentTarget.dataset.index != value[0]) {
  54. this.setData({ value: [e.detail.value[0],0],current:-0,hours: [] })
  55. this.getTime().then(res => {
  56. this.triggerEvent("change", this.data.hours[value[1]])
  57. })
  58. } else if(e.currentTarget.dataset.index == value[0]) {
  59. this.setData({
  60. current: value[1]
  61. })
  62. this.triggerEvent("change",this.data.hours[value[1]])
  63. }
  64. },
  65. /* 选择当前时间段 */
  66. onChangeHours(e) {
  67. if(this.data.hours[e.currentTarget.dataset.index].status == 0) {
  68. return;
  69. }
  70. this.setData({
  71. current: e.currentTarget.dataset.index
  72. })
  73. this.triggerEvent("change",this.data.hours[e.currentTarget.dataset.index])
  74. },
  75. /* 获取可预约时间 */
  76. // api/project/time
  77. getTime() {
  78. let { times,value } = this.data;
  79. return new Promise((resolve,reject) => {
  80. get('api/project/time',{
  81. store_id: this.data.projectData.store_id,
  82. project_id: this.data.projectData.id,
  83. order_day: times[value[0]]
  84. },(res) => {
  85. this.setData({
  86. hours: res.data
  87. })
  88. resolve(res)
  89. })
  90. })
  91. }
  92. },
  93. })