truck_active.js 7.31 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,
  getTruckList
} 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,
      simpleName:null,
    };
  },
  created() {


    // if(this.$store.getters.name.indexOf("渣土") == -1){
    //   this.simpleName = this.$store.getters.name;
    // }

    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
        });


        let param = {
          companyId:res.result.transportCompanyId,
          auditStatus:1,
          dishonestState:0
        }


        for(let i in res.result.unitCompanyList){
            let unit = res.result.unitCompanyList[i];

            let today = new Date().getTime();
            if(new Date(unit.startTime).getTime() > today || new Date(unit.endTime).getTime() < today){
               continue;
            }
            param.companyId += "," + unit.companyId;

            this.companyList.push({
              id: unit.companyId,
              name: unit.companyName
            });

        }

        getTruckList(param).then(tres=>{
          for(let i = 0;i< tres.result.length;i++){;
              this.truckList.push({licenseplateNo:tres.result[i].licenseplateNo,id:tres.result[i].id,companyName:tres.result[i].companyName});
          }
        })
      });


    },
    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) {
          let data = {
            objectId: "",
            licensePlate: "",
            constructionId:this.construction.objectId,
            construction: this.construction.name,
            earthsite: this.construction.earthsitesName,
            status: 0,
            company: this.form.company,
          }
          for (var i in this.form.licensePlate) {
            for (let j in this.truckList) {
              if (this.form.licensePlate[i] == this.truckList[j].id) {

                  data.objectId += this.form.licensePlate[i] + ",";
                  data.licensePlate += this.truckList[j].licenseplateNo + ",";

              }
            }
          }
          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);
      })
    }
  }
};