<template>
  <basic-container>
    <el-dialog :modal-append-to-body="false" :visible.sync="debitObjectVisible" title="分佣对象" width="40%">
      <div>
        <span style="margin:10px;">
          <font size="3">姓名：</font>
        </span>
        <span style="margin:10px;">
          {{debitObject.receiverAccountName}}
        </span>

      </div>
      <div>
        <span style="margin:10px;">
          <font size="3">
            银行卡编码：
          </font>
        </span>
        <span style="margin:10px;">
          {{debitObject.receiverBankCode}}
        </span>

      </div>

      <div>
        <span style="margin:10px;">
          <font size="3">
            账户类型：
          </font>
        </span>
        <span>
          {{debitObject.bankAccountType}}
        </span>
      </div>
      <div>
        <span style="margin:10px;">
          <font size="3">
            银行卡号：
          </font>
        </span>
        <span>
          {{debitObject.receiverAccountNo}}
        </span>
      </div>
      <div>
        <span style="margin:10px;">
          <font size="3">
            分佣金额：
          </font>
        </span>
        <span>
          {{debitObject.price}}
        </span>
      </div>
      <div>
        <span style="margin:10px;">
          <font size="3">
            手续费：
          </font>
        </span>
        <span>
          {{debitObject.fee}}
        </span>
      </div>
      <div>
        <span style="margin:10px;">
          <font size="3">
            分佣状态：
          </font>
        </span>
        <span>
          {{debitObject.$status}}
        </span>
      </div>
    </el-dialog>
    <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page" :permission="permissionList"
      :before-open="beforeOpen" v-model="form" ref="crud" @row-update="rowUpdate" @row-save="rowSave" @row-del="rowDel"
      @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange" @current-change="currentChange"
      @size-change="sizeChange" @refresh-change="refreshChange" @on-load="onLoad">

      <template slot="menu" slot-scope="scope">
        <el-button type="text" size="small" icon="el-icon-zoom-in" @click="handleDetail(scope.row)">分佣对象
        </el-button>
      </template>
    </avue-crud>



  </basic-container>
</template>

<script>
  import {
    getList,
    getDetail,
    add,
    update,
    remove
  } from "@/api/billrecord/bussinessdebit";
  import {
    mapGetters
  } from "vuex";

  export default {
    props: {
      requestId: {}
    },
    data() {

      return {
        debitObjectVisible: false,
        debitObject: {},
        form: {},
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        option: {
          refreshBtn: false,
          // showHeader: false,
          height: 'auto',
          calcHeight: 30,
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          index: true,
          viewBtn: false,
          selection: true,
          dialogClickModal: false,
          column: [{
              label: "广告商id",
              prop: "bussinessId",
              hide: true,
              display: false,
              rules: [{
                required: true,
                message: "请输入广告商id",
                trigger: "blur"
              }]
            },
            {
              label: "扣款类型",
              prop: "type",
              width: 200,
              type: "select",
              dicData: [{
                  label: "分佣分润",
                  value: 1
                },
                {
                  label: "曝光量收费",
                  value: 2
                },
                {
                  label: "点击量收费",
                  value: 3
                },
              ],
              rules: [{
                required: true,
                message: "请输入扣款类型： 1-分润 2-曝光量收费 3-点击量收费",
                trigger: "blur"
              }]
            },
            {
              label: "扣款金额(元)",
              prop: "price",
              width: 200,
              rules: [{
                required: true,
                message: "请输入扣款金额",
                trigger: "blur"
              }]
            },
            {
              label: "关联id： 当type=1时为分佣用户id，当type=2时为报告记录id，当type=3时为点击记录id",
              prop: "relationId",
              hide: true,
              display: false,
              rules: [{
                required: true,
                message: "请输入关联id： 当type=1时为分佣用户id，当type=2时为报告记录id，当type=3时为点击记录id",
                trigger: "blur"
              }]
            },
            {
              label: "手续费(元)",
              prop: "fee",
              width: 200,
              rules: [{
                required: true,
                message: "请输入手续费，当type=1时有值",
                trigger: "blur"
              }]
            },
            {
              label: "状态",
              prop: "status",
              width: 200,
              type: "select",
              dicData: [{
                  label: "待确认",
                  value: 1
                },
                {
                  label: "确认成功",
                  value: 2
                },
                {
                  label: "确认失败",
                  value: 3
                },
              ],
              rules: [{
                required: true,
                message: "请输入手续费，当type=1时有值",
                trigger: "blur"
              }]
            },
            {
              label: "时间",
              prop: "updateTime",
            }
          ]
        },
        data: []
      };
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.bussinessdebit_add, false),
          viewBtn: this.vaildData(true),
          delBtn: this.vaildData(this.permission.bussinessdebit_delete, false),
          editBtn: this.vaildData(this.permission.bussinessdebit_edit, false)
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
    methods: {
      handleDetail(row) {
        this.debitObjectVisible = true;
        this.debitObject = row;
      },
      rowSave(row, done, loading) {
        add(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          window.console.log(error);
        });
      },
      rowUpdate(row, index, done, loading) {
        update(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          console.log(error);
        });
      },
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(() => {
            return remove(row.id);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      },
      handleDelete() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        this.$confirm("确定将选择数据删除?", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(() => {
            return remove(this.ids);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crud.toggleSelection();
          });
      },
      beforeOpen(done, type) {
        if (["edit", "view"].includes(type)) {
          getDetail(this.form.id).then(res => {
            this.form = res.data.data;
          });
        }
        done();
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage) {
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize) {
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        this.loading = true;
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
      }
    }
  };
</script>

<style>
</style>
