<template>
    <div>
        <span class="title">
            {{ $t('trials:inspection:title:pullImage') }}
            <span>{{ tip }}</span>
        </span>
        <div class="search">
            <el-form :inline="true" class="base-search-form">
                <!-- TrialId -->
                <el-form-item class="my_multiple" :label="$t('trials:inspection:pullImage:search:TrialId')">
                    <el-select v-model="searchData.TrialId" style="width: 140px" @change="searchData.PatientID = null">
                        <el-option v-for="(item) of trialList" :key="item.TrialId" :label="item.ExperimentName"
                            :value="item.TrialId">
                        </el-option>
                    </el-select>
                </el-form-item>
                <!-- pacsDicomAEId -->
                <el-form-item class="my_multiple" :label="$t('trials:inspection:pullImage:search:pacsDicomAEId')">
                    <el-select v-model="searchData.PacsDicomAEId" style="width: 140px" @change="pacsDicomAEIdChange">
                        <el-option v-for="(item) of AElist" :key="item.Id" :label="item.CalledAE" :value="item.Id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <!-- patientID -->
                <el-form-item class="my_multiple" :label="$t('trials:inspection:pullImage:search:patientID')">
                    <el-select v-model="searchData.PatientID" style="width: 140px" clearable>
                        <el-option v-for="(item, index) of patientList" :key="index.PatientIdStr"
                            :label="item.PatientName" :value="item.PatientIdStr">
                        </el-option>
                    </el-select>
                </el-form-item>
                <!-- patientName -->
                <!-- <el-form-item class="my_multiple" :label="$t('trials:inspection:pullImage:search:patientName')">
                    <el-input v-model="searchData.PatientName" clearable style="width: 100px"
                        :maxlength="400"></el-input>
                </el-form-item> -->
                <!-- patientSex -->
                <!-- <el-form-item
            class="my_multiple"
            :label="$t('trials:inspection:pullImage:search:patientSex')"
          >
            <el-select
              v-model="searchData.PatientSex"
              clearable
              style="width: 140px"
            >
              <el-option
                v-for="item of $d.Sex"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item> -->
                <!-- patientBirthDate -->
                <!-- <el-form-item
            :label="$t('trials:inspection:pullImage:search:patientBirthDate')"
          >
            <el-date-picker
              v-model="PatientBirthDate"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyyMMDD"
            >
            </el-date-picker>
          </el-form-item> -->
                <!-- studyID -->
                <!-- <el-form-item
            class="my_multiple"
            :label="$t('trials:inspection:pullImage:search:studyID')"
          >
            <el-input
              v-model="searchData.StudyID"
              clearable
              :maxlength="400"
            ></el-input>
          </el-form-item> -->
                <!-- AccessionNumber -->
                <!-- <el-form-item
            class="my_multiple"
            :label="$t('trials:inspection:pullImage:search:AccessionNumber')"
          >
            <el-input
              v-model="searchData.AccessionNumber"
              clearable
              style="width: 100px"
              :maxlength="400"
            ></el-input>
          </el-form-item> -->
                <!-- modalitiesInStudy -->
                <!-- <el-form-item :label="$t('trials:inspection:pullImage:search:modalitiesInStudy')">
                    <el-select v-model="searchData.ModalitiesInStudyList" placeholder="" clearable multiple
                        collapse-tags style="width: 140px">
                        <el-option v-for="item in ModalityList" :key="item" :label="item" :value="item" />
                    </el-select>
                </el-form-item> -->
                <!-- studyDate -->
                <!-- <el-form-item :label="$t('trials:inspection:pullImage:search:studyDate')">
                    <el-date-picker v-model="StudyDate" type="daterange" range-separator="至" start-placeholder="开始日期"
                        end-placeholder="结束日期" value-format="yyyyMMdd" :picker-options="pickerOptions">
                    </el-date-picker>
                </el-form-item> -->
                <!-- studyTime -->
                <!-- <el-form-item
            :label="$t('trials:inspection:pullImage:search:studyTime')"
          >
            <el-time-picker
              is-range
              arrow-control
              v-model="StudyTime"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              placeholder="选择时间范围"
            >
            </el-time-picker>
          </el-form-item> -->
                <!-- bodyPartExamined -->
                <!-- <el-form-item
            class="my_multiple"
            :label="$t('trials:inspection:pullImage:search:bodyPartExamined')"
          >
            <el-input
              v-model="searchData.BodyPartExamined"
              clearable
              :maxlength="400"
            ></el-input>
          </el-form-item> -->
                <!-- studyDescription -->
                <!-- <el-form-item
            class="my_multiple"
            :label="$t('trials:inspection:pullImage:search:studyDescription')"
          >
            <el-input
              v-model="searchData.StudyDescription"
              clearable
              :maxlength="400"
            ></el-input>
          </el-form-item> -->
                <!-- studyInstanceUID -->
                <!-- <el-form-item
            class="my_multiple"
            :label="$t('trials:inspection:pullImage:search:studyInstanceUID')"
          >
            <el-input
              v-model="searchData.StudyInstanceUID"
              clearable
              :maxlength="400"
            ></el-input>
          </el-form-item> -->
                <el-form-item>
                    <!-- 查询 -->
                    <el-button type="primary" icon="el-icon-search" @click="handleSearch">
                        {{ $t('common:button:search') }}
                    </el-button>
                    <!-- 重置 -->
                    <el-button type="primary" icon="el-icon-refresh-left" @click="handleReset">
                        {{ $t('common:button:reset') }}
                    </el-button>
                    <!-- 拉取 -->
                    <el-button type="primary" :disabled="!multipleSelection || multipleSelection.length <= 0"
                        @click="openGroup({}, 2)">
                        {{ $t('trials:inspection:button:pull') }}
                    </el-button>
                </el-form-item>
            </el-form>
        </div>
        <!--检查列表-->
        <el-table ref="viewStudyList" v-loading="loading" v-adaptive="{ bottomOffset: 60 }" :data="PageList" stripe
            height="100" @sort-change="handleSortByColumn" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" />
            <el-table-column type="index" width="50">
                <template slot-scope="scope">
                    <span style="
                display: flex;
                align-items: center;
                justify-content: flex-end;
              ">
                        <el-tooltip class="item" effect="dark" :content="$t('trials:inspection:pullImage:tip:has')"
                            placement="top" style="margin-right: 3px">
                            <i v-if="scope.row.IsStudyExist" class="el-icon-success icon-i"></i>
                        </el-tooltip>
                        <span>{{ scope.$index + 1 }}</span>
                    </span>
                </template>
            </el-table-column>
            <!--patientID-->
            <el-table-column prop="PatientID" :label="$t('trials:inspection:pullImage:table:patientID')"
                show-overflow-tooltip min-width="120" sortable="custom" />
            <!--patientName-->
            <el-table-column prop="PatientName" :label="$t('trials:inspection:pullImage:table:patientName')"
                show-overflow-tooltip min-width="120" sortable="custom" />
            <!--patientSex-->
            <el-table-column prop="PatientSex" :label="$t('trials:inspection:pullImage:table:patientSex')"
                show-overflow-tooltip min-width="80" sortable="custom">
                <template slot-scope="scope">
                    <span>{{ $fd('Sex', scope.row.PatientSex) }}</span>
                </template>
            </el-table-column>
            <!--patientBirthDate-->
            <el-table-column prop="PatientBirthDate" :label="$t('trials:inspection:pullImage:table:patientBirthDate')"
                show-overflow-tooltip min-width="120" sortable="custom" />
            <!--studyID-->
            <!-- <el-table-column
          prop="StudyID"
          :label="$t('trials:inspection:pullImage:table:studyID')"
          show-overflow-tooltip
          min-width="120"
        /> -->
            <!--AccessionNumber-->
            <el-table-column prop="AccessionNumber" :label="$t('trials:inspection:pullImage:table:AccessionNumber')"
                show-overflow-tooltip min-width="120" sortable="custom" />
            <!--modalitiesInStudy-->
            <el-table-column prop="ModalitiesInStudy" :label="$t('trials:inspection:pullImage:table:modalitiesInStudy')"
                show-overflow-tooltip min-width="120" sortable="custom" />
            <!--studyDate-->
            <el-table-column prop="StudyDate" :label="$t('trials:inspection:pullImage:table:studyDate')"
                show-overflow-tooltip min-width="120" sortable="custom" />
            <!--studyTime-->
            <el-table-column prop="StudyTime" :label="$t('trials:inspection:pullImage:table:studyTime')"
                show-overflow-tooltip min-width="120" sortable="custom" />
            <!--bodyPartExamined-->
            <!-- <el-table-column
          prop="BodyPartExamined"
          :label="$t('trials:inspection:pullImage:table:bodyPartExamined')"
          show-overflow-tooltip
          min-width="120"
          sortable="custom"
        /> -->
            <!--studyDescription-->
            <el-table-column prop="StudyDescription" :label="$t('trials:inspection:pullImage:table:studyDescription')"
                show-overflow-tooltip min-width="120" sortable="custom" />
            <!--studyInstanceUID-->
            <el-table-column prop="StudyInstanceUID" :label="$t('trials:inspection:pullImage:table:studyInstanceUID')"
                show-overflow-tooltip min-width="120" sortable="custom" />
            <!--课题组-->
            <el-table-column prop="ViewHospitalGroupList"
                :label="$t('trials:inspection:pullImage:table:ViewHospitalGroupList')" show-overflow-tooltip
                min-width="100">
                <template slot-scope="scope">
                    <span>{{
                        scope.row.ViewHospitalGroupList && scope.row.ViewHospitalGroupList.length > 0 ?
                            scope.row.ViewHospitalGroupList.map(item => item.Name).join(', ') : ''}}</span>
                </template>
            </el-table-column>
            <!--操作-->
            <el-table-column :label="$t('common:action:action')" min-width="120">
                <template slot-scope="scope">
                    <el-button circle icon="el-icon-refresh" class="refreshBtn"
                        :title="$t('trials:inspection:button:pull')" @click.stop="openGroup(scope.row, 2)" />
                    <el-button circle icon="el-icon-edit-outline" :title="$t('trials:inspection:button:collect')"
                        v-if="scope.row.IsStudyExist" @click.stop="openGroup(scope.row, 1)" />
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页组件 -->
        <pagination class="page" :total="total" :page.sync="PageIndex" :limit.sync="PageSize" @pagination="paging" />
        <base-model v-if="group_model.visible" :config="group_model">
            <template slot="dialog-body">
                <el-form ref="groupFrom" :model="form" :rules="rules" label-width="100px" size="small">
                    <el-form-item :label="$t('trials:externalStaff:table:lastName')" prop="LastName" v-show="false">
                        <el-input clearable />
                    </el-form-item>
                    <!-- 用户类型 -->
                    <el-form-item :label="$t('trials:externalStaff:table:hospitalGroupIdList')"
                        prop="HospitalGroupIdList">
                        <el-select v-model="form.HospitalGroupIdList" style="width: 100%" multiple clearable>
                            <el-option v-for="item of hospitalGroupList" :key="item.Id" :label="item.Name"
                                :value="item.Id">
                                <!-- <span>{{ item.UserType }}</span> -->
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-form>
            </template>
            <template slot="dialog-footer">
                <!-- 取消 -->
                <el-button size="small" type="primary" :disabled="btnLoading" @click="handleCancelGroup">
                    {{ $t("common:button:cancel") }}
                </el-button>
                <!-- 保存 -->
                <el-button size="small" type="primary" :loading="btnLoading" @click="pullImage">
                    {{ $t("common:button:save") }}
                </el-button>
            </template>
        </base-model>
    </div>
