<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px" size="small">
      <el-form-item label="VIN码" prop="postCode">
        <el-input
          v-model="queryParams.carVin"
          clearable
          placeholder="请输入车辆VIN码"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆型号" prop="postName">
        <el-input
          v-model="queryParams.typeName"
          clearable
          placeholder="请输入车辆型号"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="能源类型" prop="status">
        <el-select v-model="queryParams.energyType" clearable placeholder="能源类型">
          <el-option label="电动" value="1"></el-option>
          <el-option label="纯油" value="2"></el-option>
          <el-option label="混动" value="3"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="档的类型" prop="status">
        <el-select v-model="queryParams.gearType" clearable placeholder="档的类型">
          <el-option label="手动" value="1"></el-option>
          <el-option label="自动" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @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-hasPermi="['system:post:add']"
          icon="el-icon-plus"
          plain
          size="mini"
          type="primary"
          @click="handleAdd"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['system:post:edit']"
          :disabled="single"
          icon="el-icon-edit"
          plain
          size="mini"
          type="success"
          @click="handleUpdate"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['system:post:remove']"
          :disabled="multiple"
          icon="el-icon-delete"
          plain
          size="mini"
          type="danger"
          @click="handleDelete"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['system:post:export']"
          icon="el-icon-download"
          plain
          size="mini"
          type="warning"
          @click="handleExport"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">
      <el-table-column align="center" type="selection" width="55"/>
      <el-table-column align="center" label="车辆表" prop="carId"/>
      <el-table-column align="center" label="车架号" prop="carFrame"/>
      <el-table-column align="center" label="车牌号" prop="carCoed"/>
      <el-table-column align="center" label="车牌颜色" prop="carColor">
        <template slot-scope="scope">
          <span v-show="(scope.row.carColor==1)">白色</span>
          <span v-show="(scope.row.carColor==2)">绿色</span>
          <span v-show="(scope.row.carColor==3)">黑色</span>
          <span v-show="(scope.row.carColor==4)">银色</span>
          <span v-show="(scope.row.carColor==5)">红色</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="VIN码" prop="carVin"/>
      <el-table-column align="center" label="驾驶员" prop="userId"/>
      <el-table-column align="center" label="车辆型号" prop="typeId"/>
      <el-table-column align="center" label="年审日期" prop="audditTime"/>
      <el-table-column align="center" label="行驶证到期日期" prop="licenseTime"/>
      <el-table-column align="center" label="保险到期日期" prop="insuranceTime"/>
      <el-table-column align="center" label="在线状态" prop="carStatus">
        <template slot-scope="scope">
          <span v-show="(scope.row.carStatus==1)">无信号</span>
          <span v-show="(scope.row.carStatus==2)">行驶中</span>
          <span v-show="(scope.row.carStatus==3)">已停止</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="创建时间" prop="createdTime"/>
      <el-table-column align="center" label="当前档位 " prop="carGears">
        <template slot-scope="scope">
          <span v-show="(scope.row.carGears==1)">R档：倒车挡。</span>
          <span v-show="(scope.row.carGears==2)">N档：空挡</span>
          <span v-show="(scope.row.carGears==3)">D档：前进挡</span>
          <span v-show="(scope.row.carGears==4)">S档：运动挡</span>
          <span v-show="(scope.row.carGears==5)">P档：停车挡</span>
          <span v-show="(scope.row.carGears==6)">L档:大马力档</span>
          <span v-show="(scope.row.carGears==7)">手动:前进1档</span>
          <span v-show="(scope.row.carGears==8)">手动:前进2档</span>
          <span v-show="(scope.row.carGears==9)">手动:前进3档</span>
          <span v-show="(scope.row.carGears==10)">手动:前进4档</span>
          <span v-show="(scope.row.carGears==11)">手动:前进5档</span>
          <span v-show="(scope.row.carGears==12)">倒挡</span>
          <span v-show="(scope.row.carGears==13)">空挡</span>
          <span v-show="(scope.row.carGears==14)">已停止</span>
          <span v-show="(scope.row.carGears==15)">已停止</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="创建时间" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['system:post:edit']"
            icon="el-icon-edit"
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
          >修改
          </el-button>
          <el-button
            v-hasPermi="['system:post:remove']"
            icon="el-icon-delete"
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加或修改岗位对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="500px">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="车辆编号" prop="carPlate">
          <el-input v-model="form.carId" :min="0" controls-position="right" disabled />
        </el-form-item>

        <el-form-item label="车辆车牌号" prop="carPlate">
          <el-input v-model="form.carCoed" :min="0" controls-position="right"/>
        </el-form-item>

        <el-form-item label="车辆颜色" prop="carColor">
          <el-select v-model="form.carColor" clearable placeholder="车辆颜色">
            <el-option label="白色" value="1"></el-option>
            <el-option label="绿色" value="2"></el-option>
            <el-option label="黑色" value="3"></el-option>
            <el-option label="银色" value="4"></el-option>
            <el-option label="红色" value="5"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="车辆配置" prop="typeId">
          <div class="block">
            <el-cascader
              v-model="form.typeId"
              :options="options"
              :props="{ expandTrigger: 'hover' }"
              @change="handleChange"></el-cascader>
          </div>
        </el-form-item>

        <el-form-item label="年审日期" prop="audditTime">
          <div class="block">
            <el-date-picker
              v-model="form.audditTime"
              type="datetime"
              placeholder="选择日期时间"
            >
