<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="订单id" prop="ddId">
        <el-input
          v-model="queryParams.ddId"
          placeholder="请输入订单id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单时间" prop="orderTime">
        <el-date-picker clearable
          v-model="queryParams.orderTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择订单时间">
        </el-date-picker>
      </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:txorder: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:txorder: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:txorder:remove']"
        >删除</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:txorder:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="txorderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单id" align="center" prop="ddId" />
      <el-table-column label="上车地址" align="center" prop="boardingAddress" />
      <el-table-column label="下车地址" align="center" prop="downAddress" />
      <el-table-column label="路程距离" align="center" prop="distance" />
      <el-table-column label="订单状态" align="center" prop="state">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_tishi_state" :value="scope.row.state"/>
        </template>
      </el-table-column>
      <el-table-column label="订单类型" align="center" prop="taxiType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_tishi_type" :value="scope.row.taxiType"/>
        </template>
      </el-table-column>
      <el-table-column label="订单时间" align="center" prop="orderTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单实制金额" align="center" prop="amount" />
      <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:txorder:edit']"
          >查看</el-button>
<!--          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:txorder: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"
    />

    <!-- 添加或修改TaxiOrder对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="司机id" prop="driverId">
          <el-input v-model="form.driverId" placeholder="请输入司机id" />
        </el-form-item>
        <el-form-item label="上车地址" prop="boardingAddress">
          <el-input v-model="form.boardingAddress" placeholder="请输入上车地址" />
        </el-form-item>
        <el-form-item label="上车经度" prop="intoLongitude">
          <el-input v-model="form.intoLongitude" placeholder="请输入上车经度" />
        </el-form-item>
        <el-form-item label="上车纬度" prop="intoLatitude">
          <el-input v-model="form.intoLatitude" placeholder="请输入上车纬度" />
        </el-form-item>
        <el-form-item label="下车地址" prop="downAddress">
          <el-input v-model="form.downAddress" placeholder="请输入下车地址" />
        </el-form-item>
        <el-form-item label="下车经度" prop="downLongitude">
          <el-input v-model="form.downLongitude" placeholder="请输入下车经度" />
        </el-form-item>
        <el-form-item label="下车维度" prop="downLatitude">
          <el-input v-model="form.downLatitude" placeholder="请输入下车维度" />
        </el-form-item>
        <el-form-item label="路程距离" prop="distance">
          <el-input v-model="form.distance" placeholder="请输入路程距离" />
        </el-form-item>
        <el-form-item label="订单状态" prop="state">
          <el-input v-model="form.state" placeholder="请输入订单状态" />
        </el-form-item>
        <el-form-item label="订单类型" prop="taxiType">
          <el-select v-model="form.taxiType" placeholder="请选择订单类型">
            <el-option
              v-for="dict in dict.type.sys_tishi_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发布者id" prop="releaseId">
          <el-input v-model="form.releaseId" placeholder="请输入发布者id" />
        </el-form-item>
        <el-form-item label="订单时间" prop="orderTime">
          <el-date-picker clearable
            v-model="form.orderTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择订单时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="登车时间" prop="boardingTime">
          <el-input v-model="form.boardingTime" placeholder="请输入登车时间" />
        </el-form-item>
        <el-form-item label="下车时间" prop="alightingTime">
          <el-input v-model="form.alightingTime" placeholder="请输入下车时间" />
        </el-form-item>
        <el-form-item label="预约时间" prop="appointmentTime">
          <el-input v-model="form.appointmentTime" placeholder="请输入预约时间" />
        </el-form-item>
        <el-form-item label="路程车费" prop="fare">
          <el-input v-model="form.fare" placeholder="请输入路程车费" />
        </el-form-item>
        <el-form-item label="高速公路费用" prop="highwayCosts">
          <el-input v-model="form.highwayCosts" placeholder="请输入高速公路费用" />
        </el-form-item>
        <el-form-item label="订单实制金额" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入订单实制金额" />
        </el-form-item>
        <el-form-item label="路上预计用时" prop="estimatedDuration">
          <el-input v-model="form.estimatedDuration" placeholder="请输入路上预计用时" />
        </el-form-item>
        <el-form-item label="备注" prop="notes">
          <el-input v-model="form.notes" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="优惠金额" prop="coupon">
          <el-input v-model="form.coupon" 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 { listTxorder, getTxorder, delTxorder, addTxorder, updateTxorder } from "@/api/system/txorder";

export default {
  name: "Txorder",
  dicts: ['sys_tishi_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // TaxiOrder表格数据
      txorderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ddId: null,
        orderTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询TaxiOrder列表 */
    getList() {
      this.loading = true;
      listTxorder(this.queryParams).then(response => {
        this.txorderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        ddId: null,
        userId: null,
        driverId: null,
        boardingAddress: null,
        intoLongitude: null,
        intoLatitude: null,
        downAddress: null,
        downLongitude: null,
        downLatitude: null,
        distance: null,
        state: null,
        taxiType: null,
        releaseId: null,
        orderTime: null,
        boardingTime: null,
        alightingTime: null,
        appointmentTime: null,
        fare: null,
        highwayCosts: null,
        amount: null,
        estimatedDuration: null,
        notes: null,
        coupon: 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.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加TaxiOrder";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTxorder(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) {
            updateTxorder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTxorder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除TaxiOrder编号为"' + ids + '"的数据项？').then(function() {
        return delTxorder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/txorder/export', {
        ...this.queryParams
      }, `txorder_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
