index.vue 11 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.pageStatus==0}" size="mini"
          @click="getList(0);">车辆激活</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button :class="{'el-button':true,'el-button--primary':this.queryParams.pageStatus==1}" size="mini"
          @click="getList(1);">车辆激活历史</el-button>
      </el-col>
    </el-row>


    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="所属企业" prop="company">
        <el-input
          v-model="queryParams.company"
          placeholder="请输入所属企业"

          size="small"

        />
      </el-form-item>
      <el-form-item label="车牌号" prop="licensePlate">
        <el-input
          v-model="queryParams.licensePlate"
          placeholder="请输入车牌号"

          size="small"

        />
      </el-form-item>
      <el-form-item label="激活时间" prop="activateTime">
        <el-date-picker  size="small" style="width: 200px"
          v-model="queryParams.activateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择激活时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-if="this.queryParams.status==0"
          type="primary"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:truckActivate:add']"
        >添加车辆并激活</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:truckActivate:export']"
        >导出</el-button>
      </el-col>
    </el-row>

   <el-card class="box-card" v-for="item in truckActivateList" style="margin-bottom: 10px;">

      <el-row class="card_row">
        <el-col :span="12" class="card_grid">
        <div class="card_title" style="font-weight: bold;">{{item.licensePlate}}</div>
        </el-col>
        <el-col :span="12" class="card_grid" >
          <span v-if="item.activateTime!=null" style="float:right;margin-top:20px;">已激活</span>
          <el-button  v-if="item.activateTime==null"
            style="float:right;"
            @click="handleUpdate(item)"
          >手动激活</el-button>
        </el-col>
      </el-row>

      <el-row class="card_row" style="margin-top: 5px;">
        <el-col :span="24">
          <div>{{item.company}}</div>
        </el-col>
      </el-row>

     <el-row class="card_row" style="margin-top: 20px;">
       <el-col :span="24">
         <div>{{item.construction}}</div>
       </el-col>
     </el-row>
    </el-card>

    <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="400px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="所属工地" prop="construction">
          <el-select v-model="form.construction" placeholder="请选择所属工地">
            <el-option v-for="item in constList" @click.native="getCompany(item)" :label="item.name" :value="item.name" :key="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属企业" prop="company">
            <el-select v-model="form.company" filterable reserve-keyword>
              <el-option v-for="item in constCompany" :label="item" :value="item"  @click.native="getTruckListByCompanyName(item)"/>
            </el-select>
        </el-form-item>
        <el-form-item label="车牌号" prop="licensePlate">
            <el-select v-model="form.licensePlate" placeholder="请选择车辆">
              <el-option  v-if="!construction.companyTrucks || construction.companyTrucks.indexOf(item.id) == -1"
                        v-for="item in companyTruckList"
                        :label="item.licenseplateNo"
                        :value="item.licenseplateNo"
                        :key="item.id"
                        @click.native="getTruck(item)"/>
            </el-select>
        </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>

  </div>
</template>

<script>
import { listTruckActivate, getTruckActivate, delTruckActivate, addTruckActivate, updateTruckActivate, exportTruckActivate } from "@/api/business/truckActivate";

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

  import pagination from '../Pagination';
  
import {
  truckList,
  companyList,
} from "@/api/dict";

export default {
  name: "TruckActivate",
    components: {pagination},
  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,
        construction: null,
        status: null,
        earthsite: null,
        objectId: null,
        createType: null,
        activateTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        construction: [{
          required: true,
          message: '请填写完整',
          trigger: 'change'
        }, ],

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


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

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

      let query = {
        'page':1,
        'size':9999,
        'creditStatus':0
      }
      companyList(query).then(response => {
        this.companyList = response.result.list;
      });


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

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

    },
    getCompany(obj){
      if(obj.companys){
        this.constCompany = obj.companys.split(",");
      }
      this.form.company = null;
      this.construction = obj;
    },

    getTruckListByCompanyName(name){
      this.form.licensePlate = null;
      for(let i in this.companyList){
        if(this.companyList[i].name == name){
          this.company = this.companyList[i];
          let remoteQuery = {
            page:1,
            size:9999,
            companyID:this.companyList[i].id,
            valid:0,
            dishonestState:0,
          }
          truckList(remoteQuery).then(res=>{
              this.companyTruckList = res.result.list;
          });

          break;
        }
      }
    },
    getTruck(truck){
      this.truck = truck;
    },
    // 取消按钮
    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) {
            this.form.objectId = this.truck.id;
            this.form.company = this.company.name;
            this.form.earthsite = this.construction.earthsitesName;
            this.form.status = 0;
            this.form.activateTime = new Date();

            addTruckActivate(this.form).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);
        })
    }
  }
};
</script>