<!--              JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")-->
            </el-date-picker>
          </div>
          <el-input v-model="form.audditTime" placeholder="请输入编码名称"/>
        </el-form-item>

        <el-form-item label="行驶证到期日期" prop="licenseTime">
          <div class="block">
            <el-date-picker
              v-model="form.licenseTime"
              type="datetime"

              placeholder="选择日期时间"
            >
            </el-date-picker>
          </div>
          <el-input v-model="form.licenseTime" placeholder="请输入编码名称"/>
        </el-form-item>

        <el-form-item label="启用状态" prop="carStatus">
          <el-select v-model="form.carStatus" clearable placeholder="启用状态">
            <el-option label="无信号" value="1"></el-option>
            <el-option label="行驶中" value="2"></el-option>
            <el-option label="已停止" value="3"></el-option>
          </el-select>
        </el-form-item>

<!--        <el-form-item label="当前档位" prop="remark">-->
<!--          <el-input v-model="form.carGears" placeholder="请输入内容" type="textarea"/>-->
<!--        </el-form-item>-->

        <el-form-item label="车辆品牌" prop="carBrand">
          <el-input v-model="form.carModel" placeholder="请输入岗位名称"/>
        </el-form-item>

        <el-form-item label="车辆型号" prop="carBrand">
          <el-input v-model="form.carBrand" placeholder="请输入车辆型号" type="textarea"/>
        </el-form-item>

        <!--        <el-form-item label="最后一次连线时间" prop="postCode">-->
        <!--          <el-input v-model="form.carLastJoinTime" placeholder="请输入编码名称"/>-->
        <!--        </el-form-item>-->

        <!--        <el-form-item label="最后一次离线时间" prop="postName">-->
        <!--          <el-input v-model="form.carLastOfflineTime" placeholder="请输入岗位名称"/>-->
        <!--        </el-form-item>-->

        <el-form-item label="所属企业" prop="companyId">
          <el-select v-model="form.companyId" clearable placeholder="启用状态">
            <el-option v-for="aa in company" :label="aa.companyName" :value="aa.companyId"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="车辆类型" prop="carType">
          <el-select v-model="form.carType" clearable placeholder="车辆类型">
            <el-option label="轿车" value="1"></el-option>
            <el-option label="跑车" value="2"></el-option>
            <el-option label="越野" value="3"></el-option>
            <el-option label="客车" value="4"></el-option>
            <el-option label="公交" value="5"></el-option>
            <el-option label="其他" value="6"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" type="textarea"/>
        </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 { CarListShow, CarListShowByCarId, deleteCar, insertCar, selectCompany, updataCar } from '@/api/car/manage'

