<style scoped>
    ::v-deep .margin-small .ant-row {
        margin-bottom: 0;
    }

    ::v-deep .ant-steps-dot .ant-steps-item-content {
        width: auto;
    }

    ::v-deep
    .ant-steps-dot
    .ant-steps-item-active
    .ant-steps-item-icon
    > .ant-steps-icon
    .ant-steps-icon-dot {
        background: rgb(11, 190, 135);
        width: 15px;
        height: 15px;
        /* margin-top: 5px; */
        margin-left: 2px;
    }

    ::v-deep .endStatus .ant-steps-item-icon > .ant-steps-icon .ant-steps-icon-dot {
        background: #1890ff !important;
        width: 15px;
        height: 15px;
        /* margin-top: 5px; */
        /* margin-left: 2px; */
    }

    ::v-deep .ant-steps-dot .ant-steps-item-icon {
        width: 15px;
        height: 15px;
        margin-top: 5px;
        margin-left: -4px;
    }
</style>
<template>
    <div class="policy-management-content">
        <div class="control-con-title">
            <div>
                <span class="policy-export-btn">垫款池子</span>
            </div>
            <div>
                <!-- <span class="add-acount-policy-btn">
                  <a-button>快递信息</a-button>
                </span> -->
                <span class="add-acount-policy-btn">
         <!-- <a-button @click="handleAdd" type="primary">新增</a-button>-->
        </span>
                <span class="add-acount-policy-btn">
          <a-button @click="handleAddPleace" type="primary">充值申请</a-button>
        </span>
            </div>
        </div>
        <div class="control-con-header">
            <a-form class="grid-form" layout="inline" :form="searchForm" hide-required-mark>
                <a-row class="grid-form-options">
                    <a-form-item class="grid-form-item" label="客户名称：" :colon="false">
                        <!-- <a-input v-model="configForm.companyName" placeholder="请输入公司名称" allow-clear/> -->
                        <a-input
                            v-model="configForm.advertiserName"
                            placeholder="请输入客户名称"
                            allow-clear
                        />
                    </a-form-item>
                    <a-form-item class="grid-form-item" label="产品名称：" :colon="false">
                        <a-input
                            v-model="configForm.productName"
                            placeholder="请输入产品名称"
                            allow-clear
                        />
                    </a-form-item>
                    <a-form-item class="grid-form-item" label="媒体：" :colon="false">
                        <a-select
                            v-model="configForm.paymentMedia"
                            style="width: 200px; margin-left: 10px"
                            :filterOption="filterOption"
                            showSearch
                            allowClear
                            placeholder="请选择媒体"
                        >
                            <a-select-option value="1"> 头条</a-select-option>
                            <a-select-option value="2"> 快手</a-select-option>
                            <a-select-option value="9"> 广点通</a-select-option>
                            <a-select-option value="7"> 磁力金牛</a-select-option>
                            <a-select-option value="11"> 头条&快手</a-select-option>
                        </a-select>
                    </a-form-item>

                    <a-form-item class="grid-form-item" label="返点类型：" :colon="false">
                        <a-select
                            v-model="configForm.rebateType"
                            style="width: 200px; margin-left: 10px"
                            :filterOption="filterOption"
                            showSearch
                            allowClear
                            placeholder="请选择返点类别"
                        >
                            <a-select-option value="1"> 返货</a-select-option>
                            <a-select-option value="2"> 返现</a-select-option>
                        </a-select>
                    </a-form-item>
                    <a-form-item class="grid-form-item" label="申请时间：" :colon="false">
                        <a-range-picker
                            v-model="configForm.time"
                            format="YYYY-MM-DD"
                            style="width: 100%"
                        />
                    </a-form-item>
                    <a-form-item class="form-handle-btn">
                        <a-button type="default" class="reset-class" @click="handleResetList"
                        >重置
                        </a-button
                        >
                        <a-button type="primary" @click="handleQueryList">搜索</a-button>
                    </a-form-item>
                </a-row>
            </a-form>
        </div>
        <div class="control-con-table">
            <a-table
                ref="table"
                size="middle"
                bordered
                :columns="columns"
                :dataSource="dataSource"
                :pagination="false"
                :loading="controlLoading"
                :scroll="{ x: 1000 }"
            >
        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">申请充值</a>
          <a-divider type="vertical"/>
            <!-- record.status == '1' ||  -->
          <a @click="handleToLog(record)">申请列表</a>
        </span>
            </a-table>
            <a-pagination
                class="pagin-table-class"
                :total="totalAll"
                :show-total="(total) => `共 ${totalAll} 条`"
                size="small"
                show-size-changer
                show-quick-jumper
                v-model="tablePag.page"
                @change="handleOnShowSizeChange"
                @showSizeChange="handleOnShowSizeChange"
            />
        </div>
        <!-- 新增、编辑政策 -->
        <a-modal
            v-if="policyOperationStatus"
            :title="addType === 'add' ? '垫款/到账申请' : '编辑垫款/到账申请'"
            :visible="policyOperationStatus"
            :confirmLoading="confirmLoading"
            @ok="handlePolicyOperationSure"
            @cancel="handlePolicyOperationCancel"
            :width="650"
        >
            <div>
                <a-form-model
                    ref="policyOperationForm"
                    :model="policyOperationForm"
                    :rules="policyOperationRules"
                    :label-col="labelCol"
                    :wrapper-col="wrapperCol"
                >
                    <a-form-model-item label="媒体" prop="paymentMedia">
                        <a-select
                            v-model="policyOperationForm.paymentMedia"
                            placeholder="请选择投放媒体"
                            allow-clear
                        >
                            <a-select-option :value="1">头条</a-select-option>
                            <a-select-option :value="2">快手</a-select-option>
                            <a-select-option :value="7">磁力金牛</a-select-option>
                            <a-select-option :value="9">广点通</a-select-option>
                            <a-select-option :value="11">头条&快手</a-select-option>
                        </a-select>
                    </a-form-model-item>
                    <a-form-model-item label="客户名称" prop="advertiserId">
                        <a-select
                            labelInValue
                            v-model="policyOperationForm.advertiserId"
                            placeholder="请选择客户名称"
                            showSearch
                            optionFilterProp="children"
                            :filterOption="filterOption"
                            allow-clear
                            @change="getProductList"
                        >
                            <a-select-option
                                :value="item.advertiserIds"
                                v-for="(item, index) of list"
                                :key="index"
                            >
                                {{ item.advertiserName }}
                            </a-select-option>
                        </a-select>
                    </a-form-model-item>
                    <a-form-model-item label="选择产品" prop="productId">
                        <a-select
                            labelInValue
                            v-model="policyOperationForm.productId"
                            placeholder="请选择产品"
                            showSearch
                            optionFilterProp="children"
                            :filterOption="filterOption"
                            allow-clear
                            @change="getInfo"
                        >
                            <a-select-option
                                :value="item.productId"
                                v-for="(item, index) of productList"
                                :key="index"
                            >
                                {{ item.productName }}
                            </a-select-option>
                        </a-select>
                        <p v-if="showRebate" style="margin-bottom: 0">
                            返点类型：{{
                            policyOperationForm.rebateType == 1 ? "返货" : "返现"
                            }}
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 返点比例：{{
                            policyOperationForm.rebateRate
                            }}%
                        </p>
                    </a-form-model-item>

                    <div v-if="writeRebate">
                        <a-form-model-item label="返点类型" prop="rebateType">
                            <a-select
                                v-model="policyOperationForm.rebateType"
                                placeholder="请选择类型"
                                allow-clear
                            >
                                <a-select-option :value="1">返货</a-select-option>
                                <a-select-option :value="2">返现</a-select-option>
                            </a-select>
                        </a-form-model-item>
                        <a-form-model-item label="返点比例" prop="rebateRate">
                            <a-input-number
                                v-model="policyOperationForm.rebateRate"
                                :step="0.01"
                                :precision="2"
                            />
                            %
                        </a-form-model-item>
                    </div>

                    <a-form-model-item label="类型" prop="paymentType">
                        <a-select
                            v-model="policyOperationForm.paymentType"
                            placeholder="请选择类型"
                            allow-clear
                            style="width: 80%"
                            :disabled="showRebate && policyOperationForm.paymentType == 2"
                        >
                            <a-select-option :value="1">预付款</a-select-option>
                            <a-select-option :value="2">垫款</a-select-option>
                        </a-select>
                    </a-form-model-item>
                    <a-form-model-item
                        label="帐显金额"
                        prop="displayAmount"
                    >
                        <a-input-number
                            v-model="policyOperationForm.displayAmount"
                            :step="0.01"
                            :precision="2"
                            :min="0"
                            @change="editMoney($event, 1)"
                        />
                    </a-form-model-item>
                    <a-form-model-item label="现金金额" prop="cashAmount">
                        <a-input-number
                            v-model="policyOperationForm.cashAmount"
                            :step="0.01"
                            :precision="2"
                            :min="0"
                            @change="editMoney($event, 2)"
                        />
                    </a-form-model-item>
                    <a-form-model-item label="端口" prop="paymentPort">
                        <a-select
                            v-model="policyOperationForm.paymentPort"
                            placeholder="请选择端口"
                            allow-clear
                        >
                            <a-select-option :value="1">汇创</a-select-option>
                            <a-select-option :value="2">骄阳</a-select-option>
                            <a-select-option :value="5">汇创&骄阳</a-select-option>
                            <a-select-option :value="3">江西五六七</a-select-option>
                            <a-select-option :value="4">北京五六七</a-select-option>
                        </a-select>
                    </a-form-model-item>
                    <a-form-model-item label="备注" prop="remarks">
                        <a-textarea
                            v-model="policyOperationForm.remarks"
                            placeholder="请输入备注"
                            allow-clear
                            @change="handleRemarksChange"
                        />
                    </a-form-model-item>
                    <a-form-model-item
                        label="图片上传"
                        prop="files"
                        :rules="{
              required: writeRebate,
              message: '请上传图片',
              trigger: 'change',
            }"
                    >
                        <uploadFile
                            :value.sync="policyOperationForm.files"
                            :multiple="true"
                            @overUpload="overUpload"
                            :fileCount="10"
                            :size="10240"
                            uploadType="image"
                        />
                    </a-form-model-item>
                </a-form-model>
            </div>
        </a-modal>

        <!-- 查看详情 -->
        <a-modal
            v-if="auditPolicyStatus"
            title="充值申请"
            :visible="auditPolicyStatus"
            :footer="null"
            v-dialog-drag
            :width="650"
            @cancel="
        auditPolicyStatus = false;
        queryByIdList = { accountList: [] };
      "
        >
            <a-form-model
                ref="queryByIdList"
                :model="queryByIdList"
                :rules="policyOperationRules"
                :label-col="labelCol"
                :wrapper-col="wrapperCol"
            >
                <a-form-model-item label="客户名称" prop="advertiserId">
                    <a-select
                        v-model="queryByIdList.advertiserId"
                        placeholder="请选择客户名称"
                        showSearch
                        optionFilterProp="children"
                        :filterOption="filterOption"
                        allow-clear
                        @change="getNewProductList"
                    >
                        <a-select-option
                            :value="item.id"
                            v-for="(item, index) of advertiserList"
                            :key="index"
                        >
                            {{ item.name }}
                        </a-select-option>
                    </a-select>
                </a-form-model-item>
                <a-form-model-item label="产品名称" prop="productId">
                    <a-select
                        v-model="queryByIdList.productId"
                        placeholder="请选择产品名称"
                        showSearch
                        optionFilterProp="children"
                        :filterOption="filterOption"
                        allow-clear
                        @change="getMediaList"
                    >
                        <a-select-option
                            :value="item.id"
                            v-for="(item, index) of productNewList"
                            :key="index"
                        >
                            {{ item.name }}
                        </a-select-option>
                    </a-select>
                </a-form-model-item>
                <a-form-model-item label="媒体" prop="paymentMedia">
                    <a-select
                        v-model="queryByIdList.paymentMedia"
                        placeholder="请选择媒体"
                        showSearch
                        optionFilterProp="children"
                        :filterOption="filterOption"
                        allow-clear
                        @change="getProjectList"
                    >
                        <a-select-option
                            :value="item.name"
                            v-for="(item, index) of mediaList"
                            :key="index"
                        >
                            {{ item.name | paymentMediaName }}
                        </a-select-option>
                    </a-select>

                </a-form-model-item>


                <a-form-model-item label="选择端口" prop="paymentPort">
                    <a-select
                        v-model="queryByIdList.paymentPort"
                        placeholder="请选择端口"
                        showSearch
                        optionFilterProp="children"
                        :filterOption="filterOption"
                        allow-clear
                        @change="getMoney"
                    >
                        <a-select-option
                            :value="item.paymentPort"
                            v-for="(item, index) of paymentPortList"
                            :key="index"
                        >
                            {{ item.portName }}
                        </a-select-option>
                    </a-select>
                    <p v-if="rebateData" style="margin-bottom: 0">
                        返点类型：{{
                        rebateData.rebateType == 1 ? "返货" : "返现"
                        }}
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 返点比例：{{
                        rebateData.rebateRate
                        }}%
                    </p>
                </a-form-model-item>


                <a-form-model-item label="可用金额" prop="totalAmount">
                    {{ totalAmount ? allMoney(totalAmount) : "-" }}
                </a-form-model-item>

                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="是否后补" prop="amends">
                    <a-radio-group v-model="amends">
                        <a-radio-button value="2">否</a-radio-button>
                        <a-radio-button value="1">是</a-radio-button>

                    </a-radio-group>
                </a-form-item>


                <a-form-model-item label="备注" prop="remarks">
                    <a-textarea
                        v-model="queryByIdList.remarks"
                        placeholder="请输入备注"
                        allow-clear
                        @change="handleRemarksChange"
                    />
                </a-form-model-item>

                <a-form-model-item label="类型" prop="rechargeType">
                    <a-select
                        v-model="queryByIdList.rechargeType"
                        placeholder="请选择类型"
                        allow-clear
                    >
                        <a-select-option :value="1">自运营充值</a-select-option>
                        <a-select-option :value="2">客运营充值</a-select-option>
                    </a-select>
                </a-form-model-item>
                <a-form-model-item label="项目" prop="projectId">
                    <a-select
                        v-model="queryByIdList.projectId"
                        placeholder="请选择项目"
                        showSearch
                        optionFilterProp="children"
                        :filterOption="filterOption"
                        allow-clear
                        @change="getAccountList"
                    >
                        <a-select-option
                            :value="item.id"
                            v-for="(item, index) of projectList"
                            :key="index"
                        >
                            {{ item.name }} ({{ item.media }})
                        </a-select-option>
                    </a-select>
                    <a @click="addAccount">添加账户</a>
                </a-form-model-item>
                <div
                    v-for="(item, index) in queryByIdList.accountList"
                    style="position: relative"
                >
                    <a-form-model-item
                        label="选择账户"
                        :prop="'accountList.' + index + '.accountId'"
                        :rules="[{ required: true, message: '请选择账户', trigger: 'change' }]"
                        v-if="queryByIdList.rechargeType == 1"
                    >
                        <a-select
                            v-model="item.accountId"
                            placeholder="请选择账户"
                            showSearch
                            optionFilterProp="children"
                            :filterOption="filterOption"
                            allow-clear
                            @change="getAccountInfo($event, item)"
                        >
                            <a-select-option
                                :value="item.id"
                                v-for="(item, index) of accountList"
                                :key="index"
                            >
                                {{ item.id }}({{ item.name }})
                            </a-select-option>
                        </a-select>
                        <p v-if="!!item.accountMoney">账户余额：{{ allMoney(item.accountMoney) }}</p>
                    </a-form-model-item>
                    <a-form-model-item
                        label="账户"
                        :prop="'accountList.' + index + '.accountId'"
                        :rules="[{ required: true, message: '请填写账户', trigger: 'blur' }]"
                        v-else-if="queryByIdList.rechargeType == 2"
                    >
                        <a-input placeholder="请输入账户" v-model.number="item.accountId"></a-input>
                    </a-form-model-item>
                    <a-form-model-item
                        label="到账金额"
                        prop="receivedAmount"
                        :prop="'accountList.' + index + '.receivedAmount'"
                        :rules="[{ required: true, message: '请输入到账金额', trigger: 'blur' }]"
                    >
                        <a-input-number
                            v-model="item.receivedAmount"
                            :step="0.01"
                            :precision="2"
                            :min="0"
                            @change="editMoneyNew($event, 1, index)"
                        />
                    </a-form-model-item>
                    <a-form-model-item
                        label="现金金额"
                        prop="cashAmount"
                        :prop="'accountList.' + index + '.cashAmount'"
                        :rules="[{ required: true, message: '请输入现金金额', trigger: 'blur' }]"
                    >
                        <a-input-number
                            v-model="item.cashAmount"
                            :step="0.01"
                            :precision="2"
                            :min="0"
                            @change="editMoneyNew($event, 2, index)"
                        />
                    </a-form-model-item>
                    <a
                        v-if="index > 0"
                        style="position: absolute; right: 0; top: 0; z-index: 10"
                        @click="removeAccount(index)"
                    >删除</a
                    >
                </div>
            </a-form-model>
            <div solt="footer" style="display: flex; justify-content: end">
                <div>
                    <a-button
                        type="primary"
                        class="cancel-btn"
                        :loading="confirmLoading"
                        @click="handleAuditSure"
                        style="margin: 0 10px"
                    >确定
                    </a-button
                    >
                </div>
                <div>
                    <a-button type="default" class="cancel-btn" @click="handleAuditCancel"
                    >取消
                    </a-button
                    >
                </div>
            </div>
        </a-modal>
        <!-- 操作记录 -->
        <a-modal
            v-if="logVisible"
            title="操作记录"
            :visible="logVisible"
            @cancel="logVisible = false"
            :footer="null"
            v-dialog-drag
        >
            <div style="height: 400px; overflow: auto; padding: 15px">
                <a-steps
                    progress-dot
                    direction="vertical"
                    v-model="logActive"
                    style="width: 100%"
                    disbaled
                >
                    <a-step
                        :title="`${item.roleName}(${item.userName})${
              item.auditStatus == '0'
                ? '创建申请'
                : item.auditStatus == -1
                ? '退回修改'
                : item.auditStatus == '3'
                ? '审核通过'
                : item.auditStatus == '4'
                ? '临时通过'
                : item.auditStatus == '5'
                ? '审核拒绝'
                : item.auditStatus == '1'
                ? '待审核'
                : '-'
            }`"
                        :description="`${item.time}`"
                        v-for="(item, index) in logList"
                        :key="index"
                        disabled
                        :class="{ endStatus: item.auditStatus == 3 }"
                    />
                </a-steps>
            </div>
        </a-modal>
    </div>
</template>
<script>
    import moment from "moment";
    import Vue from "vue";
    import {ACCESS_TOKEN} from "@/store/mutation-types";
    import {getAction, postAction, downFile} from "@/api/manage";
    import {mapGetters} from "vuex";
    import {urlAcount} from "./policy-management-server.js";
    import uploadFile from "@/components/uploadFile.vue";

    const fileSuffix = ["xlsx", "xls"];
    import JTreeSelect from "@/components/jeecg/JTreeSelect";

    function allMoney(num, n) {
        n = n || 2;
        let symbol = ",";
        if (num === null) return num;
        if (typeof num !== "number") throw new TypeError("num参数应该是一个number类型");
        if (n < 0) throw new Error("参数n不应该小于0");
        let hasDot = parseInt(num) != num; //这里检测num是否为小数，true表示小数
        let m = n != undefined && n != null ? n : 1;
        num =
            m == 0 ? num.toFixed(m) + "." : hasDot ? (n ? num.toFixed(n) : num) : num.toFixed(m);
        symbol = symbol || ",";
        num = num.toString().replace(/(\d)(?=(\d{3})+\.)/g, function (match, p1, p2) {
            return p1 + symbol;
        });
        if (n == 0 || (!hasDot && !n)) {
            //如果n为0或者传入的num是整数并且没有指定整数的保留位数，则去掉前面操作中的小数位
            num = num.substring(0, num.indexOf("."));
        }
        return num;
    }

    export default {
        name: "policy-management",
        data() {
            let handleCharacterLen30 = (rule, value, callback) => {
                this.handleExportRules(value, 1, 30, callback);
            };
            let handleCharacterLen100 = (rule, value, callback) => {
                this.handleDescRules(value, 5, 100, callback);
            };
            return {
                amends: "2",
                list: [],
                productList: [],
                advertiserList: [],
                productNewList: [],
                projectList: [],
                mediaList: [],
                paymentPortList: [],
                accountList: [],
                totalAmount: undefined,
                rebateData: undefined,
                paymentTypeDisable: true,
                writeRebate: false,
                showRebate: false,
                oldData: undefined,
                mode2: ["month", "month"],
                confirmLoading: false,
                controlLoading: false,
                logVisible: false,
                logStatus: 0,
                logActive: 2,
                logList: [],
                allSaleListOption: [],
                dataDimensionList: [],
                creativeMediaOptions: [
                    {
                        id: "",
                        name: "不限",
                    },
                    {
                        id: 1,
                        name: "头条",
                    },
                    {
                        id: 2,
                        name: "快手",
                    },

                    {
                        id: 7,
                        name: "磁力金牛",
                    },
                    {
                        id: 9,
                        name: "广点通",
                    }, {
                        id: 11,
                        name: "头条&快手",
                    },
                ],

                searchStatusOptions: [
                    {
                        id: 1,
                        name: "待审核",
                    },
                    {
                        id: 3,
                        name: "审核通过",
                    },
                    {
                        id: 4,
                        name: "临时通过",
                    },
                    {
                        id: 5,
                        name: "审核拒绝",
                    },
                ],
                subTitleMsgStatus: false,
                remarksStatus: false,
                changeRules: [
                    {required: true, message: "请输入产品名称", trigger: "blur"},
                    {validator: handleCharacterLen30, trigger: "blur"},
                ],
                addType: "add",
                labelCol: {span: 4},
                wrapperCol: {span: 16},
                rejectAuditStatus: false,
                rejectionReasonStatus: false,
                auditPolicyStatus: false,
                policyOperationStatus: false,
                voidOperationStatus: false,
                totalAll: 0,
                policyOperationForm: {},
                voidId: undefined,
                reasonForm: {
                    desc: "",
                },
                //   queryByIdListRules:{

                //   },
                policyOperationRules: {
                    advertiserId: [{required: true, message: "请选择客户", trigger: "change"}],
                    productId: [{required: true, message: "请选择产品", trigger: "change"}],
                    paymentMedia: [{required: true, message: "请选择投放媒体", trigger: "change"}],
                    paymentType: [{required: true, message: "请选择类型", trigger: "change"}],
                    rebateType: [{required: true, message: "请选择返点类型", trigger: "change"}],
                    rebateRate: [{required: true, message: "请填写返点比例", trigger: "blur"}],
                    displayAmount: [{required: true, message: "请填写垫款金额", trigger: "blur"}],
                    cashAmount: [{required: true, message: "请填写现金金额", trigger: "blur"}],
                    paymentPort: [{required: true, message: "请选择端口", trigger: "change"}],
                    rechargeType: [{required: true, message: "请选择类型", trigger: "change"}],
                    // projectId: [{required: true, message: "请选择项目", trigger: "change"}],
                },
                queryByIdList: {
                    accountList: [],
                },
                dataSource: [],
                okType: 3,
                columns: [
                    {
                        title: "客户名称",
                        align: "center",
                        dataIndex: "advertiserName",
                        width: 250,
                    },
                    {
                        title: "产品名称",
                        align: "center",
                        dataIndex: "productName",
                        width: 200,
                    },
                    {
                        title: "预付款/垫款",
                        align: "center",
                        dataIndex: "paymentType",
                        width: 100,
                        customRender(t) {
                            if (t == "1") {
                                return "预付款";
                            } else if (t == "2") {
                                return "垫款";
                            }
                        },
                        //   scopedSlots: { customRender: "media" },
                    },
                    {
                        title: "媒体",
                        align: "center",
                        dataIndex: "paymentMedia",
                        width: 100,
                        customRender(t) {
                            if (t == "1") {
                                return "头条";
                            } else if (t == "2") {
                                return "快手";
                            } else if (t == "7") {
                                return "磁力金牛";
                            } else if (t == "9") {
                                return "广点通";
                            } else if (t == "11") {
                                return "头条&快手";
                            }
                        },
                    },
                    {
                        title: "端口",
                        align: "center",
                        dataIndex: "paymentPort",
                        ellipsis: true,
                        width: 100,
                        customRender(t) {
                            if (t == "1") {
                                return "汇创";
                            } else if (t == "2") {
                                return "骄阳";
                            } else if (t == "3") {
                                return "江西五六七";
                            } else if (t == "4") {
                                return "北京五六七";
                            }else if (t == "5") {
                                return "汇创&骄阳";
                            }
                        },
                    },
                    {
                        title: "现金金额",
                        dataIndex: "cashAmount",
                        align: "center",
                        width: 100,
                        customRender(t) {
                            if (t) {
                                return allMoney(t);
                            } else {
                                return "-";
                            }
                        },
                    },
                    {
                        title: "账显金额",
                        dataIndex: "displayAmount",
                        align: "center",
                        width: 100,
                        customRender(t) {
                            if (!!t) {
                                return allMoney(t);
                            } else {
                                return "-";
                            }
                        },
                    },
                    {
                        title: "返点类型",
                        dataIndex: "rebateType",
                        align: "center",
                        width: 100,
                        customRender(t) {
                            if (t == "1") {
                                return "返货";
                            } else if (t == "2") {
                                return "返现";
                            }
                        },
                    },
                    {
                        title: "返点",
                        dataIndex: "rebateRate",
                        align: "center",
                        width: 100,
                    },
                    {
                        title: "备注",
                        align: "center",
                        dataIndex: "remarks",
                        customRender(t) {
                            if (!!t) {
                                return t;
                            } else {
                                return "-";
                            }
                        },
                        width: 250,
                    },
                    {
                        title: "操作",
                        dataIndex: "action",
                        align: "center",
                        width: 250,
                        fixed: "right",
                        scopedSlots: {customRender: "action"},
                    },
                ],
                configForm: {
                    advertiserName: undefined,
                    productName: undefined,
                    paymentMedia: undefined,
                    time: [],
                    rebateType: undefined,
                },
                tablePag: {
                    page: 1,
                    size: 10,
                },
                addAreaList: [],
                saleShowOption: [],
                addSubjectList: [],
                rejectionReasonList: {},
                tableOnlyId: "",
                saleVisible: false,
                saleInfoList: [],
                salePersonList: [],
                saleLoading: false,
                toLeaderVisible: false,
                exportLoading: false,
                lookImageVisible: false,
                lookImageData: null,
                searchForm: this.$form.createForm(this),
                loadDisabled: false,
            };
        },
        components: {
            JTreeSelect,
            uploadFile,
        },
        created() {
        },
        mounted() {
            this.handleInitTable();
            // this.handleGetAllSaleList();
            // this.handleAddGetArea();
        },
        methods: {
            lookImageClick(item) {
                this.lookImageVisible = true;
                this.lookImageData = item;
            },
            getList() {
                var params = {};
                this.getAction("/financePayment/application/getAdvertisers", params)
                    .then((res) => {
                        if (res.success) {
                            console.log(res);
                            this.list = res.result;
                        } else {
                            this.$message.warning(res.message);
                        }
                    })
                    .finally(() => {
                    });
            },
            getProductList(ids) {
                this.$set(this.policyOperationForm, "productId", undefined);
                this.$set(this.policyOperationForm, "rebateType", undefined);
                this.$set(this.policyOperationForm, "rebateRate", undefined);
                this.$set(this.policyOperationForm, "paymentType", undefined);
                if (!!ids) {
                    var params = {};
                    params.ids = ids.key;
                    this.getAction("/financePayment/application/getProductByAdvertiserIds", params)
                        .then((res) => {
                            if (res.success) {
                                this.productList = res.result;
                            } else {
                                this.$message.warning(res.message);
                            }
                        })
                        .finally(() => {
                        });
                } else {
                    this.productList = [];
                }
            },
            getInfo(type) {
                if (!!type) {
                    var params = {};
                    params.type = this.policyOperationForm.paymentMedia;
                    params.advertiserName = this.policyOperationForm.advertiserId.label
                        .replace(/[\r\n]/g, "")
                        .replace(/(^\s*)|(\s*$)/g, "");
                    params.productName = type.label
                        .replace(/[\r\n]/g, "")
                        .replace(/(^\s*)|(\s*$)/g, "");
                    // advertiserName = 广州小迈网络科技有限公司 & productName = 吉祥来电秀 & type = 2;
                    this.getAction("/financePayment/application/queryCwjsPolicyInfo", params)
                        .then((res) => {
                            if (res.success) {
                                //   this.productList = res.result;
                                if (!!res.result) {
                                    var nowDate = new Date().getTime();
                                    var checkDate = new Date(res.result.policyEndDate).getTime();
                                    if (nowDate > checkDate) {
                                        this.writeRebate = true;
                                        this.showRebate = false;
                                        this.$set(this.policyOperationForm, "rebateType", undefined);
                                        this.$set(this.policyOperationForm, "rebateRate", undefined);
                                        this.$set(this.policyOperationForm, "paymentType", undefined);
                                        this.$set(this.policyOperationForm, "displayAmount", undefined);
                                        this.$set(this.policyOperationForm, "cashAmount", undefined);
                                    } else {
                                        this.writeRebate = false;
                                        this.showRebate = true;
                                        this.oldData = res.result.advancePay == 1 ? 1 : 2;
                                        this.$set(
                                            this.policyOperationForm,
                                            "rebateType",
                                            res.result.rebateType
                                        );
                                        this.$set(
                                            this.policyOperationForm,
                                            "rebateRate",
                                            res.result.rebateRate
                                        );
                                        this.$set(
                                            this.policyOperationForm,
                                            "paymentType",
                                            res.result.advancePay == 1 ? 1 : 2
                                        );
                                        this.$set(this.policyOperationForm, "displayAmount", undefined);
                                        this.$set(this.policyOperationForm, "cashAmount", undefined);
                                    }
                                } else {
                                    this.writeRebate = true;
                                    this.showRebate = false;
                                    this.$set(this.policyOperationForm, "rebateType", undefined);
                                    this.$set(this.policyOperationForm, "rebateRate", undefined);
                                    this.$set(this.policyOperationForm, "paymentType", undefined);
                                    this.$set(this.policyOperationForm, "displayAmount", undefined);
                                    this.$set(this.policyOperationForm, "cashAmount", undefined);
                                }
                            } else {
                                this.$message.warning(res.message);
                            }
                        })
                        .finally(() => {
                        });
                } else {
                    this.showRebate = false;
                    this.$set(this.policyOperationForm, "rebateType", undefined);
                    this.$set(this.policyOperationForm, "rebateRate", undefined);
                    this.$set(this.policyOperationForm, "paymentType", undefined);
                    this.$set(this.policyOperationForm, "displayAmount", undefined);
                    this.$set(this.policyOperationForm, "cashAmount", undefined);
                }
            },
            changEditStatus() {
                if (this.policyOperationForm.paymentType == 2) {
                    this.paymentTypeDisable = true;
                } else {
                }
            },
            editMoney(value, type) {
                if (
                    type == 1 &&
                    (!!this.policyOperationForm.rebateRate ||
                        this.policyOperationForm.rebateRate == 0)
                ) {
                    this.$set(
                        this.policyOperationForm,
                        "cashAmount",
                        this.policyOperationForm.rebateType == 1
                            ? (value / (1 + this.policyOperationForm.rebateRate / 100)).toFixed(2)
                            : (value * (1 - this.policyOperationForm.rebateRate / 100)).toFixed(2)
                    );
                } else if (
                    type == 2 &&
                    (!!this.policyOperationForm.rebateRate ||
                        this.policyOperationForm.rebateRate == 0)
                ) {
                    this.$set(
                        this.policyOperationForm,
                        "displayAmount",
                        this.policyOperationForm.rebateType == 1
                            ? (value * (1 + this.policyOperationForm.rebateRate / 100)).toFixed(2)
                            : (value / (1 - this.policyOperationForm.rebateRate / 100)).toFixed(2)
                    );
                } else {
                    this.$message.error("暂未填写返点比例");
                }
            },
            ...mapGetters(["userInfo"]),
            moment,
            handleAdd() {
                this.policyOperationStatus = true;
                this.getList();
            },
            getNewAdvertiserList() {
                var params = {
                    table: "finance_payment_pool,advertiser_id,advertiser_name",
                    groupBy: "advertiser_id",
                };
                this.postDataAction("/financePayment/pool/querySheetIdAndNameList", params)
                    .then((res) => {
                        if (res.success) {
                            this.advertiserList = res.result;
                        } else {
                            this.$message.warning(res.message);
                        }
                    })
                    .finally(() => {
                    });
            },


            getNewProductList(value) {
                this.$set(this.queryByIdList, "productId", undefined);
                this.$set(this.queryByIdList, "paymentMedia", undefined);
                this.$set(this.queryByIdList, "projectId", undefined);
                this.$set(this.queryByIdList, "paymentPort", undefined);
                this.queryByIdList.accountList = [];
                this.rebateData = undefined;
                this.totalAmount = undefined;
                if (!!value) {
                    var params = {
                        table: "finance_payment_pool,product_id,product_name",
                        groupBy: "product_id",
                        paramters: [
                            {
                                paramter: "advertiser_id",
                                value: value,
                            },
                        ],
                    };
                    this.postDataAction("/financePayment/pool/querySheetIdAndNameList", params)
                        .then((res) => {
                            if (res.success) {
                                this.productNewList = res.result;
                            } else {
                                this.$message.warning(res.message);
                            }
                        })
                        .finally(() => {
                        });
                }
            },
            getMediaList(value) {
                this.$set(this.queryByIdList, "paymentMedia", undefined);
                this.$set(this.queryByIdList, "projectId", undefined);
                this.$set(this.queryByIdList, "paymentPort", undefined);
                this.queryByIdList.accountList = [];
                this.rebateData = undefined;
                this.totalAmount = undefined;
                var params = {
                    table: "finance_payment_pool,product_id,payment_media",
                    groupBy: "payment_media",
                    paramters: [
                        {
                            paramter: "advertiser_id",
                            value: this.queryByIdList.advertiserId,
                        },
                        {
                            paramter: "product_id",
                            value: value,
                        },
                    ],
                };
                this.postDataAction("/financePayment/pool/querySheetIdAndNameList", params)
                    .then((res) => {
                        if (res.success) {
                            this.mediaList = res.result;
                        } else {
                            this.$message.warning(res.message);
                        }
                    })
                    .finally(() => {
                    });
            },

            getProjectList(value) {
                this.$set(this.queryByIdList, "projectId", undefined);
                this.$set(this.queryByIdList, "paymentPort", undefined);
                this.queryByIdList.accountList = [];
                this.rebateData = undefined;
                this.totalAmount = undefined;
                if (!!value) {
                    var params = {
                        advertiserId: this.queryByIdList.advertiserId,
                        type: this.queryByIdList.paymentMedia,
                        productId: this.queryByIdList.productId,
                        paymentPort: this.queryByIdList.paymentPort,
                        paymentMedia: this.queryByIdList.paymentMedia,
                    };
                    this.getPaymentPortList(params);
                    this.getAccountList();
                    this.getAction("/financePayment/pool/queryPoolProjectList", params)
                        .then((res) => {
                            if (res.success) {
                                this.projectList = res.result;
                            } else {
                                this.$message.warning(res.message);
                            }
                        })
                        .finally(() => {
                        });
                } else {
                }
            },
            getPaymentPortList(params) {
                this.getAction("/financePayment/pool/queryPaymentPort", params)
                    .then((res) => {
                        if (res.success) {
                            this.paymentPortList = res.result;
                        } else {
                            this.$message.warning(res.message);
                        }
                    })
                    .finally(() => {
                    });
            },

            getMoney() {
                var params = {
                    advertiserId: this.queryByIdList.advertiserId,
                    type: this.queryByIdList.paymentMedia,
                    productId: this.queryByIdList.productId,
                    paymentPort: this.queryByIdList.paymentPort,
                };
                this.getAction("/financePayment/pool/queryPool", params)
                    .then((res) => {
                        if (res.success) {
                            this.totalAmount = res.result ? res.result.cashAmount : 0;
                            this.rebateData = res.result;
                        } else {
                            this.$message.warning(res.message);
                        }
                    })
                    .finally(() => {
                    });
            },
            getAccountList() {
                this.queryByIdList.accountList = [];
                var params = {
                    advertiserId: this.queryByIdList.advertiserId,
                    type: this.queryByIdList.paymentMedia,
                    projectId: this.queryByIdList.projectId,
                };
                this.getAction("/financePayment/pool/queryPoolAccountList", params)
                    .then((res) => {
                        if (res.success) {
                            this.accountList = res.result;
                        } else {
                            this.$message.warning(res.message);
                        }
                    })
                    .finally(() => {
                    });
            },
            removeAccount(index) {
                this.queryByIdList.accountList.splice(index, 1);
            },
            addAccount() {
                this.queryByIdList.accountList.push({
                    accountId: undefined,
                    cashAmount: undefined,
                    receivedAmount: undefined,
                    rebateType: undefined,
                    rebateRate: undefined,
                    accountMoney: undefined,
                });
            },
            getAccountInfo(value, item) {
                if (!!value) {
                    var params = {
                        media: this.queryByIdList.paymentMedia,
                        accountId: value,
                    };
                    this.getAction("/financePayment/pool/queryAccountBalance", params)
                        .then((res) => {
                            if (res.success) {
                                item.accountMoney = res.result;
                            } else {
                                this.$message.warning(res.message);
                            }
                        })
                        .finally(() => {
                        });
                } else {
                }
            },
            handleAddPleace() {
                this.rebateData = undefined;
                this.totalAmount = undefined;
                this.auditPolicyStatus = true;
                this.getNewAdvertiserList();
            },

            handleFilterOption(input, option) {
                return (
                    option.componentOptions.children[0].text
                        .toLowerCase()
                        .indexOf(input.toLowerCase()) >= 0
                );
            },
            filterOption(input, option) {
                return (
                    option.componentOptions.children[0].text
                        .toLowerCase()
                        .indexOf(input.toLowerCase()) >= 0
                );
            },
            handleAddTimesChange(date, dateString) {
                this.policyOperationForm.addTimes = dateString;
            },
            showAreaInfo(data) {
                if (data) {
                    var dataShow = this.saleShowOption.filter((item) => {
                        return item.saleId == data;
                    });
                    this.policyOperationForm.areaInfo = dataShow[0].nickName;
                } else {
                    this.policyOperationForm.areaInfo = undefined;
                }
            },
            handleAddGetArea(data) {
                const paramsData = {
                    userId: this.userInfo().id,
                };
                getAction(urlAcount + "/finance/cwjsPolicyInfo/queryAeraByUserId", paramsData)
                    .then((result) => {
                        if (result.code === 0) {
                            const defaultList = result.result[0].UserCompany;
                            this.saleShowOption = defaultList.map((item) => {
                                return {
                                    saleId: item.userId,
                                    saleName: item.userName,
                                };
                            });
                            this.addAreaList = defaultList[0].nickName.split(",");
                            this.addSubjectList = result.result[0].companySubjects;
                            getAction(
                                urlAcount + "/finance/cwjsSaleAssistantInfo/getCwSaleAndAssistantList",
                                paramsData
                            )
                                .then((result) => {
                                    if (result.code === 0) {
                                        for (let i = 0; i < result.result.length; i++) {
                                            if (this.saleShowOption[0].saleId == result.result[i].saleId) {
                                            } else {
                                                this.saleShowOption.push(result.result[i]);
                                            }
                                        }
                                    } else {
                                        this.$message.error(result.message);
                                    }
                                })
                                .catch((error) => {
                                    console.log(error, "eeee");
                                });
                        } else {
                            this.$message.error(result.message);
                        }
                    })
                    .catch((error) => {
                        console.log(error, "eeee");
                    });
            },
            handleExamineAll(data) {
                // const paramsData = {
                //   id: data.id,
                //   type: data.type,
                //   userId: this.userInfo().id,
                //   approvalContent: data.value,
                // };
                this.postDataAction("/financePayment/application/updateStatus", data)
                    .then((result) => {
                        if (result.code === 200) {
                            this.rejectAuditStatus = false;
                            this.auditPolicyStatus = false;
                            this.handleInitTable();
                            this.$message.success(result.message);
                        } else {
                            this.$message.error(result.message);
                        }
                    })
                    .catch((error) => {
                        console.log(error, "eeee");
                    });
            },
            // 获取所有的媒体 枚举值
            handleGetAllSaleList() {
                const paramsData = {
                    userId: this.userInfo().id,
                };
                getAction(
                    urlAcount + "/finance/cwjsSaleAssistantInfo/getSaleListByUserDepart",
                    paramsData
                )
                    .then((result) => {
                        if (result.success) {
                            this.allSaleListOption = result.result || [];
                        } else {
                            this.$message.error(result.message);
                        }
                    })
                    .catch((error) => {
                        console.log(error, "eeee");
                    });
            },
            showLog(item) {
                this.logVisible = true;
                getAction("/financePayment/application/queryAuditProcess", {id: item.id})
                    .then((result) => {
                        if (result.code === 200) {
                            this.logList = result.result;
                            this.logActive = this.logList.length - 1;
                        } else {
                            this.$message.error(result.message);
                        }
                    })
                    .catch((error) => {
                        console.log(error, "eeee");
                    })
                    .finally(() => {
                    });
            },
            // 获取默认的列表数据
            handleInitTable() {
                this.controlLoading = true;
                const paramsData = {
                    userId: this.userInfo().id,
                    advertiserName: this.configForm.advertiserName,
                    productName: this.configForm.productName,
                    paymentMedia: this.configForm.paymentMedia,
                    rebateType: this.configForm.rebateType,
                    startDate:
                        this.configForm.time && this.configForm.time.length == 2
                            ? moment(this.configForm.time[0]).format("YYYY-MM-DD")
                            : null,
                    endDate:
                        this.configForm.time && this.configForm.time.length == 2
                            ? moment(this.configForm.time[1]).format("YYYY-MM-DD")
                            : null,
                    pageNo: this.tablePag.page,
                    pageSize: this.tablePag.size,
                };
                getAction("/financePayment/pool/list", paramsData)
                    .then((result) => {
                        if (result.success == true) {
                            let defaultList = result.result.records;
                            this.dataSource = defaultList;
                            this.totalAll = result.result.total;
                        } else {
                            this.dataSource = [];
                            this.tablePag.page = 1;
                            this.totalAll = 0;
                            this.$message.error(result.message);
                        }
                    })
                    .catch((error) => {
                        console.log(error, "eeee");
                    })
                    .finally(() => {
                        this.controlLoading = false;
                    });
            },
            overUpload(urlAll) {
                console.log(urlAll);
            },
            handleRemarksChange(e) {
                const targetVal = e.target.value;
                let cnReg = /([\u4e00-\u9fa5]|[\u3000-\u303F]|[\uFF00-\uFF60])/;
                let length = 0;
                let strArr = targetVal.split("");
                strArr.forEach((item) => {
                    if (cnReg.test(item)) {
                        length += 2;
                    } else {
                        length += 1;
                    }
                });
                if (1 <= length && length <= 500) {
                    this.remarksStatus = false;
                } else {
                    this.remarksStatus = true;
                }
            },
            handleGroupAbbreviationChange(e) {
                const targetVal = e.target.value;
                let cnReg = /([\u4e00-\u9fa5]|[\u3000-\u303F]|[\uFF00-\uFF60])/;
                let length = 0;
                let strArr = targetVal.split("");
                strArr.forEach((item) => {
                    if (cnReg.test(item)) {
                        length += 2;
                    } else {
                        length += 1;
                    }
                });
                if (1 <= length && length <= 60) {
                    this.subTitleMsgStatus = false;
                } else {
                    this.subTitleMsgStatus = true;
                }
            },
            disabledDate(current) {
                return current > moment().subtract(1, "day");
            },
            handleAddOrigin() {
                const randomNum = new Date().getTime() + Math.ceil(Math.random() * 1000);
                this.policyOperationForm.defaultFormList.push({
                    id: randomNum,
                    value: "",
                });
            },
            handleDelOrigin(list) {
                if (this.policyOperationForm.defaultFormList.length === 1) {
                    return;
                }
                let formData = this.policyOperationForm.defaultFormList;
                this.policyOperationForm.defaultFormList = formData.filter(
                    (item) => list.id !== item.id
                );
            },
            handleIsDianPayChange(e) {
                if (e.target.value === 0) {
                    this.policyOperationForm.dianPayCompanyName = "";
                    this.policyOperationForm.dianPayCompanyRebateRate = 0;
                }
            },
            handlePrepaidNotChange(e) {
                if (e.target.value === 1) {
                    this.policyOperationForm.accountingPeriod = "";
                    this.policyOperationForm.dianPayCompanyName = "";
                    this.policyOperationForm.dianPayCompanyRebateRate = 0;
                    this.policyOperationForm.isDianPay = undefined;
                } else if (e.target.value === 0) {
                    this.policyOperationForm.isDianPay = 0;
                }
            },
            handleExportRules(value, min, max, callback) {
                let cnReg = /([\u4e00-\u9fa5]|[\u3000-\u303F]|[\uFF00-\uFF60])/;
                let length = 0;
                let strArr = value.split("");
                strArr.forEach((item) => {
                    if (cnReg.test(item)) {
                        length += 2;
                    } else {
                        length += 1;
                    }
                });
                if (min * 2 <= length && length <= max * 2) {
                    callback();
                } else {
                    callback(`只能输入${min}-${max}个汉字`);
                }
            },
            handleDescRules(value, min, max, callback) {
                let cnReg = /([\u4e00-\u9fa5]|[\u3000-\u303F]|[\uFF00-\uFF60])/;
                let length = 0;
                let strArr = value.split("");
                strArr.forEach((item) => {
                    if (cnReg.test(item)) {
                        length += 2;
                    } else {
                        length += 1;
                    }
                });
                if (min <= length && length <= max) {
                    callback();
                } else {
                    callback(`只能输入${min}-${max}个字符`);
                }
            },
            // 分页操作按钮
            handleOnShowSizeChange(current, pageSize) {
                this.tablePag = {
                    page: current,
                    size: pageSize,
                };
                this.handleInitTable();
            },
            //作废操作
            handleVoid(list) {
                this.voidOperationStatus = true;
                this.voidId = list.id;
            },
            // 编辑按钮操作
            handleEditTable(list) {
                this.addType = "edit";
                this.policyOperationStatus = true;
                this.queryByIdList = list;
                this.policyOperationForm = {
                    ...list,
                    advertiserId: {key: list.advertiserId, label: list.advertiserName},
                    productId: {key: list.productId, label: list.productName},
                    files: list.files == "-" ? undefined : JSON.parse(list.files),
                };
                this.getList();
                this.getProductList({key: list.advertiserId, label: list.advertiserName});
                this.getInfo({key: list.productId, label: list.productName});

                setTimeout(() => {
                    this.$set(this.policyOperationForm, "advertiserId", {
                        key: list.advertiserId,
                        label: list.advertiserName,
                    });
                    this.$set(this.policyOperationForm, "productId", {
                        key: list.productId,
                        label: list.productName,
                    });
                    this.$set(this.policyOperationForm, "paymentMedia", +list.paymentMedia);
                    this.$set(this.policyOperationForm, "paymentPort", +list.paymentPort);
                    this.$set(this.policyOperationForm, "cashAmount", list.cashAmount);
                    this.$set(this.policyOperationForm, "displayAmount", list.displayAmount);
                    this.$set(this.policyOperationForm, "rebateType", +list.rebateType);
                    this.$set(this.policyOperationForm, "rebateRate", list.rebateRate);
                    this.$set(
                        this.policyOperationForm,
                        "files",
                        list.files == "-" ? undefined : JSON.parse(list.files)
                    );
                    this.$set(this.policyOperationForm, "remarks", list.remarks);
                    this.$set(this.policyOperationForm, "paymentType", +list.paymentType);
                }, 500);
                // this.policyOperationForm = Object.assign({}, list);
            },
            // 新增政策按钮
            handleAddAccountPolicy() {
                this.$router.replace({
                    path: "/policy-management/reimbursementAdd?type=add",
                });
            },
            // 新增政策确定按钮
            handlePolicyOperationSure() {
                this.$refs.policyOperationForm.validate((valid) => {
                    if (valid) {
                        const paramsData = {
                            ...this.policyOperationForm,
                            applicanterId: this.userInfo().id,
                            userId: this.userInfo().id,
                            productId: this.policyOperationForm.productId.key,
                            advertiserId: this.policyOperationForm.advertiserId.key,
                            displayAmount: this.policyOperationForm.displayAmount,
                            /* displayAmount:
                                 this.policyOperationForm.paymentType == 2
                                     ? this.policyOperationForm.displayAmount
                                     : 0,*/
                            temporaryAdvances: !!this.oldData
                                ? this.oldData == 1 && this.policyOperationForm.paymentType == 2
                                    ? 1
                                    : 0
                                : 0,
                        };
                        this.confirmLoading = true;
                        if (this.addType === "add") {
                            this.handleAddSureBtn(paramsData, "/financePayment/application/add");
                        } else {
                            this.handleAddSureBtn({...paramsData}, "/financePayment/application/edit");
                        }
                    } else {
                        return false;
                    }
                });
            },
            handleAddSureBtn(data, url) {
                postAction(url, data)
                    .then((result) => {
                        if (result.code === 200) {
                            this.$message.success(result.message);
                            this.oldData = undefined
                            this.handlePolicyOperationCancel();
                            this.handleAuditCancel();
                            this.handleInitTable();
                        } else {
                            this.$message.error(result.message);
                        }
                    })
                    .catch((error) => {
                        console.log(error, "eeee");
                    })
                    .finally(() => {
                        this.confirmLoading = false;
                    });
            },
            // 新增政策取消按钮
            handlePolicyOperationCancel() {
                this.policyOperationForm = {};
                this.policyOperationStatus = false;
                this.confirmLoading = false;
                this.writeRebate = false;
                this.showRebate = false;
            },
            // 审核拒绝确定按钮
            handleRejectSure() {
                this.$refs.rejectRuleForm.validate((valid) => {
                    console.log(valid);
                    if (valid) {
                        const params = {
                            id: this.tableOnlyId || this.queryByIdList.id,
                            type: this.okType,
                            value: this.reasonForm.desc,
                        };
                        this.handleExamineAll(params);
                        this.handleRejectCancel();
                    } else {
                        return false;
                    }
                });
            },
            //领导审核理由
            handleVoidOk() {
                this.$refs.rejectRuleForm.validate((valid) => {
                    if (valid) {
                        const params = {
                            policyId: this.voidId,
                            delReason: this.reasonForm.desc,
                        };

                        getAction(urlAcount + "/finance/cwjsPolicyInfo/toVoidpolicy", params)
                            .then((result) => {
                                if (result.code === 0) {
                                    this.voidOperationStatus = false;
                                    this.reasonForm.desc = undefined;
                                    this.handleInitTable();
                                } else {
                                    this.$message.error(result.message);
                                }
                            })
                            .catch((error) => {
                                console.log(error, "eeee");
                            })
                            .finally(() => {
                                this.voidOperationStatus = false;
                            });
                    } else {
                        return false;
                    }
                });
            },
            //领导审核理由
            handleLeader() {
                this.$refs.rejectRuleForm.validate((valid) => {
                    if (valid) {
                        const params = {
                            id: this.tableOnlyId || this.queryByIdList.id,
                            type: 4,
                            value: this.reasonForm.desc,
                        };
                        this.handleExamineAll(params);
                        this.handleRejectCancel();
                    } else {
                        return false;
                    }
                });
            },
            // 审核拒绝取消按钮
            handleRejectCancel() {
                this.okType = 3;
                this.reasonForm.desc = "";
                this.rejectAuditStatus = false;
                this.toLeaderVisible = false;
            },
            handleToLog(item) {
                localStorage.setItem('applicationLog', item.advertiserName)
                this.$router.replace('/policy-management/appRecharge')
            },
            // 查看的按钮
            handleDetail(list, type) {
                console.log(list)
                this.auditPolicyStatus = true;
                this.queryByIdList = {...list, newFiles: undefined, type: type, accountList: []};


                this.getNewAdvertiserList();
                this.$set(this.queryByIdList, "advertiserId", list.advertiserId);
                this.getNewProductList(this.queryByIdList.advertiserId);
                this.$set(this.queryByIdList, "productId", list.productId);
                this.getMediaList(this.queryByIdList.productId);
                this.$set(this.queryByIdList, "paymentMedia", list.paymentMedia);
                this.getProjectList(this.queryByIdList.paymentMedia);
                this.$set(this.queryByIdList, "paymentPort", undefined);
               // this.rebateData = {rebateType: list.rebateType, rebateRate: list.rebateRate};
                this.rebateData = undefined;
                this.totalAmount = undefined;
            },
            // 查看的取消按钮
            handleCloseAuditPolicy() {
                this.auditPolicyStatus = false;
            },
            editMoneyNew(value, type, index) {
                if (
                    type == 1 &&
                    !!this.rebateData &&
                    (!!this.rebateData.rebateRate || this.rebateData.rebateRate == 0)
                ) {
                    this.$set(
                        this.queryByIdList.accountList[index],
                        "cashAmount",
                        this.rebateData.rebateType == 1
                            ? Math.floor((value / (1 + this.rebateData.rebateRate / 100))*100)/100
                            : Math.floor((value * (1 - this.rebateData.rebateRate / 100))*100)/100
                    );
                } else if (
                    type == 2 &&
                    !!this.rebateData &&
                    (!!this.rebateData.rebateRate || this.rebateData.rebateRate == 0)
                ) {
                    this.$set(
                        this.queryByIdList.accountList[index],
                        "receivedAmount",
                        this.rebateData.rebateType == 1
                            ? Math.floor((value * (1 + this.rebateData.rebateRate / 100))*100)/100
                            : Math.floor((value / (1 - this.rebateData.rebateRate / 100))*100)/100
                    );
                } else {
                    this.$message.error("暂未返点比例");
                }
            },
            // 查看-审核政策-审核通过-按钮
            handleAuditSure(list) {
                this.$refs.queryByIdList.validate((valid) => {
                    if (valid) {
                        var that = this;
                        var total = this.queryByIdList.accountList
                            .map((item) => {
                                return item.cashAmount;
                            })
                            .reduce((o, n) => {
                                return +o + +n;
                            }, 0);
                        var amendsStr = this.amends;
                        const paramsData = {
                            ...this.queryByIdList,
                            applicanterId: this.userInfo().id,
                            userId: this.userInfo().id,
                            totalAmount: total,
                            amends: amendsStr,
                            paymentPort: this.rebateData.paymentPort,
                            financialReview: total > +that.totalAmount ? 1 : 0,
                            list: this.queryByIdList.accountList.map((item) => {
                                return {
                                    ...item,
                                    rebateType: this.rebateData ? this.rebateData.rebateType : null,
                                    rebateRate: this.rebateData ? this.rebateData.rebateRate : null,
                                };
                            }),
                        };
                        this.confirmLoading = true;
                        if (this.addType === "add") {
                            this.handleAddSureBtn(paramsData, "/financePayment/rechargeApplication/add");
                        } else {
                            this.handleAddSureBtn(
                                {...paramsData},
                                "/financePayment/rechargeApplication/edit"
                            );
                        }
                    } else {
                        return false;
                    }
                });
            },
            okFour(data) {
                this.postDataAction("/financePayment/application/updateTemporaryFiles", data).then(
                    (result) => {
                        if (result.code === 200) {
                            this.rejectAuditStatus = false;
                            this.auditPolicyStatus = false;
                            this.handleInitTable();
                            this.$message.success(result.message);
                        } else {
                            this.$message.error(result.message);
                        }
                    }
                );
            },
            // 查看-审核政策-审核拒绝-按钮
            handleAuditCancel(data) {
                this.queryByIdList = {accountList: []};
                this.rebateData = undefined;
                this.totalAmount = undefined;
                this.auditPolicyStatus = false;
            },
            handleSubmitEdit(list) {
            },
            // 被拒理由的操作
            handleRejectionReason(val) {
                this.rejectionReasonList = val;
                this.rejectionReasonStatus = true;
            },
            // 被拒理由确定按钮
            handleModeSure() {
                this.rejectionReasonStatus = false;
            },
            // 被拒理由取消按钮
            handleModeCancel() {
                this.rejectionReasonStatus = false;
            },
            // 搜索按钮
            handleQueryList() {
                this.tablePag = {
                    page: 1,
                    size: 10,
                };
                this.handleInitTable();
            },

            // 重置搜索
            handleResetList() {
                this.configForm = {
                    companyId: undefined,
                    userName: undefined,
                    media: undefined,
                    departId: undefined,
                    time: [],
                    status: undefined,
                    type: undefined,
                };
                this.tablePag = {
                    page: 1,
                    size: 10,
                };
                this.handleInitTable();
            },
        },
    };
</script>
<style lang="less" scoped>
    @import "policy-management";
</style>
