|
|
@@ -72,6 +72,14 @@
|
|
|
@click="handleRechargeCompany(scope.row)"
|
|
|
v-hasPermi="['company:traffic:charge']"
|
|
|
>充值</el-button>
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-minus"
|
|
|
+ style="color:#E6A23C"
|
|
|
+ @click="handleDeduct(scope.row)"
|
|
|
+ v-hasPermi="['company:traffic:deduct']"
|
|
|
+ >扣减</el-button>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
</el-table>
|
|
|
@@ -147,11 +155,60 @@
|
|
|
</div>
|
|
|
</el-dialog>
|
|
|
|
|
|
+ <!-- 流量扣减对话框 -->
|
|
|
+ <el-dialog title="经销商流量扣减" :visible.sync="deductOpen" width="500px" append-to-body :before-close="cancelDeduct">
|
|
|
+ <el-form ref="deductForm" :model="deductForm" :rules="deductRules" label-width="110px">
|
|
|
+ <el-form-item label="经销商名称">
|
|
|
+ <el-input v-model="deductForm.companyName" size="small" disabled />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="当前流量余额">
|
|
|
+ <el-input :value="formatBalance({ balance: deductForm.currentBalance })" size="small" disabled />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="扣减数值" prop="deductValue">
|
|
|
+ <el-input-number
|
|
|
+ v-model="deductForm.deductValue"
|
|
|
+ :min="1"
|
|
|
+ :max="999999999"
|
|
|
+ :step="1"
|
|
|
+ :precision="0"
|
|
|
+ placeholder="请输入扣减数值"
|
|
|
+ controls-position="right"
|
|
|
+ style="width: 100%"
|
|
|
+ />
|
|
|
+ <div style="color:#909399;font-size:12px;line-height:1.4;margin-top:4px;">
|
|
|
+ 单次扣减上限:KB ≤ 1024、MB ≤ 1024、GB ≤ 1024、TB ≤ 10,超出请分次操作。
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="单位" prop="unit">
|
|
|
+ <el-select v-model="deductForm.unit" placeholder="请选择单位" style="width: 100%">
|
|
|
+ <el-option label="KB" value="KB" />
|
|
|
+ <el-option label="MB" value="MB" />
|
|
|
+ <el-option label="GB" value="GB" />
|
|
|
+ <el-option label="TB" value="TB" />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="备注" prop="remark">
|
|
|
+ <el-input
|
|
|
+ v-model="deductForm.remark"
|
|
|
+ type="textarea"
|
|
|
+ placeholder="请输入备注(0-200字)"
|
|
|
+ maxlength="200"
|
|
|
+ show-word-limit
|
|
|
+ :rows="3"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <div slot="footer" class="dialog-footer">
|
|
|
+ <el-button type="primary" @click="submitDeductForm">确 定</el-button>
|
|
|
+ <el-button @click="cancelDeduct">取 消</el-button>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
+
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { listTrafficRecords, rechargeTraffic, trafficConversion } from '@/api/company/traffic'
|
|
|
+import { listTrafficRecords, rechargeTraffic, trafficConversion, deductTraffic } from '@/api/company/traffic'
|
|
|
import { allList } from '@/api/company/company'
|
|
|
import { resetForm } from '@/utils/common'
|
|
|
import { delAdIqiyiAccount } from '@/api/ad/AdIqiyiAccount'
|
|
|
@@ -179,6 +236,8 @@ export default {
|
|
|
rechargeTitle: "",
|
|
|
// 是否显示充值弹出层
|
|
|
rechargeOpen: false,
|
|
|
+ // 是否显示扣减弹出层
|
|
|
+ deductOpen: false,
|
|
|
// 公司搜索相关
|
|
|
companySearchLoading: false,
|
|
|
companyOptions: [],
|
|
|
@@ -200,6 +259,15 @@ export default {
|
|
|
chargeAmount: null,
|
|
|
remark: null
|
|
|
},
|
|
|
+ // 流量扣减表单参数
|
|
|
+ deductForm: {
|
|
|
+ companyId: null,
|
|
|
+ companyName: null,
|
|
|
+ currentBalance: 0,
|
|
|
+ deductValue: null,
|
|
|
+ unit: 'MB',
|
|
|
+ remark: null
|
|
|
+ },
|
|
|
// 流量详情数据
|
|
|
detailData: {},
|
|
|
// 表单校验(保持不变)
|
|
|
@@ -211,6 +279,19 @@ export default {
|
|
|
{ required: true, message: "充值金额不能为空", trigger: "blur" },
|
|
|
{ type: "number", min: 1, message: "充值金额必须大于0", trigger: "blur" }
|
|
|
]
|
|
|
+ },
|
|
|
+ // 扣减表单校验
|
|
|
+ deductRules: {
|
|
|
+ deductValue: [
|
|
|
+ { required: true, message: "扣减数值不能为空", trigger: "blur" },
|
|
|
+ { type: "number", min: 1, message: "扣减数值必须大于0", trigger: "blur" }
|
|
|
+ ],
|
|
|
+ unit: [
|
|
|
+ { required: true, message: "请选择单位", trigger: "change" }
|
|
|
+ ],
|
|
|
+ remark: [
|
|
|
+ { max: 200, message: "备注最多 200 个字", trigger: "blur" }
|
|
|
+ ]
|
|
|
}
|
|
|
};
|
|
|
},
|
|
|
@@ -369,6 +450,112 @@ export default {
|
|
|
this.rechargeOpen = false;
|
|
|
this.resetForm("rechargeForm");
|
|
|
this.rechargeForm = {};
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 打开扣减弹窗 */
|
|
|
+ handleDeduct(row) {
|
|
|
+ this.deductForm = {
|
|
|
+ companyId: row.companyId,
|
|
|
+ companyName: row.companyName,
|
|
|
+ currentBalance: row.balance || 0,
|
|
|
+ deductValue: null,
|
|
|
+ unit: 'MB',
|
|
|
+ remark: null
|
|
|
+ };
|
|
|
+ this.deductOpen = true;
|
|
|
+ this.$nextTick(() => {
|
|
|
+ if (this.$refs.deductForm) {
|
|
|
+ this.$refs.deductForm.clearValidate();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 取消扣减 */
|
|
|
+ cancelDeduct() {
|
|
|
+ this.deductOpen = false;
|
|
|
+ this.deductForm = {
|
|
|
+ companyId: null,
|
|
|
+ companyName: null,
|
|
|
+ currentBalance: 0,
|
|
|
+ deductValue: null,
|
|
|
+ unit: 'MB',
|
|
|
+ remark: null
|
|
|
+ };
|
|
|
+ if (this.$refs.deductForm) {
|
|
|
+ this.$refs.deductForm.resetFields();
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 扣减数值转 KB */
|
|
|
+ convertToKB(value, unit) {
|
|
|
+ let ratio = 0;
|
|
|
+ switch (unit) {
|
|
|
+ case 'KB': ratio = 1; break;
|
|
|
+ case 'MB': ratio = 1024; break;
|
|
|
+ case 'GB': ratio = 1024 * 1024; break;
|
|
|
+ case 'TB': ratio = 1024 * 1024 * 1024; break;
|
|
|
+ default: ratio = 0;
|
|
|
+ }
|
|
|
+ return Number(value || 0) * ratio;
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 单位上限 */
|
|
|
+ getUnitLimit(unit) {
|
|
|
+ switch (unit) {
|
|
|
+ case 'KB': return 1024;
|
|
|
+ case 'MB': return 1024;
|
|
|
+ case 'GB': return 1024;
|
|
|
+ case 'TB': return 10;
|
|
|
+ default: return 0;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 提交扣减 */
|
|
|
+ submitDeductForm() {
|
|
|
+ this.$refs["deductForm"].validate(valid => {
|
|
|
+ if (!valid) return;
|
|
|
+ const value = Number(this.deductForm.deductValue || 0);
|
|
|
+ const unit = this.deductForm.unit;
|
|
|
+ const limit = this.getUnitLimit(unit);
|
|
|
+ if (limit <= 0) {
|
|
|
+ this.msgError("非法的扣减单位");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (value > limit) {
|
|
|
+ this.msgError(`单次扣减数值不能超过 ${limit} ${unit}`);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const deductKB = this.convertToKB(value, unit);
|
|
|
+ if (deductKB <= 0) {
|
|
|
+ this.msgError("扣减数值必须大于0");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (deductKB > Number(this.deductForm.currentBalance || 0)) {
|
|
|
+ this.msgError("扣减流量超过当前余额");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.$confirm(
|
|
|
+ '确定要从 [' + this.deductForm.companyName + '] 扣减 '
|
|
|
+ + this.deductForm.deductValue + ' ' + this.deductForm.unit + ' 流量吗?',
|
|
|
+ '提示',
|
|
|
+ { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }
|
|
|
+ ).then(() => {
|
|
|
+ return deductTraffic({
|
|
|
+ companyId: this.deductForm.companyId,
|
|
|
+ deductValue: this.deductForm.deductValue,
|
|
|
+ unit: this.deductForm.unit,
|
|
|
+ remark: this.deductForm.remark
|
|
|
+ });
|
|
|
+ }).then(response => {
|
|
|
+ if (response.code === 200) {
|
|
|
+ this.msgSuccess("扣减成功");
|
|
|
+ this.deductOpen = false;
|
|
|
+ this.getList();
|
|
|
+ } else {
|
|
|
+ this.msgError(response.msg);
|
|
|
+ }
|
|
|
+ }).catch(() => {});
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
};
|