index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. const currency = require("../../../../../utils/currency");
  2. const _Http = getApp().globalData.http;
  3. Component({
  4. properties: {
  5. list: {
  6. type: Array
  7. },
  8. changeAmount: { //修改产品
  9. type: Function
  10. },
  11. disabled: {
  12. type: Boolean
  13. },
  14. sa_salesforecastprojectid: {
  15. type: String
  16. }
  17. },
  18. options: {
  19. addGlobalClass: true
  20. },
  21. methods: {
  22. /* 修改产品数量/单价 */
  23. onBlur(e) {
  24. let {
  25. name,
  26. index
  27. } = e.currentTarget.dataset;
  28. let item = this.data.list[index];
  29. if (e.detail.value <= 0) {
  30. wx.showToast({
  31. title: getApp().globalData.Language.getMapText('非法数值'),
  32. icon: "none"
  33. });
  34. } else {
  35. if (item[name] == e.detail.value) return;
  36. let v = e.detail.value - 0;
  37. //处理起订量和增量
  38. if (name == 'orderqty') {
  39. if (v < item.orderminqty) {
  40. wx.showToast({
  41. title: getApp().globalData.Language.getMapText('输入数量小于起订量') + item.orderminqty,
  42. icon: "none",
  43. mask: true
  44. });
  45. item.orderqty = item.orderminqty;
  46. } else if (item.orderminqty < v) {
  47. var currencyRounding = value => currency(value, {
  48. increment: item.orderaddqty
  49. });
  50. item.orderqty = currency(currencyRounding(currency(v).subtract(item.orderminqty)).format()).add(item.orderminqty).value;
  51. if (item.orderqty != v) wx.showToast({
  52. title: getApp().globalData.Language.getMapText('输入数量不符合增减量规则,已为您取最接近的值'),
  53. icon: "none",
  54. mask: true
  55. })
  56. } else {
  57. item.orderqty = v;
  58. }
  59. } else {
  60. item[name] = v;
  61. }
  62. _Http.basic({
  63. "id": 20230705145204,
  64. "content": {
  65. "sa_salesforecastbillid": item.sa_salesforecastbillid,
  66. "sa_salesforecastprojectid": this.data.sa_salesforecastprojectid,
  67. "salesforecast": [{
  68. "itemid": item.itemid,
  69. "orderqty": item.orderqty,
  70. "orderamount": item.orderqty * item.price,
  71. "price": item.price,
  72. "sa_salesforecastid": item.sa_salesforecastid
  73. }]
  74. }
  75. }).then(res => {
  76. console.log("修改产品", res)
  77. this.triggerEvent("changeAmount")
  78. })
  79. }
  80. this.data.list[index] = item;
  81. this.setData({
  82. list: this.data.list
  83. })
  84. },
  85. deleteProduct(e) {
  86. const {
  87. item
  88. } = e.currentTarget.dataset,
  89. that = this;
  90. wx.showModal({
  91. title: getApp().globalData.Language.getMapText('提示'),
  92. content: getApp().globalData.Language.getMapText('是否确认删除') + `“${item.itemname}”?`,
  93. cancelText: getApp().globalData.Language.getMapText('取消'),
  94. confirmText: getApp().globalData.Language.getMapText('确定'),
  95. complete: ({
  96. confirm
  97. }) => {
  98. if (confirm) _Http.basic({
  99. "accesstoken": "7cbf3f38611c090666f8de7b9582a6ae",
  100. "id": 20230705145404,
  101. "content": {
  102. "sa_salesforecastprojectid": this.data.sa_salesforecastprojectid,
  103. "sa_salesforecastbillid": item.sa_salesforecastbillid,
  104. "sa_salesforecastids": [item.sa_salesforecastid]
  105. }
  106. }).then(res => {
  107. console.log("删除项目产品", res)
  108. wx.showToast({
  109. title: res.code == '1' ? getApp().globalData.Language.getMapText('删除成功') : res.msg,
  110. icon: "none"
  111. })
  112. if (res.code == '1') that.triggerEvent("changeAmount")
  113. })
  114. }
  115. })
  116. },
  117. }
  118. })