<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名称" prop="connectionName">
        <el-input
          v-model="queryParams.connectionName"
          placeholder="请输入联系人名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预约单" prop="isAppointment">
        <el-select v-model="queryParams.isAppointment" placeholder="请选择是否为预约单" clearable>
          <el-option
            v-for="dict in dict.type.yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="救援类型" prop="rescueType">
        <el-select v-model="queryParams.rescueType" placeholder="请选择救援类型" clearable>
          <el-option
            v-for="dict in dict.type.dljy_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </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="warning"-->
      <!--          plain-->
      <!--          icon="el-icon-download"-->
      <!--          size="mini"-->
      <!--          @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="名称" align="center" prop="connectionName" />
      <el-table-column label="手机号" align="center" prop="connectionPhone" />
      <el-table-column label="车牌号" align="center" prop="licenseNum" />
      <el-table-column label="是否为预约单" align="center" prop="isAppointment">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yes_no" :value="scope.row.isAppointment"/>
        </template>
      </el-table-column>
      <el-table-column label="救援时间" align="center" prop="rescueTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rescueTime, '{y}-{m}-{d} {h}:{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="救援类型" align="center" prop="rescueType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.dljy_type" :value="scope.row.rescueType"/>
        </template>
      </el-table-column>
      <el-table-column label="车辆类型" align="center" prop="carType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.car_type" :value="scope.row.carType"/>
        </template>
      </el-table-column>
      <el-table-column label="救援地点" align="center" prop="rescuePosition" />
      <el-table-column label="收费类型" align="center" prop="feeType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fee_type" :value="scope.row.feeType"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="救援状态" align="center" prop="rescueStatus" >-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.jy_order_status" :value="scope.row.rescueStatus"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="金额" align="center" prop="rescueAmount" />-->
      <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-edit"
            v-if="scope.row.rescueStatus==1||scope.row.rescueStatus==2"
            @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.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改道路救援模块对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="联系人名称" prop="connectionName">
          <el-input v-model="form.connectionName" placeholder="请输入联系人名称" />
        </el-form-item>
        <el-form-item label="联系人手机号" prop="connectionPhone">
          <el-input v-model="form.connectionPhone" placeholder="请输入联系人手机号" />
        </el-form-item>
        <el-form-item label="车牌号" prop="licenseNum">
          <el-input v-model="form.licenseNum" placeholder="请输入车牌号" />
        </el-form-item>
        <el-form-item label="是否为预约单" prop="isAppointment">
          <el-radio-group v-model="form.isAppointment">
            <el-radio
              v-for="dict in dict.type.yes_no"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="救援时间" prop="rescueTime">
          <el-date-picker clearable
                          v-model="form.rescueTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择救援时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="救援类型 1拖车2送油3搭电4换台5扣车" prop="rescueType">
          <el-select v-model="form.rescueType" placeholder="请选择救援类型 1拖车2送油3搭电4换台5扣车">
            <el-option
              v-for="dict in dict.type.dljy_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="车辆类型  大中小" prop="carType">
          <el-select v-model="form.carType" placeholder="请选择车辆类型  大中小">
            <el-option
              v-for="dict in dict.type.car_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="救援地点 详细描述" prop="rescuePosition">
          <el-input v-model="form.rescuePosition" placeholder="请输入救援地点 详细描述" />
        </el-form-item>
        <el-form-item label="救援经度" prop="rescueLongitude">
          <el-input v-model="form.rescueLongitude" placeholder="请输入救援经度" />
        </el-form-item>
        <el-form-item label="救援纬度" prop="rescueLatitude">
          <el-input v-model="form.rescueLatitude" placeholder="请输入救援纬度" />
        </el-form-item>
        <el-form-item label="收费类型" prop="feeType">
          <el-radio-group v-model="form.feeType">
            <el-radio
              v-for="dict in dict.type.fee_type"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="车辆品牌" prop="carBrand">
          <el-input v-model="form.carBrand" placeholder="请输入车辆品牌" />
        </el-form-item>
        <el-form-item label="目的地详细描述" prop="destinationInfo">
          <el-input v-model="form.destinationInfo" placeholder="请输入目的地详细描述" />
        </el-form-item>
        <el-form-item label="目的地经度" prop="destinationLongitude">
          <el-input v-model="form.destinationLongitude" placeholder="请输入目的地经度" />
        </el-form-item>
        <el-form-item label="目的地纬度" prop="destinationLatitude">
          <el-input v-model="form.destinationLatitude" placeholder="请输入目的地纬度" />
        </el-form-item>
        <el-form-item label="救援司机主键" prop="driverId">
          <el-input v-model="form.driverId" placeholder="请输入救援司机主键" />
        </el-form-item>
        <el-form-item label="金额" prop="rescueAmount">
          <el-input v-model="form.rescueAmount" 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>
  </div>
</template>

<script>
  import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/rescue/info";

  export default {
    name: "Info",
    dicts: ['dljy_type', 'fee_type', 'car_type', 'yes_no','jy_order_status'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 道路救援模块表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNo: 1,
          pageSize: 10,
          connectionName: null,
          isAppointment: null,
          rescueType: null,
          feeType: null,
          carBrand: null,
          destinationInfo: null,
          rescueStatus: null,
          rescueAmount: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          connectionName: [
            { required: true, message: "联系人名称不能为空", trigger: "blur" }
          ],
          connectionPhone: [
            { required: true, message: "联系人手机号不能为空", trigger: "blur" }
          ],
          licenseNum: [
            { required: true, message: "车牌号不能为空", trigger: "blur" }
          ],
          isAppointment: [
            { required: true, message: "是否为预约单不能为空", trigger: "change" }
          ],
          rescueType: [
            { required: true, message: "救援类型 1拖车2送油3搭电4换台5扣车不能为空", trigger: "change" }
          ],
          carType: [
            { required: true, message: "车辆类型  大中小不能为空", trigger: "change" }
          ],
          rescuePosition: [
            { required: true, message: "救援地点 详细描述不能为空", trigger: "blur" }
          ],
          feeType: [
            { required: true, message: "收费类型不能为空", trigger: "change" }
          ],
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询道路救援模块列表 */
      getList() {
        this.loading = true;
        this.queryParams.rescueStatus
        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 = {
          id: null,
          connectionName: null,
          connectionPhone: null,
          licenseNum: null,
          isAppointment: null,
          rescueTime: null,
          rescueType: null,
          carType: null,
          rescuePosition: null,
          rescueLongitude: null,
          rescueLatitude: null,
          feeType: null,
          carBrand: null,
          destinationInfo: null,
          destinationLongitude: null,
          destinationLatitude: null,
          rescueStatus: null,
          driverId: null,
          rescueAmount: null,
          createTime: null,
          createBy: null,
          updateTime: null,
          updateBy: null
        };
        this.resetForm("form");
      },


      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNo = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加道路救援模块";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getInfo(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改道路救援模块";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateInfo(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addInfo(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除道路救援模块编号为"' + ids + '"的数据项？').then(function() {
          return delInfo(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/info/export', {
          ...this.queryParams
        }, `info_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
