truck_active.js 7.27 KB
import {
  listTruckActivate,
  getTruckActivate,
  delTruckActivate,
  addTruckActivate,
  updateTruckActivate,
  exportTruckActivate
} from "@/api/business/truckActivate";



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

import {
  todayDataList,
} from "@/api/business/threestep";

import {
  mainworkcompany,
  getConstructionTruck,
  constructionById,
  truckList
} from "@/api/dict";

export default {
  name: "TruckActivate",
  components: {
    h5Page,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车辆激活表格数据
      truckActivateList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      companyList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        company: null,
        licensePlate: null,
        time: null,
        activateStatus:null,
        construction: null,
        status: null,
        earthsite: null,
        objectId: null,
        createType: null,
        activateTime: null,
        activateDate: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        construction: [{
          required: true,
          message: '请填写完整',
          trigger: 'change'
        }, ],

        company: [{
          required: true,
          message: '请填写完整',
          trigger: 'change'
        }, ],


        licensePlate: [{
          required: true,
          message: '请填写完整',
          trigger: 'change'
        }, ],
      },
      constList: [],
      truckList: [],

      construction: null,
      truck: null,
      company: null,
      openActivateTime: false,
      isLoading: false,
    };
  },
  created() {
    this.getList(0);
  },
  methods: {
    /** 查询车辆激活列表 */
    getList(index) {
      if (index == 0) {
        this.queryParams.status = "0";
        this.openActivateTime = false;
        this.queryParams.activateDate = null;
      }
      if (index == 1) {
        this.openActivateTime = true;
        this.queryParams.status = "1";
      }
      this.loading = true;
      listTruckActivate(this.queryParams).then(response => {
        this.truckActivateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });

      let data = {
        type: 0,
        status: 1,
      }

      todayDataList(data).then(res => {
        this.constList = res;
      });

    },
    getCompany(value) {
      let item;

      for (let i in this.constList) {
        if (this.constList[i].name == value) {
          this.construction = this.constList[i];
          item = this.construction;
        }
      }

      this.companyList = [];
      this.truckList = [];

      constructionById(item.objectId).then(res => {
        this.companyList.push({
          id: res.result.transportCompanyId,
          name: res.result.transportCompany
        });

        mainworkcompany(item.id).then(response => {

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

          query.companyID = res.result.transportCompanyId+ "";
          query.valid = 0;

          getConstructionTruck(item.objectId).then(res => {
            for (let i in res.result) {
              this.companyList.push({
                id: res.result[i].companyId,
                name: res.result[i].companyName
              });
              for (let j in res.result[i].vehicleList) {
                this.truckList.push({
                  id: res.result[i].vehicleList[j].id,
                  licenseplateNo: res.result[i].vehicleList[j].licenseplateNo,
                  companyName: res.result[i].companyName
                });
              }
            }
            truckList(query).then(res => {
              for (let i in res.result.list) {
                this.truckList.push(res.result.list[i]);
              }
            });
          });
        });
      });


    },
    clearTruck() {
      this.form.licensePlate = [];
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        company: null,
        licensePlate: null,
        time: null,
        construction: null,
        status: 0,
        earthsite: null,
        objectId: null,
        createBy: null,
        createType: null,
        activateTime: null,
        createTime: 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();
      this.form.id = row.id;
      updateTruckActivate(this.form).then(response => {
        this.msgSuccess("修改成功");
        this.open = false;
        this.getList();
      });

    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {

          for (var i in this.form.licensePlate) {
            for (let j in this.truckList) {
              if (this.form.licensePlate[i] == this.truckList[j].id) {

                let data = {
                  objectId: this.form.licensePlate[i],
                  licensePlate: this.truckList[j].licenseplateNo,
                  construction: this.construction.name,
                  earthsite: this.construction.earthsitesName,
                  status: 0,
                  company: this.form.company,
                }
                addTruckActivate(data).then(response => {
                  this.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                });
              }
            }
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除车辆激活编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delTruckActivate(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有车辆激活数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return exportTruckActivate(queryParams);
      }).then(response => {
        this.download(response.message);
      })
    }
  }
};