<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label="型号名称" prop="typeName">
              <el-input v-model="queryParams.typeName" placeholder="请输入型号名称" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </transition>

    <el-card shadow="hover">
      <template #header>
        <el-row :gutter="10">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="Plus" @click="handleAdd()">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" plain :disabled="single" icon="Edit" @click="handleUpdate()"> 修改 </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" plain :disabled="multiple" icon="Delete" @click="handleDelete()"> 删除 </el-button>
          </el-col>
          <right-toolbar v-model:show-search="showSearch" :search="true" @query-table="getList"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="loading" border :data="deviceTypeList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column prop="devicePic" label="设备图片">
          <template #default="scope">
            <el-popover placement="right" trigger="click">
              <template #reference>
                <img
                  v-if="scope.row.devicePic"
                  :src="scope.row.devicePic"
                  style="width: 50px; height: 50px; cursor: pointer; object-fit: contain"
                  class="hover:opacity-80 transition-opacity"
                />
                <img v-else src="@/assets/index/IMG.png" alt="" style="width: 40px; height: 40px" />
              </template>
              <img :src="scope.row.devicePic" style="max-width: 600px; max-height: 600px; object-fit: contain" />
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="型号名称" align="center" prop="typeName" />
        <el-table-column label="类型code" align="center" prop="appModelDictionary">
          <template #default="scope">
            {{ appmodelDictionaryOptions.find((item) => item.dictValue === String(scope.row.appModelDictionary))?.dictLabel }}
          </template>
        </el-table-column>
        <el-table-column label="是否支持蓝牙" align="center" prop="isSupportBle">
          <template #default="scope">
            {{ scope.row.isSupportBle ? '是' : '否' }}
          </template>
        </el-table-column>
        <el-table-column prop="locateMode" label="定位方式">
          <template #default="scope">
            <div v-if="scope.row.locateMode == 0">无</div>
            <div v-if="scope.row.locateMode == 1">GPS</div>
            <div v-if="scope.row.locateMode == 2">基站</div>
            <div v-if="scope.row.locateMode == 3">wifi</div>
            <div v-if="scope.row.locateMode == 4">北斗</div>
          </template>
        </el-table-column>
        <el-table-column prop="communicationMode" label="通讯方式">
          <template #default="scope">
            <div v-if="scope.row.communicationMode == 0">4G</div>
            <div v-if="scope.row.communicationMode == 1">蓝牙</div>
            <div v-if="scope.row.communicationMode == 2">4G&蓝牙</div>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建日期" />
        <el-table-column prop="createByName" label="创建人" />

        <el-table-column label="操作" fixed="right" width="180" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-tooltip v-if="scope.row.id !== 1" content="修改" placement="top">
              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip v-if="scope.row.id !== 1" content="删除" placement="top">
              <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip content="更多" placement="top">
              <el-button link type="primary" icon="More" @click="ShowSingleEdit(scope.row)"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" :total="total" @pagination="getList" />
    </el-card>

    <!-- 添加或修改用户配置对话框 -->
    <el-dialog ref="formDialogRef" v-model="dialog.visible" :title="dialog.title" width="30%" append-to-body @close="closeDialog">
      <el-form ref="userFormRef" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="设备类型名称" prop="typeName">
              <el-input v-model="form.typeName" placeholder="请输入设备类型名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="路由跳转" prop="appModelDictionary">
              <el-select v-model="form.appModelDictionary" placeholder="请选择" @change="handlePcRouteChange">
                <el-option v-for="item in appmodelDictionaryOptions" :key="item.dictCode" :label="item.dictLabel" :value="item.dictValue" />
              </el-select>
            </el-form-item>
            <el-form-item label="pc路由跳转" prop="pcModelDictionary" style="display: none">
              <el-select v-model="form.pcModelDictionary" placeholder="请选择">
                <el-option v-for="item in pcmodelDictionaryOptions" :key="item.dictCode" :label="item.dictLabel" :value="item.dictValue" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="是否支持蓝牙" prop="isSupportBle">
              <el-select v-model="form.isSupportBle" placeholder="请选择">
                <el-option label="是" :value="true" />
                <el-option label="否" :value="false" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="定位方式" prop="locateMode">
              <el-select v-model="form.locateMode" placeholder="请选择">
                <el-option label="无" :value="0" />
                <el-option label="GPS" :value="1" />
                <el-option label="基站" :value="2" />
                <el-option label="wifi" :value="3" />
                <el-option label="北斗" :value="4" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="通讯方式" prop="communicationMode">
              <el-select v-model="form.communicationMode" placeholder="请选择">
                <el-option label="4G" :value="0" />
                <el-option label="蓝牙" :value="1" />
                <el-option label="4G&蓝牙" :value="2" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="设备图片" prop="devicePic">
              <input type="file" id="fileTypeImg" accept="image/*" style="display: none" />
              <div class="devicePic typeImgContent" v-if="form.devicePic">
                <img class="img" :src="form.devicePic" />
                <div class="mask center" @click.stop="DropImg(form)">
                  <el-icon class="avatar-uploader-icon"><Delete /></el-icon>
                </div>
              </div>
              <div class="devicePic typeImgAdd center" v-else @click.stop="AddImg(form)">
                <el-icon class="avatar-uploader-icon"><Plus /></el-icon>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm" :loading="loadingIng">确 定</el-button>
          <el-button @click="cancel()">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <el-dialog v-model="Status.ShowEditPop" title="编辑" :draggable="true" width="50%">
      <div class="SingEditContent" v-loading="Status.fullLoading">
        <div class="Param item">
          <div class="title">产品参数</div>
          <div class="imgs">
            <div class="Preview">
              <div class="imgContent" v-for="(item, index) in cEdit.fileParam">
                <img class="img" :src="item.src" />
                <div class="opt" @click.stop="DelImg(item, index, 'fileParam')">
                  <el-icon>
                    <Delete />
                  </el-icon>
                </div>
              </div>
              <div class="clear"></div>
            </div>
          </div>
          <div class="option center" @click.stop="showCheckFile('fileParam')">添加</div>
          <div class="clear">
            <input type="file" accept="image/*" id="fileParam" class="displayNone" />
          </div>
        </div>
        <div class="Oprat item">
          <div class="title">操作说明</div>
          <div class="imgs">
            <div class="Preview">
              <div class="imgContent" v-for="(item, index) in cEdit.fileOprat">
                <img class="img" :src="item.src" />
                <div class="opt" @click.stop="DelImg(item, index, 'fileOprat')">
                  <el-icon>
                    <Delete />
                  </el-icon>
                </div>
              </div>
            </div>
          </div>
          <div class="option center" @click.stop="showCheckFile('fileOprat')">添加</div>
          <div class="clear">
            <input type="file" accept="image/*" id="fileOprat" class="displayNone" />
          </div>
        </div>
        <div class="Video item">
          <div class="title">操作视频</div>
          <div class="img fleft" style="width: calc(100% - 80px)">
            <el-input v-model="cEdit.Video" placeholder="输入网址" />
          </div>
          <div class="clear"></div>
        </div>
      </div>
      <div class="center" style="margin-top: 20px">
        <el-button type="primary" @click="SaveItemData"> 确定 </el-button>
        <el-button type="primary" plain @click="CloseSingleEdit"> 取消 </el-button>
      </div>
    </el-dialog>

    <!-- 提示框 -->
    <el-dialog :width="300" :draggable="true" v-model="Status.confirm.Visible" :title="Status.confirm.title" center>
      <span>
        {{ Status.confirm.text }}
      </span>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="Status.confirm.OkCallback"> 确定 </el-button>
          <el-button v-show="Status.confirm.showCancel" @click="Status.confirm.cancelCallback">取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="User" lang="ts">
