<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="车牌号" prop="carNum">
        <el-input
          v-model="queryParams.carNum"
          placeholder="请输入车牌"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="责任人" prop="personLiable">
        <el-input
          v-model="queryParams.personLiable"
          placeholder="请输入责任人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="使用状态" prop="onState">
        <el-select v-model="queryParams.onState" placeholder="请选择使用状态">
          <el-option label="未使用" value="0"/>
          <el-option label="使用中" value="1"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" 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
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:info:remove']"
        >删除</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		      :loading="exportLoading"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="储配站" align="center" prop="stationName" />
      <el-table-column label="车辆编号" align="center" prop="carNumber" />
      <el-table-column label="车牌" align="center" prop="carNum" />
      <el-table-column label="品牌型号" align="center" prop="brandModel" />
      <el-table-column label="车辆类型" align="center" prop="vehicleType">
        <template slot-scope="scope">
          <span v-if="scope.row.vehicleType == '1'">罐车</span>
          <span v-else-if="scope.row.vehicleType == '2'">卡车</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆载重" align="center" prop="vehicleLoad" />
      <el-table-column label="车辆大小" align="center" prop="vehicleSize" />
      <el-table-column label="车辆限乘" align="center" prop="vehicleLimt" />
      <el-table-column label="车辆检查信息" align="center" prop="vehicleInspect" />
      <el-table-column label="责任人" align="center" prop="personLiable" />
      <el-table-column label="使用状态" align="center" prop="onState">
        <template slot-scope="scope">
          <span v-if="scope.row.onState == '0'">未使用</span>
          <span v-else-if="scope.row.onState == '1'">使用中</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="使用人" align="center" prop="vehicleUser" />
      <el-table-column label="联系电话" align="center" prop="phone" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="handleDetail(scope.row)"
          >详情</el-button>
          <!--<el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:info:remove']"
          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <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="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="储配站" prop="stationName">
          <el-input v-model="form.stationName" placeholder="请输入储配站" />
        </el-form-item>
        <el-form-item label="车辆编号" prop="carNumber">
          <el-input v-model="form.carNumber" placeholder="请输入车辆编号" />
        </el-form-item>
        <el-form-item label="企业ID" prop="beyondEnterpriseId">
          <el-input v-model="form.beyondEnterpriseId" placeholder="请输入企业ID" />
        </el-form-item>
        <el-form-item label="代码" prop="vehicleCode">
          <el-input v-model="form.vehicleCode" placeholder="请输入代码" />
        </el-form-item>
        <el-form-item label="车牌" prop="carNum">
          <el-input v-model="form.carNum" placeholder="请输入车牌" />
        </el-form-item>
        <el-form-item label="品牌型号" prop="brandModel">
          <el-input v-model="form.brandModel" placeholder="请输入品牌型号" />
        </el-form-item>
        <el-form-item label="车辆类型: 1.罐车 2.卡车" prop="vehicleType">
          <el-select v-model="form.vehicleType" placeholder="请选择车辆类型: 1.罐车 2.卡车">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="车辆载重" prop="vehicleLoad">
          <el-input v-model="form.vehicleLoad" placeholder="请输入车辆载重" />
        </el-form-item>
        <el-form-item label="车辆大小" prop="vehicleSize">
          <el-input v-model="form.vehicleSize" placeholder="请输入车辆大小" />
        </el-form-item>
        <el-form-item label="车辆限乘" prop="vehicleLimt">
          <el-input v-model="form.vehicleLimt" placeholder="请输入车辆限乘" />
        </el-form-item>
        <el-form-item label="车辆检查信息" prop="vehicleInspect">
          <el-input v-model="form.vehicleInspect" placeholder="请输入车辆检查信息" />
        </el-form-item>
        <el-form-item label="责任人" prop="personLiable">
          <el-input v-model="form.personLiable" placeholder="请输入责任人" />
        </el-form-item>
        <el-form-item label="使用状态   0未使用   1使用中" prop="onState">
          <el-input v-model="form.onState" placeholder="请输入使用状态   0未使用   1使用中" />
        </el-form-item>
        <el-form-item label="使用人" prop="vehicleUser">
          <el-input v-model="form.vehicleUser" placeholder="请输入使用人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="是否删除(0正常，1删除)" prop="isDel">
          <el-input v-model="form.isDel" placeholder="请输入是否删除(0正常，1删除)" />
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注" />
        </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>

    <!-- 详情 -->
    <DetailInfo ref="detail"/>

  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo, exportInfo } from "@/api/lpgRegulation/vehicleinfo";
import DetailInfo from "./components/DetailInfo";
export default {
  name: "Info",
  components: {
    DetailInfo
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 液化石油车辆信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        carNum: null,
        personLiable: null,
        onState: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询液化石油车辆信息列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        vehicleId: null,
        stationName: null,
        carNumber: null,
        beyondEnterpriseId: null,
        vehicleCode: null,
        carNum: null,
        brandModel: null,
        vehicleType: null,
        vehicleLoad: null,
        vehicleSize: null,
        vehicleLimt: null,
        vehicleInspect: null,
        personLiable: null,
        onState: null,
        vehicleUser: null,
        phone: null,
        isDel: null,
        remarks: 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.vehicleId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加液化石油车辆信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const vehicleId = row.vehicleId || this.ids
      getInfo(vehicleId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改液化石油车辆信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.vehicleId != null) {
            updateInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const vehicleIds = row.vehicleId || this.ids;
      this.$confirm('是否确认删除液化石油车辆信息编号为"' + vehicleIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfo(vehicleIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有液化石油车辆信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportInfo(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    },
    //详情
    handleDetail(row){
      this.$refs.detail.getDetailInfo(row.vehicleId);
    },
  }
};
</script>
