<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 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 hailiang_smart_plc_test from '@/views/acs/device/driver/hailiang_smart_plc_test'
import paint_conveyor from '@/views/acs/device/driver/paint_conveyor'
import cargo_lift_conveyor from '@/views/acs/device/driver/cargo_lift_conveyor'
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 box_palletizing_manipulator from '@/views/acs/device/driver/box_palletizing_manipulator'
import oven_manipulator from '@/views/acs/device/driver/oven_manipulator'
import siemens_conveyor from '@/views/acs/device/driver/siemens_conveyor'
import slit_two_manipulator from '@/views/acs/device/driver/slit_two_manipulator'
import hongxiang_device from '@/views/acs/device/driver/hongxiang_device'
import hongxiang_conveyor from '@/views/acs/device/driver/hongxiang_conveyor'
import plug_pull_device_site from '@/views/acs/device/driver/plug_pull_device_site'
import siemens_conveyor_labeling from '@/views/acs/device/driver/siemens_conveyor_labeling'
import siemens_conveyor_ckk from '@/views/acs/device/driver/siemens_conveyor_ckk'
import siemens_onefloor_agv_conveyor from '@/views/acs/device/driver/siemens_onefloor_agv_conveyor'
import photoelectric_inspection_site from '@/views/acs/device/driver/photoelectric_inspection_site'
import standard_autodoor from '@/views/acs/device/driver/standard_autodoor'
import lamp_three_color from '@/views/acs/device/driver/lamp_three_color'


export default {
  name: 'DeviceConfig',
  components: {
    standard_ordinary_site,
    standard_inspect_site,
    standard_storage,
    standard_scanner,
    standard_conveyor_control_with_scanner,
    standard_conveyor_control,
    standard_conveyor_monitor,
    hailiang_smart_plc_test,
    paint_conveyor,
    cargo_lift_conveyor,
    empty_vehicle_stacking_position,
    agv_ndc_two,
    agv_ndc_one,
    hongxiang_device,
    hongxiang_conveyor,
    box_palletizing_manipulator,
    oven_manipulator,
    siemens_conveyor,
    slit_two_manipulator,
    plug_pull_device_site,
    siemens_conveyor_labeling,
    siemens_conveyor_ckk,
    siemens_onefloor_agv_conveyor,
    photoelectric_inspection_site,
    standard_autodoor,
    lamp_three_color
  },
  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>
