index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. const currency = require("../../../../../utils/currency")
  2. Component({
  3. properties: {
  4. list: {type:Array},
  5. deleteItem: {type:Function},
  6. changeQueue: {type:Function}, //修改队列
  7. disabled: {type:Boolean}
  8. },
  9. options: {
  10. addGlobalClass: true
  11. },
  12. methods: {
  13. /* 修改产品数量/单价 */
  14. onBlur(e) {
  15. let {
  16. name,
  17. index
  18. } = e.currentTarget.dataset;
  19. let item = this.data.list[index];
  20. console.log(item)
  21. if (e.detail.value <= 0) {
  22. wx.showToast({
  23. title: '非法数值',
  24. icon: "none"
  25. });
  26. } else {
  27. if (item[name] == e.detail.value) return;
  28. let v = e.detail.value - 0;
  29. //处理起订量和增量
  30. if (name == 'outqty') {
  31. if (v < item.orderminqty) {
  32. wx.showToast({
  33. title: `输入数量小于起订量${item.orderminqty}`,
  34. icon: "none",
  35. mask: true
  36. });
  37. item.outqty = item.orderminqty;
  38. } else if (item.orderminqty < v) {
  39. var currencyRounding = value => currency(value, {
  40. increment: item.orderaddqty
  41. });
  42. item.outqty = currency(currencyRounding(currency(v).subtract(item.orderminqty)).format()).add(item.orderminqty).value;
  43. if (item.outqty != v) wx.showToast({
  44. title: `输入数量不符合增减量规则,已为您取最接近的值`,
  45. icon: "none",
  46. mask: true
  47. })
  48. } else {
  49. item.outqty = v;
  50. }
  51. } else {
  52. item[name] = v;
  53. }
  54. item.outamount = item.outqty * item.price;
  55. if (name == "price" && item[name] > item.marketprice) item[name] = item.marketprice;
  56. let obj = {};
  57. ["sa_salesforecastid", "itemid", "orderqty", "orderamount", "invoiceqty", "price", "invoiceamount", "outqty"].forEach(v => obj[v] = item[v]);
  58. this.triggerEvent("changeQueue", obj)
  59. }
  60. this.data.list[index] = item;
  61. this.setData({
  62. list: this.data.list
  63. })
  64. },
  65. deleteProduct(e) {
  66. const {
  67. sa_salesforecastbillid,
  68. sa_salesforecastid,
  69. itemname
  70. } = e.currentTarget.dataset.item,
  71. that = this;
  72. wx.showModal({
  73. title: '提示',
  74. content: `是否确认删除“${itemname}”?`,
  75. complete: ({
  76. confirm
  77. }) => {
  78. if (confirm) that.triggerEvent("deleteItem", {
  79. sa_salesforecastbillid,
  80. sa_salesforecastid,
  81. sa_projectid: 0
  82. });
  83. }
  84. })
  85. },
  86. }
  87. })