merchantTestDialog.vue 18.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
<!-- 财务分账测试 -->
<template>
  <d2-dialog title="分账测试" :is-visible="verificationCodeVisible" class="verificationCode" width="1200px"
             @closeDialog="handleClose" @confirmDialog="handleConfirm">
    <!-- <d2-container> -->
    <el-form ref="form" border :model="form" :rules="rules" label-width="120px">
      <div class="formItem">
        <el-form-item label="商品售价:" prop="totalPrice" required>
          <el-input v-model="form.totalPrice" @input="handleInput($event, 'totalPrice')" />
        </el-form-item>
        <el-form-item label="商品成本:" prop="goodsCost" required>
          <el-input v-model="form.goodsCost" @input="handleInput($event, 'goodsCost')" />
        </el-form-item>
        <el-form-item label="虚拟对账成本:" label-width="120px" prop="virtualAccountCost">
          <el-input v-model="form.virtualAccountCost" @input="handleInput($event, 'virtualAccountCost')" />
        </el-form-item>
        <el-form-item label="回收成本:" prop="recoveryCost">
          <el-input v-model="form.recoveryCost" @input="handleInput($event, 'recoveryCost')" />
        </el-form-item>
        <el-form-item label="嘀加成本:" prop="djCost">
          <el-input v-model="form.djCost" @input="handleInput($event, 'djCost')" />
        </el-form-item>
        <el-form-item label="第三方成本:" prop="thirdPartyCost">
          <el-input v-model="form.thirdPartyCost" @input="handleInput($event, 'thirdPartyCost')" />
        </el-form-item>
        <!-- prop="goodsCost"   @input="handleInput($event,'goodsCost')"-->
        <el-form-item label="手续费:" required>
          <el-input :value="categoryTableData.serviceCharge" disabled>
            <!-- <i slot="suffix"
               class="suffix">%</i> -->
          </el-input>
        </el-form-item>
        <el-button class="subBtn" @click="submitForm" type="primary">提交测试</el-button>
      </div>

    </el-form>
    <p class="edit-sub-title">
      分账结果
    </p>
    <div class="tableHeader"><span class="serviceCharge item">手续费计算(仅针对线上支付订单)</span><span
      class="diversionSide item">导流方分润<span
      v-if="rulesTestParams.goodsTypeGroupRule.shop4sDeductChargeFlag != 'Y'">不</span>扣除手续费;服务商分润<span
      v-if="rulesTestParams.goodsTypeGroupRule.partnerDeductChargeFlag != 'Y'">不</span>扣除手续费</span>
    </div>
    <el-table :header-cell-style="{ background: '#F2F4F7', 'text-align': 'center', 'color': '#333333' }"
              :cell-style="{ 'text-align': 'center', 'color': '#666666;' }" border :span-method="objectSpanMethod"
              :data="categoryTableData.expenseCategoryCalculatedLevelItemForRuleTestsResults">
      <el-table-column prop="targetType" label="类型" width="100">
        <template slot-scope="scope">
          {{ targetType[scope.row.targetType] }}
        </template>
      </el-table-column>
      <el-table-column prop="expenseCategoryName" label="分账类目" width="143" />
      <el-table-column prop="calculateMode" label="计算模式" width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.calculateMode == 1 ? '按品类计算' : scope.row.calculateMode == 2 ? '按整单计算' : '-' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="expenseCategoryCalculateType" label="分账规则">
        <template slot-scope="scope">
          <span> {{ severSelectOptionsLabel[scope.row.expenseCategoryCalculateType] }}</span>
          <span> {{ scope.row.expenseCategoryValue }}</span>
          <span v-if="scope.row.expenseCategoryCalculateType == 10">*1</span>
          <span v-if="scope.row.expenseCategoryValue">
            {{ scope.row.expenseCategoryCalculateType == 3 || scope.row.expenseCategoryCalculateType == 10 ? '' : '%' }}</span>
          <span v-else-if="scope.row.targetType == 4">收入-流量方分润-服务商分润-其他费用({{
            rulesTestParams.goodsTypeGroupRule.goodsCostFlag == 'Y' ? '' : '不' }}包含成本)</span>
          <!-- <span v-else-if="scope.row.targetType==4">收入-流量方分润-服务商分润-产品成本-安装成本</span> -->
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column prop="calculateMode" label="子类目" width="143">
        <template slot-scope="scope">
          <div v-if="scope.row.nodeType == 2">
            {{ scope.row.children.expenseCategoryName }}
          </div>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column prop="calculateMode" label="计算模式" width="143">
        <template slot-scope="scope">
          <div v-if="scope.row.nodeType == 2">
            <!-- <div class="detail-i more">
              <div v-for="(childrenITem, num) in scope.row.children" :key="num" class="childrenItem"> -->
            {{ scope.row.children.calculateMode == 1 ? '按品类计算' : scope.row.children.calculateMode == 2 ?
              '按整单计算' : '-' }}
            <!-- </div>
            </div> -->
          </div>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column prop="calculateMode" label="分账规则" width="">
        <template slot-scope="scope">
          <div v-if="scope.row.nodeType == 2">
            <!-- <div class="detail-i more">
              <div v-for="(childrenITem, num) in scope.row.children" :key="num" class="childrenItem"> -->
            <span> {{ severSelectOptionsLabel[scope.row.children.expenseCategoryCalculateType] }}</span>
            <span> {{ scope.row.children.expenseCategoryValue }}</span>
            <span v-if="scope.row.children.expenseCategoryCalculateType == 10">*1</span>
            <span v-if="scope.row.children.expenseCategoryValue">
              {{ scope.row.children.expenseCategoryCalculateType == 3 || scope.row.children.expenseCategoryCalculateType == 10 ? '' : '%' }}</span>
            <span v-else-if="scope.row.children.targetType == 4">收入-流量方分润-服务商分润-其他费用({{
              rulesTestParams.goodsTypeGroupRule.goodsCostFlag == 'Y' ? '' : '不' }}包含成本)</span>
            <span v-else>--</span>
          </div>
          <!-- </div>
          </div> -->
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column prop="expenseCategoryResult" label="分账金额" text-align="center" width="200" />
    </el-table>
    <p class="edit-sub-title">
      实际到账结果
    </p>

    <d2-table :table-data="resultTableData" :has-num="false" :has-page="false" :row-style="{ height: '40px' }"
              :header-cell-style="{ background: '#F2F4F7', 'text-align': 'center', 'color': '#333333' }"
              :cell-style="{ 'text-align': 'center', 'color': '#666666;' }" :table-params="tableParams" />
    <!-- </d2-container> -->

  </d2-dialog>
