From d90f8f65cb841b3e7e29a18600fa5b1bdf11a108 Mon Sep 17 00:00:00 2001 From: xuyiming Date: Fri, 30 Oct 2020 18:35:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E7=94=B3=E8=AF=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/service-info/service-info.vue | 1 + src/pages/service_shop/shop_car_apply.vue | 97 ++++++++++++++------ 2 files changed, 72 insertions(+), 26 deletions(-) diff --git a/src/components/service-info/service-info.vue b/src/components/service-info/service-info.vue index 9b9e2c4..5ee4b8a 100644 --- a/src/components/service-info/service-info.vue +++ b/src/components/service-info/service-info.vue @@ -258,6 +258,7 @@ export default { query: { service_id: parseFloat(this.data.service_id), spec_id: this.specification.id, + spcs_type: this.specification.spcs_type, duration: this.duration, duration_unit: this.type, }, diff --git a/src/pages/service_shop/shop_car_apply.vue b/src/pages/service_shop/shop_car_apply.vue index 2223a96..de996e2 100644 --- a/src/pages/service_shop/shop_car_apply.vue +++ b/src/pages/service_shop/shop_car_apply.vue @@ -37,8 +37,8 @@ export default { preson: "", phone: "", }, - all_cost:'', - now_money:'', + all_cost: 0, + now_money: 0, module_arr: [ { title: "服务申请", @@ -122,7 +122,7 @@ export default { } else if (this.$route.query.app_id) { this.get_one_app(this.$route.query); } else { - console.log(JSON.parse(window.sessionStorage.getItem("shoppingCart"))); + // console.log(JSON.parse(window.sessionStorage.getItem("shoppingCart"))); var temp_arr = []; JSON.parse(window.sessionStorage.getItem("shoppingCart")).forEach((e) => { temp_arr.push(e.id); @@ -136,9 +136,8 @@ export default { get_account_money(){ this.$http .get(`/apaas/backmgt/user/myAccount`).then(res=>{ - console.log(res); if(res.data.success){ - this.now_money = res.data.data.account_balance + this.now_money = res.data.data.account_balance || 0 } }) }, @@ -201,21 +200,26 @@ export default { }, ]; this.service_arr[0]["auth"] = data.organization_name; - this.service_arr[0]["size"] = "规格:"; + this.service_arr[0]["size"] = ""; + this.service_arr[0]["count"] = ""; data.request_spcs_info.forEach((el) => { if (service_data.spec_id == el.id) { - this.service_arr[0]["size"] = - this.service_arr[0]["size"] + - "访问次数:" + - el.count + - ",访问量:" + - el.pv + - ","; + let size = ""; + + if (el.spcs_type==1) { + size = `${el.money}金币/${el.spcs_count}次` + this.service_arr[0]["num"] = "不限时长" + } else { + size = `${el.money}金币/${el.duration_unit == 1 ? "月" : "年"}` + this.service_arr[0]["num"] = service_data.duration; + } + + this.service_arr[0]["size"] = size; + this.service_arr[0]["count"] = service_data.duration*el.money+'金币'; } }); this.service_arr[0]["applytype"] = "申请方式:" + (service_data.duration_unit == 1 ? "月" : "年"); - this.service_arr[0]["num"] = service_data.duration; this.service_arr[0]["isMg"] = data.openness == 3; this.service_arr[0]["data"] = JSON.parse(data.res_fields); console.log(this.service_arr[0]["data"]); @@ -377,7 +381,7 @@ export default { this.service_arr[l]["count"] = e.duration*parseFloat(e.application.price)+'金币'; this.service_arr[l]["isMg"] = false; this.service_arr[l]["isapp"] = true; - temp_cost = temp_cost + e.duration*parseFloat(e.application.price) + temp_cost = this.floatAdd(temp_cost, e.duration*parseFloat(e.application.price)) } else { //服务 this.service_arr[l]["img"] = e.service.cover; @@ -390,21 +394,30 @@ export default { }, ]; this.service_arr[l]["auth"] = e.service.organization_name; - this.service_arr[l]["size"] = "规格:"; - e.service.request_spcs_info.forEach((el) => { + this.service_arr[l]["size"] = ""; + this.service_arr[l]["count"] = ""; + + let spcs_type_1 = e.service.request_spcs_info.spcs_type_1 || []; + let spcs_type_2 = e.service.request_spcs_info.spcs_type_2 || []; + spcs_type_1.forEach((el,ind) => { if (e.spec_id == el.id) { - this.service_arr[l]["size"] = - this.service_arr[l]["size"] + - "访问次数:" + - el.count + - ",访问量:" + - el.pv + - ","; + this.service_arr[l]["size"] = `时长收费:${el.money}金币/${el.spcs_count}次 * ${e.duration}`; + this.service_arr[l]["num"] = "不限时长"; + this.service_arr[l]["count"] = e.duration*el.money+'金币'; + temp_cost = this.floatAdd(temp_cost, e.duration*el.money); } }); + spcs_type_2.forEach((el,ind) => { + if (e.spec_id == el.id) { + this.service_arr[l]["size"] = `应用镜像部署权限:${el.money}金币/${el.duration_unit == 1 ? "月" : "年"}`; + this.service_arr[l]["num"] = e.duration; + this.service_arr[l]["count"] = e.duration*el.money+'金币'; + temp_cost = this.floatAdd(temp_cost, e.duration*el.money); + } + }); + this.service_arr[l]["applytype"] = "申请方式:" + (e.duration_method == 1 ? "月" : "年"); - this.service_arr[l]["num"] = e.duration; this.service_arr[l]["isMg"] = e.service.openness == 3; this.service_arr[l]["data"] = e.service.res_fields ? JSON.parse(e.service.res_fields) @@ -418,7 +431,39 @@ export default { }) .catch((response) => {}); }, - }, + floatAdd(arg1, arg2) { + let r1, r2, m, c; + + try { + r1 = arg1.toString().split(".")[1].length; + } catch (e) { + r1 = 0; + } + + try { + r2 = arg2.toString().split(".")[1].length; + } catch (e) { + r2 = 0; + } + + c = Math.abs(r1 - r2); + m = Math.pow(10, Math.max(r1, r2)); + if (c > 0) { + let cm = Math.pow(10, c); + if (r1 > r2) { + arg1 = Number(arg1.toString().replace(".", "")); + arg2 = Number(arg2.toString().replace(".", "")) * cm; + } else { + arg1 = Number(arg1.toString().replace(".", "")) * cm; + arg2 = Number(arg2.toString().replace(".", "")); + } + } else { + arg1 = Number(arg1.toString().replace(".", "")); + arg2 = Number(arg2.toString().replace(".", "")); + } + return (arg1 + arg2) / m; + }, + } }; -- 2.26.0