import request from '@/utils/request'
import qs from 'qs'
import { UPCLOUD_RDC_TMS_MAINDATA_SERVICE } from '@/config/serviceSettings.js'
const serviceName = UPCLOUD_RDC_TMS_MAINDATA_SERVICE

export const getQueryConfiguration = (self, data) => {
  return request({
    url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE+'/sysQueryConfiguration/getQueryConfiguration/v1.0',
    method: 'POST',
    data:qs.stringify(data),
  }).then((response) => {
    if (response.success) {

      return response.data
    } else {
      self.$exception(response)
      return false
    }
  })
}
export const getQueryListAll = (self, data) => {
  if (!self.adQueryUrl) return
  return request({
    url: self.adQueryUrl,
    method: 'POST',
    data: { pageNum: 1, pageSize: 999 }
  }).then((response) => {
    if (response.success) {

      return response.data
    } else {
      self.$exception(response)
      return false
    }
  })
}

//高级查询配置控制层-保存
export const saveConfiguration = (_this, data) => {

  let confirmLoading = true
  return new Promise((resolve) => {
    _this.$confirm({
      title: '是否保存条件' + '?',
      confirmLoading,
      onOk(clear) {
        confirmLoading = true
        return request({
          url: serviceName + '/sysQueryConfiguration/saveConfiguration/v1.0',
          method: 'post',
          data,
        })
          .then((response) => {

            if (response.success) {
              clear()
              // _this.$refs.mainTable.reload()
              _this.$message.success(response.message)
            } else {
              _this.$exception(response)
            }
            setTimeout(() => {
              confirmLoading = false
            }, 1000)
            return resolve(response)
          })
          .catch((response) => {
            confirmLoading = false
          })
      },
    })
  })
}


//设为默认
export const setDefault = (_this, data) => {

  let confirmLoading = true
  return new Promise((resolve) => {
    _this.$confirm({
      title: '是否设置默认' + '?',
      confirmLoading,
      onOk(clear) {
        confirmLoading = true
        return request({
          url: business + '/sysQueryConfiguration/setDefaultConfiguration/v1.0',
          method: 'post',
          data,
        })
          .then((response) => {
            if (response.success) {
              clear()
              _this.$refs.mainTable.reload()
              _this.$message.success(response.message)
            } else {
              _this.$exception(response)
            }
            setTimeout(() => {
              confirmLoading = false
            }, 1000)
            return resolve(response)
          })
          .catch((response) => {
            confirmLoading = false
          })
      },
    })
  })
}

// .then((res) => {
//   if (Array.isArray(res)) {
//     res.find((item) => {
//       if (item.defaultStatus === 1) {
//         this.activeKey = item.lineid
//       }
//     }, this)
//     this.tableData = res
//   }
// })
