<template>
    <view>
        <view class="mb20">
            <!-- 团队业绩 -->
            <team
                :data="form.goalsClassifyVOList[0]"
                :monthList="monthList"
                :monthIndex="monthIndex"
                @change-month="changeMonth"
                @close-fold="closeFold"
                ref="teamRef"
            />
        </view>
        <view class="mb20">
            <!-- 安置业绩 -->
            <settle 
                :data="form.goalsClassifyVOList[1]"
                :monthList="monthList"
                :monthIndex="monthIndex"
                @change-month="changeMonth"
                ref="settleRef"
            />
        </view>
        <view class="mb20">
            <!-- 推荐业绩 -->
            <recommen 
                :data="form.goalsClassifyVOList[2]"
                :monthList="monthList"
                :monthIndex="monthIndex"
                @change-month="changeMonth"
                ref="recommenRef"
            />
        </view>
        <view class="mb20">
            <!-- 推荐人数 -->
            <people 
                :data="form.goalsClassifyVOList[3]"
                :monthList="monthList"
                :monthIndex="monthIndex"
                @change-month="changeMonth"
                ref="peopleRef"
            />
        </view>
        <view class="mb20">
             <!-- 会议场次 -->
            <session 
                :data="form.goalsClassifyVOList[4]"
                :monthList="monthList"
                :monthIndex="monthIndex"
                @change-month="changeMonth"
                ref="sessionRef"
                @chang-conference-num="changConferenceNum"
                @chang-file-data="changeFileData"
            />
        </view>
        <view class="mb20">
             <!-- 会议报备 -->
            <file
                :data="form.goalsClassifyVOList[5]"
                :monthList="monthList"
                :monthIndex="monthIndex"
                @change-month="changeMonth"
                ref="fileRef"
            />
        </view>
        <view class="mb20">
            <!-- 创客空间 -->
            <maker
                :data="form.goalsClassifyVOList[6]"
                :monthList="monthList"
                :monthIndex="monthIndex"
                @change-month="changeMonth"
                ref="makerRef"
            />
        </view>

        <view class="mb20">
            <!-- 超级工作室 -->
            <studio
                :data="form.goalsClassifyVOList[7]"
                :monthList="monthList"
                :monthIndex="monthIndex"
                @change-month="changeMonth"
                ref="studioRef"
            />
        </view>
        <view class="normal-sub-btn mt20" @click="submit">{{$t('ENU_P_TYPE4')}}</view>
    </view>
</template>

<script>
import utils from '@/common/utils.js';
import team from './team.vue';
import settle from './settle.vue';
import recommen from './recommen.vue';
import people from './people.vue';
import session from './session.vue';
import file from './file.vue';
import maker from './maker.vue';
import studio from './studio.vue';

export default {
    components: {
        team,
        settle,
        recommen,
        people,
        session,
        file,
        maker,
        studio,
    },
    props:['goalType'],
    data() {
        return {
            loading: true,
            now: 0,
            monthList: [],
            monthIndex: 0,
            form: {
                // pkMember: 100000,
                goalType: 1,
                month: "",
                goalsClassifyVOList: [
                    {
                        goalClassify: 1,
                        totalAchieve: "",
                        rightAchieve: "",
                        goalsDetailVOList: []
                    },
                    {
                        goalClassify: 2,
                        totalAchieve: "",
                        rightAchieve: "",
                        goalsDetailVOList: []
                    },
                    {
                        goalClassify: 3,
                        totalAchieve: "",
                        rightAchieve: "",
                        goalsDetailVOList: []
                    },
                    {
                        goalClassify: 4,
                        totalAchieve: "",
                        rightAchieve: "",
                        goalsDetailVOList: []
                    },
                    {
                        goalClassify: 5,
                        totalAchieve: "",
                        rightAchieve: "",
                        goalsDetailVOList: []
                    },
                    {
                        goalClassify: 6,
                        totalAchieve: "",
                        rightAchieve: "",
                        goalsDetailVOList: []
                    },
                    {
                        goalClassify: 7,
                        totalAchieve: "",
                        rightAchieve: "",
                        goalsDetailVOList: []
                    },
                    {
                        goalClassify: 8,
                        totalAchieve: "",
                        rightAchieve: "",
                        goalsDetailVOList: []
                    },
                ],
            },
        };
    },
    onShow() {},
    mounted() {
        this.form.goalType = this.$props.goalType;
        this.initDate();
    },
    methods: {
        changeFileData(list){
            if(this.$refs.fileRef){
                this.$refs.fileRef.getPreData(list);
            }
            // this.form.goalsClassifyVOList[5].goalsDetailVOList = list;
        },
        async initDate() {
            let date = new Date();
            let self = this;
            let year = date.getFullYear();
            self.now = date.getMonth();
            for (var i = self.now + 1; i < self.now + 3; i++) {
                self.monthList.push(i);
            }
            let mounth = await utils.fillZ0(this.monthList[this.monthIndex])
            this.form.month = `${year}-${mounth}`
        },
        changeMonth(e) {
            this.monthIndex = e.detail.value;
            let year = new Date().getFullYear();
            let mounth = utils.fillZ0(this.monthList[this.monthIndex])
            this.form.month = `${year}-${mounth}`
            
        },
        changConferenceNum(e){
            this.$refs.fileRef.resetData(e);
        },
        submit() {
            let team = this.$refs.teamRef.submit();
            if(!team){
                return
            }
            let settle = this.$refs.settleRef.submit();
            if(!settle){
                return
            }
            let recommen = this.$refs.recommenRef.submit();
            if(!recommen){
                return
            }
            let people = this.$refs.peopleRef.submit();
            if(!people){
                return
            }
            let session = this.$refs.sessionRef.submit();
            if(!session){
                return
            }
            let file = this.$refs.fileRef.submit();
            if(!file){
                return
            }
            let maker = this.$refs.makerRef.submit();
            if(!maker){
                return
            }
            let studio = this.$refs.studioRef.submit();
            if(!studio){
                return
            }
            let self = this;
            self._post('member/api/goals/save-goals', JSON.stringify(self.form), res => {
                uni.showModal({
                    content: res.msg,
                    showCancel: false,
                    success() {
                        console.log("点击了确定")
                        self.$emit("get-data")
                    }
                });
            });
        }
    }
};
</script>

<style lang="scss" scoped></style>