const elevators = {
  state: {
    // 已存在的电梯编号
    existedElevatorCodeSet: new Set(),
    // 技术评审缓存   key：电梯规格id  value：评审LIST
    techReviewObj: {},
    // 采购报价缓存   key：电梯规格id  value：报价LIST
    buyerQuotationObj: {},
    // 采购报价缓存   key：电梯规格id  value：报价LIST
    treasurerQuotationObj: {}
  },

  mutations: {
    PUT_ELEVATOR: (state, elevator) => {
      state[elevator.id] = elevator
    },
    DEL_ELEVATOR: (state, elevator) => {
      delete state[elevator.id]
    },
    ADD_ELEVATOR_CODE: (state, elevatorCodeList) => {
      state.existedElevatorCodeSet.clear()
      if (elevatorCodeList && elevatorCodeList.length > 0) {
        for (let i = 0; i < elevatorCodeList.length; i++) {
          state.existedElevatorCodeSet.add(elevatorCodeList[i])
        }
      }
    },
    // 技术评审
    ADD_TECH_REVIEW: (state, priceDetail) => {
      state.techReviewObj[priceDetail.id] = priceDetail.data
    },
    CLEAR_TECH_REVIEW: (state) => {
      state.techReviewObj = {}
    },
    // 采购报价
    ADD_BUYER_REVIEW: (state, priceDetail) => {
      state.buyerQuotationObj[priceDetail.id] = priceDetail.data
    },
    CLEAR_BUYER_REVIEW: (state) => {
      state.buyerQuotationObj = {}
    },
    // 财务报价
    ADD_TREASURER_REVIEW: (state, priceDetail) => {
      state.treasurerQuotationObj[priceDetail.id] = priceDetail.data
    },
    CLEAR_TREASURER_REVIEW: (state) => {
      state.treasurerQuotationObj = {}
    },
  },

  actions: {
    addElevator({commit}, elevator) {
      return new Promise(() => {
        commit('PUT_ELEVATOR', elevator)
      })
    },
  }
}

export default elevators
