<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="160px">
<!--      <el-form-item label="直属上级代理" prop="agentId">
        <el-input
          v-model="queryParams.agentId"
          placeholder="请输入直属上级代理"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="货币类型" prop="currencyType">
        <el-select v-model="queryParams.currencyType" placeholder="请选择货币类型" clearable>
          <el-option
            v-for="dict in dict.type.currency_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="来源UID" prop="fromUid">
        <el-input
          v-model="queryParams.fromUid"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="兑换的商品的ID" prop="goodsId">
        <el-input
          v-model="queryParams.goodsId"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label=" 第三表记录id" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入 第三表记录id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="remarks">
        <el-input
          v-model="queryParams.remarks"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
  <!--      <el-form-item label="受益UID" prop="toUid">
          <el-input
            v-model="queryParams.toUid"
            placeholder="请输入"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>-->
      <el-form-item label="交易组ID" prop="tranGroupId">
        <el-input
          v-model="queryParams.tranGroupId"
          placeholder="请输入交易组ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="1级交易类型" prop="tranType1">
        <el-select v-model="queryParams.tranType1" placeholder="请选择" clearable>
          <el-option
            v-for="dict in dict.type.fin_tran1"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label=" 2级交易类型" prop="tranType2">
        <el-select v-model="queryParams.tranType2" placeholder="请选择" clearable>
          <el-option
            v-for="dict in dict.type.fin_tran2"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label=" 3级交易类型" prop="tranType3">
        <el-select v-model="queryParams.tranType3" placeholder="请选择" clearable>
          <el-option
            v-for="dict in dict.type.fin_tran3"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="UID" prop="uid">
        <el-input
          v-model="queryParams.uid"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="是否已满足提现（用于充值记录）" prop="withdrawFlag">
        <el-select v-model="queryParams.withdrawFlag" placeholder="请选择是否已满足提现" clearable>
          <el-option
            v-for="dict in dict.type.app_is_cash"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>-->
      <el-form-item label="日期" prop="daterange">
        <el-date-picker
          v-model="daterange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="dateChage"
        ></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="['business:tran_record: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="['business:tran_record: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="['business:tran_record: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="['business:tran_record:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tran_recordList" @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="UID" align="center" prop="uid" />
      <el-table-column label="来源UID" align="center" prop="fromUid" />
      <el-table-column label="日期" align="center" prop="createTime" width="100"/>
      <el-table-column label="货币类型" align="center" prop="currencyType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.currency_type" :value="scope.row.currencyType"/>
        </template>
      </el-table-column>
      <el-table-column label="交易金额" align="center" prop="coinChange" width="100">
        <template slot-scope="scope">
          {{scope.row.currencyType==2?scope.row.coinChange:scope.row.diamondCoinChange}}
        </template>
      </el-table-column>
      <el-table-column label="交易后剩余金额" align="center" prop="coinChange" width="100">
        <template slot-scope="scope">
          {{scope.row.currencyType==2?scope.row.afterCoin:scope.row.afterDiamondCoin}}
        </template>
      </el-table-column>
      <el-table-column label="1级交易类型" align="center" prop="tranType1" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fin_tran1" :value="scope.row.tranType1"/>
        </template>
      </el-table-column>
      <el-table-column label="2级交易类型" align="center" prop="tranType2" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fin_tran2" :value="scope.row.tranType2"/>
        </template>
      </el-table-column>
      <el-table-column label="3级交易类型" align="center" prop="tranType3" width="130">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fin_tran3" :value="scope.row.tranType3"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remarks" width="200"/>
      <el-table-column label="此记录关联的购买的商品的ID" align="center" prop="goodsId" width="130"/>
      <el-table-column label="第三表记录id" align="center" prop="orderId" width="130"/>
      <el-table-column label="交易组ID" align="center" prop="tranGroupId" width="130"/>
      <el-table-column label="是否已满足提现（用于充值判断）" align="center" prop="withdrawFlag" width="130">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_is_cash" :value="scope.row.withdrawFlag"/>
        </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="['business:tran_record:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:tran_record: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="当前剩余金币" prop="afterCoin">
          <el-input v-model="form.afterCoin" placeholder="请输入当前剩余金币" />
        </el-form-item>
        <el-form-item label="当前剩余人民币" prop="afterMoney">
          <el-input v-model="form.afterMoney" placeholder="请输入当前剩余人民币" />
        </el-form-item>
        <el-form-item label="当前剩余映票" prop="afterTicket">
          <el-input v-model="form.afterTicket" placeholder="请输入当前剩余映票" />
        </el-form-item>
        <el-form-item label="当前剩余余额" prop="afterDiamondCoin">
          <el-input v-model="form.afterDiamondCoin" placeholder="请输入当前剩余余额" />
        </el-form-item>
        <el-form-item label="直属上级代理" prop="agentId">
          <el-input v-model="form.agentId" placeholder="请输入直属上级代理" />
        </el-form-item>
        <el-form-item label="交易金币" prop="coinChange">
          <el-input v-model="form.coinChange" placeholder="请输入交易金币" />
        </el-form-item>
        <el-form-item label="变动后的余额" prop="diamondCoinChange">
          <el-input v-model="form.diamondCoinChange" placeholder="请输入变动后的余额" />
        </el-form-item>
        <el-form-item label=" 佣金关系人" prop="commissionRelatedUid">
          <el-input v-model="form.commissionRelatedUid" placeholder="请输入 佣金关系人" />
        </el-form-item>
        <el-form-item label="消费金额,基于此字段分佣" prop="consumptionCoin">
          <el-input v-model="form.consumptionCoin" placeholder="请输入消费金额,基于此字段分佣" />
        </el-form-item>
        <el-form-item label="消费人民币,基于此字段分佣" prop="consumptionMoney">
          <el-input v-model="form.consumptionMoney" placeholder="请输入消费人民币,基于此字段分佣" />
        </el-form-item>
        <el-form-item label="货币类型 1:人民币 2:金币 3:映票 4：余额" prop="currencyType">
          <el-select v-model="form.currencyType" placeholder="请选择货币类型 1:人民币 2:金币 3:映票 4：余额">
            <el-option
              v-for="dict in dict.type.currency_type"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label=" 送礼人ID" prop="fromUid">
          <el-input v-model="form.fromUid" placeholder="请输入 送礼人ID" />
        </el-form-item>
        <el-form-item label="此记录关联的购买的商品的ID" prop="goodsId">
          <el-input v-model="form.goodsId" placeholder="请输入此记录关联的购买的商品的ID" />
        </el-form-item>
        <el-form-item label="家族ID" prop="guildId">
          <el-input v-model="form.guildId" placeholder="请输入家族ID" />
        </el-form-item>
        <el-form-item label="上级经纪人ID，对应AdminUser表" prop="managerCoId">
          <el-input v-model="form.managerCoId" placeholder="请输入上级经纪人ID，对应AdminUser表" />
        </el-form-item>
        <el-form-item label="上级经纪人ID，对应AdminUser表" prop="managerId">
          <el-input v-model="form.managerId" placeholder="请输入上级经纪人ID，对应AdminUser表" />
        </el-form-item>
        <el-form-item label="人民币变动" prop="moneyChange">
          <el-input v-model="form.moneyChange" placeholder="请输入人民币变动" />
        </el-form-item>
        <el-form-item label=" 第三表记录id" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入 第三表记录id" />
        </el-form-item>
        <el-form-item label="收益比例" prop="perc">
          <el-input v-model="form.perc" placeholder="请输入收益比例" />
        </el-form-item>
        <el-form-item label=" (礼物、守护、坐骑、靓号、短视频、动态、svpi、贵族、游戏)数量" prop="proCount">
          <el-input v-model="form.proCount" placeholder="请输入 (礼物、守护、坐骑、靓号、短视频、动态、svpi、贵族、游戏)数量" />
        </el-form-item>
        <el-form-item label=" (礼物、守护、坐骑、靓号、短视频、动态、svpi、贵族、游戏、充值)ID" prop="proId">
          <el-input v-model="form.proId" placeholder="请输入 (礼物、守护、坐骑、靓号、短视频、动态、svpi、贵族、游戏、充值)ID" />
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label=" 场景id" prop="sceneId1">
          <el-input v-model="form.sceneId1" placeholder="请输入 场景id" />
        </el-form-item>
        <el-form-item label=" 某次直播时间段内的一个标识" prop="sceneId2">
          <el-input v-model="form.sceneId2" placeholder="请输入 某次直播时间段内的一个标识" />
        </el-form-item>
        <el-form-item label="映票变动" prop="ticketChange">
          <el-input v-model="form.ticketChange" placeholder="请输入映票变动" />
        </el-form-item>
        <el-form-item label=" 受益的人ID" prop="toUid">
          <el-input v-model="form.toUid" placeholder="请输入 受益的人ID" />
        </el-form-item>
        <el-form-item label="交易组ID，ID相同说明是一次交易产生的" prop="tranGroupId">
          <el-input v-model="form.tranGroupId" placeholder="请输入交易组ID，ID相同说明是一次交易产生的" />
        </el-form-item>
        <el-form-item label=" 1级交易类型" prop="tranType1">
          <el-select v-model="form.tranType1" placeholder="请选择 1级交易类型">
            <el-option
              v-for="dict in dict.type.fin_tran1"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label=" 2级交易类型 FinTranType2" prop="tranType2">
          <el-select v-model="form.tranType2" placeholder="请选择 2级交易类型 FinTranType2">
            <el-option
              v-for="dict in dict.type.fin_tran2"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label=" 3级交易类型 FinTranType3" prop="tranType3">
          <el-select v-model="form.tranType3" placeholder="请选择 3级交易类型 FinTranType3">
            <el-option
              v-for="dict in dict.type.fin_tran3"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label=" 用户ID" prop="uid">
          <el-input v-model="form.uid" placeholder="请输入 用户ID" />
        </el-form-item>
        <el-form-item label="是否已满足提现 0：未满足  1：已满足" prop="withdrawFlag">
          <el-select v-model="form.withdrawFlag" placeholder="请选择是否已满足提现 0：未满足  1：已满足">
            <el-option
              v-for="dict in dict.type.app_is_cash"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></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 { listTran_record, getTran_record, delTran_record, addTran_record, updateTran_record } from "@/api/business/tran_record";

export default {
  name: "Tran_record",
  dicts: ['currency_type', 'fin_tran2', 'fin_tran3', 'app_is_cash', 'fin_tran1'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户收支明细表格数据
      tran_recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      daterange:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        afterCoin: null,
        afterMoney: null,
        afterTicket: null,
        afterDiamondCoin: null,
        agentId: null,
        coinChange: null,
        diamondCoinChange: null,
        commissionRelatedUid: null,
        consumptionCoin: null,
        consumptionMoney: null,
        currencyType: null,
        fromUid: null,
        goodsId: null,
        guildId: null,
        managerCoId: null,
        managerId: null,
        moneyChange: null,
        orderId: null,
        perc: null,
        proCount: null,
        proId: null,
        remarks: null,
        sceneId1: null,
        sceneId2: null,
        sceneType: null,
        ticketChange: null,
        toUid: null,
        tranGroupId: null,
        tranType1: null,
        tranType2: null,
        tranType3: null,
        uid: null,
        withdrawFlag: null,
        beginTime:null,
        endTime:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    dateChage(val){
      if(undefined != val && null != val && val.length > 1){
        this.queryParams.beginTime = val[0];
        this.queryParams.endTime = val[1];
      }else{
        this.queryParams.beginTime = null;
        this.queryParams.endTime = null;
      }
    },
    /** 查询用户收支明细列表 */
    getList() {
      this.loading = true;
      listTran_record(this.queryParams).then(response => {
        this.tran_recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        afterCoin: null,
        afterMoney: null,
        afterTicket: null,
        afterDiamondCoin: null,
        agentId: null,
        coinChange: null,
        diamondCoinChange: null,
        commissionRelatedUid: null,
        consumptionCoin: null,
        consumptionMoney: null,
        createTime: null,
        currencyType: null,
        fromUid: null,
        goodsId: null,
        guildId: null,
        managerCoId: null,
        managerId: null,
        moneyChange: null,
        orderId: null,
        perc: null,
        proCount: null,
        proId: null,
        remarks: null,
        sceneId1: null,
        sceneId2: null,
        sceneType: null,
        ticketChange: null,
        toUid: null,
        tranGroupId: null,
        tranType1: null,
        tranType2: null,
        tranType3: null,
        uid: null,
        withdrawFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.daterange = [];
      this.queryParams.beginTime = null;
      this.queryParams.endTime = null;
      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
      getTran_record(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) {
            updateTran_record(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTran_record(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 delTran_record(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/tran_record/export', {
        ...this.queryParams
      }, `tran_record_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
