index.js 3.6 KB

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