const state = {
	  appointmentServiceFee: null,
	    dispatchFee: null,
	    vehicleManagementFee: null,
		startingPrice: null,
		startingHowManyMinutes: null,
		timeFee: null,
		timeMinutes: null,
		userId:null,
		isMeal:null,
		deposit:null,
		showagre:true,
};

const mutations = {
	SET_APPOINTMENT_SERVICE_FEE(state, fee) {
		state.appointmentServiceFee = fee;
		console.log('执行了', fee);
	},
	SET_DISPATCH_FEE(state, fee) {
		state.dispatchFee = fee;
	},
	SET_VEHICLE_MANAGEMENT_FEE(state, fee) {
		state.vehicleManagementFee = fee;
	},
	SET_STARTING_PRICE(state, price) {
		state.startingPrice = price;
	},
	SET_STARTING_HOW_MANY_MINUTES(state, minutes) {
		state.startingHowManyMinutes = minutes;
	},
	SET_TIME_FEE(state, fee) {
		state.timeFee = fee;
	},
	SET_TIME_MINUTES(state, minutes) {
		state.timeMinutes = minutes;
	},
	SET_USERID(state, fee) {
		state.userId = fee;
		
	},
	SET_MEAL(state, fee) {
		state.isMeal = fee;
		
	},
	SET_DEPOSIT(state, fee) {
		console.log(fee,'feefeefeefee');
		state.deposit = fee;
		
	},
	SET_SHOWAGRE(state, fee) {
			console.log(fee,'feefeefeefee');
			state.showagre = fee;
			
		
	}
};



// actions 中调用 $u 对象
const actions = {
  fetchFeeRules: ({ commit, state }, $u) => {
    return new Promise((resolve, reject) => {
      // 调用接口获取费用规则
      $u.get('/app/fee/rule').then((res) => {
        if (res.code === 200) {
          // 提交 mutation 更新费用规则
          commit('SET_APPOINTMENT_SERVICE_FEE', res.data.appointmentServiceFee);
          commit('SET_DISPATCH_FEE', res.data.dispatchFee);
          commit('SET_VEHICLE_MANAGEMENT_FEE', res.data.vehicleManagementFee);
		  commit('SET_STARTING_PRICE', res.data.startingPrice);
		  commit('SET_STARTING_HOW_MANY_MINUTES', res.data.startingHowManyMinutes);
		  commit('SET_TIME_FEE', res.data.timeFee);
		  commit('SET_TIME_MINUTES', res.data.timeMinutes);
		    commit('SET_MEAL', res.data.isMeal);
			 commit('SET_DEPOSIT', res.data.deposit);
          resolve();
        } else {
          reject(new Error('Failed to fetch fee rules'));
        }
      }).catch(error => {
        reject(error);
      });
    });
  },
  userInfo: ({ commit, state }, $u) => {
    return new Promise((resolve, reject) => {
      // 调用接口获取费用规则
      $u.get('/getAppInfo').then((res) => {
        if (res.code === 200) {
          // 提交 mutation 更新费用规则
         
  		  commit('SET_USERID', res.user.userId);
		  uni.setStorageSync('role', res.user.role);
          resolve();
        } else {
          reject(new Error('Failed to fetch fee rules'));
        }
      }).catch(error => {
        reject(error);
      });
    });
  }
};

// 安装插件的 install 方法
const install = (Vue, vm) => {
 
};

// 导出一个包含 install 方法和其他选项的对象
export default {
  state,
  mutations,
  actions,
  install,
};