index.vue 8.8 KB
<!-- 车辆管理 -->
<template>
  <d2-container class="carManagement">
    <el-form
      :inline="true"
      :model="searchForm"
      label-width="85px"
      slot="header"
    >
      <el-form-item label="子系统编号">
        <el-input v-model="searchForm.subsystemCode" placeholder="请输入子系统编号" @clear="loadingGetList" clearable></el-input>
      </el-form-item>
      <el-form-item label="类型">
        <el-select v-model="searchForm.subsystemTypeCode" placeholder="请选择类型" @clear="loadingGetList" clearable filterable>
            <el-option v-for="(item, index) in baseData.subsys"
              :key="index"
              :value="item.confCode"
              :label="item.confValue"
            ></el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="车辆编号">
          <el-input v-model="searchForm.trafficCode" placeholder="请输入车辆编号" @clear="loadingGetList" clearable></el-input>
      </el-form-item>
      <el-form-item label="生产厂家">
          <el-input v-model="searchForm.merchantName" placeholder="请输入生产厂家" @clear="loadingGetList" clearable></el-input>
      </el-form-item>
      <el-form-item>
          <el-button type="primary"  icon="el-icon-search" @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">
          <auth-button category="Button" :data="editFormReset"></auth-button>
            <!-- <el-button @click="handleEdit(editFormReset)">添加子系统</el-button> -->
            <!-- <auth-button label="添加子系统" type="" @e-auth-click="handleEdit(editFormReset)"></auth-button> -->
        </el-col>
    </el-row>
    <el-table
      :data="tableData"
      v-loading="tableLoading"
      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||160"
        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="操作"
        fix="right"
      >
        <template slot-scope="scope">
          <auth-button
            :data="scope.row"
          ></auth-button>
          <!-- <auth-button
            label="编辑"
            @e-auth-click="handleEdit(scope.row, scope.$index)"
          ></auth-button>
          <auth-button
            label="删除"
            @e-auth-click="handleDelete(scope.$index, scope.row)"
          ></auth-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"
      :subsys="baseData.subsys"
      @closeDialog="handleEditClose"
      @confirmDialog="handleEditConfirm"
    ></edit-dialog>
  </d2-container>
</template>

<script>
import EditDialog from './editDialog'
import { BaseData } from '@/common/constants'
import { getListApi, methods, editApi, removeApi } from '@api/subSysManagement'
import notice from '@/common/notice'
export default {
  name: 'fimsSubSysManagement',
  components: {
    EditDialog
  },
  data () {
    return {
      // 新增/编辑弹窗
      editVisible: false,
      editFormReset: {
        subsystemCode: '',
        systemType: '',
        trafficCode: '',
        merchantName: '',
        sendSequence: '',
        sendPort: '',
        gatewayUrl: '',
        gatewayPort: ''
      },
      editForm: {
        subsystemCode: '',
        systemType: '',
        trafficCode: '',
        merchantName: '',
        sendSequence: '',
        sendPort: '',
        gatewayUrl: '',
        gatewayPort: ''
      },
      // 搜索
      searchForm: {
        subsystemCode: '',
        subsystemTypeCode: '',
        trafficCode: '',
        merchantName: ''
      },
      tableLoading: false,
      tableData: [],
      tableColumns: [{
        label: '子系统编号',
        prop: 'subsystemCode'
      }, {
        label: '类型',
        prop: 'subsystemType'
      }, {
        label: '车辆编号',
        prop: 'trafficCode'
      }, {
        label: '生产厂家',
        prop: 'merchantName',
        width: '220'
      }, {
        label: '发送结点序列',
        prop: 'sendSequence'
      }, {
        label: '发送结点接口',
        prop: 'sendPort'
      }, {
        label: '网关地址',
        prop: 'gatewayUrl'
      }, {
        label: '网关端口',
        prop: 'gatewayPort'
      }],
      // 页码
      currentPage: 1,
      pageSize: 10,
      total: 30,
      baseData: {
        subsys: []
      }
    }
  },

  mounted () {
    this.loadingGetList()
    this.loadBaseData()
  },

  methods: {

    async loadBaseData () {
      const data = await this.$store.dispatch('d2admin/base/get', BaseData.SUBSYS.KEY)
      this.baseData.subsys = data
    },

    loadingGetList () {
      this.tableLoading = true
      this.getList()
    },
    /* 接口请求-start */
    getParams () {
      return {
        pageCount: this.pageSize,
        pageSize: this.currentPage,
        ...this.searchForm
      }
    },
    getList () {
      const params = this.getParams()
      getListApi(params).then(res => {
        this.tableData = res.subsystemList
        this.total = res.pagination.totalCount
        this.tableLoading = false
      }).catch(() => {
        notice.errorTips()
        this.tableLoading = false
      })
    },

    delObjMutiAttr (obj, key) {

    },

    editSubSystem (value) {
      const params = {
        id: '',
        subsystemCode: '',
        trafficCode: '',
        subsystemType: '',
        subsystemTypeCode: '',
        merchantName: '',
        sendSequence: '',
        sendPort: '',
        gatewayUrl: '',
        gatewayPort: ''
      }
      if (!value.id) {
        delete params.id
      } else {
        delete params.subsystemCode
        delete params.trafficCode
      }
      for (var item in params) {
        params[item] = value[item]
      }
      for (var i in this.baseData.subsys) {
        if (this.baseData.subsys[i].confCode === params.subsystemTypeCode) {
          params.subsystemType = this.baseData.subsys[i].confValue
          break
        }
      }
      params.method = value.id ? methods.Edit : methods.Add
      // console.log(params)
      editApi(params).then(res => {
        this.handleEditClose()
        notice.okTips()
        this.loadingGetList()
      }).catch(() => {
        notice.errorTips()
      })
    },
    /* 接口请求-end */
    // 搜索
    handleSearch () {
      this.loadingGetList()
    },

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

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

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

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

    handleEditConfirm () {
      var editParams = JSON.parse(JSON.stringify(this.editForm))
      this.editSubSystem(editParams)
    },

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

    handleDelete (row) {
      this.$confirm('确认删除?', '删除', {
        comfirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // console.log(index)
        // console.log(row)
        // this.$message({
        //   type: 'success',
        //   message: '删除成功'
        // })
        removeApi({
          id: row.id,
          usedStatus: 2
        }).then(() => {
          notice.okTips()
          this.loadingGetList()
        }).catch(() => {
          notice.errorTips()
        })
      }).catch(() => {})
    }
  }
}

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