<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单id" prop="dealSn">
        <el-input
          v-model="queryParams.dealSn"
          placeholder="请输入订单id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="马拉松id" prop="marathonId">
        <el-input
          v-model="queryParams.marathonId"
          placeholder="请输入对应马拉松id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入对应报名用户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="赛事包id" prop="pkgId">
        <el-input
          v-model="queryParams.pkgId"
          placeholder="请输入对应赛事包id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="对应赛事包名称" prop="pkgName">
        <el-input
          v-model="queryParams.pkgName"
          placeholder="请输入对应赛事包名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="规格id" prop="specId">
        <el-input
          v-model="queryParams.specId"
          placeholder="请输入规格id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="商品规格属性键值对(json字符串k,v)) eg:{"颜色":"中性灰","尺码":"170"}" prop="spec">
        <el-input
          v-model="queryParams.spec"
          placeholder="请输入商品规格属性键值对(json字符串k,v)) eg:{"颜色":"中性灰","尺码":"170"}"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="商品价格" prop="price">
        <el-input
          v-model="queryParams.price"
          placeholder="请输入商品价格"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="购买数量" prop="amout">
        <el-input
          v-model="queryParams.amout"
          placeholder="请输入购买数量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="支付订单号" prop="payId">
        <el-input
          v-model="queryParams.payId"
          placeholder="请输入支付订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="支付方式/0=支付宝；1=微信" prop="payType">
        <el-select v-model="queryParams.payType" placeholder="请选择支付方式/0=支付宝；1=微信" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="支付金额" prop="payMoney">
        <el-input
          v-model="queryParams.payMoney"
          placeholder="请输入支付金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单状态,0待付款，1待发货，2待收货，3交易完成,4退款中，5退款失败，6退款成功，7交易关闭,8交易完成未评价，9交易完成已评价" prop="dealStatus">
        <el-select v-model="queryParams.dealStatus" placeholder="请选择订单状态,0待付款，1待发货，2待收货，3交易完成,4退款中，5退款失败，6退款成功，7交易关闭,8交易完成未评价，9交易完成已评价" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="支付时间" prop="payAt">
        <el-date-picker clearable size="small"
          v-model="queryParams.payAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择支付时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="是否已支付/0=否；1=是" prop="isPaied">
        <el-input
          v-model="queryParams.isPaied"
          placeholder="请输入是否已支付/0=否；1=是"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createAt">
        <el-date-picker clearable size="small"
          v-model="queryParams.createAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新时间" prop="updateAt">
        <el-date-picker clearable size="small"
          v-model="queryParams.updateAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="是否删除 1=删除" prop="isDelete">
        <el-input
          v-model="queryParams.isDelete"
          placeholder="请输入是否删除 1=删除"
          clearable
          size="small"
          @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="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:LzydMarathonOrderDetail: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:LzydMarathonOrderDetail: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:LzydMarathonOrderDetail: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:LzydMarathonOrderDetail:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table v-loading="loading" :data="LzydMarathonOrderDetailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <!-- scope.row.index -->
      <el-table-column label="订单id" align="center" prop="dealSn" width="200"/>
      <el-table-column label="马拉松id" align="center" prop="marathonId" />
      <el-table-column label="用户id" align="center" prop="userId" width="200" />
      <el-table-column label="赛事包id" align="center" prop="pkgId" />
      <el-table-column label="赛事包" align="center" prop="pkgName" />
      <el-table-column label="规格id" align="center" prop="specId" />
      <!-- <el-table-column label="商品规格属性键值对(json字符串k,v)) eg:{"颜色":"中性灰","尺码":"170"}" align="center" prop="spec" /> -->
      <el-table-column label="商品价格" align="center" prop="price" />
      <el-table-column label="购买数量" align="center" prop="amout" />
      <el-table-column label="支付订单号" align="center" prop="payId" />
      <el-table-column label="支付方式" align="center" prop="payType" />
      <!-- /0=支付宝；1=微信 -->
      <el-table-column label="支付金额" align="center" prop="payMoney" />
      <el-table-column label="订单状态" align="center" prop="dealStatus" />
      <!-- 0待付款，1待发货，2待收货，3交易完成,4退款中，5退款失败，6退款成功，7交易关闭,8交易完成未评价，9交易完成已评价 -->
      <el-table-column label="支付时间" align="center" prop="payAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否已支付/0=否；1=是" align="center" prop="isPaied" />
      <el-table-column label="创建时间" align="center" prop="createAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否删除 1=删除" align="center" prop="isDelete" />
      <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:LzydMarathonOrderDetail:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:LzydMarathonOrderDetail: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="dealSn">
          <el-input v-model="form.dealSn" placeholder="请输入订单id" />
        </el-form-item>
        <el-form-item label="对应马拉松id" prop="marathonId">
          <el-input v-model="form.marathonId" placeholder="请输入对应马拉松id" />
        </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="pkgId">
          <el-input v-model="form.pkgId" placeholder="请输入对应赛事包id" />
        </el-form-item>
        <el-form-item label="对应赛事包名称" prop="pkgName">
          <el-input v-model="form.pkgName" placeholder="请输入对应赛事包名称" />
        </el-form-item>
        <el-form-item label="规格id" prop="specId">
          <el-input v-model="form.specId" placeholder="请输入规格id" />
        </el-form-item>
        <!-- <el-form-item label="商品规格属性键值对(json字符串k,v)) eg:{"颜色":"中性灰","尺码":"170"}" prop="spec">
          <el-input v-model="form.spec" placeholder="请输入商品规格属性键值对(json字符串k,v)) eg:{"颜色":"中性灰","尺码":"170"}" />
        </el-form-item> -->
        <el-form-item label="商品价格" prop="price">
          <el-input v-model="form.price" placeholder="请输入商品价格" />
        </el-form-item>
        <el-form-item label="购买数量" prop="amout">
          <el-input v-model="form.amout" placeholder="请输入购买数量" />
        </el-form-item>
        <el-form-item label="支付订单号" prop="payId">
          <el-input v-model="form.payId" placeholder="请输入支付订单号" />
        </el-form-item>
        <el-form-item label="支付方式" prop="payType">
          <el-select v-model="form.payType" placeholder="请选择支付方式">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="支付金额" prop="payMoney">
          <el-input v-model="form.payMoney" placeholder="请输入支付金额" />
        </el-form-item>
        <el-form-item label="订单状态">
          <el-radio-group v-model="form.dealStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="支付时间" prop="payAt">
          <el-date-picker clearable size="small"
            v-model="form.payAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择支付时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否已支付" prop="isPaied">
          <el-input v-model="form.isPaied" placeholder="请输入是否已支付" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createAt">
          <el-date-picker clearable size="small"
            v-model="form.createAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新时间" prop="updateAt">
          <el-date-picker clearable size="small"
            v-model="form.updateAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择更新时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否删除" prop="isDelete">
          <el-input v-model="form.isDelete" 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 { listLzydMarathonOrderDetail, getLzydMarathonOrderDetail, delLzydMarathonOrderDetail, addLzydMarathonOrderDetail, updateLzydMarathonOrderDetail, exportLzydMarathonOrderDetail } from "@/api/system/LzydMarathonOrderDetail";

