<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"
        :buy-list="buyList"
        :device-list="deviceList"
        :reader-brand-list="readerBrandList"
        :brand-list="brandList"
        :qr-brand-list="qrBrandList"
        :user-lib-list="userLibList"
        :scene-list="sceneList"
        :push-failed-record-type-list="pushFailedRecordTypeList"
        @finish="back"
        @back="back"
      />
    </div>
  </div>
</template>

<script>
import EditDeviceModule from './components/EditDeviceModule'
import { applicationTypeList, deviceModelList, purchaserList } from '@/api/configuration'
import { getIdCardReaderBrand, getQrCodeReaderBrandEnum, getReaderBrand, templateList } from '@/api/device'
import { getUserLibList } from '@/api/userlib'
import { getList as getSceneList } from '@/api/scene'
import { getPushFailedRecordTypeEnum } from '@/api/HHLocalDevice'

export default {
  components: { EditDeviceModule },
  data() {
    return {
      enumLoading: false, // 是否加载中
      applicationList: [], // 应用类型下拉
      deviceList: [], // 设备型号下拉
      buyList: [], // 购买方公司名称下拉
      brandList: [], // 身份证阅读器品牌下拉
      readerBrandList: [], // 阅读器品牌下拉
      qrBrandList: [], // 二维码读头品牌下拉
      userLibList: [], // 用户库下拉
      sceneList: [], // 场景下拉
      pushFailedRecordTypeList: [], // 记录类型下拉
      obj: null
    }
  },
  mounted() {
    // this.initData()
  },
  created() {
    this.selectInit()
  },
  methods: {
    async selectInit() {
      this.enumLoading = true
      const applicationTypeAxios = await applicationTypeList() // 获取应用类型列表
      const deviceModelAxios = await deviceModelList() // 设备型号列表
      const purchaserAxios = await purchaserList() // 购买方列表
      const templateAxios = await templateList() // 模板列表
      const qrBrandAxios = await getQrCodeReaderBrandEnum() // 获取二维码读头品牌
      const brandAxios = await getIdCardReaderBrand() // 身份证阅读器品牌下拉
      const readerBrandAxios = await getReaderBrand() // 阅读器品牌下拉
      const userLibAxios = await getUserLibList() // 获取用户库下拉
      const sceneAxios = await getSceneList({ pageNumber: 1, pageSize: 1000 }) // 获取场景下拉
      const pushFailedRecordTypeAxios = await getPushFailedRecordTypeEnum() // 记录类型下拉
      Promise.all([
        applicationTypeAxios,
        deviceModelAxios,
        purchaserAxios,
        templateAxios,
        qrBrandAxios,
        brandAxios,
        readerBrandAxios,
        userLibAxios,
        sceneAxios,
        pushFailedRecordTypeAxios
      ]).then(res => {
        const applicationTypeAxiosRes = res[0]
        this.applicationList = applicationTypeAxiosRes.data
        const deviceModelAxiosRes = res[1]
        this.deviceList = deviceModelAxiosRes.data
        const purchaserAxiosRes = res[2]
        this.buyList = purchaserAxiosRes.data
        const templateAxiosRes = res[3]
        this.templateDataList = templateAxiosRes.data
        const qrBrandAxiosRes = res[4]
        this.qrBrandList = qrBrandAxiosRes.data
        const brandAxiosRes = res[5]
        this.brandList = brandAxiosRes.data
        const readerBrandAxiosRes = res[6]
        this.readerBrandList = readerBrandAxiosRes.data
        const userLibAxiosRes = res[7]
        this.userLibList = userLibAxiosRes.data
        const sceneAxiosRes = res[8]
        this.sceneList = sceneAxiosRes.data.records
        const pushFailedRecordTypeAxiosRes = res[9]
        this.pushFailedRecordTypeList = pushFailedRecordTypeAxiosRes.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>
