index.vue 6.96 KB
<!-- 车辆管理 -->
<template>
  <d2-container class="trafficManagement">
    <el-form
      :inline="true"
      :model="searchForm"
      label-width="85px"
      slot="header"
    >
      <el-form-item label="车辆编号">
        <el-input v-model="searchForm.trafficCode" placeholder="请输入车辆编号" @clear="loadingGetList" clearable></el-input>
      </el-form-item>
      <el-form-item label="归属车辆段">
        <el-select v-model="searchForm.stationCode" placeholder="请选择归属车辆段" @clear="loadingGetList" clearable filterable>
            <el-option v-for="(item, index) in baseData.station"
              :key="index"
              :value="item.confCode"
              :label="item.confValue"
            ></el-option>
          </el-select>
      </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>
    <d2-table-header title="车辆列表"><auth-button category="Button" :data="editFormReset"></auth-button></d2-table-header>
    <el-table
      :data="tableData"
      v-loading="$store.state.d2admin.loading.value"
      :stripe="true"
      border
      :highlight-current-row="true"
    >
      <el-table-column
        align="center"
        width="60px"
        label="序号"
        type='index'
        :index="index=>index+(currentPage - 1) * pageSize + 1"
      ></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="操作"
        width="200"
      >
        <template slot-scope="scope">
          <auth-button :data="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"
      :station="baseData.station"
      @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/trafficManagement'
import notice from '@/common/notice'
export default {
  name: 'fimsTrafficManagement',
  components: {
    EditDialog
  },
  data() {
    return {
      // 新增/编辑弹窗
      editVisible: false,
      editFormReset: {
        id: '',
        trafficCode: '',
        stationCode: '',
        stationName: '',
        merchantName: '',
        openType: ''
      },
      editForm: {
        id: '',
        trafficCode: '',
        stationCode: '',
        stationName: '',
        merchantName: '',
        openType: ''
      },
      // 搜索
      searchForm: {
        trafficCode: '',
        stationCode: '',
        merchantName: '',
        openType: ''
      },
      // 表格
      tableData: [],
      tableColumns: [{
        label: '车辆编号',
        prop: 'trafficCode',
        width: '120'
      }, {
        label: '归属车辆段',
        prop: 'stationName'
      }, {
        label: '维修承包商',
        prop: 'merchantName'
      }, {
        label: '接口开放',
        prop: 'openType',
        width: '80px',
        formatter: (cellValue) => {
          if (cellValue.openType) {
            return {
              1: '是',
              2: '否'
            }[cellValue.openType]
          }
        }
      }],
      // 页码
      currentPage: 1,
      pageSize: 10,
      total: 30,
      baseData: {
        station: []
      }
    }
  },

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

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

    loadingGetList() {
      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.trafficList
        this.total = res.pagination.totalCount
      }).catch(() => {
        notice.errorTips()
      })
    },
    editTraffic(value) {
      // console.log(value)
      const params = _.cloneDeep(this.editFormReset)
      Object.keys(params).map(key => (params[key] = value[key]))
      params.stationName = this.baseData.station.find(item => item.confCode === params.stationCode).confValue
      !value.id ? delete params.id : delete params.trafficCode
      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) {
      // console.log(value)
      this.pageSize = value
      // 调接口
      this.loadingGetList()
    },

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

    handleEditClose() {
      this.editVisible = !this.editVisible
      // delete this.editForm.id
    },

    handleEditConfirm() {
      var editParams = _.cloneDeep(this.editForm)
      this.editTraffic(editParams)
    },

    // 表格-编辑
    handleEdit(row) {
      // console.log(row)
      this.editForm = _.cloneDeep(row)
      this.editVisible = !this.editVisible
    },

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

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