<style>
  .CM_look {
    padding: 4px !important;
    position: relative;
    top: 1px;
  }

  .TCommission-finance {
    font-size: 12px;
    text-decoration: underline;
    cursor: pointer;
    margin-right: 5px;
  }

</style>
<template>
  <div class="flexOne">
    <table v-loading="loading" class="singeRowTable" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <th>期数</th>
        <th v-if="userInfo.RB_Branch_id==0 || userInfo.RB_Branch_id==49 || userInfo.RB_Branch_id==userInfo.ParentCompanyId">提成总金额</th>
        <th>{{$t('admin.admin_czPerson')}}</th>
        <th>所属公司提成</th>
        <th>财务单据</th>
        <th>日期</th>
        <th>{{$t('system.table_operation')}}</th>
      </tr>
      <tr v-for="(item,index) in dataList" :key="index">
        <td>{{item.periods}}</td>
        <td v-if="userInfo.RB_Branch_id==0 || userInfo.RB_Branch_id==49 || userInfo.RB_Branch_id==userInfo.ParentCompanyId">{{item.sumPrice.toFixed(2)}}</td>
        <td>{{item.createByStr}}</td>
        <td>{{item.branchMoney.toFixed(2)}}</td>
        <td>
          <span class="TCommission-finance" v-for="(fno, i) in item.financialsArray" :key="i"
            @click="goUrl2(fno)">{{fno}}</span>
        </td>
        <td>{{item.createStr}}</td>
        <td>
          <el-tooltip class="item" effect="dark" content="查看" placement="top">
            <el-button type="primary" class="CM_look" @click="goUrl('CommissionDetail',item.id)"
              icon="iconfont icon-chakan" title="查看" circle></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="制单" placement="top">
            <el-button v-if="btnShow" type="primary" class="CM_look" @click="generalFinancacls(item)"
              icon="el-icon-plus" title="制单" circle></el-button>
          </el-tooltip>
        </td>
      </tr>
    </table>
    <!-- 分页 -->
    <el-pagination background @current-change="handleCurrentChange" :current-page.sync="currentPage"
      layout="total,prev, pager, next, jumper" :page-size="msg.PageSize" :total="total"></el-pagination>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        msg: {
          PageIndex: 1,
          PageSize: 20
        },
        loading: false,
        //数据源
        dataList: [],
        total: 0,
        currentPage: 1,
        userInfo: {},
        btnShow: false,
      };
    },
    mounted() {
      this.getList();
      this.userInfo = this.getLocalStorage();
      let userInfo = this.getLocalStorage();
      let ActionMenuCode = userInfo.ActionMenuCode;
      if (ActionMenuCode.indexOf('CommissionVoucher') != -1) {
        this.btnShow = true;
      }
    },
    methods: {
      handleCurrentChange(val) {
        this.msg.PageIndex = val;
        this.getList();
      },
      goUrl(path, id) {
        this.$router.push({
          path: path,
          query: {
            ParentId: id,
            blank: "y",
            tab: "报价详情"
          }
        });
      },
      //获取数据
      getList() {
        this.loading = true;
        this.apipost(
          "sellcommission_GetPageList",
          this.msg,
          res => {
            this.loading = false;
            if (res.data.resultCode == 1) {
              this.dataList = res.data.data.pageData;
              this.total = res.data.data.count;
              this.dataList.forEach(x => {
                if (x.financials && x.financials.length > 0) {
                  x.financialsArray = x.financials.split(",");
                }
              });
            } else {
              this.Error(res.data.message);
            }
          },
          null
        );
      },
      goUrl2(id) {
        this.$router.push({
          path: "/FinancialDocumentsDetail",
          query: {
            id,
            blank: "y",
            tab: id + "单据详情"
          }
        });
      },
      //生成提成报表
      generateTable() {
        let msg = {
          UserId: 0
        };
        this.apipost(
          "sellcommission_SetGenerateCommission",
          msg,
          res => {
            if (res.data.resultCode == 1) {
              this.getList();
              this.Success("报表生成成功");
            } else {
              this.Error(res.data.message);
            }
          },
          null
        );
      },
      generalFinancacls(item) {
        if (item.financialsArray && item.financialsArray.length > 0) {
          this.Error("请不要多次制单！")
          return;
        }
        let obj = {
          CostType: 16,
          Money: item.branchMoney,
          CurrencyId: 1,
          XSTC: 1,
        }
        let query = {
          blank: "y",
          tab: "新增付款单据",
          Type: 2,
          IsUploadPic: 1,
          orderObj: JSON.stringify(obj)
        }
        if (this.userInfo.RB_Branch_id == 0 || this.userInfo.RB_Branch_id ==this.userInfo.ParentCompanyId) {
          query.id = 28
          query.Name = "总部销售提成单"
        } else {
          query.id = 30
          query.Name = "分公司销售提成单"
        }
        this.$router.push({
          path: "/addFinancialDocuments",
          query
        });
      }
    }
  };
</script>