addDialog.vue 8.1 KB
<!-- 新增提现弹窗 -->
<template>
  <baseDialog :config="config" :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.merchant" value-key="merchantId" filterable style="width: 310px"
          placeholder="请选择门店">
          <el-option v-for="(item, index) in baseData.merchantList" :key="index" :label="item.merchantName"
            :value="item" />
        </el-select>
        <!-- <p>银盛账户余额:{{ balance || balance === 0 ? balance : "-" }}</p> -->
      </el-form-item>
      <el-form-item label="金额:" prop="tradeAmount">
        <!--   :disabled="totalAmountDisabled" -->
        <el-input v-model="infoForm.tradeAmount" placeholder="请输入金额" style="width: 310px" @input="handleUpgradeNum" />
      </el-form-item>
      <el-form-item label="收款类型:" prop="tradeType">
        <el-select v-model="infoForm.tradeType" filterable style="width: 310px" placeholder="请选择收款类型">
          <el-option v-for="(item, index) in baseData.tradeTypeList" :key="index" :label="item.label"
            :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="收款日期:" prop="tradeTime">
        <el-date-picker style="width: 310px" v-model="infoForm.tradeTime" type="datetime"
          :picker-options="tradeTimePickerOptions" placeholder="选择日期时间">
        </el-date-picker>
        <!-- <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>
    <!-- </d2-dialog> -->
  </baseDialog>
</template>

<script>
import { deepClone } from "@/common/util"
import { sendToSmsCodeApi } from "@/api/sys.base"
import { advancePaymentMerchantPage, advancePaymentTradeAdd } from "@api/prepaymentManage"
import dayjs from "dayjs"
import { limitPrice } from "@/common/format"
export default {
  // name: 'AddDialog',
  data() {
    return {
      dialogConfig: {
        title: "新增收款",
        width: "600px"
      },
      config: {
        showClose: true,
        appendToBody: true, // 是否将自身插入至 body 元素,有嵌套的弹窗时一定要设置
        isShowFooter: true,
        cancel_name: "取 消",
        confirm_name: "确 定"
      },
      infoForm: {
        // administrators: "",
        // smsCode: "",
        // remark: "",
        merchant: null,
        merchantId: "",
        // totalAmount: "",
        tradeAmount: "",
        tradeTime: "",
        tradeType: "1"
      },
      oldVal: {
        tradeAmount: ""
      },
      cashRules: {
        merchantId: [
          { required: true, message: "请选择门店", trigger: "change" }
        ],
        tradeAmount: [
          {
            required: true,
            message: "请输入金额,支持输入0~999999999的数字,支持小数点后2位",
            trigger: "change"
          }
        ],
        tradeType: [
          { required: true, message: "请选择收款类型", trigger: "change" }
        ],
        tradeTime: [
          { required: true, message: "请选择收款日期", trigger: "change" },
          { validator: (rule, value, callback) => this.validateTradeTime(rule, value, callback), trigger: "change" }
        ]
        // smsCode: [
        //   { required: true, message: "请输入验证码", trigger: "change" }
        // ]
      },
      // 验证码
      showtips: false,
      isSend: false,
      sendMsg: "获取验证码",
      time: "",
      // 基本数据
      baseData: {
        tradeTypeList: [
          // 1:银行转账(对公),2:银行承兑,3:银行转账,4:银盛收款
          {
            id: "1",
            label: "银行转账(对公)"
          }
        ],
        // administratorsList: [],
        merchantList: []
      },
      balance: "",
      // totalAmountDisabled: true
    }
  },

  props: {
    addVisible: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    visible: {
      get() {
        return this.addVisible
      },
      set(newVal) {
        this.$emit("update:addVisible", newVal)
      }
    },
    tradeTimePickerOptions() {
      const start = this.infoForm.merchant && this.infoForm.merchant.startDate
      return {
        disabledDate: (date) => {
          const a = dayjs(date).startOf('day').valueOf()
          const min = start ? dayjs(start).startOf('day').valueOf() : -Infinity
          const max = dayjs().endOf('day').valueOf()
          return a < min || a > max
        }
      }
    }
  },
  watch: {
    'infoForm.merchant'(val) {
      this.infoForm.merchantId = val ? val.merchantId : ''
      this.infoForm.merchantName = val ? val.merchantName : ''
      this.infoForm.tradeTime = ''
    }
  },

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

  methods: {
    validateTradeTime(rule, value, callback) {
      const start = this.infoForm.merchant && this.infoForm.merchant.startDate
      if (start && value) {
        const a = dayjs(value).startOf('day').valueOf()
        const min = dayjs(start).startOf('day').valueOf()
        const max = dayjs().endOf('day').valueOf()
        if (a < min) return callback(new Error('收款日期需不早于门店开始日期'))
        if (a > max) return callback(new Error('收款日期不可晚于当前时间'))
      }
      callback()
    },
    getMerchantList() {
      var params = {}
      params.currentPage = 1
      // params.pageSize = 1000000
      params.pageSize = 100
      advancePaymentMerchantPage(params).then((res) => {
        this.baseData.merchantList = res.list
      })
    },
    handleUpgradeNum(newVal) {
      var maxVal = 999999999
      if (this.balance) {
        maxVal = this.balance
      }
      //  else {
      //   newVal = ''
      // }
      this.infoForm.tradeAmount = limitPrice(
        newVal,
        this.oldVal.tradeAmount,
        13,
        2,
        -999999999,
        maxVal,
        'priceReg_negative_input'
      )
      this.oldVal.tradeAmount = this.infoForm.tradeAmount
    },

    handleCashConfirm() {
      this.$refs.formRef.validate((valid) => {
        if (valid) {
          var params = deepClone(this.infoForm)
          // params.
          if (params.tradeTime) {
            params.tradeTime = dayjs(params.tradeTime).format("YYYY-MM-DD HH:mm:ss")
          }
          // 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)

          advancePaymentTradeAdd(params).then((res) => {
            this.notice.okTips("新增成功")
            this.visible = false
            this.$emit("addDialogSuccess")
          })
        }
      })
    },
    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>