<> Functions realized

Check settlement method , import value , And the input price is verified and the input is limited .

<> Specific implementation logic
<el-form size="mini" :model="prize" ref="prize"> <el-checkbox-group
v-model="checkedPay"> <div v-for="(type, index) in payType" :key="type.label"
class="pay-name" > <el-checkbox :label="type.label"
@change="handleCheckedPayChange(index, type)" > {{ type.name }} </el-checkbox>
<el-form-item label-width="100px" label=" Unit Price " v-if="modalShow[type.label]"
style="display:inline-block;" :prop="type.label" :rules="[{ required: true,
message: ' Cannot be empty ', trigger: 'blur' }]" > <el-input step="0.1"
v-model="prize[type.label]" @change="materielExtraCostChange(type.label)"
@keyup.native=" prize[type.label] = prize[type.label].replace(
prize[type.label], RestrictedMoney(prize[type.label]) ) " ></el-input>
</el-form-item> </div> </el-checkbox-group> </el-form> <script> /** * Restrictions on input prices
*/ var plusOrMinus = (values) => { let newValue; if (!/[^0-9.-]/g.test(values))
{ newValue = values .replace(/[^\-\d.]/g, "") .replace(/\b(0+){2,}/g, "0")
.replace(/-{2,}/g, "-") .replace(/^\./g, "") .replace(/\.{2,}/g, ".")
.replace(".", "$#$") .replace(/\./g, "") .replace("$#$", "."); if (
newValue.toString().indexOf(".") > 0 &&
Number(newValue.toString().split(".")[1].length) > 2 ) { newValue =
parseInt(parseFloat(newValue) * 100) / 100; } if
(newValue.toString().split("-").length - 1 > 1) { newValue =
parseFloat(newValue) || ""; } if ( newValue.toString().split("-").length > 1 &&
newValue.toString().split("-")[0].length > 0 ) { newValue =
parseFloat(newValue) || ""; } if ( newValue.toString().length > 1 &&
(newValue.toString().charAt(0) === "0" || (newValue.toString().length > 2 &&
newValue.toString().charAt(0) === "-" && newValue.toString().charAt(1) === "0"
&& newValue.toString().charAt(2) !== ".")) && newValue.toString().indexOf(".")
< 1 ) { newValue = parseFloat(newValue) || ""; } // The maximum number of integers is 9 position if (
newValue.toString().indexOf(".") > 0 &&
Number(newValue.toString().split(".")[0].length) > 9 ) { newValue =
newValue.toString().substring(0, 9) + "." + newValue.toString().split(".")[1];
} else if ( newValue.toString().indexOf(".") < 0 &&
Number(newValue.toString().split(".")[0].length) > 9 ) { newValue =
newValue.toString().substring(0, 9); } } else { newValue =
values.replace(/[^0-9.-]/g, ""); } return newValue; } data() { var checkPrize =
(rule, value, callback) => { if (!value) { return callback(new Error(" Cannot be empty "));
} }; var RestrictedMoney = values => { return plusOrMinus(values.toString());
}; return { RestrictedMoney: RestrictedMoney, payType: [ { label: "anzhuang",
name: " install " }, { label: "jihuo", name: " activation " }, { label: "zhuce", name: " register " }, {
label: "cps", name: "CPS" } ], modalShow: {}, checkedPay: [], prize: {
anzhuang: "", jihuo: "", zhuce: "", cps: "" }, rules: { anzhuang: [{ validator:
checkPrize, trigger: "blur" }], jihuo: [{ validator: checkPrize, trigger:
"blur" }], zhuce: [{ validator: checkPrize, trigger: "blur" }], cps: [{
validator: checkPrize, trigger: "blur" }] } }; }, created() { for (let i in
this.payType) { this.$set(this.modalShow, this.payType[i].label, false); } },
methods: { handleCheckedPayChange(i, type) { if
(this.checkedPay.indexOf(type.label) !== -1) { this.modalShow[type.label] =
true; } else { this.modalShow[type.label] = false; this.prize[type.label] = "";
} }, setData() { var _self = this; return this.checkedPay.map(item => { let
current = _self.payType.find(cur => { return cur.label === item; }); return {
payment_method: current.name, payment_amount: _self.prize[current.label] || 0
}; }); }, sendPostData() { this.$refs["prize"].validate(valid => { if (valid) {
alert(' Submit ); }else { console.log(' error ); } }, materielExtraCostChange(label) { //
Prevent deletion from being empty if (!this.prize[label]) { this.prize[label] = "0.00"; } // Judgment of some wrong amount input
if ( this.prize[label].toString().indexOf(".") > 0 &&
Number(this.prize[label].toString().split(".")[1].length) < 1 ) {
this.prize[label] = this.prize[label].toString().split(".")[0]; }
this.prize[label] = parseFloat(this.prize[label]).toFixed(2); } } </script>

Technology
Daily Recommendation