<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"
                    placeholder=""
                    filterable
                    @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 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 lamp_three_color from '@/views/acs/device/driver/lamp_three_color'
import standard_autodoor from '@/views/acs/device/driver/standard_autodoor'
import standard_conveyor_monitor from '@/views/acs/device/driver/standard_conveyor_monitor'
import lnsh_mixing_mill from '@/views/acs/device/driver/lnsh/lnsh_mixing_mill'
import lnsh_press from '@/views/acs/device/driver/lnsh/lnsh_press'
import lnsh_palletizing_manipulator from '@/views/acs/device/driver/lnsh/lnsh_palletizing_manipulator'
import lnsh_kiln_truss from '@/views/acs/device/driver/lnsh/lnsh_kiln_truss'
import lnsh_out_kiln_truss from '@/views/acs/device/driver/lnsh/lnsh_out_kiln_truss'
import lnsh_pallet_storage from '@/views/acs/device/driver/lnsh/lnsh_pallet_storage'
import lnsh_labeling_machine from '@/views/acs/device/driver/lnsh/lnsh_labeling_machine'
import lnsh_split_manipulator from '@/views/acs/device/driver/lnsh/lnsh_split_manipulator'
import lnsh_rgv from '@/views/acs/device/driver/lnsh/lnsh_rgv'
import lnsh_fold_disc_site from '@/views/acs/device/driver/lnsh/lnsh_fold_disc_site'
import lnsh_kiln_lane from '@/views/acs/device/driver/lnsh/lnsh_kiln_lane'
import lnsh_package_line from '@/views/acs/device/driver/lnsh/lnsh_package_line'
import lnsh_package_pallet_manipulator from '@/views/acs/device/driver/lnsh/lnsh_package_pallet_manipulator'
import lnsh_station from '@/views/acs/device/driver/lnsh/lnsh_station'
import lnsh_Laminating_machine from '@/views/acs/device/driver/lnsh/lnsh_Laminating_machine'
import lnsh_package_site from '@/views/acs/device/driver/lnsh/lnsh_package_site'
import lnsh_crusher from '@/views/acs/device/driver/lnsh/lnsh_crusher'
import lnsh_palletizing_manipulator_site from '@/views/acs/device/driver/lnsh/lnsh_palletizing_manipulator_site'
import conveyor_ssx_barcode from '@/views/acs/device/driver/lnsh/conveyor_ssx_barcode'
import conveyor_press_station from '@/views/acs/device/driver/lnsh/conveyor_press_station'
import xg_agv from '@/views/acs/device/driver/xg/xg_agv'
import rgv_station from '@/views/acs/device/driver/rgv_station'
import standard_elevator from '@/views/acs/device/driver/standard_elevator'
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 package_site from './driver/lnsh/package_site.vue'
import nl4_station from '@/views/acs/device/driver/nl4/nl4_station.vue'
import photoelectric_detection_station from '@/views/acs/device/driver/shangdianke/photoelectric_detection_station.vue'

export default {
  name: 'DeviceConfig',
  components: {
    standard_ordinary_site,
    standard_inspect_site,
    lamp_three_color,
    standard_storage,
    standard_scanner,
    standard_conveyor_control_with_scanner,
    standard_conveyor_control,
    standard_conveyor_monitor,
    lnsh_mixing_mill,
    lnsh_press,
    standard_autodoor,
    lnsh_palletizing_manipulator,
    lnsh_fold_disc_site,
    lnsh_kiln_lane,
    lnsh_kiln_truss,
    lnsh_package_line,
    lnsh_out_kiln_truss,
    lnsh_package_pallet_manipulator,
    lnsh_pallet_storage,
    lnsh_labeling_machine,
    lnsh_split_manipulator,
    lnsh_rgv,
    lnsh_station,
    lnsh_Laminating_machine,
    lnsh_package_site,
    lnsh_crusher,
    lnsh_palletizing_manipulator_site,
    conveyor_ssx_barcode,
    conveyor_press_station,
    agv_ndc_one,
    agv_ndc_two,
    package_site,
    nl4_station,
    photoelectric_detection_station,
    xg_agv,
    rgv_station,
    standard_elevator
  },
  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>
