equipmentDataRetransmission.vue 9.19 KB
<template>
    <a-form :model="queryForm" layout="inline" :label-col="{ style: { width: '70px' } }">
        <a-form-item label="集团:">
            <a-select v-model:value="queryForm.account_id"
                      style="width: 200px"
                      :options="accountList"
                      @change="onAccountChange"
                      optionFilterProp="label"
                      show-search
            >
            </a-select>
        </a-form-item>
        <a-form-item label="广场:">
            <a-select v-model:value="queryForm.plaza_id"
                        mode="multiple"
                        :maxTagCount="1"
                        @change="onPlazaChange"
                      style="width: 200px"
                      :options="plazaList"
                      optionFilterProp="label"
                      show-search
            >
            </a-select>
        </a-form-item>
        <a-form-item label="选择设备:">
            <a-select v-model:value="queryForm.device_id"
                      style="width: 300px"
                      mode="multiple"
                      :maxTagCount="1"
                      optionFilterProp="label"
                      :options="deviceList"
                      show-search
            ></a-select>
        </a-form-item>
        <a-form-item label="选择日期:">
            <a-date-picker v-model:value="queryForm.date" :format="'YYYY-MM-DD'" style="width: 150px"/>
        </a-form-item>
        <a-form-item label="选择时间:">
            <a-time-picker v-model:value="queryForm.startTime" style="width: 100px"/>
            <a-time-picker v-model:value="queryForm.endTime" style="width: 100px"/>
        </a-form-item>
        <a-form-item>
            <a-button type="primary" @click="confirmSearch" style="margin-right: 10px;">查询</a-button>
            <a-button type="primary" @click="implement">执行</a-button>
        </a-form-item>
    </a-form>
    <a-table :dataSource="deviceList" v-loading="isLoading" :rowKey="record=>record.serialnum"  :columns="columns" :pagination="false">
    </a-table>
</template>

<script>
    import {reactive, ref, toRaw} from 'vue'
    import moment from 'moment'
    import {isArray} from '@/PublicUtil/Judgment'
    import snapshotRecordApi from '@/views/SnapshotCluster/SnapshotRecord/SnapshotRecordApi'
    import api from './api.js'
    import axios from 'axios'
	import {ElMessage} from 'element-plus'
    export default{
        setup(){
             const accountList = ref([])
             const plazaList = ref([])
             const deviceList = ref([])
             const isLoading = ref(false)
             const columns = ref([
                  {
                        title: '序号',
                        align:'center',
                        dataIndex: "index",
                  },
                  {
                        title: 'IP配置',
                        dataIndex: 'localIp',
                        align:'center',
                  },
                  {
                        title: '设备序列号',
                        dataIndex: 'serialnum',
                        align:'center',
                  },
                   {
                        title: '数据重传状态',
                        dataIndex: 'retransmission',
                        align:'center',
                  },
                   {
                        title: '设备重启状态',
                        dataIndex: 'restart',
                        align:'center',
                  }
                ])
             const queryForm = reactive(
                 {
                     account_id: '',
                     plaza_id: [],
                     device_id: [],
                     date: moment().format('YYYY-MM-DD'),
                     startTime: moment().format('YYYY-MM-DD 08:00:00'),
                     endTime: moment().format('YYYY-MM-DD 23:59:59'),
                 }
             )
             const getAccountList = function() {
                 queryForm.account_id = []
                 accountList.value = []
                 snapshotRecordApi.getAccountList().then(
                     (r) => {
                         if (isArray(r))
                         {
                             for (const item of r)
                             {
                                 accountList.value.push(
                                     {
                                         value: item.id,
                                         label: item.name,
                                     }
                                 )
                             }
                         }
                     }
                 )
             }
             const onAccountChange = function() {
                 getPlazaList()
             }
             
             const getPlazaList = function() {
                 queryForm.plaza_id = []
                 plazaList.value = []
                 snapshotRecordApi.getPlazaList(
                     {
                         account_id: queryForm.account_id.toString()
                     }
                 ).then(
                     (r) => {
                         if (isArray(r))
                         {
                             for (const item of r)
                             {
                                 plazaList.value.push(
                                     {
                                         value: item.id,
                                         label: item.name,
                                     }
                                 )
                             }
                         }
                     }
                 )
             }
             const onPlazaChange = function(){
                 queryForm.device_id = []
                 deviceList.value = []
                 getDevice()
             }
             const getDevice = function(){
                 // 获取设备
                 const rawData = toRaw(queryForm)
                 const data = {
                     mallIds: rawData.plaza_id.toString()
                 }
                 api.getDeviceList(data).then(
                     (r) => {
                         isLoading.value = false
                         if (isArray(r))
                         {
                             for (var i = 0; i < r.length; i++) {
                                 r[i].index = i+1
                                 r[i].label = r[i].serialnum+"——"+r[i].localIp
                                 r[i].value = r[i].serialnum
                                 deviceList.value.push(r[i])
                             }
                         }
                     }
                 )
             }
             const confirmSearch = function(){
                 queryForm.device_id = []
                 deviceList.value = []
                 isLoading.value = true
                 getDevice()
             }
             const implement = function(){
				if(queryForm.device_id.length<1){
					ElMessage({
					message: `请选择设备`,
					type: 'warning'
					});
					return false
				}
                 deviceList.value.forEach(item=>{
                     queryForm.device_id.forEach(serialnum=>{
                        if(item.serialnum == serialnum){
                             if(item.localIp){
								let parmas = {
									ip:item.localIp,
									startTime:moment(queryForm.date).format('YYYY-MM-DD')+' '+moment(queryForm.startTime).format('HH:mm:ss'),
									endTime:moment(queryForm.date).format('YYYY-MM-DD')+' '+moment(queryForm.endTime).format('HH:mm:ss'),
								}
                                isLoading.value = true
								api.getResultresend(parmas).then( (r) =>{
                                    isLoading.value = false
								        if(r&&r.success){
                                            item.retransmission = '重传成功'
                                            api.getReboot({ip:item.localIp}).then( (r) =>{
                                                    if(r&&r.success){
                                                        item.restart = '重启成功'
                                                    }else{
                                                        item.restart = '重启失败'
                                                    }
                                                    console.log(deviceList.value)
                                                }
                                            )
                                        }else{
                                            item.retransmission = '重传失败'
                                        }
								    }
								)
							}
                        }
                     })
                 })
             }
             const __main = function() {
                 getAccountList()
             }
             
             __main()
             return{
                 deviceList,
                 accountList,
                 plazaList,
                 columns,
                 isLoading,
                 queryForm,
                 onAccountChange,
                 confirmSearch,
                 implement,
                 onPlazaChange
             }
        }
    }
</script>

<style>
</style>