// 车辆审核
<template>
  <div class="center">
    <div class="center_css">
      <div class="top_css">
        <el-row>
          <el-col :span="14" style="height: 45px;">
            <!-- <el-button type="primary">添加</el-button> -->
          </el-col>
          <el-col :span="10">
            <div class="screen">
              <el-input placeholder="可按司机姓名、账号、车牌号查找" v-model="searchkeyWord" clearable @change="find"></el-input>
              <el-button class="search" @click="find"><img width="16" height="16" style="margin-left: -8px"
                  src="../../../public/img/sousuo.png" /></el-button><span
                class="count_css">共{{ deptBudgetTotal }}条</span>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <div class="search_btn">
              <div :class="search == '' ? 'search' : 'searchNo'" class="search_item search_block"
                @click="searchBtn('')">
                全部
              </div>
              <div :class="search == 1 ? 'search' : 'searchNo'" class="search_item" @click="searchBtn(1)">
                待审核
              </div>
              <div :class="search == 2 ? 'search' : 'searchNo'" class="search_item" @click="searchBtn(2)">
                已通过
              </div>
              <div :class="search == 3 ? 'search' : 'searchNo'" class="search_item" @click="searchBtn(3)">
                已驳回
              </div>
              <div :class="search == 4 ? 'search' : 'searchNo'" class="search_item" @click="searchBtn(4)">
                已删除
              </div>
              <div :class="search == 5 ? 'search' : 'searchNo'" class="search_item" @click="searchBtn(5)">
                已注销
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
      <el-table :data="tableData" style="width: 98%; margin: 0 auto; border-radius: 10px" height="55.8vh" border>
        <el-table-column prop="driverName" label="司机姓名" min-width="130"></el-table-column>
        <el-table-column prop="driverPhone" label="账号" min-width="110"></el-table-column>
        <el-table-column prop="numberCard" label="身份证号" min-width="165"></el-table-column>
        <el-table-column prop="carCategory" label="车型">
          <template scope="scope">
            <span>{{scope.row.carCategory}}</span>
            <span>{{scope.row.carType}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="carNumber" label="车牌号"></el-table-column>
        <el-table-column prop="guaCarNumber" label="挂车车牌号"></el-table-column>
        <el-table-column prop="amountMoney" label="附件" min-width="133">
          <template scope="scope">
            <div>
              <span class="btn_css" @click="fujianLook(scope.row)">查看</span>
              <el-tooltip placement="top" v-if="
                scope.row.overdueFlag == 1 ||
                scope.row.driverOverdueFlag == 1 || //驾驶证过期标志
                scope.row.drivingOverdueFlag == 1 || //行驶证过期标志
                scope.row.trailerOverdueFlag == 1 ||  //挂车行驶证过期标志
                scope.row.operationOverdueFlag == 1 || //运营证过期标志
                scope.row.operationOverdueFlag == 1 || //道路运输证过期标志
                scope.row.trailerOperationOverdueFlag == 1 //挂车道路运输证过期标志
              ">
                <div slot="content">
                  <span v-if="scope.row.overdueFlag == 1">身份证已过有效期<br /></span>
                  <span v-if="scope.row.driverOverdueFlag == 1">驾驶证已过有效期<br /></span>
                  <span v-if="scope.row.drivingOverdueFlag == 1">行驶证已过有效期<br /></span>
                  <span v-if="scope.row.trailerOverdueFlag == 1">挂车行驶证已过有效期<br /></span>
                  <span v-if="scope.row.operationOverdueFlag == 1">运营证已过有效期<br /></span>
                  <span v-if="scope.row.operationOverdueFlag == 1">道路运输证已过有效期<br /></span>
                  <span v-if="scope.row.trailerOperationOverdueFlag == 1">挂车道路运输证已过有效期<br /></span>
                </div>
                <span style="margin-top: 10px"></span>
                <img src="../../../public/img/wenhao.png" alt="" class="ask_css" />
              </el-tooltip>
            </div>

          </template>
        </el-table-column>
        <el-table-column prop="energyType" label="能源类型"></el-table-column>
        <el-table-column prop="status" label="状态"></el-table-column>
        <el-table-column prop="updateDate" label="更新日期"></el-table-column>
        <el-table-column label="操作" min-width="350">
          <template slot-scope="scope">
            <el-link target="_blank" @click="adopt(scope.row)" type="primary" :underline="false"
              :disabled="scope.row.status != '审核中'">通过</el-link>
            <el-divider direction="vertical"></el-divider>
            <el-link target="_blank" @click="reject(scope.row)" type="primary" :underline="false"
              :disabled="scope.row.status != '审核中'">驳回</el-link>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
      style="text-align: center; margin-top: 10px" :page-size="deptCircularPage.pageSize"
      layout="total, sizes, prev, pager, next, jumper" :total="deptBudgetTotal">
    </el-pagination>
    <el-dialog :close-on-click-modal='false' title="车辆信息" :visible.sync="carInfo" width="500px" :before-close="carClose">
      <div class="car_css">
        <div class="title_css">人车合影</div>
        <img :src="carSee.addressUrl" class="car_item" />
        <div class="title_css">身份证人像面</div>
        <img :src="carSee.cardAddressUrl" class="car_item" />
        <div class="title_css">身份证国徽面</div>
        <img :src="carSee.cardAddressUrl" class="car_item" />
        <div class="form_btn">
          <el-button @click="carClose">关闭</el-button>
        </div>
      </div>
    </el-dialog>
    <el-dialog :close-on-click-modal='false' title="附件" :visible.sync="fujianInfo" width="830px" :before-close="fujianClose">
      <div class="file">
        <div class="fujian_css">
          <div class="fujian_item" :class="count == 1 ? 'file_btn' : ''" @click="btnChange(1)">
            身份证
          </div>
          <!-- <div class="fujian_item" :class="count == 2 ? 'file_btn' : ''" @click="btnChange(2)">
            驾驶证
          </div> -->
          <div class="fujian_item" :class="count == 3 ? 'file_btn' : ''" @click="btnChange(3)">
            行驶证
          </div>
          <!-- <div class="fujian_item" :class="count == 4 ? 'file_btn' : ''" @click="btnChange(4)">
            从业资格证
          </div> -->
          <div class="fujian_item" :class="count == 5 ? 'file_btn' : ''" @click="btnChange(5)">
            挂车行驶证
          </div>
          <div class="fujian_item" :class="count == 6 ? 'file_btn' : ''" @click="btnChange(6)">
            道路运输证
          </div>
          <div class="fujian_item" :class="count == 7 ? 'file_btn' : ''" @click="btnChange(7)">
            挂车道路运输证
          </div>
          <div class="fujian_item" :class="count == 8 ? 'file_btn' : ''" @click="btnChange(8)">
            人车合影
          </div>
        </div>
        <div class="file_img">
          <img :src="img[index]" class="img_css" @click="enlarge(img[index])" />
        </div>
        <div class="btn">
          <el-button style="margin-right: 120px" @click="index = 0"
            v-if="count == 1 || count == 2 || count == 3 || count == 5">{{ abilityName }}</el-button>
          <el-button @click="index = 1" v-if="count == 1 || count == 2 || count == 3 || count == 5">{{ abilityName1 }}
          </el-button>
        </div>
      </div>
    </el-dialog>
    <el-dialog :close-on-click-modal='false' title="驳回认证" :visible.sync="rejectInfo" width="400px" :before-close="rejectClose">
      <div>
        <!-- <div><span class="sign">*</span>选择驳回原因</div> -->
        <div class="form_css">
          <el-form ref="form" :model="form" label-width="80px">
            <!-- <el-checkbox-group v-model="form.checkList">
							<el-checkbox label="证件照片不清晰"></el-checkbox>
							<el-checkbox label="证件照片上传错误"></el-checkbox>
							<el-checkbox label="身份信息填写错误"></el-checkbox>
							<el-checkbox label="证件信息填写错误"></el-checkbox>
							<el-checkbox label="其他"></el-checkbox>
						</el-checkbox-group> -->
            <div style="margin-bottom: 20px;">驳回原因描述（必填）</div>
            <el-input type="textarea" :rows="3" resize="none" placeholder="输入驳回原因，5-50个字" maxlength="50"
              v-model="form.rejectReasonDescription"></el-input>
            <div class="form_btn">
              <el-button @click="rejectClose">取消</el-button>
              <el-button @click="submit" type="primary">确定</el-button>
            </div>
          </el-form>
        </div>
      </div>
    </el-dialog>
    <el-image-viewer v-if="imgsVisible" :on-close="closeImgViewer" :url-list="srcList" style="z-index:9999" />
  </div>
</template>
<script>
  import {
    getCarList,
    toCarExamine
  } from '@/api/driverManagement'
  export default {
    components: {
      "el-image-viewer": () =>
        import("element-ui/packages/image/src/image-viewer"),
    },
    data() {
      return {
        tableData: [],
        //分页
        searchkeyWord: "",
        currentPage: 1,
        pageSize: 10,
        deptBudgetTotal: 0,
        deptCircularPage: {},
        search: "",
        addressUrl: [],
        disabled: false,
        carInfo: false,
        rejectInfo: false,
        checkList: [],
        form: {},
        carSee: {},
        //附件
        file: {},
        img: [],
        index: "0",
        count: "1",
        abilityName: "身份证人像面",
        abilityName1: "身份证国徽面",
        fujianInfo: false,
        //图片预览
        srcList: [],
        imgsVisible: false,
      };
    },
    mounted() {
      this.getList()
    },
    methods: {
      closeImgViewer() {
         this.srcList = []
        this.imgsVisible = false;
      },
      enlarge(url) {
        this.imgsVisible = true;
        this.srcList.push(url)
      },
      fujianLook(row) {
        this.file = row;
        this.index = 0;
        this.img[0] = this.file.cardAddressUrl;
        this.img[1] = this.file.cardBackAddressUrl;
        this.fujianInfo = true;
      },
      fujianClose() {
        this.count = 1;
        this.fujianInfo = false;
      },
      btnChange(num) {
        this.count = num;
        if (num == 1) {
          this.abilityName = "身份证人像面";
          this.abilityName1 = "身份证国徽面";
          this.img[0] = this.file.cardAddressUrl;
          this.img[1] = this.file.cardBackAddressUrl;
        } else if (num == 2) {
          this.abilityName = "驾驶证主页";
          this.abilityName1 = "驾驶证副页";
          this.img[0] = this.file.driverLicenseHomePage;
          this.img[1] = this.file.driverLicenseBackPage;
        } else if (num == 3) {
          this.abilityName = "行驶证主页";
          this.abilityName1 = "行驶证副页";
          this.img[0] = this.file.drivingLicenseHomePage;
          this.img[1] = this.file.drivingLicenseBackPage;
        } else if (num == 4) {
          this.index = 0;
          this.img[0] = this.file.qualificationCertificate;
        } else if (num == 5) {
          this.abilityName = "挂车行驶证主页";
          this.abilityName1 = "挂车行驶证副页";
          this.img[0] = this.file.trailerLicenseHomePage;
          this.img[1] = this.file.trailerLicenseBackPage;
        } else if (num == 6) {
          this.index = 0;
          this.img[0] = this.file.operationCertificate;
        } else if (num == 7) {
          this.index = 0;
          this.img[0] = this.file.trailerOperationCertificate;
        } else if (num == 8) {
          this.index = 0;
          this.img[0] = this.file.addressUrl;
        }
      },

      getList() {
        this.loading = true
        let _obj = {}
        _obj.currentPage = this.currentPage
        _obj.pageSize = this.pageSize
        _obj.searchKeyWord = this.searchkeyWord
        _obj.searchType = this.search
        getCarList(_obj).then(response => {
            this.tableData = response.data.records
            this.deptBudgetTotal = response.data.total
            this.listLoading = false
          })
          .catch(() => {
            this.loading = false
          })
      },
      adopt(row) {
        this.$confirm('确定通过' + row.carNumber + '的审核？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
          })
          .then(() => {
            this.listLoading = true
            var _examine = {}
            _examine.id = row.id
            _examine.flag = 1
            toCarExamine(_examine).then(response => {
                this.$notify({
                  title: '成功',
                  message: '通过成功！',
                  type: 'success'
                });
                this.getList()
                this.listLoading = false
              })
              .catch(() => {
                this.loading = false
              })
          })

      },
      reject(row) {
        this.form.id = row.id
        this.form.flag = 2
        this.rejectInfo = true
      },
      rejectClose() {
        this.form = {}
        this.rejectInfo = false
      },
      submit() {
        if (!this.form.rejectReasonDescription) {
          this.$message.error("请输入驳回原因")
          return
        }
        if (this.form.rejectReasonDescription.length < 6 || this.form.rejectReasonDescription.length > 50) {
          this.$message.error("驳回原因字数应在6-50之间")
          return
        }
        this.listLoading = true
        toCarExamine(this.form).then(response => {
            this.$notify({
              title: '成功',
              message: '驳回成功！',
              type: 'success'
            });
            this.form = {}
            this.rejectInfo = false
            this.getList()
            this.listLoading = false
          })
          .catch(() => {
            this.loading = false
          })
      },
      carLook(row) {
        this.carSee.addressUrl = row.addressUrl
        this.carSee.cardAddressUrl = row.cardAddressUrl
        this.carSee.cardBackAddressUrl = row.cardBackAddressUrl
        this.carInfo = true;
      },
      carClose() {
        this.carInfo = false;
      },
      searchBtn(num) {
        this.search = num;
        this.getList();
      },
      find() {
        this.getList();
      },
      onChange() {
        this.$refs.upload
          .handleSaveBill()
          .then(async (response) => {
            this.formData.addressUrl = response;
          })
          .catch((res) => {
            EventBus.$emit("error", (JSON.parse(res) || {}).message);
            this.$refs.upload.clearFiles();
          });
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.pageSize = val;
        this.getList();
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        console.log(`当前页: ${val}`);
        this.getList();
      },
    },
  };