import api from '@/api/equipmentManagement/deviceType/index';
import { deviceTypeQuery } from '@/api/equipmentManagement/deviceType/types';
import { getDicts } from '@/api/system/dict/data';
import { to } from 'await-to-js';
import debug from '@/api/debugCenter/debugCenter';
import common from '@/utils/common';
import { ComponentInternalInstance, getCurrentInstance, onMounted, reactive, ref, toRefs } from 'vue';
import {
  ElDialog,
  ElForm,
  ElFormItem,
  ElInput,
  ElRow,
  ElCol,
  ElButton,
  ElCard,
  ElSelect,
  ElOption,
  ElDatePicker,
  ElTable,
  ElTableColumn,
  ElTooltip,
  ElSwitch
} from 'element-plus';
interface deviceTypeVO {
  id: string | number;
  typeName: string;
  isSupportBle: boolean;
  locateMode: number;
  modelDictionary: string;
  appModelDictionary: string;
  pcModelDictionary: string;
  communicationMode: number;
  createTime: string;
  createByName: string;
  devicePic: string;
}
interface DeviceTypeForm extends deviceTypeVO {}
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const deviceTypeList = ref<deviceTypeVO[]>();
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<deviceTypeVO[]>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const queryFormRef = ref<InstanceType<typeof ElForm>>();
const userFormRef = ref<InstanceType<typeof ElForm>>();
const formDialogRef = ref<InstanceType<typeof ElDialog>>();
const loadingIng = ref(false);
const appmodelDictionaryOptions = ref<any[]>([]);
const pcmodelDictionaryOptions = ref<any[]>([]);
var fileC = null;
var uploadFile = false;

