<template>
  <el-dialog :visible.sync="visible" v-bind="modalOptions">
    <div>
      <el-descriptions title="" :column="2" border>
        <el-descriptions-item label="手机号码：">
          {{ withdrawalInfo.phone }}
        </el-descriptions-item>
        <el-descriptions-item label="银行名称：">
          {{ withdrawalInfo.bankName }}
        </el-descriptions-item>
        <el-descriptions-item label="银行卡号：">
          {{ withdrawalInfo.bankCard }}
        </el-descriptions-item>
        <el-descriptions-item label="收款人姓名：">
          {{ withdrawalInfo.name }}
        </el-descriptions-item>
        <el-descriptions-item label="提现金额：">
          {{ withdrawalInfo.withdrawalMoney }}
        </el-descriptions-item>
        <el-descriptions-item label="实际到账：">
          {{ withdrawalInfo.actualReceipt }}
        </el-descriptions-item>
        <el-descriptions-item label="申请时间：">
          {{ withdrawalInfo.applyTime }}
        </el-descriptions-item>
        <el-descriptions-item label="处理时间：">
          {{ withdrawalInfo.handleTime }}
        </el-descriptions-item>
        <el-descriptions-item label="拒绝打款理由：">
          {{ withdrawalInfo.rejectReason || '--' }}
        </el-descriptions-item>

        <!-- <el-descriptions-item label="账户可提现金额：">
          {{ watherInfo.price }}
        </el-descriptions-item>
        <el-descriptions-item label="账户总金额：">
          {{ watherInfo.totalPrice }}
        </el-descriptions-item> -->
        <el-descriptions-item label="提现中：">
          {{ watherInfo.pendingWithdrawal }}
        </el-descriptions-item>
        <el-descriptions-item label="已提现：">
          {{ watherInfo.alreadyPrice }}
        </el-descriptions-item>
      </el-descriptions>
    </div>

    <el-tabs value="entryRecord">
      <el-tab-pane label="入账记录列表" name="entryRecord">
        <div v-if="entryRecordList && entryRecordList.length" style="margin-top: 32px;">
          <el-table
            v-loading="!entryRecordList.length" height="60vh" element-loading-text="暂无入账记录数据" :data="entryRecordList"
            v-bind="{ stripe: true, size: 'small', border: true, fit: true, highlightCurrentRow: true }"
          >
            <el-table-column align="center" min-width="80" prop="id" label="ID" show-overflow-tooltip></el-table-column>
            <el-table-column align="center" min-width="80" prop="buyerUserId" label="入账用户Id" show-overflow-tooltip></el-table-column>
            <el-table-column prop="transactionId" label="第三方流水号" />
            <el-table-column align="center" label="来源类型" prop="sourceType">
              <template slot-scope="{ row }">
                <el-tag v-if="row.sourceType === 1" effect="plain" type="info">平台</el-tag>
                <el-tag v-else-if="row.sourceType === 2" effect="plain" type="success">商圈</el-tag>
                <el-tag v-else-if="row.sourceType === 3" effect="plain" type="success">用户</el-tag>
                <el-tag v-else-if="row.sourceType === 4" effect="plain" type="success">社区</el-tag>
                <el-tag v-else-if="row.sourceType === 5" effect="plain" type="success">商城</el-tag>
                <span v-else>--</span>
              </template>
            </el-table-column>
            <el-table-column align="center" min-width="80" prop="sourceId" label="来源Id" show-overflow-tooltip></el-table-column>
            <el-table-column align="center" width="150" prop="orderFormid" label="来源订单编号" show-overflow-tooltip />
            <el-table-column align="center" width="150" prop="commissionNumber" label="入账数量" show-overflow-tooltip />
            <el-table-column align="center" label="活动配置类型" prop="waterType">
              <template slot-scope="{ row }">
                <el-tag v-if="row.waterType === -1" effect="plain" type="info">退款退回</el-tag>
                <el-tag v-else-if="row.waterType === 1" effect="plain" type="info">升级活动</el-tag>
                <el-tag v-else-if="row.waterType === 2" effect="plain" type="success">分佣活动</el-tag>
                <el-tag v-else-if="row.waterType === 3" effect="plain" type="success">社区活动</el-tag>
                <el-tag v-else-if="row.waterType === 4" effect="plain" type="success">赠券活动</el-tag>
                <el-tag v-else-if="row.waterType === 5" effect="plain" type="success">赠金活动</el-tag>
                <el-tag v-else-if="row.waterType === 6" effect="plain" type="success">商圈订单</el-tag>
                <el-tag v-else-if="row.waterType === 7" effect="plain" type="success">爆品家具</el-tag>
                <el-tag v-else-if="row.waterType === 8" effect="plain" type="success">社区订单</el-tag>
                <el-tag v-else-if="row.waterType === 9" effect="plain" type="success">用户代金券转赠</el-tag>
                <el-tag v-else-if="row.waterType === 10" effect="plain" type="success">商家代金券转赠</el-tag>
                <el-tag v-else-if="row.waterType === 11" effect="plain" type="success">同城联盟卡</el-tag>
                <span v-else>--</span>
              </template>
            </el-table-column>
            <el-table-column align="center" width="150" prop="effectiveTime" label="有效时间" show-overflow-tooltip />
            <el-table-column align="center" width="150" prop="isProportion" label="佣金比例" show-overflow-tooltip />
            <el-table-column align="center" width="150" prop="commissionTotal" label="佣金总额" show-overflow-tooltip />
            <el-table-column align="center" label="受益用户类型" prop="buyerUserType">
              <template slot-scope="{ row }">
                <el-tag v-if="row.buyerUserType === 100" effect="plain" type="info">代理商</el-tag>
                <el-tag v-else-if="row.buyerUserType === 200" effect="plain" type="success">加盟商</el-tag>
                <el-tag v-else-if="row.buyerUserType === 300" effect="plain" type="success">小区店</el-tag>
                <el-tag v-else-if="row.buyerUserType === 400" effect="plain" type="success">团长</el-tag>
                <el-tag v-else-if="row.buyerUserType === 500" effect="plain" type="success">合伙人</el-tag>
                <span v-else>--</span>
              </template>
            </el-table-column>
            <el-table-column align="center" min-width="80" prop="withdrawalId" label="提现Id" show-overflow-tooltip></el-table-column>
            <el-table-column align="center" width="150" prop="createTime" label="创建时间" show-overflow-tooltip />
          </el-table>
        </div>
        <div v-else style="font-size: 16px;font-weight: bold;">无入账记录数据</div>
      </el-tab-pane>
      <el-tab-pane label="出账记录列表" name="outgoingRecord">
        <div v-if="outgoingRecordList && outgoingRecordList.length" style="margin-top: 32px;">
          <el-table
            v-loading="!outgoingRecordList.length" height="60vh" element-loading-text="暂无出账记录数据" :data="outgoingRecordList"
            v-bind="{ stripe: true, size: 'small', border: true, fit: true, highlightCurrentRow: true }"
          >
            <el-table-column align="center" min-width="80" prop="id" label="ID" show-overflow-tooltip></el-table-column>
            <el-table-column align="center" min-width="80" prop="buyerUserId" label="出账用户Id" show-overflow-tooltip></el-table-column>
            <el-table-column align="center" width="150" prop="orderFormid" label="购买订单编号" show-overflow-tooltip />
            <el-table-column align="center" width="150" prop="commissionNumber" label="出账数量" show-overflow-tooltip />
            <el-table-column align="center" label="出账类型" prop="waterType">
              <template slot-scope="{ row }">
                <el-tag v-if="row.waterType === 1" effect="plain" type="info">商城购买</el-tag>
                <el-tag v-else-if="row.waterType === 2" effect="plain" type="success">商圈购买</el-tag>
                <el-tag v-else-if="row.waterType === 3" effect="plain" type="success">社区购买</el-tag>
                <el-tag v-else-if="row.waterType === 4" effect="plain" type="success">提现</el-tag>
                <el-tag v-else-if="row.waterType === 5" effect="plain" type="success">退款扣除</el-tag>
                <el-tag v-else-if="row.waterType === 6" effect="plain" type="success">代金券购买</el-tag>
                <span v-else>--</span>
              </template>
            </el-table-column>
            <el-table-column align="center" min-width="80" prop="destinationId" label="去向Id" show-overflow-tooltip></el-table-column>
            <el-table-column align="center" width="150" prop="createTime" label="创建时间" show-overflow-tooltip />
          </el-table>
        </div>
        <div v-else style="font-size: 16px;font-weight: bold;">无出账记录数据</div>
      </el-tab-pane>
    </el-tabs>
  </el-dialog>
