<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="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="第三方订单号" label-width="100px" prop="outTradeNo">
        <el-input
          v-model="queryParams.outTradeNo"
          placeholder="请输入第三方订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="用户ID" prop="userId">-->
<!--        <el-input-->
<!--          v-model="queryParams.userId"-->
<!--          placeholder="请输入用户ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="计费规则id" prop="ruleId">-->
<!--        <el-input-->
<!--          v-model="queryParams.ruleId"-->
<!--          placeholder="请输入计费规则id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="MAC" prop="deviceMac">
        <el-input
          v-model="queryParams.deviceMac"
          placeholder="请输入MAC"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="sn码" prop="sn">
        <el-input
          v-model="queryParams.sn"
          placeholder="请输入sn码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付时间" prop="payTime">
        <el-date-picker clearable
          v-model="queryParams.payTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择支付时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="支付方式" prop="payType">
        <el-select v-model="queryParams.payType" placeholder="请选择支付方式" clearable>
          <el-option
            v-for="dict in dict.type.et_pay_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="支付状态" prop="paid">-->
<!--        <el-input-->
<!--          v-model="queryParams.paid"-->
<!--          placeholder="请输入支付状态"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="订单总金额" prop="totalFee">-->
<!--        <el-input-->
<!--          v-model="queryParams.totalFee"-->
<!--          placeholder="请输入订单总金额"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="实际支付金额" prop="payFee">-->
<!--        <el-input-->
<!--          v-model="queryParams.payFee"-->
<!--          placeholder="请输入实际支付金额"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="调度费" prop="dispatchFee">-->
<!--        <el-input-->
<!--          v-model="queryParams.dispatchFee"-->
<!--          placeholder="请输入调度费"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="租赁费" prop="ridingFee">-->
<!--        <el-input-->
<!--          v-model="queryParams.ridingFee"-->
<!--          placeholder="请输入租赁费"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="订单时长" prop="duration">-->
<!--        <el-input-->
<!--          v-model="queryParams.duration"-->
<!--          placeholder="请输入订单时长"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.rl_order_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="还车时间" prop="returnTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.returnTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择还车时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否押金抵扣" prop="depositDeduction">-->
<!--        <el-input-->
<!--          v-model="queryParams.depositDeduction"-->
<!--          placeholder="请输入是否押金抵扣"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="扣除金额" prop="deductionAmount">-->
<!--        <el-input-->
<!--          v-model="queryParams.deductionAmount"-->
<!--          placeholder="请输入扣除金额"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="还车结算___小时后自动退押金" prop="autoRefundDeposit">-->
<!--        <el-input-->
<!--          v-model="queryParams.autoRefundDeposit"-->
<!--          placeholder="请输入还车结算___小时后自动退押金"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="租赁单位" prop="rentalUnit">-->
<!--        <el-select v-model="queryParams.rentalUnit" placeholder="请选择租赁单位" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.rl_rental_unit"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="手续费" prop="handlingCharge">-->
<!--        <el-input-->
<!--          v-model="queryParams.handlingCharge"-->
<!--          placeholder="请输入手续费"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="服务费" prop="platformServiceFee">-->
<!--        <el-input-->
<!--          v-model="queryParams.platformServiceFee"-->
<!--          placeholder="请输入服务费"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="运营商分账" prop="operatorDividend">-->
<!--        <el-input-->
<!--          v-model="queryParams.operatorDividend"-->
<!--          placeholder="请输入运营商分账"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="支付渠道id" prop="payChannel">-->
<!--        <el-input-->
<!--          v-model="queryParams.payChannel"-->
<!--          placeholder="请输入支付渠道id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="配送方式" prop="deliveryMethod">-->
<!--        <el-select v-model="queryParams.deliveryMethod" placeholder="请选择配送方式" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.rl_distribution_mode"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="取车时间" prop="pickupTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.pickupTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择取车时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="代理商id" prop="agentId">-->
<!--        <el-input-->
<!--          v-model="queryParams.agentId"-->
<!--          placeholder="请输入代理商id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="店铺id" prop="storeId">-->
<!--        <el-input-->
<!--          v-model="queryParams.storeId"-->
<!--          placeholder="请输入店铺id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="取车城市" prop="pickupCity">-->
<!--        <el-input-->
<!--          v-model="queryParams.pickupCity"-->
<!--          placeholder="请输入取车城市"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="取车地点  " prop="pickupLoc">-->
<!--        <el-input-->
<!--          v-model="queryParams.pickupLoc"-->
<!--          placeholder="请输入取车地点  "-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="取车经度" prop="pickupLon">-->
<!--        <el-input-->
<!--          v-model="queryParams.pickupLon"-->
<!--          placeholder="请输入取车经度"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="取车纬度" prop="pickupLat">-->
<!--        <el-input-->
<!--          v-model="queryParams.pickupLat"-->
<!--          placeholder="请输入取车纬度"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="租车周期" prop="rentalPeriod">-->
<!--        <el-input-->
<!--          v-model="queryParams.rentalPeriod"-->
<!--          placeholder="请输入租车周期"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </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="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="代理商" align="center" prop="agentName" />-->
<!--      <el-table-column label="店铺" align="center" prop="storeName" />-->
<!--      <el-table-column label="订单id" align="center" prop="orderId" />-->
      <el-table-column label="订单号" width="150" align="center" prop="orderNo" />
      <el-table-column label="第三方订单号" width="150" align="center" prop="outTradeNo" />
      <el-table-column label="用户" align="center" prop="realName" />
      <el-table-column label="手机号" align="center" prop="phone" />