</template>

<script>
import { severSelectOptionsLabel, defaultSelectOptions } from '@/common/constant/merchant'
import { merchantSettleDistributeRuleTestRule } from '@api/merchant'
import { limitPrice } from '@/common/format'
const targetType = {
  1: '流量方',
  2: '服务商',
  3: '其他费用',
  4: '平台费用'
}
const targetMerchantType = {
  1: '平台方',
  2: '服务商',
  3: '4s店',
  4: '平台方'
}
export default {
  name: 'MerchantTestDialog',
  props: {
    visible: {
      // 弹窗是否展示
      type: Boolean,
      default: false
    },
    rulesTestParams: {
      // 测试参数
      type: Object,
      default: () => { }
    }
  },
  computed: {
    verificationCodeVisible: {
      // return this.
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', false)
      }
    }
    // serviceChargeValue() {
    //   return this.form.totalPrice ? (this.form.totalPrice * 0.006).toFixed(2) : 0
    // }
  },
  // data() {
  //   return {

  //   }
  // },
  data() {
    return {
      defaultSelectOptions,
      // merchantType,
      severSelectOptionsLabel,
      targetType: Object.freeze(targetType),
      targetMerchantType: Object.freeze(targetMerchantType),
      form: {
        // model: ''
        totalPrice: '',
        goodsCost: '',
        virtualAccountCost: '',
        recoveryCost: '',
        djCost: '',
        thirdPartyCost: ''
      },
      oldVal: {
        totalPrice: 0,
        goodsCost: 0
      },
      rules: {
        totalPrice: [{ required: true, message: '请输入商品价格', trigger: ['change', 'blur'] }],
        // virtualAccountCost: [{ required: true, message: '请输虚拟对账成本', trigger: ['change', 'blur'] }]
        // recoveryCost: [{ required: true, message: '请输回收成本', trigger: ['change', 'blur'] }],
        goodsCost: [{ required: true, message: '请输入商品成本', trigger: ['change', 'blur'] },
          {
            validator: (rule, value, callback) => {
              if (!this.form.totalPrice) return callback(new Error('请先输入商品价格'))
              if (value > Number(this.form.totalPrice)) return callback(new Error('成本不能大于商品价格'))
              return callback()
            },
            trigger: 'change'
          }
        ]
      },
      tableParams: {
        // btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        // listName: 'list',
        tableOption: false,
        tableColumns: [{
          label: '分账对象',
          // prop: 'orderCode',
          width: '200px',
          formatter: (cellValue) => {
            // realityMerchantName 实际分账对象
            return this.targetMerchantType[cellValue.targetMerchantType] + ':' + cellValue.realityMerchantName
          }
        }, {
          label: '分账类目',
          prop: 'expenseCategorys',
          formatter: (cellValue) => {
            let label = ''
            if (cellValue.expenseCategorys) {
              label = cellValue.expenseCategorys.reduce((prv, item, index) => {
                if (item.expenseCategoryName) {
                  const name = index ? `-${item.expenseCategoryName}` : item.expenseCategoryName
                  console.log(name)
                  prv = prv + name
                }
                return prv
              }, '')
            }

            // this.expenseCategoryCalculatedItemForRuleTestsResults
            // const label = cellValue.expenseCategorys && cellValue.expenseCategorys.reduce((prv, item, index) => {
            //   const name = index ? `-${item.expenseCategoryName}` : item.expenseCategoryName
            //   prv = prv.concat(name)
            // }, '')

            return label
          }
        }, {
          label: '实际到账金额',
          prop: 'divisionMoney',
          width: '120px',
          formatter: (cellValue) => {
            return "¥" + cellValue.divisionMoney
          }
        }]
      },
      resultTableData: [],
      categoryTableData: {}
    }
  },
  mounted() {
    // debugger
    // console.log(this.form)
    // console.log(this.form, 'this.form')
  },
  methods: {
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex == 0) {
        // console.log(this.getSpanArr(this.categoryTableData.expenseCategoryCalculatedItemForRuleTestsResults))
        // 处理要合并的行数
        const _row = this.getSpanArr(this.categoryTableData.expenseCategoryCalculatedLevelItemForRuleTestsResults).one[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
      if (columnIndex == 1) {
        // console.log(this.getSpanArr(this.categoryTableData.expenseCategoryCalculatedItemForRuleTestsResults))
        // 处理要合并的行数
        const _row = this.getSpanArrChildren(this.categoryTableData.expenseCategoryCalculatedLevelItemForRuleTestsResults).one[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
      if (columnIndex == 2) {
        // console.log(this.getSpanArr(this.categoryTableData.expenseCategoryCalculatedItemForRuleTestsResults))
        // 处理要合并的行数
        const _row = this.getSpanArrChildren(this.categoryTableData.expenseCategoryCalculatedLevelItemForRuleTestsResults).one[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
      if (columnIndex == 3) {
        // console.log(this.getSpanArr(this.categoryTableData.expenseCategoryCalculatedItemForRuleTestsResults))
        // 处理要合并的行数
        const _row = this.getSpanArrChildren(this.categoryTableData.expenseCategoryCalculatedLevelItemForRuleTestsResults).one[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
      // 要合并的子类目行数
      // if ([4,5,7].includes(columnIndex)) {
      //   // return {
      //   //       rowspan: 2,
      //   //       colspan: 1
      //   //     };
      // }
    },
    getSpanArr(arr) {
      // debugger
      if (arr) {
        const spanOneArr = []
        let concatOne = 0
        arr.forEach((item, index) => {
          if (index === 0) {
            spanOneArr.push(1)
          } else {
            if (item.targetType === arr[index - 1].targetType) {
              // 第一列需合并相同内容的判断条件
              spanOneArr[concatOne] += 1
              spanOneArr.push(0)
            } else {
              spanOneArr.push(1)
              concatOne = index
            }
          }
        })
        return { one: spanOneArr }
      }
    },
    getSpanArrChildren(arr) {
      // debugger
      if (arr) {
        const spanOneArr = []
        let concatOne = 0
        arr.forEach((item, index) => {
          if (index === 0) {
            spanOneArr.push(1)
          } else {
            if (item.expenseCategoryId === arr[index - 1].expenseCategoryId) {
              // 第一列需合并相同内容的判断条件
              spanOneArr[concatOne] += 1
              spanOneArr.push(0)
            } else {
              spanOneArr.push(1)
              concatOne = index
            }
          }
        })
        return { one: spanOneArr }
      }
    },

    handleInput(newVal, name) {
      console.log(newVal)
      newVal = newVal.replace(/[^\d.]/g, '') // 清除“数字”和“.”以外的字符
      // console.log(limitPrice(newVal, this.form[name], 8, 2))
      this.form[name] = limitPrice(newVal, this.oldVal[name], 6, 2)
      this.oldVal[name] = this.form[name]
    },
    submitForm() {
      this.$refs.form.validate((valid) => {
        console.log(valid)
        if (valid) {
          // this.rulesTest()
          this.getTestResult()
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    getTestResult() {
      const params = {
        ...this.form,
        ...this.rulesTestParams
      }
      if (!params?.goodsTypeGroupRule?.goodsTypeGroupRelations) delete params.goodsTypeGroupRule.goodsTypeGroupRelations
      merchantSettleDistributeRuleTestRule(params).then((result) => {
        console.log('result', result)
        result.expenseCategoryCalculatedLevelItemForRuleTestsResults = result.expenseCategoryCalculatedLevelItemForRuleTestsResults.sort((a, b) => {
          return a.targetType - b.targetType
        })
        result.expenseCategoryCalculatedLevelItemForRuleTestsResults.push({
          // expenseCategoryId: 4
          targetType: 4,
          nodeType: 1,
          // expenseCategoryName,
          calculateMode: result.glProfitMoneyCalculateMode,
          expenseCategoryName: '平台费',
          expenseCategoryResult: result.glProfitMoney
        })
        console.log(result.expenseCategoryCalculatedLevelItemForRuleTestsResults)

        result.expenseCategoryCalculatedLevelItemForRuleTestsResults.forEach((item) => {
          item.expenseCategoryResult = '¥' + parseFloat(item.expenseCategoryResult).toFixed(2)
        })
        const list = []
        result.expenseCategoryCalculatedLevelItemForRuleTestsResults.forEach((item) => {
          if (item.nodeType == 1) {
            list.push(item)
          }
          if (item.nodeType == 2) {
            item.children.forEach((ele) => {
              list.push({
                // ...ele,
                ...item,
                children: ele,
                // expenseCategoryId: item.expenseCategoryId,
                expenseCategoryResult: '¥' + parseFloat(ele.expenseCategoryResult).toFixed(2)
              })
            })
          }
          // list.push(item.expenseCategoryName)
        })
        result.expenseCategoryCalculatedLevelItemForRuleTestsResults = list
        //  ¥ { { scope.row ? parseFloat(scope.row.expenseCategoryResult).toFixed(2) : '' } }
        // result.expenseCategoryCalculatedLevelItemForRuleTestsResults
        this.categoryTableData = result
        this.resultTableData = result.merchantDistributions
      })
    },
    rulesTest() {
      merchantSettleDistributeRuleTestRule(params).then((result) => {
        console.log()
      })
    },
    handleClose() {
      // this.$emit('dialogClose')
      // this.$update
      this.verificationCodeVisible = false
    },

    handleConfirm() {
      this.handleClose()
    }
  }
}
</script>

<style scoped lang="scss">
.tableHeader {
  display: flex;
  background: #f2f4f7;
  font-family: PingFangSC-Medium;
  font-weight: 600;
  font-size: 14px;
  color: #333333;
  border: 1px solid #e8e8ea;
  border-bottom: none;
  margin-bottom: -4px;

  .item {
    flex: 1;
    padding: 10px 0;
    text-align: center;
  }

  .item+.item {
    border-left: 1px solid #e8e8ea;
  }
}

.formItem {
  display: flex;
  flex-wrap: wrap;
}

.subBtn {
  margin-left: 20px;
  height: 36px;
}

.childrenItem {
  min-height: 40px;
  width: 100%;
  text-align: center;
  line-height: 40px;
  border-bottom: 1px solid #e8e8ea;
}
</style>