import step from '../data/step';

export default <LibMixins>{

    data(){
        return {
            stepData:step,

            // 当前步骤
            stepNumber:-1,

            // 设置当前步骤
            stepItem:{}
        }
    },

    provide(){
      return {
          setStep:(index:number)=> this.setStep(index),
          setResultData:(data:Record<string, any>)=> this.setResultData(data),
          close:()=> this.close()
      }
    },

    methods:{

        setStep(index:number){
            if (this.stepNumber !== index) {
                this.stepNumber = index;
                this.stepItem = step[index]
            }
        },

        setResultData(data:Record<string, any> = {}):Record<string, any>{

            for (let key in data) {
                if (data.hasOwnProperty(key) && this.storageResultData[key] !== data[key]) {
                    this.storageResultData[key] = data[key];
                }
            }
            
            return this.storageResultData;

        },

    },

    created(){
        // 直接跳转到第一步
        this.setStep(1);
        // 用于存储提交数据
        this.storageResultData = {
            gid: this.config.gid
        };
    }

}