import tool from './tool'

let filterHelper = {

  /**
   * 筛选
   * @param thisObj
   * @param filterData
   */
  handleFilterUser(thisObj, filterData) {
    thisObj.filterModel = {}
    if (filterData.userIds !== 'all') {
      thisObj.$set(thisObj.filterModel, 'userIds', `in,${filterData.userIds.join()}`)
    }
    for (let i in filterData.otherFilterTypes) {
      let filterValue = `${filterData.otherFilterTypes[i].filterSymbol},${filterData.otherFilterTypes[i].filterValue}`
      if (filterData.otherFilterTypes[i].hasOwnProperty('filterOther')) {
        filterValue += `,${filterData.otherFilterTypes[i].filterOther}`
      }
      let filterType = filterData.otherFilterTypes[i].filterType
      if (thisObj.filterModel[filterType]) {
        thisObj.$set(thisObj.filterModel, filterType, (thisObj.filterModel[filterType] + '|' + filterValue))
      } else {
        thisObj.$set(thisObj.filterModel, filterType, filterValue)
      }
    }
    // this.filterModel放在地址栏 供刷新时可以保留筛选结果
    tool.insertUrlParam('filter', thisObj.filterModel)

    thisObj.getData()
  },
  /**
   * 清空筛选条件
   * @param thisObj
   */
  clearFilterOption(thisObj){
    thisObj.filterModel = {}
    tool.insertUrlParam('filter', '')
    window.location.href = window.location.href.replace(/(\?|&)filter=/, '')
    if(thisObj.$refs.filterUser){
      thisObj.$refs.filterUser.handleFilterClear()
    }
  },

}

export default filterHelper