<!--      <el-table-column label="计费规则id" align="center" prop="ruleId" />-->
<!--      <el-table-column label="MAC" align="center" prop="deviceMac" />-->
      <el-table-column label="sn码" align="center" prop="sn" />
      <el-table-column label="支付时间" align="center" prop="payTime" width="90">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付方式" align="center" prop="payType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.et_pay_type" :value="scope.row.payType"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="支付状态" align="center" prop="paid" />-->
      <el-table-column label="支付状态" align="center" prop="paid">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.et_order_pay_status" :value="scope.row.paid"/>
        </template>
      </el-table-column>
      <el-table-column label="类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.rl_order_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="订单总金额" align="center" prop="totalFee" />
      <el-table-column label="实际支付金额" align="center" prop="payFee" />
      <el-table-column label="调度费" align="center" prop="dispatchFee" />
      <el-table-column label="租赁费" align="center" prop="leaseFee" />
      <el-table-column label="备注" align="center" prop="mark" />
      <el-table-column label="订单时长" align="center" prop="duration" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.rl_order_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="还车时间" align="center" prop="returnTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.returnTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="是否押金抵扣" align="center" prop="depositDeduction" />-->
      <el-table-column label="扣除金额" align="center" prop="deductionAmount" />
<!--      <el-table-column label="还车结算___小时后自动退押金" align="center" prop="autoRefundDeposit" />-->
      <el-table-column label="租赁单位" align="center" prop="rentalUnit">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.rl_rental_unit" :value="scope.row.rentalUnit"/>
        </template>
      </el-table-column>
      <el-table-column label="手续费" align="center" prop="handlingCharge" />
      <el-table-column label="服务费" align="center" prop="platformServiceFee" />
      <el-table-column label="支付渠道" align="center" prop="channelName" />
      <el-table-column label="取车时间" align="center" prop="pickupTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.pickupTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <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:order:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['system:order: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"
    />

    <!-- 添加或修改订单对话框 -->
    <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="订单号" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="第三方订单号" prop="outTradeNo">
          <el-input v-model="form.outTradeNo" placeholder="请输入第三方订单号" />
        </el-form-item>
        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="计费规则id" prop="ruleId">
          <el-input v-model="form.ruleId" placeholder="请输入计费规则id" />
        </el-form-item>
        <el-form-item label="MAC" prop="deviceMac">
          <el-input v-model="form.deviceMac" placeholder="请输入MAC" />
        </el-form-item>
        <el-form-item label="sn码" prop="sn">
          <el-input v-model="form.sn" placeholder="请输入sn码" />
        </el-form-item>
        <el-form-item label="支付时间" prop="payTime">
          <el-date-picker clearable
            v-model="form.payTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择支付时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="支付方式" prop="payType">
          <el-select v-model="form.payType" placeholder="请选择支付方式">
            <el-option
              v-for="dict in dict.type.et_pay_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="支付状态" prop="paid">
          <el-input v-model="form.paid" placeholder="请输入支付状态" />
        </el-form-item>
        <el-form-item label="订单总金额" prop="totalFee">
          <el-input v-model="form.totalFee" placeholder="请输入订单总金额" />
        </el-form-item>
        <el-form-item label="实际支付金额" prop="payFee">
          <el-input v-model="form.payFee" placeholder="请输入实际支付金额" />
        </el-form-item>
        <el-form-item label="调度费" prop="dispatchFee">
          <el-input v-model="form.dispatchFee" placeholder="请输入调度费" />
        </el-form-item>
        <el-form-item label="租赁费" prop="ridingFee">
          <el-input v-model="form.ridingFee" placeholder="请输入租赁费" />
        </el-form-item>
        <el-form-item label="备注" prop="mark">
          <el-input v-model="form.mark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="订单时长" prop="duration">
          <el-input v-model="form.duration" placeholder="请输入订单时长" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择状态">
            <el-option
              v-for="dict in dict.type.rl_order_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="还车时间" prop="returnTime">
          <el-date-picker clearable
            v-model="form.returnTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择还车时间">
          </el-date-picker>
        </el-form-item>
