<template>
  <div class="app-container">
    <el-row :gutter="15">
      <el-col>
        <el-card class="box-card" shadow="never">
          <div slot="header" class="clearfix">
            <span class="role-span">基本信息：{{ device_code }}</span>
          </div>
          <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="78px">
            <el-row>
              <el-col :span="12">
                <el-form-item label="设备类型" prop="device_type">
                  <el-select
                    v-model="form.device_type"
                    placeholder=""
                    disabled
                  >
                    <el-option
                      v-for="item in dict.device_type"
                      :key="item.id"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                  <span style="color: #C0C0C0;margin-left: 10px;" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="设备编号" prop="device_code">
                  <el-input v-model="form.device_code" disabled />
                  <span style="color: #C0C0C0;margin-left: 10px;" />
                </el-form-item>
              </el-col>
            </el-row>

            <el-row>
              <el-col :span="12">
                <el-form-item label="设备名称" prop="device_name">
                  <el-input v-model="form.device_name" disabled />
                  <span style="color: #C0C0C0;margin-left: 10px;" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="设备驱动" prop="driver_code">
                  <el-select
                    v-model="form.driver_code"
                    filterable
                    placeholder=""
                    @change="changeDriver"
                  >
                    <el-option
                      v-for="item in deviceDriverList"
                      :key="item.code"
                      :label="item.name"
                      :value="item.code"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-card>
      </el-col>

      <!--  组件-->
      <component :is="currentComponent" :parent-form="form" />

    </el-row>
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import { get, selectDriverCodeList } from '@/api/acs/device/driverConfig'
import { getDicts } from '@/api/system/dict'
import weighing_site from './driver/weighing_site'
import machines_site from './driver/machines_site'
import standard_emptypallet_site from './driver/standard_emptypallet_site'
import standard_manipulator_inspect_site from './driver/standard_manipulator_inspect_site'
import standard_special_inspect_site from './driver/standard_special_inspect_site'
import special_ordinary_site from './driver/special_ordinary_site'
import standard_conveyor_control_with_plcscanner
from '@/views/acs/device/driver/standard_conveyor_control_with_plcscanner'
import non_line_manipulator_inspect_site from '@/views/acs/device/driver/non_line_manipulator_inspect_site'
import non_line_inspect_site from '@/views/acs/device/driver/non_line_inspect_site'
import manipulator_inspect_site_NDC from '@/views/acs/device/driver/manipulator_inspect_site_NDC'
import standard_manipulator_stacking_site from '@/views/acs/device/driver/standard_manipulator_stacking_site'
import standard_photoelectric_inspect_site from '@/views/acs/device/driver/standard_photoelectric_inspect_site'
import standard_inspect_site from './driver/standard_inspect_site'
import standard_ordinary_site from './driver/standard_ordinary_site'
import lamp_three_color from './driver/lamp_three_color'
import standard_autodoor from './driver/standard_autodoor'
import standard_storage from '@/views/acs/device/driver/standard_storage'
import standard_scanner from '@/views/acs/device/driver/standard_scanner'
import standard_conveyor_control_with_scanner from '@/views/acs/device/driver/standard_conveyor_control_with_scanner'
import standard_conveyor_control from '@/views/acs/device/driver/standard_conveyor_control'
import standard_conveyor_monitor from '@/views/acs/device/driver/standard_conveyor_monitor'

import hailiang_special_pick_station from '@/views/acs/device/driver/hailiang_one/hailiang_special_pick_station'
import hailiang_special_empty_station from '@/views/acs/device/driver/hailiang_one/hailiang_special_empty_station'
import hailiang_special_full_station from '@/views/acs/device/driver/hailiang_one/hailiang_special_full_station'
import hailiang_special_pour_station from '@/views/acs/device/driver/hailiang_one/hailiang_special_pour_station'
import hailiang_special_device from '@/views/acs/device/driver/hailiang_one/hailiang_special_device'
import hailiang_engraving_machine from '@/views/acs/device/driver/hailiang_one/hailiang_engraving_machine'
import hailiang_engraving_cache from '@/views/acs/device/driver/hailiang_one/hailiang_engraving_cache'
import hailiang_packer_station from '@/views/acs/device/driver/hailiang_one/hailiang_packer_station'
import hailiang_auto_cache_line from '@/views/acs/device/driver/hailiang_one/hailiang_auto_cache_line'
import hailiang_cleaning_feeding_line from '@/views/acs/device/driver/hailiang_one/hailiang_cleaning_feeding_line'
import hailiang_cleaning_machine from '@/views/acs/device/driver/hailiang_one/hailiang_cleaning_machine'
import hailiang_cleaning_machine_storage_station
from '@/views/acs/device/driver/hailiang_one/hailiang_cleaning_machine_storage_station'
import agv_ndc_one from '@/views/acs/device/driver/agv/agv_ndc_one'
import agv_ndc_two from '@/views/acs/device/driver/agv/agv_ndc_two'
import hailiang_xj_plc_test from '@/views/acs/device/driver/hailiang_one/hailiang_xj_plc_test'
import hailiang_smart_plc_test from '@/views/acs/device/driver/hailiang_one/hailiang_smart_plc_test'
import hailiang_threestation_smart from '@/views/acs/device/driver/hailiang_one/hailiang_threestation_smart'
import hailiang_foldingDisc_smart from '@/views/acs/device/driver/hailiang_one/hailiang_foldingDisc_smart'
import hailiang_elevator_wiring from '@/views/acs/device/driver/hailiang_one/hailiang_elevator_wiring'
import hailiang_paint_line from '@/views/acs/device/driver/hailiang_one/hailiang_paint_line'
import hailiang_stacking_station from '@/views/acs/device/driver/hailiang_one/hailiang_stacking_station'