const Status = reactive<any>({
  ShowEditPop: false,
  fullLoading: false,
  confirm: {
    //弹出框的配置
    Visible: false,
    title: '',
    text: '',
    cancelCallback: null,
    OkCallback: null,
    showCancel: true
  }
});

var cEdit = reactive({
  deviceId: '',
  deviceImei: '',
  fileBoot: { name: '', type: '', size: '', src: '', file: null },
  fileParam: [],
  fileOprat: [],
  Video: '',
  fileIds: []
});
var fileInput = document.getElementById('fileInput');
var fileInputs = {
  fileParam: null,
  fileOprat: null
};

const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});
const initFormData: DeviceTypeForm = {
  typeName: '',
  isSupportBle: false,
  locateMode: 0,
  // modelDictionary: '',
  appModelDictionary: '',
  pcModelDictionary: '',
  communicationMode: 0,
  id: '',
  createTime: '',
  createByName: ''
};

const initData = {
  form: { ...initFormData },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    typeName: ''
  },
  rules: {
    typeName: [{ required: true, message: '请输入设备类型名称', trigger: 'blur' }],
    appModelDictionary: [{ required: true, message: '请选择类型code', trigger: 'blur' }],
    locateMode: [{ required: true, message: '请选择定位方式', trigger: 'blur' }],
    communicationMode: [{ required: true, message: '请选择通讯方式', trigger: 'blur' }]
  }
};

const data = reactive<{
  form: DeviceTypeForm;
  queryParams: deviceTypeQuery;
  rules: any;
}>(initData);

const { queryParams, form, rules } = toRefs(data);

/** 查询用户列表 */
const getList = async () => {
  loading.value = true;
  const res = await api.deviceType(queryParams.value);
  loading.value = false;
  deviceTypeList.value = res.rows;
  total.value = res.total;
};
const getDict = async () => {
  const res = await getDicts('app_model_dictionary');
  appmodelDictionaryOptions.value = res.data;
};
const pcgetDict = async () => {
  const res = await getDicts('pc_model_dictionary');
  pcmodelDictionaryOptions.value = res.data;
};
/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};
/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  queryParams.value.pageNum = 1;
  getList();
};
// PC路由变化时，同步对应APP路由
const handlePcRouteChange = (pcDictValue: string) => {
  const selectedPcItem = appmodelDictionaryOptions.value.find((item) => item.dictValue === pcDictValue);
  if (!selectedPcItem) return;
  const matchedAppItem = pcmodelDictionaryOptions.value.find((item) => item.dictLabel === selectedPcItem.dictLabel);
  if (matchedAppItem) {
    form.value.pcModelDictionary = matchedAppItem.dictValue;
  } else {
    form.value.pcModelDictionary = '';
    console.warn(`没有找到dictLabel为${selectedPcItem.dictLabel}的APP路由`);
  }
};

