<template>
  <div class="app-container">
    <div class="flexBet searchTop">
      <!-- <div class="title flex m20">
        <div class="bar"></div>
        <div class="text">平台流水明细</div>
      </div> -->

    </div>

    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="106px" class="flex form"
      style="position: relative">

      <el-form-item label="单号" prop="businessNo">
        <el-input size="medium" v-model="queryParams.businessNo" placeholder="请输入流水号或业务单号或商户订单号"
          @keyup.enter.native="handleQuery" style="width: 280px; border-color: #e6f1ff" />
      </el-form-item>
      <el-form-item label="账号" prop="accountName">
        <el-input size="medium" v-model="queryParams.accountName" placeholder="请输入账号" @keyup.enter.native="handleQuery"
          style="width: 180px; border-color: #e6f1ff" />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input size="medium" v-model="queryParams.remark" placeholder="请输入备注" @keyup.enter.native="handleQuery"
          style="width: 180px; border-color: #e6f1ff" />
      </el-form-item>
      <el-form-item label="变动类型" prop="opType">
        <el-select v-model="queryParams.opType" placeholder="请选择变动类型" size="medium">
          <el-option v-for="dict in typeCon" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="金额类型" prop="amountType">
        <el-select v-model="queryParams.amountType" placeholder="请选择金额类型" size="medium">
          <el-option v-for="dict in moneyCon" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>



      <el-form-item label="订单类型" prop="source">
        <el-select v-model="queryParams.source" placeholder="请选择订单类型" size="medium">
          <el-option v-for="dict in dict.type.source" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="创建时间">
        <el-date-picker v-model="dateRange" size="small" style="width: 340px" value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :unlink-panels="true"
          :default-time="['00:00:00', '23:59:59']"></el-date-picker>

      </el-form-item>
      <el-form-item>
        <div class="searchTop flexBet" style="align-items: center">
          <el-row :gutter="10" class="mb8">
            <el-button type="primary" icon="" size="medium" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="medium" @click="resetQuery">重置</el-button>
          </el-row>
          <el-row :gutter="10" class="mb8" style="margin-left:8px">
            <el-col :span="1.5">
              <el-button type="primary" plain icon="" size="medium" @click="handleExport()">导出</el-button>
            </el-col>
          </el-row>
          <!-- <el-row :gutter="10" class="mb8">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row> -->

        </div>
      </el-form-item>
    </el-form>
    <div class="searchTop flexBet" style="align-items: center">

    </div>


    <div class="bg">


      <el-table stripe :data="infoList" v-loading="loading">
        <el-table-column label="流水号" align="center" prop="id" />
        <el-table-column label="业务单号" align="center" prop="businessNo" />
        <el-table-column label="商户订单号" align="center" prop="merchantOrderNo" />
        <el-table-column label="账号" align="center" prop="accountName" />
        <el-table-column :label="'账号属性'" align="center" prop="accountType">
          <template slot-scope="scope">
            {{ scope.row.accountType == 2 ? '码商' : '商户' }}
          </template>
        </el-table-column>
        <el-table-column :label="'金额类型'" align="center" prop="amountType">
          <template slot-scope="scope">
            {{ scope.row.amountType == 1 ? (scope.row.accountType == 2 ? '分佣' : '余额') : scope.row.amountType == 2 ? '冻结' : '押金' }}
          </template>
        </el-table-column>
        <el-table-column :label="'变动金额'" align="center" prop="change_amount">
          <template slot-scope="scope">
            {{ parseFloat(NumberDiv(scope.row.changeAmount, 100)).toFixed(2) }}
          </template>
        </el-table-column>
        <el-table-column :label="'变动后金额'" align="center" prop="afterBalance">
          <template slot-scope="scope">
            {{ parseFloat(NumberDiv(scope.row.afterBalance, 100)).toFixed(2) }}
          </template>
        </el-table-column>

        <el-table-column :label="'变动类型'" align="center" prop="opType">
          <template slot-scope="scope">
            {{ scope.row.opType == 1 ? '加余额' :
              scope.row.opType == 2 ? '减余额' :
                scope.row.opType == 3 ? '加冻结金额' :
                  scope.row.opType == 4 ? '减冻结金额' :
                    scope.row.opType == 5 ? '加保证金' :
                      '减少保证金'
            }}
          </template>
        </el-table-column>

        <el-table-column :label="'订单类型'" align="center" prop="source">
          <template slot-scope="scope">
            {{ scope.row.source == 1 ? '手动调账' :
              scope.row.source == 2 ? '充值' :
                scope.row.source == 3 ? '提现' :
                  scope.row.source == 4 ? '代付' :
                    scope.row.source == 5 ? '收款' :
                      scope.row.source == 6 ? '代付分佣' :
                        '代收分佣' }}
          </template>
        </el-table-column>

        <el-table-column label="备注" align="center" prop="remark" />

        <el-table-column label="创建时间" align="center" prop="createTime" min-width="180" />




      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList">
      </pagination>
    </div>




  </div>