<!--        <el-form-item label="是否押金抵扣" prop="depositDeduction">-->
<!--          <el-input v-model="form.depositDeduction" placeholder="请输入是否押金抵扣" />-->
<!--        </el-form-item>-->
        <el-form-item label="扣除金额" prop="deductionAmount">
          <el-input v-model="form.deductionAmount" placeholder="请输入扣除金额" />
        </el-form-item>
        <el-form-item label="还车结算___小时后自动退押金" prop="autoRefundDeposit">
          <el-input v-model="form.autoRefundDeposit" placeholder="请输入还车结算___小时后自动退押金" />
        </el-form-item>
        <el-form-item label="租赁单位" prop="rentalUnit">
          <el-select v-model="form.rentalUnit" placeholder="请选择租赁单位">
            <el-option
              v-for="dict in dict.type.rl_rental_unit"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手续费" prop="handlingCharge">
          <el-input v-model="form.handlingCharge" placeholder="请输入手续费" />
        </el-form-item>
        <el-form-item label="服务费" prop="platformServiceFee">
          <el-input v-model="form.platformServiceFee" placeholder="请输入服务费" />
        </el-form-item>
        <el-form-item label="运营商分账" prop="operatorDividend">
          <el-input v-model="form.operatorDividend" placeholder="请输入运营商分账" />
        </el-form-item>
        <el-form-item label="支付渠道id" prop="payChannel">
          <el-input v-model="form.payChannel" placeholder="请输入支付渠道id" />
        </el-form-item>
<!--        <el-form-item label="配送方式" prop="deliveryMethod">-->
<!--          <el-select v-model="form.deliveryMethod" placeholder="请选择配送方式">-->
<!--            <el-option-->
<!--              v-for="dict in dict.type.rl_distribution_mode"-->
<!--              :key="dict.value"-->
<!--              :label="dict.label"-->
<!--              :value="parseInt(dict.value)"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
        <el-form-item label="取车时间" prop="pickupTime">
          <el-date-picker clearable
            v-model="form.pickupTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择取车时间">
          </el-date-picker>
        </el-form-item>
<!--        <el-form-item label="代理商id" prop="agentId">-->
<!--          <el-input v-model="form.agentId" placeholder="请输入代理商id" />-->
<!--        </el-form-item>-->
        <el-form-item label="店铺id" prop="storeId">
          <el-input v-model="form.storeId" placeholder="请输入店铺id" />
        </el-form-item>
        <el-form-item label="取车城市" prop="pickupCity">
          <el-input v-model="form.pickupCity" placeholder="请输入取车城市" />
        </el-form-item>
        <el-form-item label="取车地点  " prop="pickupLoc">
          <el-input v-model="form.pickupLoc" placeholder="请输入取车地点  " />
        </el-form-item>
        <el-form-item label="取车经度" prop="pickupLon">
          <el-input v-model="form.pickupLon" placeholder="请输入取车经度" />
        </el-form-item>
        <el-form-item label="取车纬度" prop="pickupLat">
          <el-input v-model="form.pickupLat" placeholder="请输入取车纬度" />
        </el-form-item>
        <el-form-item label="租车周期" prop="rentalPeriod">
          <el-input v-model="form.rentalPeriod" 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 { listOrder, getOrder, delOrder, addOrder, updateOrder } from "@/api/system/order";

export default {
  name: "Order",
  dicts: ['rl_order_status', 'et_pay_type', 'rl_distribution_mode', 'rl_rental_unit','rl_order_type','et_order_pay_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        outTradeNo: null,
        userId: null,
        ruleId: null,
        deviceMac: null,
        sn: null,
        payTime: null,
        payType: null,
        paid: null,
        type: null,
        totalFee: null,
        payFee: null,
        dispatchFee: null,
        ridingFee: null,
        mark: null,
        duration: null,
        status: null,
        returnTime: null,
        depositDeduction: null,
        deductionAmount: null,
        autoRefundDeposit: null,
        rentalUnit: null,
        handlingCharge: null,
        platformServiceFee: null,
        operatorDividend: null,
        payChannel: null,
        deliveryMethod: null,
        pickupTime: null,
        agentId: null,
        storeId: null,
        pickupCity: null,
        pickupLoc: null,
        pickupLon: null,
        pickupLat: null,
        rentalPeriod: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderNo: [
          { required: true, message: "订单号不能为空", trigger: "blur" }
        ],
        userId: [
          { required: true, message: "用户ID不能为空", trigger: "blur" }
        ],
        paid: [
          { required: true, message: "支付状态不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "类型不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderId: null,
        orderNo: null,
        outTradeNo: null,
        userId: null,
        ruleId: null,
        deviceMac: null,
        sn: null,
        payTime: null,
        payType: null,
        paid: null,
        type: null,
        totalFee: null,
        payFee: null,
        dispatchFee: null,
        ridingFee: null,
        mark: null,
        duration: null,
        status: null,
        createTime: null,
        returnTime: null,
        depositDeduction: null,
        depositOrderNo: null,
        deductionAmount: null,
        usedSn: null,
        changeReason: null,
        autoRefundDeposit: null,
        rentalUnit: null,
        handlingCharge: null,
        platformServiceFee: null,
        operatorDividend: null,
        payChannel: null,
        deliveryMethod: null,
        pickupTime: null,
        agentId: null,
        storeId: null,
        pickupCity: null,
        pickupLoc: null,
        pickupLon: null,
        pickupLat: null,
        rentalPeriod: 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.orderId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderId = row.orderId || this.ids
      getOrder(orderId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.orderId != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderIds = row.orderId || this.ids;
      this.$modal.confirm('是否确认删除订单编号为"' + orderIds + '"的数据项？').then(function() {
        return delOrder(orderIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