export default {
  name: "LzydMarathonOrderDetail",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 马拉松赛事包订单详情表格数据
      LzydMarathonOrderDetailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dealSn: null,
        marathonId: null,
        userId: null,
        pkgId: null,
        pkgName: null,
        specId: null,
        spec: null,
        price: null,
        amout: null,
        payId: null,
        payType: null,
        payMoney: null,
        dealStatus: null,
        payAt: null,
        isPaied: null,
        createAt: null,
        updateAt: null,
        isDelete: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询马拉松赛事包订单详情列表 */
    getList() {
      this.loading = true;
      listLzydMarathonOrderDetail(this.queryParams).then(response => {
        this.LzydMarathonOrderDetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        dealSn: null,
        marathonId: null,
        userId: null,
        pkgId: null,
        pkgName: null,
        specId: null,
        spec: null,
        price: null,
        amout: null,
        payId: null,
        payType: null,
        payMoney: null,
        dealStatus: 0,
        payAt: null,
        isPaied: null,
        createAt: null,
        updateAt: null,
        isDelete: 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
      getLzydMarathonOrderDetail(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) {
            updateLzydMarathonOrderDetail(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLzydMarathonOrderDetail(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除马拉松赛事包订单详情编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delLzydMarathonOrderDetail(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有马拉松赛事包订单详情数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportLzydMarathonOrderDetail(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
