// /**分页查询接口重试日志 */
import request from '@/utils/request'
import store from '@/store'

// export default function () {

//   store.dispatch('getSign');

// }
import { UPCLOUD_RDC_TMS_MAINDATA_SERVICE } from '@/config/serviceSettings.js'

const serviceName = UPCLOUD_RDC_TMS_MAINDATA_SERVICE

// //分页查询接口重试日志 GET
//export const mainTableInfoUrl = serviceName + '/provider/paging_query';
export const mainTableInfoUrl = serviceName + '/sysParamConfig/query'

export const queryAppointment = (_this, data) => {
  return request({
    url: mainTableInfoUrl,
    method: 'post',
  }).then((response) => {
    if (response.success) {
      let value = {}
      response.data.forEach((data) => {
        if (['RELATION_THIRD_SYSTEM', 'EVENT_FEEDBACK_MODE'].includes(data.code)) {
          data.value = data.value?.split(',') ?? []
          if (data.code === 'RELATION_THIRD_SYSTEM') {
            if (data.value.includes('0')) {
              _this.options.RELATION_THIRD_SYSTEM.forEach(item => {
                if (item.value !== '0') item.disabled = true
              })
            } else {
              _this.options.RELATION_THIRD_SYSTEM.forEach(item => {
                if (item.value === '0') item.disabled = true
              })
            }
          }
          if (data.code === 'EVENT_FEEDBACK_MODE') {
            if (data.value.includes('1')) {
              _this.options.EVENT_FEEDBACK_MODE.forEach(item => {
                if (item.value === '2') item.disabled = true
              })
            }
            if (data.value.includes('2')) {
              _this.options.EVENT_FEEDBACK_MODE.forEach(item => {
                if (item.value === '1') item.disabled = true
              })
            }
            if (data.value.includes('3')) {
              _this.options.EVENT_FEEDBACK_MODE.forEach(item => {
                if (item.value === '4') item.disabled = true
              })
            }
            if (data.value.includes('4')) {
              _this.options.EVENT_FEEDBACK_MODE.forEach(item => {
                if (item.value === '3') item.disabled = true
              })
            }
          }
        }
        value[data.code] = data.value
      })

      _this.sysConfig = value
    } else {
      _this.$exception(response)
    }

    return response
  })
}
function responseThen(response) {
  if (response.success) {
    this.visible = false
    this.$message.success(response.message)
  } else {
    this.$exception(response)
  }
  setTimeout(() => {
    this.confirmLoading = false
  }, 1000)
  return response
}

//新增|修改

export const mainSaveData = (context, data) => {
  let confirmLoading = false
  return new Promise((resolve) => {
    context.$confirm({
      title: '确认是否保存!',
      confirmLoading,
      onOk(clear) {
        context.confirmLoading = true
        return request({
          url: serviceName + '/sysParamConfig/save',
          method: 'post',
          data,
        })
          .then((response) => {
            if (response.success) {
              clear()
              context.$message.success(response.message)
              context.$store.dispatch('getParameter_TMS')
              //context.$store.commit('SET_PARAMETER_BMS', data)
            } else {
              context.$exception(response)
            }
            confirmLoading = false
            return resolve(response)
          })
          .catch((error) => {
            confirmLoading = false
          })
      },
    })
  })
}
