setPriceDialog.vue 2.68 KB
<template>
  <GLDialog :title="isConversionRate ? '兑换价' : '批量改价'" mode="small" :visible.sync="visible" :show-close="true" :before-close="handleClose" @onOk="confirmPriceChange" @onCancel="handleClose" okText="提交" cancelText="取消">
    <div class="dialog-wrap">
      <span>
        {{ isConversionRate ? '兑换价 = ' : '兑换价 = 供货价1:1积分  +' }}
      </span>

      <el-input v-if="isConversionRate" size="small" type="text" onkeyup="value = value.replace(/[^\d]/g,'').replace(/^[0]+[0-9]*$/gi,'')" v-model="batchCount" placeholder="请输入积分">
        <span slot="append">积分</span>
      </el-input>
      <el-input v-else size="small" type="text" onkeyup="value = value.replace(/[^\d]/g,'').replace(/^0\d/g, '0')" v-model="batchCount" placeholder="请输入积分">
        <span slot="append">积分</span>
      </el-input>
      <span>&nbsp; +</span>
      <el-input size="small" type="text" onkeyup="value = value ? value.replace(/^0\d/g, '0').replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/^\d{6}\d+(\.\d+)?/g, value.substr(0,6)).replace(/\.{2,}/g, '').replace('.', '$#$')
            .replace(/\./g, '').replace('$#$', '.').replace(/^(-)*(\d+)\.(\d\d).*$/, '$1$2.$3') : value" v-model="batchPrice" placeholder="请输入金额" disabled="true">
        <span slot="append">元</span>
      </el-input>
    </div>
  </GLDialog>
</template>

<script>
import { limitPrice } from '@/common/constant'
export default {
  name: 'setPriceDialog',
  props: {
    isConversionRate: {
      type: Boolean,
      default: false
    },
    visible: {
      type: Boolean,
      default: false
    },
    echoParams: {
      type: Object,
      default: () => {
      }
    }
  },

  data() {
    return {
      batchCount: this.isConversionRate ? this.echoParams.redeemPoints : '',
      batchPrice: this.isConversionRate ? this.echoParams.salePrice : '',
    }
  },
  watch: {
    batchCount(newValue, oldValue) {
      this.batchCount = limitPrice(newValue, oldValue, 5, 0, 1, 99999)
    }
  },

  methods: {
    confirmPriceChange() {
      const batchParams = {
        batchPrice: this.batchPrice,
        batchCount: this.batchCount
      }
      this.$emit('confirm', batchParams)
    },
    handleClose() {
      this.$emit('handleClose')
    }
  }
}
</script>
<style lang="scss" scoped>
.dialog-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;

  span {
    white-space: nowrap;
    margin-right: 8px;
  }

  /deep/ .el-input {
    &,
    .el-input__inner {
      width: 100px;
    }

    .el-input-group__append {
      box-sizing: border-box;
      padding: 0 11px;

      span {
        margin: 0;
      }
    }
  }
}
</style>