driver_credit.js 5.87 KB
import {
  listCredit,
  getCredit,
  delCredit,
  addCredit,
  updateCredit,
  exportCredit,
  getNames,
  getlicenseplates,
  historyCredit
} from "@/api/business/driver";
import h5Page from '@/views/h5/Pagination';
import {
  companyList,
  driverList
} from "@/api/dict";

export default {
  name: "ConstructionCredit",
  components: {
  h5Page
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      infoDialog :false,
      // 总条数
      total: 0,
      // 工地表格数据
      creditList: [],
      creditListInfo: [],
      dictNames:[],
      dictLicenseplateNo:[],
      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: 'change' },
        ],reason: [
          { required: true, message: '请填写原因', trigger: 'change' },
        ]}
    };
  },
  created() {
    this.init();
  },
  methods: {
    init(){
      this.reset();

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

        this.licenseplateData();


      let data = {valid:0};
        driverList(data).then(res=>{

          this.driverList = res.list;

        });

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

    },
    licenseplateData(){
      getlicenseplates(this.queryParams).then(response => {
        this.dictLicenseplateNo = response;
      });
    },

    getNamesData(){
      getNames(this.queryParams).then(response => {
        this.dictNames = response;
      });
    },
    getData(stauts){
      this.queryParams.status=0;
      this.queryParams.lostCredit=stauts;
      this.resetQuery();
      this.getList();
    },
    getHistoryData(){
      this.queryParams.status=1;
      this.resetQuery();
      this.init();
    },
    colStyle(obj){
      if(obj.column.property == "id"){
        return {background:"#f8f8f9"}
      }
    },
    getObjId(value){
      for(let i in this.driverList){
          if(this.driverList[i].name == value){
            this.form.objectId = this.driverList[i].id;
            this.form.idNumber = this.driverList[i].identityNo;
            if(this.driverList[i].licenseplateNo){
              this.form.licenseplateNo = this.driverList[i].licenseplateNo;
            }else{
              this.form.licenseplateNo = "未绑定车辆";
            }
            break;
          }
      }
    },
    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");
      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.message);
      })
    }
  }
};