/** 删除按钮操作 */
const handleDelete = async (row?: deviceTypeVO) => {
  const deviceTypeIds = row ? [row.id] : ids.value.map((item) => item.id);
  const typeNames = row ? row.typeName : ids.value.map((item) => item.typeName).join(',');
  const [err] = await to(
    proxy?.$modal.confirm('是否确认删除"' + typeNames + '"的数据项？', '系统提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }) as any
  );
  if (!err) {
    await api.deleteDeviceType(deviceTypeIds);
    await getList();
    proxy?.$modal.msgSuccess('删除成功');
  }
};

/** 选择条数  */
const handleSelectionChange = (selection: deviceTypeVO[]) => {
  ids.value = selection;
  single.value = selection.length != 1;
  multiple.value = !selection.length;
};

/** 重置操作表单 */
const reset = () => {
  form.value = { ...initFormData };
  userFormRef.value?.resetFields();
};
/** 取消按钮 */
const cancel = () => {
  dialog.visible = false;
  reset();
};

/** 新增按钮操作 */
const handleAdd = async () => {
  reset();
  dialog.visible = true;
  dialog.title = '新增设备类型';
};

/** 修改按钮操作 */
const handleUpdate = async (row?: DeviceTypeForm) => {
  reset();
  dialog.visible = true;
  dialog.title = '修改设备类型';
  try {
    const deviceData = row || ids.value[0];
    Object.assign(form.value, deviceData);
    // 确保数据类型正确
    form.value.appModelDictionary = String(form.value.appModelDictionary || '');
    form.value.pcModelDictionary = String(form.value.pcModelDictionary || '');
    form.value.locateMode = Number(form.value.locateMode) || 0;
    form.value.communicationMode = Number(form.value.communicationMode) || 0;
  } catch (error) {
    dialog.visible = false;
  }
};

/** 提交按钮 */
const submitForm = () => {
  userFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      loadingIng.value = true;
      try {
        let payload = {
          ...form.value,
          appModelDictionary: form.value.appModelDictionary,
          pcModelDictionary: form.value.pcModelDictionary,

          locateMode: Number(form.value.locateMode),
          communicationMode: Number(form.value.communicationMode)
        };

        let formData = new FormData();
        let keys = Object.keys(payload);

        keys.forEach((key) => {
          if (key !== 'devicePic') {
            if (payload[key] !== null && payload[key] !== undefined) {
              formData.append(key, payload[key]);
            }
          }
        });

        if (uploadFile && fileC && fileC.files.length) {
          formData.append('file', fileC.files[0]);
        }

        //如果要上传文件就用formData,不上传使用payload
        form.value.id ? await api.updateDeviceType(formData) : await api.addDeviceType(formData);
        proxy?.$modal.msgSuccess('操作成功');
        dialog.visible = false;
        await getList();
      } finally {
        loadingIng.value = false;
      }
    }
  });
};

//删除图片
function DropImg(item) {
  ElMessageBox.confirm('删除后不可恢复，您确认要删除吗?', '提醒', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning'
  })
    .then(() => {
      form.value.devicePic = null;
    })
    .catch(() => {});
}

//选择图片
function AddImg(item) {
  uploadFile = false;
  initControl();
  fileC.click();
}
/**
 * 关闭用户弹窗
 */
const closeDialog = () => {
  dialog.visible = false;
  resetForm();
};

/**
 * 重置表单
 */
const resetForm = () => {
  userFormRef.value?.resetFields();
  userFormRef.value?.clearValidate();
  form.value.id = '';
};

