<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="oid">
        <el-input
          v-model="queryParams.oid"
          placeholder="请输入订单id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单号" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日志订单号" prop="logOrderId">
        <el-input
          v-model="queryParams.logOrderId"
          placeholder="请输入日志订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="定金" prop="deposit">
        <el-input
          v-model="queryParams.deposit"
          placeholder="请输入定金"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="定金支付状态" prop="depPaid">
        <el-input
          v-model="queryParams.depPaid"
          placeholder="请输入定金支付状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="定金支付时间" prop="depPayTime">
        <el-input
          v-model="queryParams.depPayTime"
          placeholder="请输入定金支付时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="定金订单号" prop="depLogId">
        <el-input
          v-model="queryParams.depLogId"
          placeholder="请输入定金订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付金额" prop="price">
        <el-input
          v-model="queryParams.price"
          placeholder="请输入支付金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付状态 1：未支付 2：已支付" prop="paid">
        <el-input
          v-model="queryParams.paid"
          placeholder="请输入支付状态 1：未支付 2：已支付"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付时间" prop="payTime">
        <el-input
          v-model="queryParams.payTime"
          placeholder="请输入支付时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付订单号" prop="logId">
        <el-input
          v-model="queryParams.logId"
          placeholder="请输入支付订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工人id" prop="workerId">
        <el-input
          v-model="queryParams.workerId"
          placeholder="请输入工人id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="第一次接单师傅" prop="firstWorkerId">
        <el-input
          v-model="queryParams.firstWorkerId"
          placeholder="请输入第一次接单师傅"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="1：转单之前操作，放弃订单" prop="giveUp">
        <el-input
          v-model="queryParams.giveUp"
          placeholder="请输入1：转单之前操作，放弃订单"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工人费用" prop="workerCost">
        <el-input
          v-model="queryParams.workerCost"
          placeholder="请输入工人费用"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="优惠金额" prop="reductionPrice">
        <el-input
          v-model="queryParams.reductionPrice"
          placeholder="请输入优惠金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="1：开始 2：暂停" prop="isPause">
        <el-input
          v-model="queryParams.isPause"
          placeholder="请输入1：开始 2：暂停"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="优惠券ID" prop="couponId">
        <el-input
          v-model="queryParams.couponId"
          placeholder="请输入优惠券ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="优惠金额" prop="deduction">
        <el-input
          v-model="queryParams.deduction"
          placeholder="请输入优惠金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="历史师傅订单" prop="workerLogId">
        <el-input
          v-model="queryParams.workerLogId"
          placeholder="请输入历史师傅订单"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="createdAt">
        <el-date-picker clearable
          v-model="queryParams.createdAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="${comment}" prop="updatedAt">
        <el-date-picker clearable
          v-model="queryParams.updatedAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="${comment}" prop="deletedAt">
        <el-date-picker clearable
          v-model="queryParams.deletedAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </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:OrderLog: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:OrderLog: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:OrderLog: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:OrderLog:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="OrderLogList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="${comment}" align="center" prop="id" />
      <el-table-column label="订单id" align="center" prop="oid" />
      <el-table-column label="订单号" align="center" prop="orderId" />
      <el-table-column label="日志订单号" align="center" prop="logOrderId" />
      <el-table-column label="标题" align="center" prop="title" />
      <el-table-column label="1：生成订单， 2：接单 ，3：上门 ，4：到达，5：评估报价，6：服务" align="center" prop="type" />
      <el-table-column label="内容" align="center" prop="content" />
      <el-table-column label="定金" align="center" prop="deposit" />
      <el-table-column label="定金支付状态" align="center" prop="depPaid" />
      <el-table-column label="定金支付时间" align="center" prop="depPayTime" />
      <el-table-column label="定金订单号" align="center" prop="depLogId" />
      <el-table-column label="支付金额" align="center" prop="price" />
      <el-table-column label="支付状态 1：未支付 2：已支付" align="center" prop="paid" />
      <el-table-column label="支付时间" align="center" prop="payTime" />
      <el-table-column label="支付订单号" align="center" prop="logId" />
      <el-table-column label="工人id" align="center" prop="workerId" />
      <el-table-column label="第一次接单师傅" align="center" prop="firstWorkerId" />
      <el-table-column label="1：转单之前操作，放弃订单" align="center" prop="giveUp" />
      <el-table-column label="工人费用" align="center" prop="workerCost" />
      <el-table-column label="优惠金额" align="center" prop="reductionPrice" />
      <el-table-column label="1：开始 2：暂停" align="center" prop="isPause" />
      <el-table-column label="优惠券ID" align="center" prop="couponId" />
      <el-table-column label="优惠金额" align="center" prop="deduction" />
      <el-table-column label="历史师傅订单" align="center" prop="workerLogId" />
      <el-table-column label="${comment}" align="center" prop="createdAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="${comment}" align="center" prop="updatedAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatedAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="${comment}" align="center" prop="deletedAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deletedAt, '{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:OrderLog:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:OrderLog: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="订单id" prop="oid">
          <el-input v-model="form.oid" placeholder="请输入订单id" />
        </el-form-item>
        <el-form-item label="订单号" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="日志订单号" prop="logOrderId">
          <el-input v-model="form.logOrderId" placeholder="请输入日志订单号" />
        </el-form-item>
        <el-form-item label="标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入标题" />
        </el-form-item>
        <el-form-item label="内容">
          <editor v-model="form.content" :min-height="192"/>
        </el-form-item>
        <el-form-item label="定金" prop="deposit">
          <el-input v-model="form.deposit" placeholder="请输入定金" />
        </el-form-item>
        <el-form-item label="定金支付状态" prop="depPaid">
          <el-input v-model="form.depPaid" placeholder="请输入定金支付状态" />
        </el-form-item>
        <el-form-item label="定金支付时间" prop="depPayTime">
          <el-input v-model="form.depPayTime" placeholder="请输入定金支付时间" />
        </el-form-item>
        <el-form-item label="定金订单号" prop="depLogId">
          <el-input v-model="form.depLogId" placeholder="请输入定金订单号" />
        </el-form-item>
        <el-form-item label="支付金额" prop="price">
          <el-input v-model="form.price" placeholder="请输入支付金额" />
        </el-form-item>
        <el-form-item label="支付状态 1：未支付 2：已支付" prop="paid">
          <el-input v-model="form.paid" placeholder="请输入支付状态 1：未支付 2：已支付" />
        </el-form-item>
        <el-form-item label="支付时间" prop="payTime">
          <el-input v-model="form.payTime" placeholder="请输入支付时间" />
        </el-form-item>
        <el-form-item label="支付订单号" prop="logId">
          <el-input v-model="form.logId" placeholder="请输入支付订单号" />
        </el-form-item>
        <el-form-item label="工人id" prop="workerId">
          <el-input v-model="form.workerId" placeholder="请输入工人id" />
        </el-form-item>
        <el-form-item label="第一次接单师傅" prop="firstWorkerId">
          <el-input v-model="form.firstWorkerId" placeholder="请输入第一次接单师傅" />
        </el-form-item>
        <el-form-item label="1：转单之前操作，放弃订单" prop="giveUp">
          <el-input v-model="form.giveUp" placeholder="请输入1：转单之前操作，放弃订单" />
        </el-form-item>
        <el-form-item label="工人费用" prop="workerCost">
          <el-input v-model="form.workerCost" placeholder="请输入工人费用" />
        </el-form-item>
        <el-form-item label="优惠金额" prop="reductionPrice">
          <el-input v-model="form.reductionPrice" placeholder="请输入优惠金额" />
        </el-form-item>
        <el-form-item label="1：开始 2：暂停" prop="isPause">
          <el-input v-model="form.isPause" placeholder="请输入1：开始 2：暂停" />
        </el-form-item>
        <el-form-item label="优惠券ID" prop="couponId">
          <el-input v-model="form.couponId" placeholder="请输入优惠券ID" />
        </el-form-item>
        <el-form-item label="优惠金额" prop="deduction">
          <el-input v-model="form.deduction" placeholder="请输入优惠金额" />
        </el-form-item>
        <el-form-item label="历史师傅订单" prop="workerLogId">
          <el-input v-model="form.workerLogId" placeholder="请输入历史师傅订单" />
        </el-form-item>
        <el-form-item label="${comment}" prop="createdAt">
          <el-date-picker clearable
            v-model="form.createdAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="updatedAt">
          <el-date-picker clearable
            v-model="form.updatedAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="deletedAt">
          <el-date-picker clearable
            v-model="form.deletedAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </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 { listOrderLog, getOrderLog, delOrderLog, addOrderLog, updateOrderLog } from "@/api/system/OrderLog"

