| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- const currency = require("../../../../../utils/currency");
- Component({
- properties: {
- list: {
- type: Array
- },
- deleteItem: {
- type: Function
- },
- changeQueue: {
- type: Function
- }, //修改队列
- disabled: {
- type: Boolean
- }
- },
- options: {
- addGlobalClass: true
- },
- lifetimes: {
- attached: function () {
- getApp().globalData.Language.getLanguagePackage(this)
- this.setData({
- siteid: wx.getStorageSync('userMsg').siteid
- })
- }
- },
- methods: {
- onBlur(e) {
- let {
- index,
- name
- } = e.currentTarget.dataset,
- detail = name == 'qty' ? e.detail.value - 0 : (e.detail.value - 0).toFixed(2),
- item = this.data.list[index];
- switch (name) {
- case "qty":
- item.qty = detail;
- //处理起订量和增量
- if (detail < item.orderminqty) {
- wx.showToast({
- title: getApp().globalData.Language.getMapText('输入数量小于起订量') + `${item.orderminqty}`,
- icon: "none",
- mask: true
- });
- item.qty = item.orderminqty;
- } else if (item.orderminqty < detail) {
- var currencyRounding = value => currency(value, {
- increment: item.orderaddqty
- });
- item.qty = currency(currencyRounding(currency(detail).subtract(item.orderminqty)).format()).add(item.orderminqty).value;
- if (item.qty != detail) wx.showToast({
- title: getApp().globalData.Language.getMapText('输入数量不符合增减量规则,已为您取最接近的值'),
- icon: "none",
- mask: true
- })
- } else {
- item.qty = detail;
- }
- item.amount = (item.price * item.qty).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.amount = (item.price * item.qty).toFixed(2);
- 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.amount = (item.price * item.qty).toFixed(2);
- item.discountrate = this.getPercent(item.price, item.marketprice).toFixed(2);
- break;
- case "remarks":
- item.remarks = e.detail.value;
- break;
- }
- this.setData({
- [`list[${index}]`]: item
- })
- let obj = {};
- ["sa_contract_itemsid", "itemid", "price", "discountrate", "qty", "remarks", 'marketprice'].forEach(v => obj[v] = item[v]);
- obj.discountrate = (obj.discountrate / 100).toFixed(4);
- obj.showAmount = item.amount;
- 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_contract_itemsid,
- itemname
- } = e.currentTarget.dataset.item,
- that = this;
- wx.showModal({
- title: getApp().globalData.Language.getMapText('提示'),
- content: getApp().globalData.Language.getMapText('是否确认删除') + `“${itemname}”?`,
- cancelText: getApp().globalData.Language.getMapText('取消'),
- confirmText: getApp().globalData.Language.getMapText('确定'),
- complete: ({
- confirm
- }) => {
- if (confirm) that.triggerEvent("deleteItem", [sa_contract_itemsid]);
- }
- })
- },
- }
- })
|