selectDate_two.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. var app = getApp()
  2. var that,yearIndex;
  3. // 设置默认年份
  4. app.globalData.yearArr.forEach((item,index)=>{
  5. if(item==app.globalData.year){
  6. yearIndex=index
  7. }
  8. })
  9. Component({
  10. mixins: [],
  11. data: {
  12. dateIndex: "1",
  13. year: app.globalData.year,//年
  14. month: app.globalData.month,//月
  15. jdYear: app.globalData.year,//季度年
  16. jdji: 0,//季度季
  17. jdArr: ['一季度', '二季度', '三季度', '四季度'],
  18. yearIndex:yearIndex,
  19. yearArr:app.globalData.yearArr,
  20. jdYearIndex:yearIndex,
  21. },
  22. props: {
  23. onClose: (data) => console.log(data),
  24. onConfirm: (data) => console.log(data),
  25. dateObj:{
  26. type:'3',
  27. date:app.globalData.month
  28. },
  29. },
  30. didMount() {
  31. this.setData({
  32. isShow: this.props.isShow,
  33. })
  34. if(this.props.dateObj.type){
  35. this.setData({
  36. dateIndex:this.props.dateObj.type,
  37. })
  38. if(this.props.dateObj.type==1){
  39. this.data.yearArr.forEach((item,index)=>{
  40. if(this.props.dateObj.date==item){
  41. this.setData({
  42. yearIndex:index,
  43. })
  44. }
  45. })
  46. }else if(this.props.dateObj.type==2){
  47. var data=String(this.props.dateObj.date);
  48. this.data.yearArr.forEach((item,index)=>{
  49. if(data.substr(0,4)==item){
  50. this.setData({
  51. jdYearIndex:index,
  52. })
  53. }
  54. })
  55. this.setData({
  56. jdji:data.substr(data.length-1,1)-1
  57. })
  58. }else{
  59. this.setData({
  60. month:this.props.dateObj.date,
  61. })
  62. }
  63. }
  64. },
  65. didUpdate() { },
  66. didUnmount() { },
  67. methods: {
  68. selectYear2(e) {
  69. this.setData({
  70. jdYearIndex: e.detail.value,
  71. });
  72. },
  73. selectYear(e) {
  74. this.setData({
  75. yearIndex: e.detail.value,
  76. });
  77. },
  78. setjdji(e) {
  79. this.setData({
  80. jdji: e.detail.value,
  81. });
  82. },
  83. onConfirm() {
  84. var obj;
  85. switch (this.data.dateIndex) {
  86. case "1":
  87. obj = {
  88. type: this.data.dateIndex,
  89. date: this.data.yearArr[this.data.yearIndex]
  90. }
  91. break
  92. case "2":
  93. var year=this.data.yearArr[this.data.jdYearIndex];
  94. var num=this.data.jdji;
  95. num++;
  96. let arrNew=new Array()
  97. arrNew.push(year)
  98. arrNew.push(num)
  99. let strNew=arrNew.join('')
  100. obj = {
  101. type: this.data.dateIndex,
  102. date:parseInt(strNew)
  103. }
  104. break
  105. case "3":
  106. obj = {
  107. type: this.data.dateIndex,
  108. date: this.data.month
  109. }
  110. break
  111. };
  112. this.props.onConfirm(obj);
  113. this.props.onClose();
  114. },
  115. onClose() {
  116. this.props.onClose();
  117. },
  118. selectDay() {
  119. dd.datePicker({
  120. format: 'yyyy',
  121. currentDate: this.data.jdYear,
  122. success: (res) => {
  123. this.setData({
  124. jdYear: res.date
  125. })
  126. },
  127. });
  128. },
  129. selectDay2() {
  130. },
  131. selectDate() {
  132. dd.datePicker({
  133. format: 'yyyy-MM',
  134. currentDate: this.data.month,
  135. success: (res) => {
  136. this.setData({
  137. month: res.date
  138. })
  139. },
  140. });
  141. },
  142. activeDate(e) {
  143. this.setData({ dateIndex: e.target.dataset.index })
  144. },
  145. },
  146. });