|
|
@@ -1,11 +1,87 @@
|
|
|
Component({
|
|
|
properties: {
|
|
|
- list: Array
|
|
|
+ list: Array,
|
|
|
+ deleteItem: Function,
|
|
|
+ changeQueue: Function, //修改队列
|
|
|
+ disabled: Boolean
|
|
|
},
|
|
|
- data: {
|
|
|
-
|
|
|
+ options: {
|
|
|
+ addGlobalClass: true
|
|
|
},
|
|
|
methods: {
|
|
|
-
|
|
|
+ onBlur(e) {
|
|
|
+ let {
|
|
|
+ index,
|
|
|
+ name
|
|
|
+ } = e.currentTarget.dataset,
|
|
|
+ detail = name == 'outqty' ? e.detail.value - 0 : (e.detail.value - 0).toFixed(2),
|
|
|
+ item = this.data.list[index];
|
|
|
+ switch (name) {
|
|
|
+ case "outqty":
|
|
|
+ item.outqty = detail;
|
|
|
+ //改变数量 现数量*现价
|
|
|
+ item.outamount = (item.price * item.outqty).toFixed(2);
|
|
|
+ break;
|
|
|
+ case "discountrate":
|
|
|
+ if (detail >= 100) {
|
|
|
+ item.discountrate = 100
|
|
|
+ } else if (detail <= 0) {
|
|
|
+ item.discountrate = 1
|
|
|
+ } else {
|
|
|
+ item.discountrate = detail;
|
|
|
+ }
|
|
|
+ //改变折扣 重新计算现价和总价
|
|
|
+ item.price = (item.marketprice * (item.discountrate / 100) - 0).toFixed(2);
|
|
|
+ item.outamount = (item.price * item.outqty).toFixed(2);
|
|
|
+ console.log(item.price)
|
|
|
+ break;
|
|
|
+ case "price":
|
|
|
+ if (detail >= item.marketprice) {
|
|
|
+ item.price = item.marketprice
|
|
|
+ } else if (detail <= 0) {
|
|
|
+ item.discountrate = 1;
|
|
|
+ item.price = (item.marketprice * (item.discountrate / 100) - 0).toFixed(2);
|
|
|
+ } else {
|
|
|
+ item.price = detail;
|
|
|
+ }
|
|
|
+ //改变现价 重新计算总价和折扣
|
|
|
+ item.outamount = (item.price * item.outqty).toFixed(2);
|
|
|
+ item.discountrate = this.getPercent(item.price, item.marketprice).toFixed(2);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ [`list[${index}]`]: item
|
|
|
+ })
|
|
|
+ let obj = {};
|
|
|
+ ["sa_quotedprice_itemsid", "itemid", "oldprice", "price", "discountrate", "outqty"].forEach(v => obj[v] = item[v]);
|
|
|
+ obj.discountrate = (obj.discountrate / 100).toFixed(4);
|
|
|
+ if (name != 'outqty') obj.price = 0;
|
|
|
+ this.triggerEvent("changeQueue", obj)
|
|
|
+ },
|
|
|
+ /* 计算百分比 */
|
|
|
+ getPercent(num, total) {
|
|
|
+ num = parseFloat(num);
|
|
|
+ total = parseFloat(total);
|
|
|
+ if (isNaN(num) || isNaN(total)) {
|
|
|
+ return "-";
|
|
|
+ }
|
|
|
+ return total <= 0 ? "0%" : Math.round((num / total) * 10000) / 100;
|
|
|
+ },
|
|
|
+ deleteProduct(e) {
|
|
|
+ const {
|
|
|
+ sa_quotedprice_itemsid,
|
|
|
+ itemname
|
|
|
+ } = e.currentTarget.dataset.item,
|
|
|
+ that = this;
|
|
|
+ wx.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: `是否确认删除“${itemname}”?`,
|
|
|
+ complete: ({
|
|
|
+ confirm
|
|
|
+ }) => {
|
|
|
+ if (confirm) that.triggerEvent("deleteItem", [sa_quotedprice_itemsid]);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
}
|
|
|
})
|