index.vue 6.37 KB
<!-- 车辆管理 -->
<template>
  <d2-container class="carManagement">
    <el-form
      :inline="true"
      :model="searchForm"
      label-width="85px"
    >
      <el-form-item label="子系统编号">
        <el-input v-model="searchForm.subSystemNum" placeholder="请输入子系统编号" clearable></el-input>
      </el-form-item>
      <el-form-item label="类型">
        <el-select v-model="searchForm.type" placeholder="请选择类型" clearable filterable>
            <el-option label="座椅" value="1"></el-option>
            <el-option label="桌板" value="2"></el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="车辆编号">
          <el-input v-model="searchForm.carNum" placeholder="请输入车辆编号" clearable></el-input>
      </el-form-item>
      <el-form-item label="生产厂家">
          <el-input v-model="searchForm.manufacturer" placeholder="请输入生产厂家" clearable></el-input>
      </el-form-item>
      <el-form-item>
          <el-button type="primary" @click="handleSearch">查询</el-button>
      </el-form-item>
    </el-form>
    <el-row style="height: 40px; line-height: 40px">
        <el-col :span="12">子系统列表</el-col>
        <el-col :span="12" style="text-align: right">
            <el-button @click="handleAdd">添加子系统</el-button>
        </el-col>
    </el-row>
    <el-table
      :data="tableData"
      border
      style="margin: 20px 0;"
    >
      <el-table-column
        align="center"
        width="60px"
        label="序号"
        type='index'
      ></el-table-column>
      <el-table-column
        v-for="(item, index) in tableColumns"
        :key="index"
        :label="item.label"
        :prop="item.prop"
        :width="item.width"
        align="center"
      >
        <template slot-scope="scope">
          <template v-if="item.formatter">
            {{item.formatter(scope.row)}}
          </template>
          <template v-else>
            {{tableData[scope.$index][item.prop]}}
          </template>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="操作"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleEdit(scope.$index, scope.row)"
          >编辑</el-button>
          <el-button
            type="text"
            @click="handleDelete(scope.$index, scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10,20,30,40]"
      :page-size="pageSize"
      :total="total"
      layout="sizes,total,->,prev,pager,next,jumper"
    >
    </el-pagination>
    <edit-dialog
      :isVisible="editVisible"
      :editForm="editForm"
      @closeDialog="handleEditClose"
      @confirmDialog="handleEditConfirm"
    ></edit-dialog>
  </d2-container>
</template>

<script>
import EditDialog from './editDialog'
export default {
  name: 'subSysManagement',
  components: {
    EditDialog
  },
  data () {
    return {
      // 新增/编辑弹窗
      editVisible: false,
      editForm: {
        subSystemNum: '',
        type: '',
        carNum: '',
        manufacturer: '',
        xl: '',
        jk: '',
        wgdz: '',
        wgdk: ''
      },
      // 搜索
      searchForm: {
        subSystemNum: '',
        type: '',
        carNum: '',
        manufacturer: ''
      },
      tableData: [{
        subSystemNum: '3#1F',
        type: '座椅',
        carNum: 'CRH45661-5648',
        manufacturer: '长春通富机电设备有限公司',
        xl: '1.56',
        jk: '4000',
        wgdz: '192.168.1.1',
        wgdk: '8000'
      }, {
        subSystemNum: '3#2F',
        type: '桌板',
        carNum: 'CRH45661-5648',
        manufacturer: '长春通富机电设备有限公司',
        xl: '1.56',
        jk: '4000',
        wgdz: '192.168.1.1',
        wgdk: '8000'
      }, {
        subSystemNum: '3#3F',
        type: '座椅',
        carNum: 'CRH45661-5648',
        manufacturer: '长春通富机电设备有限公司',
        xl: '1.56',
        jk: '4000',
        wgdz: '192.168.1.1',
        wgdk: '8000'
      }],
      tableColumns: [{
          label: '子系统编号',
          prop: 'subSystemNum'
      }, {
          label: '类型',
          prop: 'type'
      }, {
          label: '车辆编号',
          prop: 'carNum'
      }, {
          label: '生产厂家',
          prop: 'manufacturer'
      }, {
          label: '发送结点序列',
          prop: 'xl'
      }, {
          label: '发送结点接口',
          prop: 'jk'
      }, {
          label: '网关地址',
          prop: 'wgdz'
      }, {
          label: '网关端口',
          prop: 'wgdk'
      }],
      // 页码
      currentPage: 1,
      pageSize: 10,
      total: 30
    }
  },

  methods: {
    // 搜索
    handleSearch () {
      console.log(this.searchForm)
    },

    // 页码
    handleSizeChange (value) {
      console.log(value)
      this.pageSize = value
      // 调接口
    },

    handleCurrentChange (value) {
      console.log(value)
      this.currentPage = value
      // 调接口
    },

    resetForm(obj) {
      for (var item in obj) {
        if (obj[item] instanceof Array) {
          obj[item] = []
        } else {
          obj[item] = ''
        }
      }
    },

    handleAdd () {
      this.editVisible = !this.editVisible
    },

    handleEditClose() {
      this.editVisible = !this.editVisible
      this.resetForm(this.editForm)
    },

    handleEditConfirm() {
      console.log(JSON.parse(JSON.stringify(this.editForm)))
      this.editVisible = !this.editVisible
      this.resetForm(this.editForm)
    },

    // 表格-编辑
    handleEdit (index, row) {
      console.log(index)
      console.log(row)
      this.editForm = JSON.parse(JSON.stringify(row))
      this.editVisible = !this.editVisible
    },

    handleDelete (index, row) {
      this.$confirm('确认删除?', '删除', {
        comfirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        console.log(index)
        console.log(row)
        this.$message({
          type: 'success',
          message: '删除成功'
        })
      }).catch(err => {})
    }
  }
}

</script>
<style scoped>
</style>