addDialog.vue 7.86 KB
<!-- 新增提现弹窗 -->
<template>
  <baseDialog
    :dialog-config="dialogConfig"
    :is-show.sync="visible"
    class="accountDailog"
    @handleClick="handleCashConfirm"
  >
    <el-form
      ref="formRef"
      :model="infoForm"
      :rules="cashRules"
      label-width="120px"
    >
      <el-form-item label="提现方:" prop="merchantId">
        <el-select
          v-model="infoForm.merchantId"
          filterable
          style="width: 310px"
          placeholder="请选择提现商户"
          @change="getBankBalance"
        >
          <el-option
            v-for="(item, index) in baseData.merchantList"
            :key="index"
            :label="item.merchantName"
            :value="item.merchantId"
          />
        </el-select>
        <p>银盛账户余额:{{ balance || balance === 0 ? balance : "-" }}</p>
      </el-form-item>
      <el-form-item label="提现金额:" prop="totalAmount">
        <el-input
          v-model="infoForm.totalAmount"
          placeholder="请输入提现金额"
          style="width: 310px"
          :disabled="totalAmountDisabled"
          @input="handleUpgradeNum"
        />
      </el-form-item>
      <el-form-item label="财务管理员:" prop="administrators">
        <el-select
          v-model="infoForm.administrators"
          filterable
          style="width: 310px"
        >
          <el-option
            v-for="(item, index) in baseData.administratorsList"
            :key="index"
            :label="item.name + ' ' + item.phone"
            :value="item.phone"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="验证码:" prop="smsCode">
        <el-input
          v-model="infoForm.smsCode"
          placeholder="请输入验证码"
          maxlength="6"
          style="width: 200px"
        />
        <el-button
          type="primary"
          size="small"
          @click="handleSend"
          :disabled="isSend"
          class="cash-btn"
        >
          {{ isSend ? sendMsg + "秒后,重试" : "获取验证码" }}
        </el-button>
        <p v-show="showtips">
          已向尾号为{{
            infoForm.administrators ? infoForm.administrators.slice(-4) : ""
          }}的手机号发送验证码,验证码30分钟内有效
        </p>
      </el-form-item>
      <el-form-item label="备注:" prop="remark">
        <el-input
          v-model="infoForm.remark"
          type="textarea"
          maxlength="50"
          placeholder="请输入备注"
          show-word-limit
          :rows="4"
          style="width: 310px"
        />
      </el-form-item>
    </el-form>
    <!-- </d2-dialog> -->
  </baseDialog>
</template>

<script>
import { createWithdraw } from "@api/account"
import { sendToSmsCodeApi } from "@/api/sys.base"
import { getWithdrawTreasurerList } from "@api/transferAccountsManage"
import { getListApi } from "@api/publicAccount"
import {
  transferAccountsRecordCreate,
  getBankBalance
} from "@api/withdrawalManage"
import { limitPrice } from "@/common/format"
import { getDjzhySubMerchant } from "@api/merchant"
export default {
  // name: 'AddDialog',
  data() {
    return {
      dialogConfig: {
        title: "新增提现",
        width: "600px"
      },
      infoForm: {
        administrators: "",
        smsCode: "",
        remark: "",
        merchantId: "",
        totalAmount: ""
      },
      oldVal: {
        totalAmount: ""
      },
      cashRules: {
        merchantId: [
          { required: true, message: "请选择提现方", trigger: "change" }
        ],
        totalAmount: [
          {
            required: true,
            message: "请输入金额,支持输入0~999999的数字,支持小数点后2位",
            trigger: "change"
          }
        ],
        administrators: [
          { required: true, message: "请选择财务管理员", trigger: "change" }
        ],
        smsCode: [
          { required: true, message: "请输入验证码", trigger: "change" }
        ]
      },
      // 验证码
      showtips: false,
      isSend: false,
      sendMsg: "获取验证码",
      time: "",
      // 基本数据
      baseData: {
        administratorsList: [],
        merchantList: []
      },
      balance: "",
      totalAmountDisabled: true
    }
  },

  props: {
    addVisible: {
      type: Boolean,
      default: false
    }
  },

  // watch: {
  //   addVisible(newVal, val) {
  //     newVal ? this.reset() : this.closeReset()
  //   }
  // },
  computed: {
    visible: {
      get() {
        return this.addVisible
      },
      set(newVal) {
        this.$emit("dialogClose", { flag: newVal, attrName: "addVisible" })
      }
    }
  },

  mounted() {
    this.getMerchantList()
    this.getAdminList()
  },

  methods: {
    getMerchantList() {
      var params = {}
      params.currentPage = 1
      params.pageSize = 10000
      params.accountStatus = 3 // 生效
      params.merchantTypeList = [2, 7, -1]
      getListApi(params).then((res) => {
        this.baseData.merchantList = res.list
        // 获取获取嘀加智慧云子商户信息
        // getDjzhySubMerchant({}).then((res) => {
        //   // 转入方选项中去除嘀加智慧云子商户
        //   // this.baseData.merchantList = this.baseData.merchantList.filter((item) => item.merchantId != res.merchantId)
        //   this.baseData.merchantList = this.baseData.merchantList
        // })
      })
    },
    getAdminList() {
      getWithdrawTreasurerList({}).then((res) => {
        this.baseData.administratorsList = res
        this.infoForm.administrators = res[0].phone
      })
    },
    getBankBalance(val) {
      this.infoForm.totalAmount = ""
      this.balance = ""
      getBankBalance({ merchantId: val }).then((res) => {
        if (res || res == 0) {
          this.balance = res
          if (this.balance) {
            this.totalAmountDisabled = false
          } else {
            this.totalAmountDisabled = true
          }
        }
      })
    },
    handleUpgradeNum(newVal) {
      var maxVal = 999999
      if (this.balance) {
        maxVal = this.balance
      }
      //  else {
      //   newVal = ''
      // }
      this.infoForm.totalAmount = limitPrice(
        newVal,
        this.oldVal.totalAmount,
        6,
        2,
        0,
        maxVal
      )
      this.oldVal.totalAmount = this.infoForm.totalAmount
    },

    handleCashConfirm() {
      this.$refs.formRef.validate((valid) => {
        if (valid) {
          var params = {}
          params.remark = this.infoForm.remark
          params.smsCode = this.infoForm.smsCode
          params.phone = this.infoForm.administrators
          params.merchantId = this.infoForm.merchantId
          if (this.infoForm.totalAmount > 0) {
            params.totalAmount = this.infoForm.totalAmount
          } else {
            this.$message({
              message: "提现金额必须大于0",
              type: "warning",
              showClose: true
            })
            return
          }
          console.log(params)

          transferAccountsRecordCreate(params).then((res) => {
            this.notice.okTips("操作成功")
            this.visible = true
          })
        }
      })
    },
    handleSend() {
      if (!this.infoForm.administrators) {
        this.notice.warningTips("请选择管理员")
        return
      }
      sendToSmsCodeApi({ phone: this.infoForm.administrators }).then((res) => {
        this.notice.okTips("已发送,30分钟内有效")
        this.isSend = true
        this.showtips = true
        this.sendMsg = 60
        this.msgDown()
      })
    },
    msgDown() {
      this.time = setTimeout(() => {
        clearTimeout(this.time)
        if (this.sendMsg > 1) {
          --this.sendMsg
          this.msgDown()
        } else {
          this.isSend = false
        }
      }, 1000)
    }
  }
}
</script>
<style scoped>
p {
  margin: 0 0;
}
.cash-btn {
  margin-left: 20px;
}
</style>