xiaohaizhao 3 лет назад
Родитель
Сommit
981ea05b56

+ 7 - 2
packageA/offers/detail.js

@@ -1,4 +1,9 @@
-const _Http = getApp().globalData.http;
+const _Http = getApp().globalData.http,
+    currency = require("../../utils/currency"),
+    CNY = value => currency(value, {
+        symbol: "¥",
+        precision: 2
+    }).format();
 Page({
     data: {
         isLeader: false, //是否为负责人
@@ -190,7 +195,7 @@ Page({
             value: (res.data.discountrate * 100).toFixed(2) + '%'
         }, {
             label: "总金额",
-            value: res.data.sumamount
+            value: CNY(res.data.sumamount)
         }, {
             label: "是否特价",
             value: res.data.specialoffer == 1 ? '是' : '否'

+ 54 - 49
packageA/offers/modules/product/index.js

@@ -1,9 +1,13 @@
 const _Http = getApp().globalData.http,
-    file = require("../../../../utils/matchingFeilType");
-
+    file = require("../../../../utils/matchingFeilType"),
+    currency = require("../../../../utils/currency"),
+    CNY = value => currency(value, {
+        symbol: "¥",
+        precision: 2
+    }).format();
 let queue = [],
-    downCounter = null;
-
+    downCounter = null,
+    sa_quotedpriceid = 0;
 Component({
     properties: {
         disabled: Boolean, //禁用
@@ -15,14 +19,12 @@ Component({
         sumamount(newData) {
             let savePage = this.data.savePage;
             let i = savePage.data.list1.findIndex(v => v.label == '总金额');
-            if (i != -1 && savePage.data.list1[i].value != (newData - 0)) savePage.setData({
+            if (i != -1 && savePage.data.list1[i].value != newData) savePage.setData({
                 [`list1[${i}].value`]: newData
             })
         }
     },
     data: {
-        sumamount: 0,
-        sa_quotedpriceid: 0,
         "content": {
             nocache: true,
             "pageNumber": 1,
@@ -49,6 +51,7 @@ Component({
         getList(id, init) {
             let content = this.data.content;
             content.sa_quotedpriceid = id;
+            sa_quotedpriceid = id;
             if (init) content.pageNumber = 1;
             _Http.basic({
                 "id": "20221021095503",
@@ -65,12 +68,18 @@ Component({
                         let image = value.attinfos.find(v => v.fileType == "image");
                         value.cover = image ? image.cover : "";
                     }
-                    value.minPrice = (value.mindiscountrate * value.marketprice).toFixed(2);
-                    value.mindiscountrate = (value.mindiscountrate * 100).toFixed(2)
-                    value.discountrate = (value.discountrate * 100).toFixed(2);
+                    //最低价 = 牌价*最低折扣
+                    value.minPrice = currency(value.marketprice).multiply(value.mindiscountrate).value;
+                    value.mindiscountrate = currency(value.mindiscountrate).multiply(100).value;
+                    value.discountrate = currency(value.discountrate).multiply(100).value;
+                    value.price = currency(value.price).value;
+
+                    //显示格式化金额
+                    value.showMarketprice = CNY(value.marketprice);
+                    value.discountDifferenceAmount = CNY(value.discountDifferenceAmount)
+                    value.showAmount = CNY(value.amount)
                     value.className = value.itemclass.length == 0 ? "暂无类目" : value.itemclass.map(v => v.itemclassname);
                     value.brandName = value.brand.length == 0 ? "暂无品牌" : value.brand.map(v => v.brandname);
-                    value.price = (value.price - 0).toFixed(2);
                     return value;
                 })
                 this.setData({
@@ -79,11 +88,10 @@ Component({
                     "content.pageSize": res.pageSize,
                     "content.pageTotal": res.pageTotal,
                     "content.total": res.total,
-                    sa_quotedpriceid: id,
                     savePage: getCurrentPages().find(v => v.__route__ == 'packageA/offers/detail'),
                 })
                 if (res.pageNumber == 1) this.setData({
-                    sumamount: (res.data[0].rowstotal[0].sumamount - 0).toFixed(2) || 0
+                    sumamount: CNY(res.data[0].rowstotal[0].sumamount || 0)
                 })
             })
         },
@@ -119,7 +127,7 @@ Component({
                         nocache: true,
                         total: null,
                         sa_projectid,
-                        sa_quotedpriceid: this.data.sa_quotedpriceid,
+                        sa_quotedpriceid,
                         where: {
                             condition: ""
                         }
@@ -133,15 +141,6 @@ Component({
             list
         }) {
             console.log('项目产品添加', list)
-            console.log(list.map(v => {
-                return {
-                    "sa_quotedprice_itemsid": 0,
-                    "itemid": v.itemid,
-                    "price": v.price,
-                    "discountrate": v.price / v.marketprice,
-                    "qty": v.qty
-                }
-            }))
             let that = this;
             wx.showModal({
                 title: '提示',
@@ -153,13 +152,13 @@ Component({
                         "id": 20221021095403,
                         "version": 1,
                         "content": {
-                            "sa_quotedpriceid": that.data.sa_quotedpriceid,
+                            sa_quotedpriceid,
                             items: list.map(v => {
                                 return {
                                     "sa_quotedprice_itemsid": 0,
                                     "itemid": v.itemid,
                                     "price": v.price,
-                                    "discountrate": v.price / v.marketprice,
+                                    "discountrate": currency(v.price).divide(v.marketprice).value,
                                     "qty": v.qty
                                 }
                             })
@@ -171,7 +170,7 @@ Component({
                             icon: "none"
                         });
                         if (res.msg == '成功') setTimeout(() => {
-                            that.getList(that.data.sa_quotedpriceid, true)
+                            that.getList(sa_quotedpriceid, true)
                             wx.navigateBack()
                         }, 300)
                     })
@@ -194,7 +193,7 @@ Component({
                         "id": 20221021095403,
                         "version": 1,
                         "content": {
-                            "sa_quotedpriceid": that.data.sa_quotedpriceid,
+                            sa_quotedpriceid,
                             items: list.map(v => {
                                 return {
                                     "sa_quotedprice_itemsid": 0,
@@ -212,7 +211,7 @@ Component({
                             icon: "none"
                         });
                         if (res.msg == '成功') setTimeout(() => {
-                            that.getList(that.data.sa_quotedpriceid, true)
+                            that.getList(sa_quotedpriceid, true)
                             wx.navigateBack()
                         }, 300)
                     })
@@ -237,7 +236,7 @@ Component({
                 })
                 if (res.msg == '成功') {
                     let i = this.data.list.findIndex(v => v.sa_quotedprice_itemsid == detail);
-                    let sumamount = (this.data.sumamount - this.data.list[i].amount).toFixed(2);
+                    let sumamount = CNY(currency(this.data.sumamount).subtract(this.data.list[i].amount));
                     this.data.list.splice(i, 1);
                     this.setData({
                         list: this.data.list,
@@ -246,6 +245,7 @@ Component({
                 }
             })
         },
+
         /* 生成修改队列 */
         changeQueue({
             detail
@@ -264,7 +264,7 @@ Component({
                 "id": 20221021095403,
                 "version": 1,
                 "content": {
-                    "sa_quotedpriceid": this.data.sa_quotedpriceid,
+                    sa_quotedpriceid,
                     items
                 }
             }, false).then(res => {
@@ -277,27 +277,32 @@ Component({
                         title: res.msg,
                         icon: "none"
                     })
-                    this.setData({
-                        list
-                    })
                     return;
-                }
-                items.forEach(v => {
-                    v.discountrate = (v.discountrate * 100).toFixed(2);
-                    let i = list.findIndex(value => v.sa_quotedprice_itemsid == value.sa_quotedprice_itemsid);
-                    if (i != -1) {
-                        this.data.list[i] = {
-                            ...list[i],
-                            ...v
+                } else {
+                    items.forEach(v => {
+                        let i = list.findIndex(value => v.sa_quotedprice_itemsid == value.sa_quotedprice_itemsid);
+                        if (i != -1) {
+                            v.discountrate = (v.discountrate * 100).toFixed(2);
+                            this.setData({
+                                sumamount: CNY(currency(this.data.sumamount).subtract(list[i].amount).add(v.amount))
+                            })
+                            v.showAmount = CNY(v.amount)
+                            this.data.list[i] = Object.assign(list[i], v);
                         }
-                        let sumamount = ((this.data.sumamount - list[i].amount) + (v.sum - 0)).toFixed(2);
-                        this.setData({
-                            sumamount
-                        })
-                        this.data.list[i].amount = v.sum;
-                    }
-                });
-                getCurrentPages()[getCurrentPages().length - 1].getDetail();
+                    });
+
+                }
+                this.setData({
+                    list
+                })
+                let page = getCurrentPages().find(v => v.__route__ == 'packageA/offers/detail');
+                if (page) {
+                    let index = page.data.list1.findIndex(v => v.label == '总金额');
+                    if (index != -1) page.setData({
+                        [`list1[${index}].value`]: this.data.sumamount
+                    })
+                }
+
             })
         }
     }

+ 16 - 8
packageA/offers/modules/product/list/index.js

@@ -1,3 +1,9 @@
+const currency = require("../../../../../utils/currency"),
+    CNY = value => currency(value, {
+        symbol: "¥",
+        precision: 2
+    }).format();
+
 Component({
     properties: {
         list: Array,
@@ -16,25 +22,27 @@ Component({
             } = e.currentTarget.dataset,
                 detail = name == 'qty' ? e.detail.value - 0 : (e.detail.value - 0).toFixed(2),
                 item = this.data.list[index];
-            item[name] = detail;
+            if (item[name] == detail) return;
+
+            item[name] = currency(detail).value;
             if (name == 'price') {
                 if (item.price > item.marketprice) item.price = item.marketprice
                 if (item.price <= 0) item.price = 1
                 item.discountrate = this.getPercent(item.price, item.marketprice).toFixed(2);
             } else if (name == 'discountrate') {
-                if (item.discountrate > 100) item.discountrate = 100.00;
-                if (item.discountrate <= 0) item.discountrate = 1.00;
-                item.price = (item.marketprice * (item.discountrate / 100) - 0).toFixed(2);
+                if (item.discountrate > 100) item.discountrate = 100;
+                if (item.discountrate <= 0) item.discountrate = 1;
+                item.price = currency(item.marketprice).multiply((item.discountrate / 100)).value;
             }
-            item.amount = (item.price * item.qty).toFixed(2);
-            item.discountDifferenceAmount = (item.price - item.minPrice).toFixed(2);
+            item.showAmount = CNY(currency(item.price).multiply(item.qty));
+            item.amount = currency(item.price).multiply(item.qty).value;
+            item.discountDifferenceAmount = CNY(currency(item.price).subtract(item.minPrice));
             this.setData({
                 [`list[${index}]`]: item
             })
             let obj = {};
-            ["sa_quotedprice_itemsid", "itemid", "price", "discountrate", "qty", "mindiscountrate"].forEach(v => obj[v] = item[v]);
+            ["sa_quotedprice_itemsid", "itemid", "price", "discountrate", "qty", "mindiscountrate", "discountDifferenceAmount", "amount"].forEach(v => obj[v] = item[v]);
             obj.discountrate = (obj.discountrate / 100).toFixed(4);
-            obj.sum = (obj.price * obj.qty).toFixed(2);
             this.triggerEvent("changeQueue", obj)
         },
         /* 计算百分比 */

+ 2 - 2
packageA/offers/modules/product/list/index.wxml

@@ -23,7 +23,7 @@
                     <text class="line-1">型号:{{item.model||' --'}}</text>
                 </view>
                 <view class="subfield">
-                    <text class="line-1" style="margin-right: 6rpx;">牌价:{{item.marketprice||' --'}}</text>
+                    <text class="line-1" style="margin-right: 6rpx;">牌价:{{item.showMarketprice||' --'}}</text>
                     <text class="line-1" style="margin-right: 6rpx;">单价差额:<text style="color: {{(item.mindiscountrate-0)>(item.discountrate-0)?'var(--error)':'var(--success)'}};">{{item.discountDifferenceAmount||' --'}}</text></text>
                 </view>
                 <view class="subfield">
@@ -53,7 +53,7 @@
                 <input class="input" style="width: 180rpx;" type="digit" disabled="{{!disabled}}" value="{{item.price}}" data-name="price" data-index="{{index}}" bindblur="onBlur" />
             </view>
             <view class="money">
-                金额:<text>¥{{item.amount}}</text>
+                金额:<text>{{item.showAmount}}</text>
             </view>
         </view>
     </view>

+ 7 - 1
packageA/project/detail.js

@@ -1,4 +1,9 @@
-const _Http = getApp().globalData.http;
+const _Http = getApp().globalData.http,
+    currency = require("../../utils/currency"),
+    CNY = value => currency(value, {
+        symbol: "¥",
+        precision: 2
+    }).format();
 Page({
     data: {
         isLeader: false, //是否为负责人
@@ -126,6 +131,7 @@ Page({
                 label: "结束"
             })
         }
+        data.signamount_due = CNY(data.signamount_due);
         this.setData({
             isLeader,
             tabbarList,

+ 7 - 1
packageA/project/modules/product/index.js

@@ -1,5 +1,10 @@
 const _Http = getApp().globalData.http,
-    file = require("../../../../utils/matchingFeilType");
+    file = require("../../../../utils/matchingFeilType"),
+    currency = require("../../../../utils/currency"),
+    CNY = value => currency(value, {
+        symbol: "¥",
+        precision: 2
+    }).format();
 let queue = [],
     downCounter = null,
     Counter = null;
@@ -85,6 +90,7 @@ Component({
                     value.attinfos = file.fileList(value.attinfos)
                     let image = value.attinfos.find(v => v.fileType == "image");
                     value.cover = image ? image.cover : "";
+                    value.amount = CNY(value.amount);
                     value.className = value.itemclass.length == 0 ? "暂无类目" : value.itemclass.map(v => v.itemclassname);
                     value.brandName = value.brand.length == 0 ? "暂无品牌" : value.brand.map(v => v.brandname);
                     value.discountrate = value.discountrate * 100;

+ 7 - 3
packageA/project/modules/product/list/index.js

@@ -1,3 +1,8 @@
+const currency = require("../../../../../utils/currency"),
+    CNY = value => currency(value, {
+        symbol: "¥",
+        precision: 2
+    }).format();
 Component({
     properties: {
         list: Array,
@@ -16,7 +21,6 @@ Component({
                 index
             } = e.currentTarget.dataset;
             let item = this.data.list[index];
-            console.log(e)
             if (e.detail.value <= 0) {
                 wx.showToast({
                     title: '非法数值',
@@ -25,8 +29,8 @@ Component({
             } else {
                 if (item[name] == e.detail.value) return;
                 item[name] = e.detail.value - 0;
-                if (name == "price" && item[name] > item.marketprice) item[name] = item.marketprice;
-                item.amount = item.qty * item.price;
+                if (name == "price") item[name] = item[name] > item.marketprice ? item[name] = item.marketprice : (item[name] - 0).toFixed(2) - 0;
+                item.amount = CNY(currency(item.price).multiply(item.qty));
                 let obj = {};
                 ["sa_project_itemsid", "itemid", "qty", "remarks", "marketprice", "price"].forEach(v => obj[v] = item[v]);
                 this.triggerEvent("changeQueue", obj)

+ 1 - 1
packageA/project/modules/product/list/index.wxml

@@ -25,7 +25,7 @@
                 <view class="subfield">
                     <text class="line-1" style="margin-right: 6rpx;">牌价:{{item.marketprice||' --'}}</text>
                     <view class="money line-1">
-                        总金额:<text>{{item.amount}}</text>
+                        总金额:<text>{{item.amount}}</text>
                     </view>
                 </view>
                 <view class="delete" wx:if="{{disabled}}" data-item="{{item}}" catchtap="deleteProduct">

+ 7 - 1
packageA/select/product/select.js

@@ -1,5 +1,10 @@
 const _Http = getApp().globalData.http,
-    file = require("../../../utils/matchingFeilType");
+    file = require("../../../utils/matchingFeilType"),
+    currency = require("../../../utils/currency"),
+    CNY = value => currency(value, {
+        symbol: "¥",
+        precision: 2
+    }).format();
 
 Page({
     data: {
@@ -68,6 +73,7 @@ Page({
                 value.attinfos = file.fileList(value.attinfos)
                 let image = value.attinfos.find(v => v.fileType == "image");
                 value.cover = image ? image.cover : "";
+                value.showMarketprice = CNY(value.marketprice);
                 value.className = value.itemclass.length == 0 ? "暂无类目" : value.itemclass.map(v => v.itemclassname);
                 value.brandName = value.brand.length == 0 ? "暂无品牌" : value.brand.map(v => v.brandname);
                 return value;

+ 3 - 3
packageA/select/product/select.wxml

@@ -37,13 +37,13 @@
                     产品类别:{{item.className}}
                 </view>
                 <view class="price line-1">
-                    牌价:<text class="num">¥{{item.marketprice}}</text><text>/{{item.axunitname}}</text>
+                    牌价:<text class="num">{{item.showMarketprice}}</text><text>/{{item.axunitname}}</text>
                 </view>
             </view>
         </view>
         <view class="bot">
-            <text>规格:{{item.spec||' --'}}</text>
-            <text>型号:{{item.model||' --'}}</text>
+            <text class="line-1">规格:{{item.spec||' --'}}</text>
+            <text class="line-1">型号:{{item.model||' --'}}</text>
         </view>
     </navigator>
     <view wx:if="{{!radio}}" style="height: 230rpx;" />

+ 13 - 1
packageA/setclient/modules/account/index.js

@@ -1,4 +1,9 @@
-const _Http = getApp().globalData.http;
+const _Http = getApp().globalData.http,
+    currency = require("../../../../utils/currency"),
+    CNY = value => currency(value, {
+        symbol: "¥",
+        precision: 2
+    }).format();
 
 Component({
     properties: {
@@ -40,6 +45,13 @@ Component({
                     title: res.data,
                     icon: "none"
                 })
+                if (res.data.length) res.data = res.data.map(v => {
+                    console.log(v.balance)
+                    console.log(CNY(v.balance))
+                    v.balance = CNY(v.balance);
+                    v.creditquota = CNY(v.creditquota);
+                    return v
+                })
                 this.setData({
                     list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
                     "content.pageNumber": res.pageNumber + 1,

+ 2 - 2
packageA/setclient/modules/account/index.wxml

@@ -5,7 +5,7 @@
 <view class="box" wx:for="{{list}}" wx:key="index">
     <view class="label">{{item.accountname}}</view>
     <view class="exp">账户编号:{{item.accountno}}</view>
-    <view class="exp">账户余额:{{item.balance}}</view>
-    <view class="exp">信用额度:{{item.creditquota}}</view>
+    <view class="exp">账户余额:{{item.balance}}</view>
+    <view class="exp">信用额度:{{item.creditquota}}</view>
 </view>
 <My_empty wx:if="{{!list.length}}" />

+ 1 - 1
project.private.config.json

@@ -2,7 +2,7 @@
     "projectname": "YOS_wechat",
     "setting": {
         "compileHotReLoad": true,
-        "urlCheck": true
+        "urlCheck": false
     },
     "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
     "condition": {

+ 5 - 0
utils/currency.js

@@ -0,0 +1,5 @@
+(function(e,g){"object"===typeof exports&&"undefined"!==typeof module?module.exports=g():"function"===typeof define&&define.amd?define(g):(e=e||self,e.currency=g())})(this,function(){function e(b,a){if(!(this instanceof e))return new e(b,a);a=Object.assign({},m,a);var d=Math.pow(10,a.precision);this.intValue=b=g(b,a);this.value=b/d;a.increment=a.increment||1/d;a.groups=a.useVedic?n:p;this.s=a;this.p=d}function g(b,a){var d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:!0;var c=a.decimal;
+var h=a.errorOnInvalid,k=a.fromCents,l=Math.pow(10,a.precision),f=b instanceof e;if(f&&k)return b.intValue;if("number"===typeof b||f)c=f?b.value:b;else if("string"===typeof b)h=new RegExp("[^-\\d"+c+"]","g"),c=new RegExp("\\"+c,"g"),c=(c=b.replace(/\((.*)\)/,"-$1").replace(h,"").replace(c,"."))||0;else{if(h)throw Error("Invalid Input");c=0}k||(c=(c*l).toFixed(4));return d?Math.round(c):c}var m={symbol:"$",separator:",",decimal:".",errorOnInvalid:!1,precision:2,pattern:"!#",negativePattern:"-!#",format:function(b,
+a){var d=a.pattern,c=a.negativePattern,h=a.symbol,k=a.separator,l=a.decimal;a=a.groups;var f=(""+b).replace(/^-/,"").split("."),q=f[0];f=f[1];return(0<=b.value?d:c).replace("!",h).replace("#",q.replace(a,"$1"+k)+(f?l+f:""))},fromCents:!1},p=/(\d)(?=(\d{3})+\b)/g,n=/(\d)(?=(\d\d)+\d\b)/g;e.prototype={add:function(b){var a=this.s,d=this.p;return e((this.intValue+g(b,a))/(a.fromCents?1:d),a)},subtract:function(b){var a=this.s,d=this.p;return e((this.intValue-g(b,a))/(a.fromCents?1:d),a)},multiply:function(b){var a=
+this.s;return e(this.intValue*b/(a.fromCents?1:Math.pow(10,a.precision)),a)},divide:function(b){var a=this.s;return e(this.intValue/g(b,a,!1),a)},distribute:function(b){var a=this.intValue,d=this.p,c=this.s,h=[],k=Math[0<=a?"floor":"ceil"](a/b),l=Math.abs(a-k*b);for(d=c.fromCents?1:d;0!==b;b--){var f=e(k/d,c);0<l--&&(f=f[0<=a?"add":"subtract"](1/d));h.push(f)}return h},dollars:function(){return~~this.value},cents:function(){return~~(this.intValue%this.p)},format:function(b){var a=this.s;return"function"===
+typeof b?b(this,a):a.format(this,Object.assign({},a,b))},toString:function(){var b=this.s,a=b.increment;return(Math.round(this.intValue/this.p/a)*a).toFixed(b.precision)},toJSON:function(){return this.value}};return e});