import { findLocations } from './../../../service/itemPassportService'
import util from './../../../util/util'

var bindRoomLogic = function () {
  this.memberId = localStorage.getItem('memberId')
}

bindRoomLogic.prototype = {
  makeRoomQueryParams: function () {
    return new Promise((resolve, reject) => {
      if (util.isNotEmpty(this.memberId)) {
        let params = {
          memberId: this.memberId
        }
        resolve(params)
      } else {
        let err = new Error('会员ID有误')
        reject(err)
      }
    })
  },

  queryBindRoomList: function (params) {
    let that = this
    return new Promise((resolve, reject) => {
      if (util.isNotEmpty(params)) {
        let pathArr = [1] // 1表示认证房屋数据
        findLocations(pathArr, params).then((res) => {
          if (res.status === '200') {
            resolve(res.data.authBuildings)
          } else {
            let err = new Error(res.message)
            reject(err)
          }
        }).catch((err) => {
          util.debugLog(err)
          reject(err)
        })
      } else {
        let err = new Error('请求参数错误')
        reject(err)
      }
    })
  }
}

export default bindRoomLogic