<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="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户号" prop="usercode">
        <el-input
          v-model="queryParams.usercode"
          placeholder="请输入用户号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="跟踪ID" prop="traceId">
        <el-input
          v-model="queryParams.traceId"
          placeholder="请输入跟踪ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="下单body" prop="body">
        <el-input
          v-model="queryParams.body"
          placeholder="请输入下单body"
          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="活动ID" prop="activityId">
        <el-input
          v-model="queryParams.activityId"
          placeholder="请输入活动ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="活动标题" prop="activityTitle">
        <el-input
          v-model="queryParams.activityTitle"
          placeholder="请输入活动标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单说明" prop="orderName">
        <el-input
          v-model="queryParams.orderName"
          placeholder="请输入订单说明"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <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="支付时间" 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="appId" prop="appid">
        <el-input
          v-model="queryParams.appid"
          placeholder="请输入appId"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="operateIp">
        <el-input
          v-model="queryParams.operateIp"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="后台操作管理员ID" prop="adminId">
        <el-input
          v-model="queryParams.adminId"
          placeholder="请输入后台操作管理员ID"
          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="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['xq:activityOrder: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="['xq:activityOrder: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="['xq:activityOrder: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="['xq:activityOrder:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="activityOrderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="" align="center" prop="id" v-if="true"/>
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="用户号" align="center" prop="usercode" />
      <el-table-column label="跟踪ID" align="center" prop="traceId" />
      <el-table-column label="下单body" align="center" prop="body" />
      <el-table-column label="" align="center" prop="price" />
      <el-table-column label="活动ID" align="center" prop="activityId" />
      <el-table-column label="活动标题" align="center" prop="activityTitle" />
      <el-table-column label="订单说明" align="center" prop="orderName" />
      <el-table-column label="订单号" align="center" prop="orderNo" />
      <el-table-column label="平台" align="center" prop="platformType" />
      <el-table-column label="状态 0-待支付 1-已支付 5-已退款 10-无需支付" align="center" prop="payStatus" />
      <el-table-column label="支付时间" align="center" prop="payTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="appId" align="center" prop="appid" />
      <el-table-column label="" align="center" prop="returnContent" />
      <el-table-column label="" align="center" prop="operateIp" />
      <el-table-column label="后台操作管理员ID" align="center" prop="adminId" />
      <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="['xq:activityOrder:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['xq:activityOrder: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="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="用户号" prop="usercode">
          <el-input v-model="form.usercode" placeholder="请输入用户号" />
        </el-form-item>
        <el-form-item label="跟踪ID" prop="traceId">
          <el-input v-model="form.traceId" placeholder="请输入跟踪ID" />
        </el-form-item>
        <el-form-item label="下单body" prop="body">
          <el-input v-model="form.body" placeholder="请输入下单body" />
        </el-form-item>
        <el-form-item label="" prop="price">
          <el-input v-model="form.price" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="活动ID" prop="activityId">
          <el-input v-model="form.activityId" placeholder="请输入活动ID" />
        </el-form-item>
        <el-form-item label="活动标题" prop="activityTitle">
          <el-input v-model="form.activityTitle" placeholder="请输入活动标题" />
        </el-form-item>
        <el-form-item label="订单说明" prop="orderName">
          <el-input v-model="form.orderName" placeholder="请输入订单说明" />
        </el-form-item>
        <el-form-item label="订单号" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="支付时间" prop="payTime">
          <el-date-picker clearable
            v-model="form.payTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择支付时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="appId" prop="appid">
          <el-input v-model="form.appid" placeholder="请输入appId" />
        </el-form-item>
        <el-form-item label="">
          <editor v-model="form.returnContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="" prop="operateIp">
          <el-input v-model="form.operateIp" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="后台操作管理员ID" prop="adminId">
          <el-input v-model="form.adminId" placeholder="请输入后台操作管理员ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listActivityOrder, getActivityOrder, delActivityOrder, addActivityOrder, updateActivityOrder } from "@/api/xq/activityOrder";

export default {
  name: "ActivityOrder",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 相亲会订单表格数据
      activityOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,
        usercode: undefined,
        traceId: undefined,
        body: undefined,
        price: undefined,
        activityId: undefined,
        activityTitle: undefined,
        orderName: undefined,
        orderNo: undefined,
        platformType: undefined,
        payStatus: undefined,
        payTime: undefined,
        appid: undefined,
        returnContent: undefined,
        operateIp: undefined,
        adminId: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        userId: [
          { required: true, message: "用户ID不能为空", trigger: "blur" }
        ],
        usercode: [
          { required: true, message: "用户号不能为空", trigger: "blur" }
        ],
        traceId: [
          { required: true, message: "跟踪ID不能为空", trigger: "blur" }
        ],
        body: [
          { required: true, message: "下单body不能为空", trigger: "blur" }
        ],
        price: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        activityId: [
          { required: true, message: "活动ID不能为空", trigger: "blur" }
        ],
        activityTitle: [
          { required: true, message: "活动标题不能为空", trigger: "blur" }
        ],
        orderName: [
          { required: true, message: "订单说明不能为空", trigger: "blur" }
        ],
        orderNo: [
          { required: true, message: "订单号不能为空", trigger: "blur" }
        ],
        platformType: [
          { required: true, message: "平台不能为空", trigger: "change" }
        ],
        payStatus: [
          { required: true, message: "状态 0-待支付 1-已支付 5-已退款 10-无需支付不能为空", trigger: "change" }
        ],
        payTime: [
          { required: true, message: "支付时间不能为空", trigger: "blur" }
        ],
        appid: [
          { required: true, message: "appId不能为空", trigger: "blur" }
        ],
        returnContent: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        operateIp: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        adminId: [
          { required: true, message: "后台操作管理员ID不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询相亲会订单列表 */
    getList() {
      this.loading = true;
      listActivityOrder(this.queryParams).then(response => {
        this.activityOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        userId: undefined,
        usercode: undefined,
        traceId: undefined,
        body: undefined,
        price: undefined,
        activityId: undefined,
        activityTitle: undefined,
        orderName: undefined,
        orderNo: undefined,
        platformType: undefined,
        payStatus: undefined,
        payTime: undefined,
        appid: undefined,
        returnContent: undefined,
        operateIp: undefined,
        adminId: undefined,
        createTime: undefined,
        updateTime: undefined
      };
      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.loading = true;
      this.reset();
      const id = row.id || this.ids
      getActivityOrder(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改相亲会订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateActivityOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addActivityOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除相亲会订单编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delActivityOrder(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('xq/activityOrder/export', {
        ...this.queryParams
      }, `activityOrder_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