</template>
<script>
import Pagination from '@/components/Pagination'
import {
    getCFindStudyList,
    cmoveStudyList,
    cMoveVerify,
    getUserJoinedTrialPatientList
} from '@/api/inspection.js'
import { getDicomAEList } from '@/api/dicomAE.js'
import BaseModel from '@/components/BaseModel'
const defaultSearchData = () => {
    return {
        PacsDicomAEId: null,
        PatientID: null,
        PatientName: null,
        // ModalitiesInStudyList: null,   
        StudyDate: null,
        TrialId: null,

        PatientSex: null,
        PatientBirthDate: null,
        StudyID: null,
        StudyTime: null,
        BodyPartExamined: null,
        StudyDescription: null,
        StudyInstanceUID: null,
        AccessionNumber: null,
    }
}
export default {
    name: 'byTrials',
    components: { Pagination, BaseModel },
    props: {
        calledAeList: {
            required: true,
            default: () => {
                return []
            },
        },
        callingAeList: {
            required: true,
            default: () => {
                return []
            },
        },
    },
    data() {
        return {
            // 查询
            searchData: defaultSearchData(),
            ModalityList: [],
            timeFrame: null,
            MaxStudyCount: null,
            PatientBirthDate: [],
            // StudyDate: [],
            // 可加入项目列表
            loading: false,
            list: [],
            PageList: [],
            total: 0,
            PageIndex: 1,
            PageSize: 50,
            AElist: [],
            multipleSelection: [],

            trialList: [],

            group_model: {
                visible: false,
                title: this.$t('trials:inspection:dialogTitle:collect'),
                width: '400px',
                appendToBody: true
            },
            form: {
                HospitalGroupIdList: [],
            },
            rules: {
                HospitalGroupIdList: [
                    {
                        required: true,
                        type: "array",
                        message: this.$t('common:ruleMessage:specify'),
                        trigger: ['blur', 'change']
                    }
                ]
            },
            btnLoading: false,
            hospitalGroupList: [],
            groupStatus: 1, // 1收藏 2拉取
            currentData: {}
        }
    },
    computed: {
        // pickerOptions() {
        //     return {
        //         shortcuts: [
        //             {
        //                 text: this.$t('trials:inspection:pullImage:picker:today'),
        //                 onClick: (picker) => {
        //                     const end = new Date()
        //                     const start = new Date()
        //                     // picker.$emit('pick', [start, end])
        //                     this.StudyDate = [start, end]
        //                 },
        //             },
        //             {
        //                 text: this.$t('trials:inspection:pullImage:picker:week'),
        //                 onClick: (picker) => {
        //                     const end = new Date()
        //                     const start = new Date()
        //                     if (!this.timeFrame || this.timeFrame > 3) {
        //                         start.setTime(start.getTime() - 3600 * 1000 * 24 * 2)
        //                     } else {
        //                         start.setTime(
        //                             start.getTime() - 3600 * 1000 * 24 * (this.timeFrame - 1)
        //                         )
        //                     }

        //                     // picker.$emit('pick', [start, end])
        //                     this.StudyDate = [start, end]
        //                 },
        //             },
        //             {
        //                 text: this.$t('trials:inspection:pullImage:picker:month'),
        //                 onClick: (picker) => {
        //                     const end = new Date()
        //                     const start = new Date()
        //                     let month = this.$moment().subtract(1, 'months')
        //                     let day = this.$moment().diff(month, 'day')
        //                     if (!this.timeFrame || this.timeFrame > day) {
        //                         start.setTime(start.getTime() - 3600 * 1000 * 24 * (day - 1))
        //                     } else {
        //                         start.setTime(
        //                             start.getTime() - 3600 * 1000 * 24 * (this.timeFrame - 1)
        //                         )
        //                     }
        //                     // picker.$emit('pick', [start, end])
        //                     this.StudyDate = [start, end]
        //                 },
        //             },
        //             {
        //                 text: this.$t('trials:inspection:pullImage:picker:trimester'),
        //                 onClick: (picker) => {
        //                     const end = new Date()
        //                     const start = new Date()
        //                     let month = this.$moment().subtract(3, 'months')
        //                     let day = this.$moment().diff(month, 'day')
        //                     if (!this.timeFrame || this.timeFrame > day) {
        //                         start.setTime(start.getTime() - 3600 * 1000 * 24 * (day - 1))
        //                     } else {
        //                         start.setTime(
        //                             start.getTime() - 3600 * 1000 * 24 * (this.timeFrame - 1)
        //                         )
        //                     }
        //                     // picker.$emit('pick', [start, end])
        //                     this.StudyDate = [start, end]
        //                 },
        //             },
        //         ],
        //         disabledDate: (time) => {
        //             if (!this.timeFrame) return false
        //             let curDate = new Date().getTime()
        //             let three = this.timeFrame * 24 * 3600 * 1000
        //             let threeMonths = curDate - three
        //             return time.getTime() >= Date.now() || time.getTime() <= threeMonths
        //         },
        //     }
        // },
        tip() {
            if (!this.searchData.PacsDicomAEId) return ''
            let message = `( ${this.$t('trials:inspection:pullImage:PacsTip')} )`
            message = message.replace(
                'xxx',
                this.AElist.find((item) => item.Id === this.searchData.PacsDicomAEId)
                    .CalledAE
            )
            if (!this.timeFrame) {
                message = message.replace(
                    'yyy',
                    this.$t('trials:inspection:pullImage:unlimit')
                )
            } else {
                message = message.replace(
                    'yyy',
                    `${this.timeFrame}${this.$t('trials:inspection:unit:day')}`
                )
            }
            if (!this.MaxStudyCount) {
                message = message.replace(
                    'zzz',
                    this.$t('trials:inspection:pullImage:unlimit')
                )
            } else {
                message = message.replace(
                    'zzz',
                    `${this.MaxStudyCount}${this.$t('trials:inspection:unit:article')}`
                )
            }
            message = message.replace('kkk', this.ModalityList.join('，'))
            return message
        },
        patientList() {
            let arr = []
            if (this.searchData.TrialId) {
                arr = this.trialList.find(item => item.TrialId === this.searchData.TrialId).PatientList
            }
            return arr
        }
    },
    created() {
        this.getTrialList()
    },
    methods: {
        // 获取项目
        async getTrialList() {
            try {
                let res = await getUserJoinedTrialPatientList()
                if (res.IsSuccess) {
                    this.trialList = res.Result
                    if (!this.trialList || this.trialList.length <= 0) return false
                    this.searchData.TrialId = this.trialList[0].TrialId
                    this.getAEList(false, true)
                }
            } catch (err) {
                console.log(err)
            }
        },
        pacsDicomAEIdChange(val, f = false) {
            let pacs = this.AElist.find((item) => item.Id === val)
            this.ModalityList = pacs.ModalityList
            this.timeFrame = pacs.PacsSearchMaxDays
            this.MaxStudyCount = pacs.MaxStudyCount
            if (!f) {
                this.handleReset()
            }
        },
        // 验证pacs
        async cMoveVerify(data) {
            try {
                let res = await cMoveVerify(data)
                if (res.IsSuccess) {
                    return res.Result
                }
                return false
            } catch (err) {
                console.log(err)
                return false
            }
        },
        async getList() {
            if (!this.searchData.TrialId) return false
            if (!this.searchData.PacsDicomAEId)
                return this.$message.warning(
                    this.$t('trials:inspection:pullImage:message:mustPacsDicomAEId')
                )
            let data = {}
            Object.keys(this.searchData).forEach((key) => {
                data[key] = this.searchData[key]
            })
            // if (
            //   this.PatientBirthDate &&
            //   this.PatientBirthDate[0] &&
            //   this.PatientBirthDate[1]
            // ) {
            //   data.PatientBirthDate =
            //     this.PatientBirthDate[0] + '-' + this.PatientBirthDate[1]
            // } else {
            //   data.PatientBirthDate = null
            // }
            // if (this.StudyDate && this.StudyDate[0] && this.StudyDate[1]) {
            //     data.StudyDate =
            //         this.$moment(this.StudyDate[0]).format('YYYYMMDD') +
            //         '-' +
            //         this.$moment(this.StudyDate[1]).format('YYYYMMDD')
            // } else {
            //     data.StudyDate = null
            // }
            // if (this.StudyTime && this.StudyTime[0] && this.StudyTime[1]) {
            //   data.StudyTime =
            //     this.$moment(this.StudyTime[0]).format('HHmmss') +
            //     '-' +
            //     this.$moment(this.StudyTime[1]).format('HHmmss')
            // } else {
            //   data.StudyTime = null
            // }
            try {
                this.loading = true
                let res = await getCFindStudyList(data)
                this.loading = false
                if (res.IsSuccess) {
                    this.list = res.Result
                    this.total = res.Result.length
                    this.paging()
                    let MaxStudyCount = this.MaxStudyCount || 50
                    if (this.total >= MaxStudyCount) {
                        let message = this.$t(
                            'trials:inspection:pullImage:confirm:limit50'
                        ).replace('xxx', MaxStudyCount)
                        this.$confirm(message, '', {
                            type: 'warning',
                            showCancelButton: false,
                        })
                    }
                }
            } catch (err) {
                this.loading = false
                console.log(err)
            }
        },
        // 获取列表
        async getAEList(f = false, isFirst = false) {
            let data = {
                CalledAE: null,
                IP: null,
                Port: null,
                PacsTypeEnum: 2,
                IsTestOK: true,
                PageIndex: 1,
                PageSize: 1000,
                SortField: 'CreateTime',
                Asc: false,
            }
            try {
                this.loading = true
                let res = await getDicomAEList(data)
                this.loading = false
                if (res.IsSuccess) {
                    this.AElist = res.Result.CurrentPageData
                    if (this.AElist.length > 0) {
                        if (!f) {
                            this.searchData.PacsDicomAEId = this.AElist[0].Id
                            this.ModalityList = this.AElist[0].ModalityList
                            this.timeFrame = this.AElist[0].PacsSearchMaxDays
                            this.MaxStudyCount = this.AElist[0].MaxStudyCount
                            // this.searchData.ModalitiesInStudyList = [this.ModalityList[0]]
                            // this.StudyDate = [new Date(), new Date()]
                        } else {
                            this.pacsDicomAEIdChange(this.searchData.PacsDicomAEId, true)
                        }
                        if (!isFirst) {
                            this.getList()
                        }

                    }
                }
            } catch (err) {
                console.log(err)
            }
        },
        // 分页
        paging() {
            this.PageList = []
            if (!this.list || this.list.length <= 0) return false
            this.PageList = this.list.slice(
                (this.PageIndex - 1) * this.PageSize,
                this.PageIndex * this.PageSize
            )
        },
        // 查询
        handleSearch() {
            //   this.searchData.PageIndex = 1
            this.getAEList(true)
        },
        // 重置
        handleReset() {
            this.reset()
            this.getAEList(true)
        },
        // 初始化
        reset() {
            //   this.searchData = defaultSearchData()
            Object.keys(this.searchData).forEach((key) => {
                if (key !== 'PacsDicomAEId' && key !== 'TrialId') {
                    this.searchData[key] = null
                }
            })
            // this.PatientBirthDate = []
            // this.StudyDate = []
            // this.StudyTime = [new Date(new Date().getTime() - 10800000), new Date()]
        },
        // 表格排序
        handleSortByColumn(sort) {
            if (sort.order === 'ascending') {
                this.list.sort((a, b) => (a[sort.prop] > b[sort.prop] ? 1 : -1))
            }
            if (sort.order === 'descending') {
                this.list.sort((a, b) => (b[sort.prop] > a[sort.prop] ? 1 : -1))
            }
            this.paging()
        },
        async handleSaveGroup() {
            try {
                let validate = await this.$refs.groupFrom.validate()
                if (!validate) return false
                let ScPstudyIdList = []
                let row = this.currentData
                if (!row) {
                    if (this.multipleSelection.length <= 0) return false
                    ScPstudyIdList = this.multipleSelection.map(item => item.SCPStudyId)
                } else {
                    ScPstudyIdList = [this.currentData.SCPStudyId]
                }
                let data = {
                    ScPstudyIdList,
                    AddOrDelete: 1,
                    HospitalGroupIdList: this.form.HospitalGroupIdList
                }
                this.btnLoading = true
                let res = await modifySCPStudyHospitalGroup(data)
                this.btnLoading = false
                if (res.IsSuccess) {
                    this.$message.success(this.$t('common:message:savedSuccessfully'))
                    this.handleCancelGroup()
                    this.getList()
                }
            } catch (err) {
                console.log(err)
                this.btnLoading = false
            }
        },
        handleCancelGroup() {
            this.form.HospitalGroupIdList = []
            this.groupStatus = 1
            this.group_model.visible = false
        },
        openGroup(row, type = 1) {
            this.currentData = row
            this.groupStatus = type
            if (row) {
                this.hospitalGroupList = row.CurrentUserHospitalGroupList
            } else {
                this.hospitalGroupList = this.multipleSelection[0].CurrentUserHospitalGroupList
            }
            if (type === 1) {
                this.group_model.title = this.$t('trials:inspection:dialogTitle:collect')
            } else {
                this.group_model.title = this.$t('trials:inspection:dialogTitle:pull')
            }
            this.group_model.visible = true
        },
        // 拉取pacs数据
        async pullImage() {
            let validate = await this.$refs.groupFrom.validate()
            if (!validate) return false
            if (this.groupStatus === 1) return this.handleSaveGroup()
            try {
                let row = this.currentData
                let data = {
                    PacsDicomAEId: this.searchData.PacsDicomAEId,
                    HospitalGroupIdList: this.form.HospitalGroupIdList
                    //   studyIDList: [row.StudyID],
                }
                if (row) {
                    data.StudyInstanceUIDList = [row.StudyInstanceUID]
                } else {
                    data.StudyInstanceUIDList = this.multipleSelection.map(
                        (item) => item.StudyInstanceUID
                    )
                }
                let r = await this.cMoveVerify(data)
                if (!r) return false
                let isPullList = []
                Object.keys(r).forEach((key) => {
                    if (r[key]) {
                        isPullList.push(key)
                    }
                })
                let message = this.$t('trials:inspection:pullImage:confirm:pull')
                let patientMessage = ''
                if (isPullList.length > 0) {
                    isPullList.forEach((key) => {
                        patientMessage += `患者：${r[key].PatientName}，检查申请号：${r[key].AccessionNumber}<br/>`
                    })
                    if (patientMessage) {
                        message =
                            patientMessage +
                            '<br/>' +
                            this.$t('trials:inspection:pullImage:message:isHasPull') +
                            '，' +
                            message
                    }
                }
                let confirm = await this.$confirm(message, '', {
                    dangerouslyUseHTMLString: true,
                })
                if (!confirm) return false

                this.loading = true
                this.btnLoading = true
                let res = await cmoveStudyList(data)
                this.loading = false
                this.btnLoading = true
                if (res.IsSuccess) {
                    this.$message.success(
                        this.$t('trials:inspection:pullImage:message:pullSuccess')
                    )
                    this.handleCancelGroup()
                }
            } catch (err) {
                this.loading = false
                this.btnLoading = true
                console.log(err)
            }
        },
        handleSelectionChange(val) {
            this.multipleSelection = val
        },
    },
}
</script>
<style lang="scss" scoped>
.icon-i {
    color: #67c23a;
    cursor: pointer;
}

.refreshBtn {
    // transform: rotate(0);
    transition: 0.5s;

    &:hover {
        transform: rotate(180deg);
        transition: 0.5s;
    }
}
</style>