index.vue 12.1 KB
<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button :class="{'el-button':true, 'el-button--primary':this.queryParams.status==0}"  size="mini" @click="getData(1);" >失信驾驶员</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button  :class="{'el-button':true,'el-button--primary':this.queryParams.status==1}" size="mini" @click="getHistoryData(1);">历史驾驶员</el-button>
      </el-col>
    </el-row>

    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-row type="flex" justify="center">
        <el-col>
          <el-form-item label="驾驶员姓名" prop="name"
                        style="float:right;">
            <el-select v-model="queryParams.name"
                       filterable
                       clearable
                       reserve-keyword
                       placeholder="驾驶员姓名"
                       size="small"
                       :loading="loading">
              <el-option
                v-for="item in dictNames"
                :label="item"
                :value="item">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col>
        <el-form-item label="失信日期" prop="time" v-show="queryParams.status==0">
          <el-date-picker clearable size="small" style="width: 200px" v-model="queryParams.time" type="date"
                          value-format="yyyy-MM-dd" placeholder="失信日期">
          </el-date-picker>
        </el-form-item>
      </el-col>
      </el-row>

    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary"  size="mini" @click="handleAdd" v-hasPermi="['driver:credit:add']"  v-if="queryParams.status==0">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button  size="mini" @click="handleExport" v-hasPermi="['driver:credit:export']">导出</el-button>
      </el-col>

      <el-col :span="20" style="height: 1px;"></el-col>
      <el-col :span="1.5">
        <el-button type="primary"  size="mini" @click="handleQuery">查询</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button  size="mini" @click="resetQuery">重置</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="creditList" @selection-change="handleSelectionChange" :cell-style="colStyle" border>
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="驾驶员姓名" align="center" prop="name" />
      <el-table-column label="证件号码" align="center" prop="idNumber" />
      <el-table-column label="失信时间" align="center" prop="time" width="180" v-if="queryParams.status==0">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.time, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="失信原因" align="center" prop="reason" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['driver:credit:edit']" v-if="queryParams.status==0">撤销失信</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="getDataInfo(scope.row)" v-if="queryParams.status==1">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList" />

    <!-- 添加或修改工地对话框 -->
    <el-dialog :title="title" :visible.sync="open"  width="500px" append-to-body  v-loading="loading">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="驾驶员姓名" prop="name">
          <el-select
            v-model="form.name"
            filterable
            reserve-keyword
            placeholder="驾驶员姓名">
            <el-option
              @click.native="getObjId(item)"
              v-for="item in driverList"
              :key="item.id"
              :label="item.name"
              :value="item.name">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="证件号码" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="证件号码" disabled/>
        </el-form-item>
        <el-form-item label="失信原因" prop="reason">
          <el-input v-model="form.reason" placeholder="失信原因" />
        </el-form-item>
        <el-input v-model="form.lostCredit" value="1" type="hidden" />
        <el-input v-model="form.objectId" type="hidden" />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">保存</el-button>
        <el-button @click="cancel">退出</el-button>
      </div>
    </el-dialog>


    <el-dialog  title="撤销失信" :visible.sync="isEdit"  width="500px" append-to-body  v-loading="loading">
      <el-form ref="form" :model="updateForm" :rules="rules" label-width="120px">
        <el-form-item label="情况说明" prop="reason">
          <el-input v-model="updateForm.reason" type="textarea" maxlength="200" show-word-limit/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">保存</el-button>
        <el-button @click="cancel">退出</el-button>
      </div>
    </el-dialog>

    <el-dialog  title="历史失信" :visible.sync="infoDialog"  width="800px" append-to-body>
      <el-table v-loading="loading" :data="creditListInfo" :cell-style="colStyle" border>
        <el-table-column label="序号" align="center" prop="id" />
        <el-table-column label="失信时间" align="center" prop="time" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.time, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="情况说明" align="center" prop="reason" />
        <el-table-column label="操作历史" align="center" prop="lostCredit">
          <template slot-scope="scope">
            <span>{{ scope.row.lostCredit== 0 ? "撤销失信" : "失信" }}</span>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import {
  listCredit,
  getCredit,
  delCredit,
  addCredit,
  updateCredit,
  exportCredit,
  getNames,
  historyCredit
} from "@/api/business/driver";

import {
  companyList,
  driverList
} from "@/api/dict";

export default {
  name: "ConstructionCredit",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      infoDialog :false,
      // 总条数
      total: 0,
      // 工地表格数据
      creditList: [],
      creditListInfo: [],
      dictNames:[],
      dictTypes:[],
      dictPlaces:[],
      driverList:[],
      names:[],
      idNumbers:[],
      places:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      isEdit:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        idNumber: null,
        time: null,
        reason: null,
        status: 0,
        lostCredit: 1
      },
      // 表单参数
      form: {},
      updateForm:{},
      // 表单校验
      rules: {name: [
          { required: true, message: '请选择驾驶员', trigger: 'blur' },
        ],reason: [
          { required: true, message: '请填写原因', trigger: 'blur' },
        ]}
    };
  },
  created() {
    this.init();
  },
  methods: {
    init(){
      this.reset();

      this.getList();
      this.getNamesData();

      let query = {
        'page':1,
        'size':9999,
        'creditStatus':0
      }

      companyList(query).then(response => {

        let companys = response.result.list;

        let ids = [];

        for(let i = 0 ;i<companys.length;i++){
          ids.push(companys[i].id);
        }
        query.companyIds = ids + "";
        query.status = 3;

        driverList(query).then(res=>{

          this.driverList = res.result;

        });

      });
    },
    getDataInfo(row){
      let param ={"objectId":row.objectId}
      listCredit(param).then(response => {
        this.creditListInfo = response.rows;
        this.infoDialog = true;
      });

    },
    getNamesData(){
      getNames(this.queryParams).then(response => {
        this.dictNames = response;
      });
    },
    getData(stauts){
      this.queryParams.status=0;
      this.queryParams.lostCredit=stauts;
      this.getList();
    },
    getHistoryData(){
      this.queryParams.status=1;
      this.init();
    },
    colStyle(obj){
      if(obj.column.property == "id"){
        return {background:"#f8f8f9"}
      }
    },
    getObjId(a){
      this.form.objectId = a.id;
      if(a.identityNo)
        this.form.idNumber = a.identityNo;
      else
        this.form.idNumber = a.phoneNo  ;
    },
    getList() {
      this.loading = true;
      if(this.queryParams.status==0){
        listCredit(this.queryParams).then(response => {
          this.creditList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      }
      if(this.queryParams.status==1){
        historyCredit(this.queryParams).then(response => {
          this.creditList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      }

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.isEdit = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        idNumber: null,
        time: null,
        reason: null,
        lostCredit: null,
        objectId: null,
      };
      this.updateForm = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      console.log(this.queryParams);
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加驾驶员";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCredit(id).then(response => {
        this.form = response.data;
        this.isEdit = true;
      });
    },
    /** 提交按钮 */
    submitForm() {
      if(this.open){
        this.updateForm.reason = "1";
      }
      this.$refs["form"].validate(valid => {
        if (valid) {
          
            this.loading = true;
          if (this.form.id != null) {
            this.updateForm.id = this.form.id;
            updateCredit(this.updateForm).then(response => {
              this.msgSuccess("撤销成功");
              this.isEdit = false;
              this.init();
            });
          } else {
            this.form.lostCredit = 1;
            addCredit(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.init();
            });
          }
        }
      });
    },
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有驾驶员数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return exportCredit(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>