selectDate_two.js 3.4 KB

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