123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- var app = getApp()
- var that,yearIndex;
- // 设置默认年份
- app.globalData.yearArr.forEach((item,index)=>{
- if(item==app.globalData.year){
- yearIndex=index
- }
- })
- Component({
- mixins: [],
- data: {
- dateIndex: "1",
- day: app.globalData.day,//日
- year: app.globalData.year,//年
- month: app.globalData.month,//月
- jdYear: app.globalData.year,//季度年
- jdji: 0,//季度季
- jdArr: ['一季度', '二季度', '三季度', '四季度'],
- yearIndex:yearIndex,
- yearArr:app.globalData.yearArr,
- jdYearIndex:yearIndex,
- isShowArr:[true,true,true],
- showSelect:false,
- customIndOn: app.globalData.day,
- customIndTw: app.globalData.day,
- // custom: '',
- },
- props: {
- onClose: (data) => console.log(data),
- onConfirm: (data) => console.log(data),
- showSelectP:false,
- dateObj:{
- type:'3',
- date:app.globalData.month
- },
- },
- didMount() {
- this.setData({isShow: this.props.isShow,showSelect:this.props.showSelectP})
- if(this.props.dateObj.type){
- this.setData({
- dateIndex:this.props.dateObj.type,
- })
- if(this.props.dateObj.type==1){
- this.data.yearArr.forEach((item,index)=>{
- if(this.props.dateObj.date==item){
- this.setData({
- yearIndex:index,
- })
- }
- })
- }else if(this.props.dateObj.type==2){
- var data=String(this.props.dateObj.date);
- this.data.yearArr.forEach((item,index)=>{
- if(data.substr(0,4)==item){
- this.setData({
- jdYearIndex:index,
- })
- }
- })
- this.setData({
- jdji:data.substr(data.length-1,1)-1
- })
- }else if(this.props.dateObj.type==4){
- this.setData({
- customIndOn: this.props.dateObj.date.start_date,
- customIndTw: this.props.dateObj.date.end_date,
- })
- }else{
- this.setData({
- month:this.props.dateObj.date,
- })
- }
- }
- },
- didUpdate() { },
- didUnmount() { },
- methods: {
- selectYear2(e) {
- this.setData({
- jdYearIndex: e.detail.value,
- });
- },
- selectYear(e) {
- this.setData({
- yearIndex: e.detail.value,
- });
- },
- setjdji(e) {
- this.setData({
- jdji: e.detail.value,
- });
- },
- onConfirm() {
- var obj;
- switch (this.data.dateIndex) {
- case "1":
- obj = {
- type: this.data.dateIndex,
- date: this.data.yearArr[this.data.yearIndex]
- }
- break
- case "2":
- var year=this.data.yearArr[this.data.jdYearIndex];
- var num=this.data.jdji;
- num++;
- let arrNew=new Array()
- arrNew.push(year)
- arrNew.push(num)
- let strNew=arrNew.join('')
- obj = {
- type: this.data.dateIndex,
- date:parseInt(strNew)
- }
- break
- case "3":
- obj = {
- type: this.data.dateIndex,
- date: this.data.month
- }
- break
- case "4":
- function tsTamp(ydm) {
- return new Date(ydm).getTime()
- }
- let timeC = (tsTamp(this.data.customIndOn) - tsTamp(this.data.customIndTw)) / (60 * 60 * 24 * 1000)
- if(timeC > 0){
- app.globalData.showToast("开始时间不能大于结束时间")
- return
- }
- // if(Math.abs(timeC) > 30) {
- // app.globalData.showToast("自定义事件区间不能大于一个月")
- // return
- // }
- obj = {
- type: this.data.dateIndex,
- date: {
- start_date: this.data.customIndOn,
- end_date: this.data.customIndTw
- }
- }
- break
- };
- this.props.onConfirm(obj);
- this.props.onClose();
- },
- onClose() {
- this.props.onClose();
- },
- selectDay() {
- dd.datePicker({
- format: 'yyyy',
- currentDate: this.data.jdYear,
- success: (res) => {
- this.setData({
- jdYear: res.date
- })
- },
- });
- },
- selectDay2() {
- },
- selectDate() {
- dd.datePicker({
- format: 'yyyy-MM',
- currentDate: this.data.month,
- success: (res) => {
- this.setData({
- month: res.date
- })
- },
- });
- },
- customDate(e) {
- console.log(e)
- let cust = e.target.dataset.index
- dd.datePicker({
- format: 'yyyy-MM-dd',
- currentDate: this.data[cust],
- success : res =>{
- console.log(res)
- this.setData({
- [cust]: res.date
- })
- },
- })
- },
-
- activeDate(e) {
- this.setData({ dateIndex: e.target.dataset.index })
- },
- },
- });
|