truck_credit.js 7.12 KB
 import {
    listCredit,
    getCredit,
    delCredit,
    addCredit,
    updateCredit,
    exportCredit,
    getNames,
    getCompanys,
    historyCredit
  } from "@/api/business/truck";

import h5Page from '@/views/h5/Pagination';

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

  export default {
    name: "Credit",
    components: {
    h5Page
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        infoDialog: false,
        // 总条数
        total: 0,
        // 工地表格数据
        creditList: [],
        creditListInfo: [],
        dictNames: [],
        dictCompanys: [],
        companyList:[],
        truckList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        isEdit: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          companyId: null,
          licensePlate: null,
          time: null,
          reason: null,
          status: 0,
          lostCredit: 1
        },
        // 表单参数
        form: {},
        updateForm: {},
        // 表单校验
        rules: {
          companyId: [{
            required: true,
            message: '请选择运输公司',
            trigger: 'change'
          }, ],
          reason: [{
            required: true,
            message: '请填写原因',
            trigger: 'change'
          }, ],
          licensePlate: [{
            required: true,
            message: '请选择车辆',
            trigger: 'change'
          }],
        },
        rules2: {
          reason: [{
            required: true,
            message: '请填写原因',
            trigger: 'change'
          }, ],
        }
      };
    },
    created() {
      this.init();
    },
    methods: {

      init() {
        this.getList();
        getNames(this.queryParams).then(response => {
           this.dictNames = response;
        });

         getCompanys(this.queryParams).then(response => {
           this.dictCompanys = response;
        });

          let query = {
            'page':1,
            'size':9999,
          }
        companyList(query).then(response => {

          let companys = response.result.list;
          this.companyList = companys;
          let ids = [];

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

          truckList(query).then(res=>{
            this.truckList = res.result.list;
          });

        });


      },
      getDataInfo(row) {
        console.log(row);

        let param = {
          "objectId": row.objectId
        }

        listCredit(param).then(response => {
          this.creditListInfo = response.rows;
          this.infoDialog = true;
        });

      },
      getData(stauts) {
        this.queryParams.status = 0;
        this.queryParams.lostCredit = stauts;
        this.resetQuery();
        this.init();
      },
      getHistoryData() {
        this.queryParams.status = 1;
        this.resetQuery();
        this.init();
      },
      colStyle(obj) {
        if (obj.column.property == "id") {
          return {
            background: "#f8f8f9"
          }
        }
      },
      getObjId(a) {
        this.form.companyId = a.companyName;
        this.form.objectId = a.id;
      },
      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,
          companyId: null,
          licensePlate: null,
          time: null,
          reason: null,
          status: null,
          lostCredit: null
        };
        this.queryParams.licensePlate = null;
        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.isEdit){
          this.$refs["updateForm"].validate(valid => {
            if (valid) {
                this.loading = true;
                this.form.lostCredit = 0;
                this.updateForm.id = this.form.id;
              let data = [{creditStatus:this.form.lostCredit,id:this.form.objectId}];
              updateTruck(data).then(res=>{
                updateCredit(this.updateForm).then(response => {
                  this.msgSuccess("撤销成功");
                  this.isEdit = false;
                  this.updateForm = {};
                  this.init();
                });
                });
            }
          });
        }else{
          this.$refs["form"].validate(valid => {
            if (valid) {
                this.loading = true;
                this.form.lostCredit = 1;
                this.form.createType = 0;
                  let data = [{creditStatus:this.form.lostCredit,id:this.form.objectId}];
                  updateTruck(data).then(res=>{
                    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);
        })
      }
    }
  };