</template>

<script>
import { applicationGetById, getUserWater, getCommissionAll } from '@/api/application'

export default {
  name: 'DetailModal',
  components: {
  },
  data() {
    return {
      modalOptions: {
        closeOnClickModal: false,
        width: '1220px',
        title: '查看提现详情'
      },
      visible: false,
      formData: {
        withdrawalId: ''
      },
      withdrawalInfo: {
        actualReceipt: '',
        applyTime: '',
        bankCard: '',
        bankName: '',
        batchId: '',
        buyerUserId: '',
        cost: '',
        handleTime: '',
        isConfirm: '',
        name: '',
        orderSn: '',
        phone: '',
        rejectReason: '',
        state: '',
        withdrawalId: '',
        withdrawalMoney: ''
      },
      watherInfo: {},
      recordQuery: {
        // page: 1,
        // pageSize: 20,
        // acquirerId: '',
        withdrawalId: ''
      },
      outgoingRecordList: [],
      entryRecordList: []
    }
  },
  methods: {
    handleClose() {
      this.visible = false
    },
    async initList() {
      const res1 = await applicationGetById({ withdrawalId: this.formData.withdrawalId })
      this.withdrawalInfo = res1.data
      const res2 = await getUserWater({ userId: this.withdrawalInfo.buyerUserId })
      this.watherInfo = res2.data
      const res3 = await getCommissionAll({ ...this.recordQuery, withdrawalId: this.withdrawalInfo.withdrawalId })
      this.outgoingRecordList = res3.data.outgoing
      this.entryRecordList = res3.data.entry
    },
    handleOpen(params = {}) {
      this.formData = Object.assign(this.$options.data().formData, params)
      this.initList()
      if (params.withdrawalId) {
        // this.getInfo(params.withdrawalId)
      }
      this.visible = true
    },
    async getInfo(id) {
      const loading = this.$loading({ text: '加载中' })
      try {
        const res = await xxx({ withdrawalId: id })
        this.formData = Object.assign(this.$options.data().formData, res.data, {
          withdrawalId: res.data.withdrawalId || ''
        })
      } finally {
        loading.close()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.small-padding {
	.cell {
		padding-left: 5px;
		padding-right: 5px;
	}
}

.fixed-width {
	.el-button--mini {
		padding: 7px 10px;
	}
}
</style>