export default {
  name: "Post",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      options: [
        {
          value: '标准版',
          label: '标准版',
          children: [{
            value: '1',
            label: '纯电',
            children:[{
              value: '1',
              label: '手动'
            }, {
              value: '2',
              label: '自动'
            }]
          },
          {
            value: '2',
            label: '纯油',
            children:[{
              value: '1',
              label: '手动'
            }, {
              value: '2',
              label: '自动'
            }]
          },
          {
            value: '3',
            label: '混动',
            children:[{
              value: '1',
              label: '手动'
            }, {
              value: '2',
              label: '自动'
            }]
          }]
        },

        {
          value: '舒适版',
          label: '舒适版',
          children: [{
            value: '1',
            label: '纯电',
            children:[{
              value: '1',
              label: '手动'
            }, {
              value: '2',
              label: '自动'
            }]
          },
            {
              value: '2',
              label: '纯油',
              children:[{
                value: '1',
                label: '手动'
              }, {
                value: '2',
                label: '自动'
              }]
            },
            {
              value: '3',
              label: '混动',
              children:[{
                value: '1',
                label: '手动'
              }, {
                value: '2',
                label: '自动'
              }]
            },
          ]
        },

        {
          value: '豪华版',
          label: '豪华版',
          children: [
            {
            value: '1',
            label: '纯电',
            children:[{
              value: '1',
              label: '手动'
            }, {
              value: '2',
              label: '自动'
            }]
          },
            {
              value: '2',
              label: '纯油',
              children:[{
                value: '1',
                label: '手动'
              }, {
                value: '2',
                label: '自动'
              }]
            },
            {
              value: '3',
              label: '混动',
              children:[{
                value: '1',
                label: '手动'
              }, {
                value: '2',
                label: '自动'
              }]
            },
          ]
        },
      ],
      //企业
      company:{},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,

      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        carCoed: [
          {required: true, message: "车牌号不能为空", trigger: "blur"}
        ],
        typeId: [
          {required: true, message: "车辆配置不能为空", trigger: "blur"}
        ],
        companyId: [
          {required: true, message: "所属企业不能为空", trigger: "blur"}
        ],
        carType: [
          {required: true, message: "车辆类型不能为空", trigger: "blur"}
        ]
      }
    };
  },
  created() {
    this.getCompany();
    this.getList();
  },
  methods: {
    // 获取级联的值
    handleChange(value) {
      debugger
      alert(value)
      if(value[0] == "标准版" && value[1] == "1" && value[2] == "1" ){
        this.form.typeId = 1
      }else if(value[0] == "舒适版" && value[1] == "1" && value[2] == "1" ){
        this.form.typeId = 2
      }else if(value[0] == "豪华版" && value[1] == "1" && value[2] == "1" ){
        this.form.typeId = 3
      }else if(value[0] == "标准版" && value[1] == "1" && value[2] == "2" ){
        this.form.typeId = 4
      }else if(value[0] == "舒适版" && value[1] == "1" && value[2] == "2" ){
        this.form.typeId = 5
      }else if(value[0] == "豪华版" && value[1] == "1" && value[2] == "2" ){
        this.form.typeId = 6
      }else if(value[0] == "标准版" && value[1] == "2" && value[2] == "1" ){
        this.form.typeId = 7
      }else if(value[0] == "舒适版" && value[1] == "2" && value[2] == "1" ){
        this.form.typeId = 8
      }else if(value[0] == "豪华版" && value[1] == "2" && value[2] == "1" ){
        this.form.typeId = 9
      }else if(value[0] == "标准版" && value[1] == "2" && value[2] == "2" ){
        this.form.typeId = 10
      }else if(value[0] == "舒适版" && value[1] == "2" && value[2] == "2" ){
        this.form.typeId = 11
      }else if(value[0] == "豪华版" && value[1] == "2" && value[2] == "2" ){
        this.form.typeId = 12
      }else if(value[0] == "标准版" && value[1] == "3" && value[2] == "1" ){
        this.form.typeId = 13
      }else if(value[0] == "舒适版" && value[1] == "3" && value[2] == "1" ){
        this.form.typeId = 14
      }else if(value[0] == "豪华版" && value[1] == "3" && value[2] == "1" ){
        this.form.typeId = 15
      }else if(value[0] == "标准版" && value[1] == "3" && value[2] == "2" ){
        this.form.typeId = 16
      }else if(value[0] == "舒适版" && value[1] == "3" && value[2] == "2" ){
        this.form.typeId = 17
      }else if(value[0] == "豪华版" && value[1] == "3" && value[2] == "2" ){
        this.form.typeId = 18
      }
      debugger
      console.log(this.form.typeId)
      alert(this.form.typeId)
    },
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      CarListShow(this.queryParams).then(response => {
        console.log(response)
        this.postList = response.data;
        this.loading = false;
      });
    },
    getCompany(){
      selectCompany().then(res=>{
        this.company = res.data
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        postId: undefined,
        postCode: undefined,
        postName: undefined,
        postSort: 0,
        status: "0",
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.postId)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加岗位";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const carId = row.carId || this.ids
      CarListShowByCarId(carId).then(response => {
        console.log(response)
        debugger
        this.form = response.data[0];
        this.open = true;
        this.title = "修改岗位";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.carId != undefined) {
            updataCar(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            insertCar(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const carIds = row.carId || this.ids;
      this.$modal.confirm('是否确认删除为"' + carIds + '"的车辆？').then(function () {
        return deleteCar(carIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/post/export', {
        ...this.queryParams
      }, `post_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
