// /**分页查询接口重试日志 */
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 + '/signconfig/query'

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 = (_this, data, st) => {
  _this.confirmLoading = true
  return request({
    url: serviceName + (st === 2 ? '/signconfig/save' : '/signconfig/update'),
    method: 'post',
    data
  })
    .then(responseThen.bind(_this)).then(response => {
      store.dispatch('getSign')
      return response
    })
    .catch(response => {
      _this.confirmLoading = false
    })
}

export const deleteMainItem = (context, id) => {
  let confirmLoading = false
  return new Promise(resolve => {
    context.$confirm({
      title: '删除之后,不能再启用,确认是否删除!',
      confirmLoading,
      onOk(clear) {
        context.confirmLoading = true
        return request({
          url: serviceName + '/signconfig/delete',
          method: 'post',
          data: id
        })
          .then(response => {
            if (response.success) {
              clear()
              context.$refs.mainTable.reload()
            } else {
              context.$exception(response)
            }
            confirmLoading = false
             store.dispatch('getSign');
            return resolve(response)
          })
          .catch(error => {
            confirmLoading = false
          })
      }
    })
  })
}
