<template>
  <div class="app-container">
    <div class="head">
      添加配置模板
      <el-button
        type="primary"
        size="mini"
        style="margin-left: 20px"
        @click="back"
      >返回</el-button>
    </div>
    <div
      v-loading="enumLoading"
      element-loading-text="加载中..."
    >
      <edit-device-module
        style="margin-left: 16px"
        :obj="obj"
        :application-list="applicationList"
        :device-list="deviceList"
        :brand-list="brandList"
        :reader-brand-list="readerBrandList"
        :qr-brand-list="qrBrandList"
        :camera-type-list="cameraTypeList"
        :live-type-list="liveTypeList"
        :push-failed-record-type-list="pushFailedRecordTypeList"
        :success-show-personal-info-type-list="successShowPersonalInfoTypeList"
        :set-personal-type-list="setPersonalTypeList"
        @finish="back"
        @back="back"
      />
    </div>
  </div>
</template>

<script>
import EditDeviceModule from './components/EditDeviceModule'
import { applicationTypeList, deviceModelList } from '@/api/configuration'
import { getIdCardReaderBrand, getQrCodeReaderBrandEnum, getReaderBrand } from '@/api/device'
import {
  getCameraTypeEnum,
  getLiveTypeEnum,
  getPushFailedRecordTypeEnum, getSetPersonalListEnum,
  getSuccessShowPersonalInfoListEnum
} from '@/api/HHLocalDevice'

export default {
  components: { EditDeviceModule },
  data() {
    return {
      enumLoading: false, // 是否加载中
      applicationList: [], // 设备型号下拉
      deviceList: [], // 设备型号下拉
      brandList: [], // 身份证阅读器品牌下拉
      readerBrandList: [], // 阅读器品牌下拉
      qrBrandList: [], // 二维码读头品牌下拉
      cameraTypeList: [], // 摄像头类型下拉
      liveTypeList: [], // 活体检测模式下拉
      pushFailedRecordTypeList: [], // 记录类型下拉
      successShowPersonalInfoTypeList: [], // 成功显示人员信息下拉
      setPersonalTypeList: [], // 设置——人员列表下拉
      obj: null
    }
  },
  mounted() {
    // this.initData()
  },
  created() {
    this.selectInit()
  },
  methods: {
    async selectInit() {
      this.enumLoading = true
      const applicationTypeAxios = await applicationTypeList() // 获取应用类型列表
      const deviceModelAxios = await deviceModelList() // 设备型号列表
      const qrBrandAxios = await getQrCodeReaderBrandEnum() // 获取二维码读头品牌
      const brandAxios = await getIdCardReaderBrand() // 身份证阅读器品牌下拉
      const readerBrandAxios = await getReaderBrand() // 阅读器品牌下拉
      const cameraTypeAxios = await getCameraTypeEnum() // 摄像头类型下拉
      const liveTypeAxios = await getLiveTypeEnum() // 活体检测模式下拉
      const pushFailedRecordTypeAxios = await getPushFailedRecordTypeEnum() // 记录类型下拉
      const successShowPersonalInfoTypeAxios = await getSuccessShowPersonalInfoListEnum() // 成功显示人员信息下拉
      const setPersonalTypeAxios = await getSetPersonalListEnum() // 设置——人员列表下拉
      Promise.all([
        applicationTypeAxios,
        deviceModelAxios,
        qrBrandAxios,
        brandAxios,
        readerBrandAxios,
        cameraTypeAxios,
        liveTypeAxios,
        pushFailedRecordTypeAxios,
        successShowPersonalInfoTypeAxios,
        setPersonalTypeAxios
      ]).then(res => {
        const applicationTypeAxiosRes = res[0]
        this.applicationList = applicationTypeAxiosRes.data
        const deviceModelAxiosRes = res[1]
        this.deviceList = deviceModelAxiosRes.data
        const qrBrandAxiosRes = res[2]
        this.qrBrandList = qrBrandAxiosRes.data
        const brandAxiosRes = res[3]
        this.brandList = brandAxiosRes.data
        const readerBrandAxiosRes = res[4]
        this.readerBrandList = readerBrandAxiosRes.data
        const cameraTypeAxiosRes = res[5]
        this.cameraTypeList = cameraTypeAxiosRes.data
        const liveTypeAxiosRes = res[6]
        this.liveTypeList = liveTypeAxiosRes.data
        const pushFailedRecordTypeAxiosRes = res[7]
        this.pushFailedRecordTypeList = pushFailedRecordTypeAxiosRes.data
        const successShowPersonalInfoTypeAxiosRes = res[8]
        this.successShowPersonalInfoTypeList = successShowPersonalInfoTypeAxiosRes.data
        const setPersonalTypeAxiosRes = res[9]
        this.setPersonalTypeList = setPersonalTypeAxiosRes.data
      }).finally(() => {
        this.enumLoading = false
      })
    },
    back() {
      this.$router.back()
    }
  }
}
</script>

<style scoped>
.head {
  margin-left: 16px;
  font-weight: 600;
  font-size: 18px;
  color: #333333;
}
.foot-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 34px;
  padding-right: 180px;
  margin-bottom: 20px;
}
</style>