function initControl() {
  if (fileC) {
    fileC.value = '';
    return;
  }

  fileC = document.getElementById('fileTypeImg');
  fileC.addEventListener('change', function () {
    if (this.files.length) {
      let file = this.files[0];
      if (file.type.indexOf('image/') === 0) {
        let reader = new FileReader();

        reader.onload = function (e) {
          uploadFile = true;
          form.value.devicePic = e.target.result;
        };

        reader.onerror = function () {
          console.log('读取文件失败！');
        };

        reader.readAsDataURL(file);
      } else {
        // form.value.devicePic = null;
      }
    } else {
      // form.value.devicePic = null;
    }
  });
}

function ShowSingleEdit(item) {
  debugger;
  Status.ShowEditPop = true;
  //期待接口返回以下4个字段

  cEdit.deviceId = item.deviceTypeId;

  // cEdit.fileBoot.src=item.fileBoot;

  // cEdit.fileOprat.src = item.fileOprat;
  // cEdit.fileParam.src =item.fileParam;

  debug.getDeviceInfoById(item.deviceTypeId).then((res) => {
    if (res.code == 200) {
      let video = res.data.appOperationVideoVoList.find((v) => {
        return v.videoUrl;
      });

      if (video) {
        cEdit.Video = video.videoUrl;
      }

      let arr = res.data.appBusinessFileVoList;

      cEdit.fileOprat = arr
        .filter((v) => {
          return v.fileType == 1;
        })
        .map((v) => {
          return { id: v.id, name: v.fileName, type: '', size: '', src: v.fileUrl, file: null };
        });

      cEdit.fileParam = arr
        .filter((v) => {
          return v.fileType == 2;
        })
        .map((v) => {
          return { id: v.id, name: v.fileName, type: '', size: '', src: v.fileUrl, file: null };
        });
    }
  });

  setTimeout(addFileEvt, 500);
}

function addFileEvt() {
  var checkImgOver = function (res, type) {
    cEdit[type].push(res);
  };
  if (!fileInputs.fileOprat || !fileInputs.fileParam) {
    fileInputs.fileOprat = document.getElementById('fileOprat');
    fileInputs.fileParam = document.getElementById('fileParam');

    let keys = Object.keys(fileInputs);
    keys.forEach((k) => {
      fileInputs[k].addEventListener('change', () => {
        handleFiles(fileInputs[k].files).then((res) => {
          checkImgOver(res, k);
        });
      });
    });
  }
}

// 处理选择的文件
function handleFiles(files) {
  return new Promise((resolve, reject) => {
    try {
      if (files.length === 0) {
        reject();
        return;
      }

      let file = files[0];
      if (file.size > 10485760) {
        alert('请选择10M以内的文件');
        reject();
        return;
      }
      if (file.type.indexOf('image/') == -1) {
        alert('只能选择图片文件');
        reject();
        return;
      }
      let json = { file: '', name: '', type: '', size: '', src: null };
      json.file = file;
      json.name = file.name;
      json.type = file.type.replace('image/', '');
      json.size = common.formatBytes(file.size);

      const reader = new FileReader();

      // 读取完成后设置图片源
      reader.onload = function (e) {
        json.src = e.target.result; // 结果是DataURL
        resolve(json);
      };
      reader.onerror = function (ex) {
        resolve(json);
      };

      // 读取图片文件
      reader.readAsDataURL(file);
    } catch (ex) {
      reject();
    }
  });
}

function DelImg(item, index, type) {
  
  confirm('您确认删除吗?', () => {
    if (item.id) {
      cEdit.fileIds.push(item.id);
      cEdit[type].splice(index, 1);
    } else {
      cEdit[type].splice(index, 1);
    }
  });
}

function showCheckFile(type) {
  if (!type) {
    fileInput.click();
  } else {
    let dom = fileInputs[type];
    if (!dom) {
      dom = document.getElementById(type);
    }
    dom.click();
  }
}