import hailiang_old_special_device from '@/views/acs/device/driver/hailiang_one/hailiang_old_special_device'
import hailiang_old_special_empty_station from '@/views/acs/device/driver/hailiang_one/hailiang_old_special_empty_station'
import hailiang_old_special_full_station from '@/views/acs/device/driver/hailiang_one/hailiang_old_special_full_station'
import hailiang_old_special_pick_station from '@/views/acs/device/driver/hailiang_one/hailiang_old_special_pick_station'
import hailiang_old_special_pour_station from '@/views/acs/device/driver/hailiang_one/hailiang_old_special_pour_station'

import hailiang_ealing_machine from '@/views/acs/device/driver/hailiang_one/hailiang_ealing_machine'
import hailiang_sealing_machine from '@/views/acs/device/driver/hailiang_one/hailiang_sealing_machine'
import hailiang_unboxing_machine from '@/views/acs/device/driver/hailiang_one/hailiang_unboxing_machine'

import hailiang_old_palletizing_station from '@/views/acs/device/driver/hailiang_old/hailiang_old_palletizing_station'
import hailiang_old_stacking_manipulator from '@/views/acs/device/driver/hailiang_old/hailiang_old_stacking_manipulator'
import hailiang_old_package_ssx_station from '@/views/acs/device/driver/hailiang_old/hailiang_old_package_ssx_station'
import hailiang_old_lettering_package_device from '@/views/acs/device/driver/hailiang_old/hailiang_old_lettering_package_device'
import hailiang_old_unboxing_machine from '@/views/acs/device/driver/hailiang_old/hailiang_old_unboxing_machine'
import hailiang_old_package_receiving_machine from '@/views/acs/device/driver/hailiang_old/hailiang_old_package_receiving_machine'
import hailiang_cleaning_put_line from '@/views/acs/device/driver/hailiang_one/hailiang_cleaning_put_line'
import hailiang_engraving_in from '@/views/acs/device/driver/hailiang_one/hailiang_engraving_in'
export default {
  name: 'DeviceConfig',
  components: {
    hailiang_ealing_machine,
    hailiang_sealing_machine,
    hailiang_unboxing_machine,
    hailiang_old_special_device,
    hailiang_old_special_empty_station,
    hailiang_old_special_full_station,
    hailiang_old_special_pick_station,
    hailiang_old_special_pour_station,
    standard_ordinary_site,
    standard_inspect_site,
    standard_autodoor,
    standard_emptypallet_site,
    standard_manipulator_inspect_site,
    standard_special_inspect_site,
    lamp_three_color,
    standard_storage,
    special_ordinary_site,
    standard_scanner,
    standard_conveyor_control_with_scanner,
    standard_conveyor_control_with_plcscanner,
    standard_conveyor_control,
    standard_conveyor_monitor,
    weighing_site,
    machines_site,
    non_line_manipulator_inspect_site,
    non_line_inspect_site,
    manipulator_inspect_site_NDC,
    standard_manipulator_stacking_site,
    standard_photoelectric_inspect_site,
    agv_ndc_two,
    agv_ndc_one,
    hailiang_packer_station,
    hailiang_engraving_cache,
    hailiang_special_pick_station,
    hailiang_special_empty_station,
    hailiang_special_full_station,
    hailiang_special_pour_station,
    hailiang_special_device,
    hailiang_engraving_machine,
    hailiang_auto_cache_line,
    hailiang_cleaning_feeding_line,
    hailiang_cleaning_machine,
    hailiang_cleaning_machine_storage_station,
    hailiang_xj_plc_test,
    hailiang_smart_plc_test,
    hailiang_threestation_smart,
    hailiang_foldingDisc_smart,
    hailiang_elevator_wiring,
    hailiang_paint_line,
    hailiang_stacking_station,
    hailiang_old_stacking_manipulator,
    hailiang_old_palletizing_station,
    hailiang_old_package_ssx_station,
    hailiang_old_lettering_package_device,
    hailiang_old_unboxing_machine,
    hailiang_old_package_receiving_machine,
    hailiang_cleaning_put_line,
    hailiang_engraving_in
  },
  dicts: ['device_type'],
  mixins: [crud],
  data() {
    return {
      currentComponent: '',
      activeName: 'first',
      device_name: '',
      tableHeight: 550,
      columnLoading: false,
      configLoading: false,
      dicts: [],
      syncLoading: false,
      genLoading: false,
      form: { id: null, device_name: '', device_type: '', name: '', code: '', driver_code: '' },
      deviceDriverList: [],
      rules: {
        driver_code: [
          { required: true, message: '设备驱动不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.tableHeight = document.documentElement.clientHeight - 385
    this.device_code = this.$route.params.device_code
    this.$nextTick(() => {
      get(this.device_code).then(data => {
        debugger
        this.form = data.device
        // 默认是普通站点
        // this.currentComponent = 'standard_ordinary_site'
        if (data.device.driver_code) {
          this.currentComponent = data.device.driver_code
        }
      })
      selectDriverCodeList(this.device_code).then(data => {
        this.deviceDriverList = data
      })
      getDicts().then(data => {
        this.dicts = data
      })
    })
  },
  methods: {
    changeDriver(val) {
      this.currentComponent = val
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
.edit-input {
  .el-input__inner {
    border: 1px solid #e5e6e7;
  }
}
</style>

<style scoped>
::v-deep .input-with-select .el-input-group__prepend {
  background-color: #fff;
}
</style>
