// @ts-nocheck
import Vue from 'vue'
import axios from '@/common/services/axios-instance'
import store from '@/common/store'
import pickValues from '@/common/services/pick-values'
import { message } from 'ant-design-vue'
// import IamSealPickerModal from '@product/iam/seal/iam-seal-picker-modal'
// import AuditSystemMaterialPicker from './components/audit-system-material-picker'
import IcSimpleInfoModal from '../ic/evaluation/ic-simple-info-modal'
import IcWriteResultModal from '../ic/evaluation/ic-write-result-modal'

class IamLightService {
  // 系统集成资料
  // selectSystemMaterial() {
  //   return pickValues(AuditSystemMaterialPicker, { single: true })
  // }

  // // 获取印章
  // getYinzhangUrl(flowData) {
  //   let mixin
  //   const p = new Promise(function(resolve, reject) {
  //     mixin = {
  //       data() {
  //         return {
  //           flowData,
  //         }
  //       },
  //       methods: {
  //         handleOk() {
  //           if (!this.sealId) {
  //             message.warn('请选择印章')
  //           } else {
  //             axios
  //               .get('api/framework/v1/attachment-extend/attachments-info/' + this.sealId)
  //               .then((res) => {
  //                 const code = res.data[0]?.code
  //                 if (code) {
  //                   const url = `${location.origin}${location.pathname}api/framework/v1/task-form-process/download-attachments/${code}?fileName=${res.data[0].name}`
  //                   resolve(url)
  //                   this.visible = false
  //                   this.gaizhangvisible = false
  //                 } else {
  //                   message.warn('对应的印章不存在')
  //                 }
  //               })
  //           }
  //         },
  //       },
  //     }
  //   })
  //   const mixins = { mixins: [mixin] }
  //   const c = { ...IamSealPickerModal, ...mixins }
  //   const vm = new Vue(c).$mount()
  //   document.body.appendChild(vm.$el)
  //   return p
  // }

  // 测试底稿-样本信息
  simpleInfo(model, simpleData) {
    let mixin
    const p = new Promise(function(resolve, reject) {
      mixin = {
        data() {
          return {
            model,
            simpleData,
          }
        },
        methods: {
          handleOk() {
            this.$refs.childTable.valid().then((flag) => {
              if (flag) {
                this.visible = false
                resolve(this.value)
              }
            })
          },
        },
      }
    })
    const mixins = { mixins: [mixin], store }
    const c = { ...IcSimpleInfoModal, ...mixins }
    const vm = new Vue(c).$mount()
    document.body.appendChild(vm.$el)
    return p
  }

  // 测试底稿-填写结果
  writeResult(pageId, readonly, model) {
    let mixin
    const p = new Promise(function(resolve, reject) {
      mixin = {
        data() {
          return {
            pageId,
            readonly,
            model,
          }
        },
        methods: {
          actionBtnClick(evt, button) {
            if (button.buttonId === 'save') {
              evt.preventDefault()
              this.$refs.resultModal.validateFields().then((flag) => {
                if (flag) {
                  const clues = this.$refs.resultModal.getFieldValue('isClues')
                  const handOverObject = this.$refs.resultModal.getFieldValue('handOver')
                  if (clues === '1' && !handOverObject) {
                    return message.warn('请选择移交对象！')
                  }
                  this.$refs.resultModal.hide()
                  const backendData = this.$refs.resultModal.getBackendValues()
                  resolve(backendData)
                }
              })
            }
          },
        },
      }
    })
    const mixins = { mixins: [mixin], store }
    const c = { ...IcWriteResultModal, ...mixins }
    const vm = new Vue(c).$mount()
    document.body.appendChild(vm.$el)
    return p
  }
}

export default new IamLightService()