//保存单个设备的数据
function SaveItemData() {
  // if (!cEdit.fileBoot.file && !cEdit.fileParam.length && !cEdit.fileOprat.length && !cEdit.Video) {
  //   alert('开机画面、产品参数、操作说明、操作视频四个项至少填写一项。');
  //   return;
  // }
  Status.fullLoading = true;
  var formData = new FormData();
  formData.append('deviceId', cEdit.deviceId);
  formData.append('deviceImei', cEdit.deviceImei);
  formData.append('fileIds', cEdit.fileIds);

  cEdit.fileParam.forEach((v) => {
    if (v.file) {
      formData.append('parameterFiles', v.file); //产品参数
    }
  });

  cEdit.fileOprat.forEach((v) => {
    if (v.file) {
      formData.append('explanationFiles', v.file); //操作说明
    }
  });

  formData.append('videoUrl', cEdit.Video); //操作视频

  let promise1 = debug.updateItem(formData);

  Promise.allSettled([promise1])
    .then((res) => {
      if (res[0].status == 'fulfilled') {
        if (res[0].value.code == 200) {
          CloseSingleEdit();
          alert('操作成功');
          return;
        }
      }
      alert('全部失败或部分失败');
    })
    .finally(() => {
      Status.fullLoading = false;
    });
}

function CloseSingleEdit() {
  Status.ShowEditPop = false;
  cEdit.Video = '';
  cEdit.fileBoot = { name: '', type: '', size: '', src: '', file: null };
  cEdit.fileOprat = [];
  cEdit.fileParam = [];
  cEdit.fileIds = [];
}

window.confirm = function (text, OK, cancel, title) {
  let Cfg = {
    Visible: true,
    title: title ? title : '提示',
    text: text ? text : '此操作不可逆，您确定这样做吗？',
    OkCallback: () => {
      Status.confirm.Visible = false;
      if (OK) {
        OK();
      }
    },
    showCancel: true,
    cancelCallback: () => {
      Status.confirm.Visible = false;
      if (cancel) {
        cancel();
      }
    }
  };

  Status.confirm = Cfg;
};

window.alert = function (text, OK, title) {
  let Cfg = {
    Visible: true,
    title: title ? title : '提示',
    text: text ? text : '不符合规则',
    OkCallback: () => {
      Status.confirm.Visible = false;
      if (OK) {
        OK();
      }
    },
    showCancel: false,
    cancelCallback: null
  };

  Status.confirm = Cfg;
};

onMounted(() => {
  getList(); // 初始化列表数据
  getDict();
  pcgetDict(); //pc跳转
});
</script>

<style>
.devicePic {
  width: 120px;
  height: 120px;
  border-radius: 6px;
  box-sizing: border-box;
  overflow: hidden;
}

.typeImgContent {
  background-color: #ffffff;
  border: 1px solid rgb(220, 223, 230);
  position: relative;
}

.typeImgContent .img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  position: absolute;
  top: 0px;
  left: 0px;
  z-index: 0;
  padding: 10px;
}

.center {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-content: center;
  align-items: center;
  justify-content: center;
}

.typeImgAdd {
  background-color: #fafafa;
  border: 1px dashed rgb(205, 208, 214);
  font-size: 30px;

  cursor: pointer;
}

.mask {
  background-color: #1c1c1c80;
  position: absolute;
  top: 0px;
  left: 0px;
  z-index: 1;
  width: 0px;
  height: 0px;
  cursor: pointer;
  overflow: hidden;
  color: #ff0000;
  font-size: 25px;
}

.typeImgContent:hover .mask {
  width: 100%;
  height: 100%;
}

.fleft {
  float: left;
}

.fright {
  float: right;
}

.clear {
  clear: both;
}

.center {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-content: center;
  align-items: center;
  justify-content: center;
}

.displayNone {
  display: none !important;
}

.content {
  width: 100%;
  min-height: calc(100vh - 84px);
  height: calc(100vh - 84px);
  background: rgba(247, 248, 252, 1);
  font-size: 16px;
  box-sizing: border-box;
  padding: 8px 20px;
  font-family: 'Microsoft YaHei';
}

.topTool {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-content: center;
  justify-content: space-between;
  align-items: flex-start;
  width: 100%;
  border-bottom: 1px solid #e1e2e5f2;
  margin-bottom: 15px;
}
.percent100 {
  width: 100%;
  height: 100%;
  border-radius: 4px;
  box-shadow: 0px 0px 6px 0px rgba(0, 34, 96, 0.1);
  background: rgba(255, 255, 255, 1);
  box-sizing: border-box;
  padding: 15px;
}

