<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="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入联系电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </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"-->
<!--          v-hasPermi="['system:info:export']"-->
<!--        >导出</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="车辆id" align="center" prop="vehicleId" />-->
      <el-table-column label="储配站" align="center" prop="siteStationName">
        <template slot-scope="scope">
          <span v-if="scope.row.siteStationName!=null">{{scope.row.siteStationName}}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="所属企业" align="center" prop="beyondEnterpriseName" />
      <el-table-column label="车牌号" align="center" prop="carNum">
        <template slot-scope="scope">
          <span v-if="scope.row.carNum!=null">{{scope.row.carNum}}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="品牌型号" align="center" prop="brandModel">
        <template slot-scope="scope">
          <span v-if="scope.row.brandModel!=null">{{scope.row.brandModel}}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆类型" align="center" prop="vehicleType">
        <template slot-scope="scope">
          <span v-if="scope.row.vehicleType == 1">罐车</span>
          <span v-if="scope.row.vehicleType == 2">卡车</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆载重" align="center" prop="vehicleLoad">
        <template slot-scope="scope">
          <span v-if="scope.row.vehicleLoad!=null">{{scope.row.vehicleLoad}}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆大小" align="center" prop="vehicleSize">
        <template slot-scope="scope">
          <span v-if="scope.row.vehicleSize!=null">{{scope.row.vehicleSize}}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆限乘" align="center" prop="vehicleLimt">
        <template slot-scope="scope">
          <span v-if="scope.row.vehicleLimt!=null">{{scope.row.vehicleLimt}}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆检测信息" align="center" prop="vehicleInspect">
        <template slot-scope="scope">
          <span v-if="scope.row.vehicleInspect!=null">{{scope.row.vehicleInspect}}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="责任人" align="center" prop="personLiable">
        <template slot-scope="scope">
          <span v-if="scope.row.personLiable!=null">{{scope.row.personLiable}}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="经度" align="center" prop="longitude">
        <template slot-scope="scope">
          <span v-if="scope.row.longitude!=null">{{scope.row.longitude}}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="经度" align="center" prop="latitude">
        <template slot-scope="scope">
          <span v-if="scope.row.latitude!=null">{{scope.row.latitude}}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="联系电话" align="center" prop="phone" />
      <el-table-column label="备注" align="center" prop="remarks" />
      <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-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="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="140px">

        <el-row>
          <el-col :span="11">
        <el-form-item label="车牌号" prop="carNum">
          <el-input v-model="form.carNum" placeholder="请输入车牌号" />
        </el-form-item>
          </el-col>

          <el-col :span="11">
        <el-form-item label="品牌型号" prop="brandModel">
          <el-input v-model="form.brandModel" placeholder="请输入品牌型号" />
        </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="11">
            <el-form-item label="车辆类型"  prop="vehicleType">
              <el-select v-model="form.vehicleType" placeholder="请选择车辆类型" style="width: 100%;">
                <el-option label="罐车" value="1" />
                <el-option label="卡车" value="2" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="11">
        <el-form-item label="车辆载重" prop="vehicleLoad">
          <el-input v-model="form.vehicleLoad" placeholder="请输入车辆载重" />
        </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="11">
        <el-form-item label="车辆大小" prop="vehicleSize">
          <el-input v-model="form.vehicleSize" placeholder="请输入车辆大小" />
        </el-form-item>
          </el-col>

          <el-col :span="11">
        <el-form-item label="车辆限乘" prop="vehicleLimt">
          <el-input v-model="form.vehicleLimt" placeholder="请输入车辆限乘" />
        </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="11">
        <el-form-item label="车辆检测信息" prop="vehicleInspect">
          <el-input v-model="form.vehicleInspect" placeholder="请输入车辆检测信息" />
        </el-form-item>
          </el-col>
          <el-col :span="11">
<!--            -->
<!--        <el-form-item label="所属企业" prop="beyondEnterpriseId">-->
<!--          <el-input v-model="form.beyondEnterpriseId" placeholder="请输入所属企业" />-->
<!--        </el-form-item>-->
            <el-form-item label="所属企业" prop="beyondEnterpriseId">
              <el-select v-model="form.beyondEnterpriseId" placeholder="请选择所属企业"   >
                <el-option
                  v-for = "dict in enterpriseList"
                  :key = "dict.enterpriseId"
                  :label = "dict.enterpriseName"
                  :value = "dict.enterpriseId"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="11">
        <el-form-item label="责任人" prop="personLiable">
          <el-input v-model="form.personLiable" placeholder="请输入责任人" />
        </el-form-item>
          </el-col>
          <el-col :span="11">
        <el-form-item label="联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系电话" />
        </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="22">
        <el-form-item label="备注" prop="remarks">
          <el-input type="textarea" v-model="form.remarks" placeholder="请输入备注" />
        </el-form-item>
          </el-col>
        </el-row>

      </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 { listInfo, getInfo, delInfo, addInfo, updateInfo, exportInfo } from "@/api/system/license";
import {enterpriseList} from "@/api/system/eventInfo";
export default {
  name: "Info",
  components: {
  },
  data() {
    return {
      enterpriseList:[],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 燃气车辆信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        carNum: null,
        brandModel: null,
        vehicleType: null,
        vehicleLoad: null,
        vehicleSize: null,
        vehicleLimt: null,
        vehicleInspect: null,
        beyondEnterpriseId: null,
        personLiable: null,
        phone: null,
        isDel: null,
        remarks: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    qiyechang(value){
      let obj = {};
      obj = this.enterpriseList.find((item)=>{
        return item.enterpriseId === value;
        ``});
      this.form.beyondEnterpriseName = obj.enterpriseName;
      this.form.beyondEnterpriseId = value;
    },
    /** 查询燃气车辆信息列表 */
    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,
        carNum: null,
        brandModel: null,
        vehicleType: null,
        vehicleLoad: null,
        vehicleSize: null,
        vehicleLimt: null,
        vehicleInspect: null,
        beyondEnterpriseId: null,
        personLiable: 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 = "添加燃气车辆信息";
      enterpriseList(this.queryParams).then(response => {
        this.enterpriseList = response.data;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const vehicleId = row.vehicleId || this.ids
      enterpriseList(this.queryParams).then(response => {
        this.enterpriseList = response.data;
      });
      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('是否确认删除此数据项?', "警告", {
          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(() => {});
    }
  }
};
</script>
