<template>
  <el-dialog class="dialog-container" :model-value="modelValue" :title="title" :before-close="close">

    <div style="height: 300px;overflow: auto" v-infinite-scroll="load">
      <el-radio-group v-model="radio" @change="changeRadio" v-if="lyquery.rows.length > 0">
        <el-radio :label="item.modelId" v-for="(item) in lyquery.rows" :key="item.id">
          {{ item.modelName }}
        </el-radio>
      </el-radio-group>
      <div class="ww100 flex just-center">
        <MOSTY.Empty :show="lyquery.rows.length == 0"></MOSTY.Empty>
      </div>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="onComfirm">
          确认
        </el-button>
      </div>
    </template>
  </el-dialog>

  <SelectingPeople v-model="showDialog" :createProcess="createProcess" @close="close" :radioData="radioData"
    :path="path" @getList="emit('getList')" :userData="userData" />
</template>

<script setup>
import { ref, getCurrentInstance, reactive, watch } from 'vue'
import SelectingPeople from './SelectingPeople.vue';
import * as MOSTY from "@/components/MyComponents/index";
import { splGet, splPost } from '@/api/spl'
import { qcckGet } from '@/api/qcckApi'
import { getItem,setItem } from '@/utils/storage'
const props = defineProps({
  modelValue: {
    type: Boolean,
    required: true
  }, title: {
    type: String,
    default: '发起流程'
  }, data: {
    type: Object,
    default: () => { }
  }, userData: {
    type: Object,
    default: () => {
      return {
        ajmc: "",
        flowType: ""
      }
    }
  }, path: {
    type: Object,
    default: {}
  }
})

const showDialog = ref(false)
const emit = defineEmits(['update:modelValue', 'getList'])
const titles = ref(props.title)
const deptId=getItem('deptId')
const lyquery = reactive({
  rows: [],
  total: 0,
  promes: {
    page: 1,
    rows: 100,
    // orgCode:deptId[0].orgCode
    modelName: props.userData.modelName
  }

})
const radio = ref(3)

const qcckGetList = () => {
  const prrmes = {
    ...lyquery.promes
  }
  splGet(prrmes, '/model/queryModel').then(res => {
    lyquery.rows = lyquery.promes.page == 1 ? res.rows : lyquery.rows.concat(res.rows)
    lyquery.total = res.total
  })
}
const Sfzh = getItem('idEntityCard')
const qcckGetCount = () => {
  if (!getItem('cookie') ) {
    qcckGet({ sfzh: Sfzh },'/mosty-base/fzmsg/getCokie').then(res => {
      document.cookie = res.cookie
      setItem('userOrg',res.userOrg)
      qcckGetList()
    })
  }
}

watch(() => props.modelValue, (newVal) => {
  if (newVal) {
    qcckGetCount()
  }
})
const createProcess = ref({})
const radioData = ref('')
// const InterfaceAddress = 'http://192.168.0.231:8006/mosty-api/mosty-gsxt/'
// const InterfaceAddress = 'http://192.168.0.231:8006/mosty-api/mosty-gsxt/'
//  const InterfaceAddress = 'http://155.540.22.30:50037/mosty-api/mosty-gsxt/'
const InterfaceAddress = 'http://192.168.1.32:8006/mosty-api/mosty-gsxt/'
const changeRadio = (e) => {
  radioData.value = e
  const item = lyquery.rows.find(item => item.modelId == e)
  if (item) {
    createProcess.value = {
      modelId: e,
      processName: item.modelName ? item.modelName : '',
      processType: 1,
      processData:
      {
        iframe: `#/${props.path.clueVerification}?id=${props.data.id}`,
        hostPrefix: "sgxtPath",
        rwbh: props.data.id,
        flowType: 'SGSP',
        sqrw: props.data,
        ajmc: props.userData.ajmc,
        // flowType: "ZyCompany",
       callback: {
        "START": "",//流程开始
        "APPROVE": "",//节点审批通过
        "BACK": "",//退回上一节点
        "REVOKE": "",//撤回审批
        "DONE": `${InterfaceAddress}${props.path.byMeansOf}?id=${props.data.id}&bkZt=05`,//流程审批通过
        "ABORT": `${InterfaceAddress}${props.path.nobyMeansOf}?id=${props.data.id}&bkZt=06`,//审批不通过
        "RECOVER": "",//流程回收
        "AGAIN": `${InterfaceAddress}${props.path.recycle}?id=${props.data.id}&bkZt=07`//流程退回初始
    },
      }

    }
  }
}

const onComfirm = () => {
  showDialog.value = true
}
const load = () => {
  if (lyquery.total == lyquery.rows.length) {
    return
  } else {
    lyquery.promes.page++
    qcckGetList()
  }

}

const close = () => {
  radio.value = ''
  emit('update:modelValue', false)
}
</script>

<style lang="scss" scoped>
@import "@/assets/css/homeScreen.scss";

::v-deep .el-dialog__body {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

.dialog-container {
  height: 500px;
}

::v-deep .el-radio__label {
  color: #000;
}
</style>