</template>
  
<script>
import { listPlatformBankCard, getPlatformBankCard, delPlatformBankCard, addPlatformBankCard, updatePlatformBankCard, exportPlatformBankCard } from "@/api/platform/platformBankCard";
import { common_api, payFinance } from "@/api/form";
import { getToken } from "@/utils/auth";
import cardMerchantOrderRefreshMixin from "@/api/cardMerchantOrderRefresh.mixin";

export default {
  name: "PlatformBankCard",
  dicts: ['op_type', 'source'],
  components: {
  },
  mixins: [cardMerchantOrderRefreshMixin],
  data() {
    return {
      moneyCon: [
        {
          label: '全部',
          value: null,
        },
        {
          label: '分佣/余额',
          value: 1,
        },
        {
          label: '冻结',
          value: 2,
        },
        {
          label: '押金',
          value: 3,
        },
      ],
      typeCon: [
        {

          label: '全部',
          value: null,
        },
        {

          label: '加余额',
          value: 1
        },
        {

          label: '减余额',
          value: 2
        },
        {

          label: '加冻结金额',
          value: 3
        },
        {

          label: '减冻结金额',
          value: 4
        },
        {

          label: '加保证金',
          value: 5
        },
        {

          label: '减少保证金',
          value: 6
        },
      ],
      dateRange: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 平台银行卡表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        businessNo: null,
        merchantOrderNo: null,
        remark: null,
        orderStatus: null,
        source: null,
        accountName: null,
        amountType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        bankName: [
          { required: true, message: "银行名称不能为空", trigger: "blur" }
        ],
        accountName: [
          { required: true, message: "开户名不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        cardNumber: [
          { required: true, message: "银行卡号不能为空", trigger: "blur" }
        ],
        branchName: [
          { required: true, message: "支行名称不能为空", trigger: "blur" }
        ],
        maxAmount: [
          { required: true, message: "最大收款额度不能为空", trigger: "blur" }
        ],
        qrCode: [
          { required: true, message: "收款二维码不能为空", trigger: "blur" }
        ],
        remark: [
          { required: true, message: "备注不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "状态：1-启用， 2-禁用不能为空", trigger: "blur" }
        ],
        todayReceived: [
          { required: true, message: "今日已收金额不能为空", trigger: "blur" }
        ],
        bankCode: [
          { required: true, message: "银行代码不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.init()
  },
  methods: {
    sortNum(a, b) {//排序方法
      return a - b;
    },
    timerHandler(queryParams) {
      payFinance.listInfo(this.addSESDateRange(this.queryParams, this.dateRange)).then(response => {
        this.infoList = response.rows;
        this.infoList = this.infoList.sort(this.sortNum)//调用排序方法
        this.total = Number(response.total);
      });
    },
    getList() {
      this.loading = true;
      payFinance.listInfo(this.addSESDateRange(this.queryParams, this.dateRange)).then(response => {
        this.infoList = response.rows;
        this.infoList = this.infoList.sort(this.sortNum)//调用排序方法
        this.total = Number(response.total);
        this.loading = false;
        this.startTimer(this.queryParams)
      });
    },
    init() {

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {

      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange = []
      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
      getPlatformBankCard(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改平台银行卡";
        this.imageUrl = this.form.qrCode;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePlatformBankCard(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPlatformBankCard(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 delPlatformBankCard(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return payFinance.export(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>
<style scoped lang="scss"></style>