<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">{{ $t('device.driver_configuration.basic_information') }}：{{ 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="$t('device.device_table_title.device_type')" 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="$t('device.device_table_title.device_encoding')" 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="$t('device.device_table_title.device_name')" 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="$t('device.driver_configuration.basic_information')" 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 '@/views/system/dict/dict'
import standard_autodoor from '@/views/acs/device/driver/standard_autodoor'
import standard_inspect_site from './driver/standard_inspect_site'
import standard_ordinary_site from './driver/standard_ordinary_site'
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 double_station_stacker from '@/views/acs/device/driver/double_station_stacker'
// import hailiang_smart_plc_test from '@/views/acs/device/driver/hailiang_smart_plc_test'
// import paint_conveyor from '@/views/acs/device/driver/paint_conveyor'
import standard_stacker from '@/views/acs/device/driver/standard_stacker'
import siemens_conveyor_labeling from '@/views/acs/device/driver/siemens_conveyor_labeling'
import siemens_conveyor from '@/views/acs/device/driver/siemens_conveyor'
import belt_conveyor from '@/views/acs/device/driver/belt_conveyor'
import lamp_three_color from '@/views/acs/device/driver/lamp_three_color'
import box_palletizing_manipulator from '@/views/acs/device/driver/box_palletizing_manipulator'
import hongxiang_conveyor from '@/views/acs/device/driver/hongxiang_conveyor'
import hongxiang_device from '@/views/acs/device/driver/hongxiang_device'
import oven_manipulator from '@/views/acs/device/driver/oven_manipulator'
import plug_pull_device_site from '@/views/acs/device/driver/plug_pull_device_site'
import slit_two_manipulator from '@/views/acs/device/driver/slit_two_manipulator'
// import empty_vehicle_stacking_position from '@/views/acs/device/driver/empty_vehicle_stacking_position'
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 xg_agv from '@/views/acs/device/driver/agv/xg_agv'
import led_screen from './driver/led_screen'
import standard_station from '@/views/acs/device/driver/standard_station'
import double_belt_conveyor from '@/views/acs/device/driver/double_belt_conveyor.vue'
import with_station_device from '@/views/acs/device/driver/with_station_device.vue'
import standard_manipulator from '@/views/acs/device/driver/standard_manipulator.vue'
import box_manipulator from '@/views/acs/device/driver/box_manipulator.vue'
import conveyor_with_scanner_weight from '@/views/acs/device/driver/conveyor_with_scanner_weight.vue'
import box_manipulator_site from '@/views/acs/device/driver/box_manipulator_site.vue'
import rgv from '@/views/acs/device/driver/rgv.vue'
import dry_manipulator from '@/views/acs/device/driver/dry_manipulator.vue'
import blanking_button from '@/views/acs/device/driver/blanking_button.vue'
import pull_head_manipulator from '@/views/acs/device/driver/pull_head_manipulator.vue'
import pull_tail_manipulator from '@/views/acs/device/driver/pull_tail_manipulator.vue'
import green_foil_machine_button from '@/views/acs/device/driver/green_foil_machine_button.vue'
import inflatable_shaft_library from '@/views/acs/device/driver/inflatable_shaft_library.vue'
import manipulator_agv_station from '@/views/acs/device/driver/manipulator_agv_station.vue'
import subvolume_weighing_station from '@/views/acs/device/driver/subvolume_weighing_station.vue'
import waste_foil_weighing_station from '@/views/acs/device/driver/waste_foil_weighing_station.vue'
import blank_manipulator from '@/views/acs/device/driver/blank_manipulator.vue'
import trapped_manipulator from '@/views/acs/device/driver/one_manipulator/trapped_manipulator.vue'
import box_package_manipulator from '@/views/acs/device/driver/one_manipulator/box_package_manipulator.vue'
import box_storage_manipulator from '@/views/acs/device/driver/one_manipulator/box_storage_manipulator.vue'
import return_good_manipulator from '@/views/acs/device/driver/one_manipulator/return_good_manipulator.vue'
import box_storage_out_conveyor from '@/views/acs/device/driver/one_conveyor/box_storage_out_conveyor.vue'
import box_subvolumes_conveyor from '@/views/acs/device/driver/one_conveyor/box_subvolumes_conveyor.vue'
import finished_product_out_with_bind_lable_conveyor from '@/views/acs/device/driver/one_conveyor/finished_product_out_with_bind_lable_conveyor.vue'
import fold_disc_site from '@/views/acs/device/driver/one_conveyor/fold_disc_site.vue'
import scanner_weight_conveyor from '@/views/acs/device/driver/one_conveyor/scanner_weight_conveyor.vue'
import un_box_lable_conveyor from '@/views/acs/device/driver/one_conveyor/un_box_lable_conveyor.vue'
import xg_agv_car from '@/views/acs/device/driver/agv/xg_agv_car.vue'
import oven_inspect_site from '@/views/acs/device/driver/oven_inspect_site.vue'
export default {
  name: 'DeviceConfig',
  components: {
    standard_autodoor,
    standard_ordinary_site,
    standard_inspect_site,
    standard_storage,
    standard_scanner,
    standard_conveyor_control_with_scanner,
    standard_conveyor_control,
    standard_conveyor_monitor,
    agv_ndc_two,
    agv_ndc_one,
    xg_agv,
    led_screen,
    standard_stacker,
    siemens_conveyor_labeling,
    siemens_conveyor,
    belt_conveyor,
    double_station_stacker,
    lamp_three_color,
    box_palletizing_manipulator,
    hongxiang_conveyor,
    hongxiang_device,
    standard_station,
    oven_manipulator,
    plug_pull_device_site,
    slit_two_manipulator,
    double_belt_conveyor,
    with_station_device,
    standard_manipulator,
    box_manipulator,
    conveyor_with_scanner_weight,
    box_manipulator_site,
    rgv,
    dry_manipulator,
    blank_manipulator,
    box_package_manipulator,
    box_storage_manipulator,
    return_good_manipulator,
    trapped_manipulator,
    un_box_lable_conveyor,
    scanner_weight_conveyor,
    fold_disc_site,
    box_storage_out_conveyor,
    box_subvolumes_conveyor,
    finished_product_out_with_bind_lable_conveyor,
    blanking_button,
    waste_foil_weighing_station,
    subvolume_weighing_station,
    pull_head_manipulator,
    pull_tail_manipulator,
    inflatable_shaft_library,
    green_foil_machine_button,
    xg_agv_car,
    oven_inspect_site,
    manipulator_agv_station
  },
  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 => {
        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>
