<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单号" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="二维码标识" prop="qrcodeId">-->
        <!--<el-input-->
          <!--v-model="queryParams.qrcodeId"-->
          <!--placeholder="请输入二维码标识"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="卡类型" prop="type">-->
        <!--<el-select v-model="queryParams.type" placeholder="请选择卡类型" clearable size="small">-->
          <!--<el-option label="请选择字典生成" value="" />-->
        <!--</el-select>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="卡ID" prop="cardId">-->
        <!--<el-input-->
          <!--v-model="queryParams.cardId"-->
          <!--placeholder="请输入卡ID"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <el-form-item label="卡号" prop="cardNo">
        <el-input
          v-model="queryParams.cardNo"
          placeholder="请输入卡号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年份" prop="year">
        <el-input
          v-model="queryParams.year"
          placeholder="请输入年份"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phonenumber">
        <el-input
          v-model="queryParams.phonenumber"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="微信订单号" prop="transactionId">-->
        <!--<el-input-->
          <!--v-model="queryParams.transactionId"-->
          <!--placeholder="请输入微信订单号"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->

      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </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" v-if="false">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['back:bBusiPaymentOrders:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5" v-if="false">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['back:bBusiPaymentOrders:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5" v-if="false">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['back:bBusiPaymentOrders:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['back:bBusiPaymentOrders:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="bBusiPaymentOrdersList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />

      <!--<el-table-column label="卡类型" align="center" prop="type" />-->
      <el-table-column label="卡ID" align="center" prop="cardId" />
      <el-table-column label="卡号" align="center" prop="cardNo" />
      <el-table-column label="年份" align="center" prop="year" />
      <el-table-column label="手机号" align="center" prop="phonenumber" />
      <el-table-column label="微信订单号" align="center" prop="transactionId" />
      <!--<el-table-column label="用户code" align="center" prop="customerCode" />-->
      <el-table-column label="过期时间" align="center" prop="outTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.outTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!--<el-table-column label="单价" align="center" prop="price" />-->
      <!--<el-table-column label="数量" align="center" prop="num" />-->
      <!--<el-table-column label="金额" align="center" prop="fee" />-->
      <!--<el-table-column label="应付金额" align="center" prop="totalFee" />-->
      <el-table-column label="实付金额(分)" align="center" prop="payFee" />
      <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
      <el-table-column label="订单号" align="center" prop="code" />
      <el-table-column label="二维码标识" align="center" prop="qrcodeId" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180" />
      <!--<el-table-column label="创建者" align="center" prop="creator" />-->
      <!--<el-table-column label="回调描述" align="center" prop="body" />-->
      <!--<el-table-column label="详情" align="center" prop="detail" />-->
      <!--<el-table-column label="附加数据" align="center" prop="attach" />-->
      <!--<el-table-column label="微信预支付标识" align="center" prop="prepayId" />-->
      <!--<el-table-column label="支付者" align="center" prop="payer" />-->
      <el-table-column label="支付时间" align="center" prop="payTime" width="180" />

      <!--<el-table-column label="支付回调结果" align="center" prop="feedBack" />-->
      <!--<el-table-column label="确认时间" align="center" prop="syncTime" width="180" />-->
      <!--<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="['back:bBusiPaymentOrders:edit']"-->
          <!--&gt;修改</el-button>-->
          <!--<el-button-->
            <!--size="mini"-->
            <!--type="text"-->
            <!--icon="el-icon-delete"-->
            <!--@click="handleDelete(scope.row)"-->
            <!--v-hasPermi="['back:bBusiPaymentOrders:remove']"-->
          <!--&gt;删除</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="code">
          <el-input v-model="form.code" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="二维码标识" prop="qrcodeId">
          <el-input v-model="form.qrcodeId" placeholder="请输入二维码标识" />
        </el-form-item>
        <el-form-item label="卡类型" prop="type">
          <el-select v-model="form.type" placeholder="请选择卡类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="卡ID" prop="cardId">
          <el-input v-model="form.cardId" placeholder="请输入卡ID" />
        </el-form-item>
        <el-form-item label="卡号" prop="cardNo">
          <el-input v-model="form.cardNo" placeholder="请输入卡号" />
        </el-form-item>
        <el-form-item label="年份" prop="year">
          <el-input v-model="form.year" placeholder="请输入年份" />
        </el-form-item>
        <el-form-item label="手机号" prop="phonenumber">
          <el-input v-model="form.phonenumber" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="微信订单号" prop="transactionId">
          <el-input v-model="form.transactionId" placeholder="请输入微信订单号" />
        </el-form-item>
        <el-form-item label="用户code" prop="customerCode">
          <el-input v-model="form.customerCode" placeholder="请输入用户code" />
        </el-form-item>
        <el-form-item label="失效日期" prop="outTime">
          <el-date-picker clearable size="small"
                          v-model="form.outTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择失效日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="单价" prop="price">
          <el-input v-model="form.price" placeholder="请输入单价" />
        </el-form-item>
        <el-form-item label="数量" prop="num">
          <el-input v-model="form.num" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="金额" prop="fee">
          <el-input v-model="form.fee" 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="creator">
          <el-input v-model="form.creator" placeholder="请输入创建者" />
        </el-form-item>
        <el-form-item label="回调描述" prop="body">
          <el-input v-model="form.body" placeholder="请输入回调描述" />
        </el-form-item>
        <el-form-item label="详情" prop="detail">
          <el-input v-model="form.detail" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="附加数据" prop="attach">
          <el-input v-model="form.attach" placeholder="请输入附加数据" />
        </el-form-item>
        <el-form-item label="微信预支付标识" prop="prepayId">
          <el-input v-model="form.prepayId" placeholder="请输入微信预支付标识" />
        </el-form-item>
        <el-form-item label="支付者" prop="payer">
          <el-input v-model="form.payer" placeholder="请输入支付者" />
        </el-form-item>
        <el-form-item label="支付时间" prop="payTime">
          <el-date-picker clearable size="small"
                          v-model="form.payTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择支付时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="支付回调结果" prop="feedBack">
          <el-input v-model="form.feedBack" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="确认时间" prop="syncTime">
          <el-date-picker clearable size="small"
                          v-model="form.syncTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择确认时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择状态">
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </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 { listBBusiPaymentOrders, getBBusiPaymentOrders, delBBusiPaymentOrders, addBBusiPaymentOrders, updateBBusiPaymentOrders, exportBBusiPaymentOrders } from "@/api/back/bBusiPaymentOrders";

  export default {
    name: "BBusiPaymentOrders",
    components: {
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 在线电子卡订单表格数据
        bBusiPaymentOrdersList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 状态(-2:已退费,-1:支付失败,0:无效,1:未支付,2:已支付)字典
        statusOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          code: null,
          qrcodeId: null,
          type: null,
          cardId: null,
          cardNo: null,
          year: null,
          phonenumber: null,
          transactionId: null,
          customerCode: null,
          outTime: null,
          price: null,
          num: null,
          fee: null,
          totalFee: null,
          payFee: null,
          createTime: null,
          creator: null,
          body: null,
          detail: null,
          attach: null,
          prepayId: null,
          payer: null,
          payTime: null,
          feedBack: null,
          syncTime: null,
          status: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          code: [
            { required: true, message: "订单号不能为空", trigger: "blur" }
          ],
          year: [
            { required: true, message: "年份不能为空", trigger: "blur" }
          ],
          price: [
            { required: true, message: "单价不能为空", trigger: "blur" }
          ],
          num: [
            { required: true, message: "数量不能为空", trigger: "blur" }
          ],
          fee: [
            { required: true, message: "金额不能为空", trigger: "blur" }
          ],
          totalFee: [
            { required: true, message: "应付金额不能为空", trigger: "blur" }
          ],
          payFee: [
            { required: true, message: "实付金额不能为空", trigger: "blur" }
          ],
          createTime: [
            { required: true, message: "创建时间不能为空", trigger: "blur" }
          ],
          creator: [
            { required: true, message: "创建者不能为空", trigger: "blur" }
          ],
          status: [
            { required: true, message: "状态不能为空", trigger: "change" }
          ]
        }
      };
    },
    created() {
      this.getList();
      this.getDicts("ecard_status").then(response => {
        this.statusOptions = response.data;
      });
    },
    methods: {
      /** 查询在线电子卡订单列表 */
      getList() {
        this.loading = true;
        listBBusiPaymentOrders(this.queryParams).then(response => {
          this.bBusiPaymentOrdersList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 状态(-2:已退费,-1:支付失败,0:无效,1:未支付,2:已支付)字典翻译
      statusFormat(row, column) {
        return this.selectDictLabel(this.statusOptions, row.status);
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          code: null,
          qrcodeId: null,
          type: null,
          cardId: null,
          cardNo: null,
          year: null,
          phonenumber: null,
          transactionId: null,
          customerCode: null,
          outTime: null,
          price: null,
          num: null,
          fee: null,
          totalFee: null,
          payFee: null,
          createTime: null,
          creator: null,
          body: null,
          detail: null,
          attach: null,
          prepayId: null,
          payer: null,
          payTime: null,
          feedBack: null,
          syncTime: null,
          status: 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
        getBBusiPaymentOrders(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) {
              updateBBusiPaymentOrders(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addBBusiPaymentOrders(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 delBBusiPaymentOrders(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有在线电子卡订单数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportBBusiPaymentOrders(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        })
      }
    }
  };
</script>