:deep .el-collapse-item__header {
  display: none !important;
}
:deep .el-collapse,
:deep .el-collapse-item__wrap {
  border: none !important;
}

.MultiEditContent {
  height: 230px;
  width: 100%;
  box-sizing: border-box;
  box-sizing: border-box;
  border: 1px dashed rgba(56, 64, 79, 0.4);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  align-content: center;
  align-items: center;
  justify-content: center;
}

#MultiEditContent.active {
  border-color: #3498db;
  background-color: #f0f7ff;
}

.txt1 {
  color: rgba(56, 64, 79, 1);

  font-family: Microsoft YaHei;
  font-size: 14px;
  font-weight: 700;
  line-height: 18px;
  letter-spacing: 0px;
  text-align: left;
}

.txt2 {
  color: rgba(56, 64, 79, 0.6);

  font-family: Microsoft YaHei;
  font-size: 14px;
  font-weight: 400;
  line-height: 18px;
  letter-spacing: 0px;
  text-align: left;
}
.txt3 {
  color: rgba(2, 124, 251, 1);
  cursor: pointer;
  font-family: Microsoft YaHei;
  font-size: 14px;
  font-weight: 400;
  line-height: 18px;
  letter-spacing: 0px;
  text-align: left;
}

.SingEditContent .item {
  width: 100%;
  min-height: 90px;
  height: auto;
  border-bottom: 1px dashed #e7e7e7;

  padding: 12px 0px;
}

.Multi .item {
  display: flex;
  flex-direction: row;
  align-content: center;
  align-items: center;
  justify-content: flex-start;
  padding-top: 0px !important;
}

.SingEditContent .item.Video {
  height: 32px;
  border: none;
}

.SingEditContent .item .title {
  width: 80px;
  float: left;
  color: rgba(56, 64, 79, 1);

  font-family: Microsoft YaHei;
  font-size: 14px;
  font-weight: 400;
  line-height: 18px;
  letter-spacing: 0px;
  text-align: left;
}

.SingEditContent .item .imgs {
  width: calc(100% - 110px);
  float: left;
  min-height: 90px;
  height: auto;
}

.SingEditContent .item .option {
  width: 30px;
  float: left;
  height: 100%;
  color: rgba(2, 124, 251, 1);
  cursor: pointer;
  font-family: Microsoft YaHei;
  font-size: 14px;
  font-weight: 400;
  line-height: 18px;
  letter-spacing: 0px;
  text-align: left;
}

#dropArea.active {
  border-color: #3498db;
  background-color: #f0f7ff;
}
.imgPreview {
  width: 100%;
  height: 60px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  margin-top: 20px;
  padding-left: 100px;
  box-sizing: border-box;
}
.imgPreview .img {
  width: 60px;
  height: 60px;
  object-fit: contain;
}
.imgPreview .txt {
  padding-left: 10px;
  width: calc(100% - 60px);
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.SingEditContent .Preview {
  width: 100%;
  height: 100%;
}

.SingEditContent .Preview .img {
  height: 90px;
  width: 160px;
  object-fit: contain;
  border-radius: 4px;
  border: 1px solid #d3d5d7;
}

.SingEditContent .item .imgContent {
  height: 90px;
  width: 160px;
  float: left;
  margin-right: 8px;
  position: relative;
}

.SingEditContent .item .imgContent .opt {
  position: absolute;
  z-index: 1;
  background-color: #00000091;
  display: none;
  top: 0px;
  left: 0px;
  height: 90px;
  width: 160px;
  cursor: pointer;
  color: #bd2b2b;
  font-size: 30px;
  text-align: center;
  line-height: 90px;
}
.SingEditContent .item .imgContent:hover .opt {
  display: block !important;
}

.green {
  color: rgba(0, 165, 82, 1);
}

.red {
  color: rgba(224, 52, 52, 1);
}
</style>