export default {
  name: "OrderLog",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单服务记录表格数据
      OrderLogList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        oid: null,
        orderId: null,
        logOrderId: null,
        title: null,
        type: null,
        content: null,
        deposit: null,
        depPaid: null,
        depPayTime: null,
        depLogId: null,
        price: null,
        paid: null,
        payTime: null,
        logId: null,
        workerId: null,
        firstWorkerId: null,
        giveUp: null,
        workerCost: null,
        reductionPrice: null,
        isPause: null,
        couponId: null,
        deduction: null,
        workerLogId: null,
        createdAt: null,
        updatedAt: null,
        deletedAt: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        oid: [
          { required: true, message: "订单id不能为空", trigger: "blur" }
        ],
        orderId: [
          { required: true, message: "订单号不能为空", trigger: "blur" }
        ],
        title: [
          { required: true, message: "标题不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "1：生成订单， 2：接单 ，3：上门 ，4：到达，5：评估报价，6：服务不能为空", trigger: "change" }
        ],
        content: [
          { required: true, message: "内容不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询订单服务记录列表 */
    getList() {
      this.loading = true
      listOrderLog(this.queryParams).then(response => {
        this.OrderLogList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        oid: null,
        orderId: null,
        logOrderId: null,
        title: null,
        type: null,
        content: null,
        deposit: null,
        depPaid: null,
        depPayTime: null,
        depLogId: null,
        price: null,
        paid: null,
        payTime: null,
        logId: null,
        workerId: null,
        firstWorkerId: null,
        giveUp: null,
        workerCost: null,
        reductionPrice: null,
        isPause: null,
        couponId: null,
        deduction: null,
        workerLogId: null,
        createdAt: null,
        updatedAt: null,
        deletedAt: 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 = "添加订单服务记录"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getOrderLog(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) {
            updateOrderLog(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addOrderLog(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 delOrderLog(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/OrderLog/export', {
        ...this.queryParams
      }, `OrderLog_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