</script>
<style lang="scss" scoped>
  .center {
    padding: 10px 20px;
    background: #f5f6f7;
    height: calc(100vh - 5vh);

    .top_css {
      padding: 10px;

      .search_btn {
        height: 80px;
        display: flex;
        margin-top: 20px;
        background: linear-gradient(#fafbfb, #ffffff);

        .search_block {
          margin-left: 20px;
        }

        .search_item {
          text-align: center;
          font-size: 14px;
          font-weight: 600;
          line-height: 40px;
          width: 112px;
          height: 40px;
          background: #f7f8f9;
          cursor: pointer;
          margin-top: 30px;
        }

        .searchNo {
          color: #323233;
        }

        .search {
          color: #2f53eb;
          background: #ffffff;
        }
      }
    }

    .center_css {
      background: #ffffff;
      border-radius: 1px;
      margin-top: 10px;
      padding-bottom: 10px;
    }

    .screen {
      display: flex;

      .search {
        width: 40px;
        height: 40px;
        background: #f7f8fa;
        border-radius: 0px 2px 2px 0px;
        border: 1px solid #f0f1f2;
      }

      .count_css {
        width: 80px;
        text-align: center;
        line-height: 40px;
        color: #666666;
      }
    }

    .el-button {
      padding: 10px 20px !important;
    }

    .center_css {

      ::v-deep .el-table th,
      ::v-deep .el-table td {
        text-align: center;
      }

      .fujian {
        font-size: 24px;
        color: #409eff;
      }

      .warning {
        font-size: 14px;
        color: #ed1d1d;
      }
    }
  }

  .car_css {
    margin-bottom: 20px;

    .title_css {
      margin-bottom: 10px;
      color: #999999;
    }


    .car_item {
      width: 370px;
      height: 220px;
      margin-bottom: 20px;
    }

    .form_btn {
      text-align: right;
    }
  }

  ::v-deep .el-table--border .el-table__header th {
    background: #f7f8f9;
  }

  .btn_css {
    color: #409EFF;
    cursor: pointer
  }

  .sign {
    font-size: 14px;
    color: red;
  }

  .form_css {
    width: 100%;
    margin: 0 auto 20px;

    ::v-deep .el-checkbox {
      width: 40%;
      height: 30px;
    }

    ::v-deep .el-dialog__body {
      padding: 10px 20px;
    }

    ::v-deep .el-dialog__title {
      font-size: 16px;
    }

    ::v-deep .el-textarea__inner {
      background: #F0F1F2;
    }

    .form_btn {
      text-align: right;
      margin-top: 10px;
    }
  }

  //查看附件
  .file {
    .fujian_css {
      width: 620px;
      display: flex;
      margin: 0 auto;
      text-align: center;
      line-height: 32px;
      border: 1px solid #f0f1f2;
      border-right: 0px;
      border-radius: 2px 0px 0px 2px;

      .fujian_item {
        cursor: pointer;
        width: 105px;
        height: 32px;
        border-right: 1px solid #f0f1f2;
      }

      .file_btn {
        color: #2f53eb;
        background-color: #cfdbfe;
      }
    }


    .file_img {
      width: 525px;
      height: 332px;
      margin: 20px auto;
    }

    .img_css {
      width: 525px;
      height: 332px;
    }

    .btn {
      width: 410px;
      margin: 0 auto;
    }
  }

  .ask_css {
    position: absolute;
    margin: 2px 0 0 10px;
  }
</style>
