<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item prop="unitId">
        <!-- <el-input
          v-model="queryParams.unitId"
          placeholder="请输入单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select
          v-model="queryParams.peopleId"
          placeholder="请选择用车人姓名"
          @change="handleQuery"
          filterable
          class="input_xiala"
        >
          <el-option
            v-for="item in renYuans"
            :key="item.id"
            :label="item.name"
            :value="item.id"
            class="input_xiala"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <!-- <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        > -->
        <el-button  size="btr" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <!-- 列表选项 -->
    <el-table
      v-loading="loading"
      :data="thebusApplyList"
      @selection-change="handleSelectionChange"
      :header-cell-style="{ background: '#003C69', color: 'white' }"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id">
        <template scope="scope">
          <span>{{
            (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆型号" align="center" prop="unitName" />
      <el-table-column label="用车人员单位" align="center" prop="unitName" />
      <el-table-column label="用车人员姓名" align="center" prop="peopleName" />
      <el-table-column label="联系方式" align="center" prop="contact" />
      <!-- <el-table-column label="事由" align="center" prop="cause" /> -->
      <el-table-column label="出车路线" align="center" prop="route" />
      <el-table-column label="出车状态" align="center" prop="">
        <template slot-scope="scope">
          <el-col v-if="scope.row.outstatus == 0" style="color: #ffba00"
            >未出车</el-col
          >
          <el-col v-if="scope.row.outstatus == 1" style="color: #13ce66"
            >已出车</el-col
          >
        </template>
      </el-table-column>
      <el-table-column label="出车时间" align="center" prop="authEtime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.authEtime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="200"
      >
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.outstatus == 0"
            size="btu"
            type="text"
            @click="handleAdd(scope.row)"
            v-hasPermi="['militaryvehicleManagement:thebusApply:edit']"
            >出车</el-button
          >
          <el-button
          class="a1"
            v-else
            size=""
            type="text"
            @click="singles(scope.row)"
            v-hasPermi="['militaryvehicleManagement:thebusApply:edit']"
            >查看</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 :close-on-click-modal="false">
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="80px"
        inline
      >
        <el-form-item label="单位" prop="unitId">
          <el-input
            placeholder="选择单位"
            v-model="form.unitName"
            readonly
          ></el-input>
        </el-form-item>
        <el-form-item label="人员名称" prop="peopleId">
          <el-input
            placeholder="请选择人员名称"
            v-model="form.peopleName"
            readonly
          ></el-input>
        </el-form-item>

        <el-form-item label="人数" prop="peopleCount">
          <el-input
            v-model="form.peopleCount"
            placeholder="请输入人数"
            readonly
          />
        </el-form-item>
        <el-form-item label="联系方式" prop="contact">
          <el-input
            v-model="form.contact"
            placeholder="请输入联系方式"
            readonly
          />
        </el-form-item>
        <el-form-item label="外出事由" prop="cause">
          <el-input
            v-model="form.cause"
            placeholder="请输入外出事由"
            readonly
          />
        </el-form-item>
        <div class="box3">
          <el-form v-for="(item1, e) in checkShop" :key="e">
            <el-form-item label="" prop="bdglThebusId">
              <el-select
                v-model="item1.bdglThebusId"
                placeholder="请选择车辆车牌"
                filterable
              >
                <el-option
                  v-for="(item, i) in chucarlist"
                  :key="i"
                  :label="item.vehiclenumber"
                  :value="item.id"
                  @click.native="chuche"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="" prop="twoshenpirenid">
              <el-select
                v-model="item1.driverId"
                placeholder="请选择司机"
                filterable
              >
                <el-option
                  v-for="(item, i) in driverList"
                  :key="i"
                  :label="item.peopleName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                icon="el-icon-plus"
                size="btc"
                @click="addForms"
                v-if="e == checkShop.length - 1"
              ></el-button>
              <el-button
                type="primary"
                icon="el-icon-delete"
                size="btd"
                v-if="e > 0"
                @click="delForms(e)"
              ></el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="jiben">出车路线</div>
        <el-form-item prop="route">
          <el-input
            v-model="form.route"
            type="textarea"
            placeholder="请输入出车路线"
            disabled
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel" size="btn">取 消</el-button>
      </div>
    </el-dialog>



    <!-- 查看会话框 -->
    <el-dialog
      title="查看可出车列表"
      :visible.sync="opens"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        ref="form"
        :model="forms"
        :rules="rules"
        label-width="80px"
        inline
      >
        <el-form-item label="单位" prop="unitId">
          <el-input v-model="forms.unitName"></el-input>
        </el-form-item>
        <el-form-item label="人员名称" prop="peopleId">
          <el-input v-model="forms.peopleName"></el-input>
        </el-form-item>
        <el-form-item label="人数" prop="peopleCount">
          <el-input v-model="forms.peopleCount" />
        </el-form-item>
        <el-form-item label="联系方式" prop="contact">
          <el-input v-model="forms.contact" />
        </el-form-item>
        <el-form-item label="外出事由" prop="cause">
          <el-input v-model="forms.cause" />
        </el-form-item>
        <div class="box4">
          <table border="1"
          style="
          border-collapse: collapse;
          border: none;
          mso-border-left-alt: 0.5pt solid windowtext;
          mso-border-top-alt: 0.5pt solid windowtext;
          mso-border-right-alt: 0.5pt solid windowtext;
          mso-border-bottom-alt: 0.5pt solid windowtext;
          mso-border-insideh: 0.5pt solid windowtext;
          mso-border-insidev: 0.5pt solid windowtext;
          mso-padding-alt: 0pt 0pt 0pt 0pt;
        "
        width="907px"
          >
           <tbody style="">
            <tr align="center" class="tr">
              <td width="220" height="40">车牌型号</td>
              <td width="220" height="40">号牌号码</td>
              <td width="220" height="40">司机</td>
              <td width="220" height="40">司机联系方式</td>
            </tr>
            <tr
              align="center"
              class="tr"
              v-for="(item, i) in chaCarLists"
              :key="i"
            >
              <td width="220" height="40">
                <template>
                  {{ names }}
                </template>
              </td>
              <td width="220" height="40">{{ item.vehiclenumber }}</td>
              <td width="220" height="40">{{ item.driverName }}</td>
              <td width="220" height="40">{{ item.driverPhone }}</td>
            </tr>
           </tbody>
          </table>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {
  listThebusApply,
  getThebusApply,
  delThebusApply,
  exportThebusApply,
  exportThebusCar,
  exportThebusCha,
  zaiweiCar,
} from "@/api/militaryvehicleManagement/thebusApply";
// 查询字典
import { getDicts } from "@/api/system/dict/data";
import { listDriver } from "@/api/militaryvehicleManagement/driver";
import { getAll } from "@/api/grassrootsregistration/bdglmeeting";
// import {} from "@/api/militaryvehicleManagement/thebus";
export default {
  name: "ThebusApply",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用车申请表格数据
      thebusApplyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // 人员列表
      renYuan: [],
      //出车对话框司机
      checkShop: [
        {
          vehiclemodel: null,
          driverId: null,
        },
      ],
      // 车牌型号
      brand: [],
      // 司机
      driverList: [],
      // 查看
      forms: {},
      // 查看框显示
      opens: false,
      // 外面的人员
      renYuans: [],
      // 查看司机，车辆列表
      chaCarLists: [],
      // 出车获取车辆列表
      chucarlist: [],
      // 车牌型号的保存
      names: "",
    };
  },
  created() {
    this.getList();
    this.getSuo();
    getDicts("brand").then((response) => {
      this.brand = response.data;
    });
  },
  methods: {
    // 翻译车牌型号
    car(value) {
      console.log(value, 1);
      this.brand.map((item) => {
        if (item.dictValue == value) {
          this.names = item.dictLabel;
        }
        console.log(this.names);
        // return this.names;
      });
    },
    chuche(data) {
      console.log(data);
    },
    // 获取搜索所有人
    getSuo() {
      getAll().then((res) => {
        this.renYuans = res.rows;
      });
    },
    // 查看
    singles(row) {
      this.form = row;
      exportThebusCha(this.form).then((res) => {
        this.forms = res.data;
        this.opens = true;
        this.chaCarLists = res.data.bdglDepartureInfos;
        this.car(this.chaCarLists[0].vehiclemodel);
      });
    },
    // 获取司机
    getSi() {
      listDriver().then((response) => {
        this.driverList = response.rows;
      });
    },
    // 获取车辆型号
    getCar() {
      zaiweiCar().then((res) => {
        this.chucarlist = res.rows;
        console.log(res);
      });
    },

    // 删除对话框查铺
    delForms(i) {
      this.checkShop.splice(i, 1);
    },

    // 增加对话框查铺
    addForms() {
      this.checkShop.push({
        driverId: null,
        vehiclemodel: null,
      });
    },
    /** 查询出车申请列表 */
    getList() {
      this.loading = true;
      listThebusApply(this.queryParams).then((response) => {
        this.thebusApplyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.peopleId = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 出车按钮操作 */
    handleAdd(row) {
      this.form.id = row.id;
      this.form = row;
      this.getCar();
      this.getSi();
      this.open = true;
      this.title = "选择司机";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.getTreeList();
      const id = row.id || this.ids;
      getThebusApply(id).then((response) => {
        this.form = response.data;
        this.getRen(this.form.unitId);
        this.open = true;
        this.title = "修改用车申请";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.form.bdglDepartureInfos = this.checkShop;
      this.form.outstatus = "1";
      exportThebusCar(this.form).then((response) => {
        this.$modal.msgSuccess("新增成功");
        this.open = false;
        this.getList();
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除用车申请的数据项？")
        .then(function () {
          return delThebusApply(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal
        .confirm("是否确认导出所有用车申请数据项？")
        .then(() => {
          this.exportLoading = true;
          return exportThebusApply(queryParams);
        })
        .then((response) => {
          this.$download.name(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>
<style scoped>
/* 对话框背景颜色 */
::v-deep .el-dialog {
  background: #004d86 !important;
  width: 800px !important;
}
::v-deep .el-textarea__inner {
  width: 920px;
  height: 104px;
  margin: auto;
}
::v-deep .el-dialog__header {
  border-bottom: 1px solid #718a9d;
}
::v-deep .el-dialog__title {
  color: #fff;
  font: 18px;
}
::v-deep .el-dialog__headerbtn .el-dialog__close {
  color: #fff;
}
::v-deep .el-form-item__label {
  font: 16px;
  color: #fff;
  width: 100px !important;
}
::v-deep .el-input__inner {
  /* width: 200px !important;
  height: 36px; */
  background: transparent;
  color: #fff;
   border: 1px solid white !important;
}
/* 单位框背景颜色 */
::v-deep .vue-treeselect__control {
  background: #004d86 !important;
}
/* 基本信息背景 */
.jiben {
  width: 920px;
  height: 32px;
  background-image: url(../../../images/小标题底.png);
  margin-bottom: 25px;
  color: #fff;
  padding-left: 16px;
  line-height: 32px;
}
/*调整表单间距 */
::v-deep .el-form-item__content {
  width: 200px;
}
::v-deep .el-input__inner {
  cursor: pointer !important;
}
/* 底部确定取消按钮 */
::v-deep .el-dialog__footer {
  padding: 30px 50px;
}
::v-deep .el-dialog__body {
  margin: 10px 24px 20px 30px;
  padding-top: 20px !important;
  box-sizing: border-box;
  /* padding: 30px 12px 30px 28px; */
}
.contents {
  padding: 0px 40px !important;
}
/* 下拉菜单 */
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
/* 下拉菜单字体/背景颜色 */
.el-select-dropdown__item.hover,
.el-select-dropdown__item:hover {
  background-color: #004d86;
  color: #111;
}
.el-select-dropdown__item {
  color: #111;
}
/* 时间选择 */
::v-deep .el-input--small .el-input__inner {
  width: 200px;
  height: 36px;
  line-height: 36px;
}
.el-date-editor.el-input {
  width: 200px;
  height: 36px;
  line-height: 36px;
}
::v-deep .el-date-editor.el-input .el-input__inner {
  height: 36px;
  line-height: 36px;
}
/* 单位框背景颜色 */
::v-deep .vue-treeselect__control {
  background: #004d86 !important;
  color: #fff;
}
/* 单位下拉菜单选中字体颜色 */
::v-deep .vue-treeselect__single-value {
  color: #fff !important;
}
/* 分页按钮 */
::v-deep .el-pagination.is-background .el-pager li {
  background-color: #004d86;
  color: #fff;
}
::v-deep .el-pagination.is-background .btn-next {
  background-color: #004d86;
  color: #fff;
}
/* 底部确定取消按钮 */
::v-deep .el-dialog__footer {
  padding: 18px 50px;
  margin-right: 28px;
}
/* 增加按钮弹框 */
::v-deep .el-dialog {
  width: 1060px !important;
}
::v-deep .el-dialog__body {
  padding: 30px 35px;
}
/* 小手样式 */
::v-deep .el-table__cell {
  cursor: pointer;
}
.el-button--mini {
  width: 80px !important;
  border: 1px solid transparent;
  padding: 3px 8px;
  font-size: 14px;
  line-height: 1.5;
  border-radius: 3px;
  color: #fff;
  background-color: #1890ff;
}
.box3 {
  width: 920px;
  min-height: 70px;
  border: 1px solid white;
  border-radius: 5px;
  /* background: #409eff; */
  margin-bottom: 30px;
  padding-top: 15px;
  padding-left: 15px;
}
/* 调整输入框提示文字颜色 */
::v-deep .vue-treeselect__placeholder {
  color: #bdbdbd4f !important;
}
::v-deep input::-webkit-input-placeholder {
  color: #bdbdbd4f !important;
}
::v-deep input:-moz-placeholder {
  color: #bdbdbd4f !important;
}
/* 查看表格 */
.box4 {
  width: 923px;
  min-height: 70px;
  border-radius: 5px;
  /* background: #409eff; */
  margin-bottom: 30px;
  padding-top: 15px;
  padding-left: 15px;
}
.box4 tr {
  color: #fff;
}
.box4 .tr td {
  border-bottom: 1px solid #fff;
}
.box4 table {
  border-color: #fff;
}
::v-deep .box4 table td {
  border-bottom: 1px solid white !important;
}
.a1{
  width: 46px !important;
    border: 1px solid transparent;
    padding: 3px 8px;
    font-size: 14px;
    line-height: 1.5;
    border-radius: 3px;
    color: #fff;
    background-color: #1890ff;
}
</style>

