index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. lifetimes: {
  21. attached: function () {
  22. getApp().globalData.Language.getLanguagePackage(this)
  23. this.setData({
  24. siteid: wx.getStorageSync('userMsg').siteid
  25. })
  26. }
  27. },
  28. methods: {
  29. onBlur(e) {
  30. let {
  31. index,
  32. name
  33. } = e.currentTarget.dataset,
  34. detail = name == 'qty' ? e.detail.value - 0 : (e.detail.value - 0).toFixed(2),
  35. item = this.data.list[index];
  36. switch (name) {
  37. case "qty":
  38. item.qty = detail;
  39. //处理起订量和增量
  40. if (detail < item.orderminqty) {
  41. wx.showToast({
  42. title: getApp().globalData.Language.getMapText('输入数量小于起订量') + `${item.orderminqty}`,
  43. icon: "none",
  44. mask: true
  45. });
  46. item.qty = item.orderminqty;
  47. } else if (item.orderminqty < detail) {
  48. var currencyRounding = value => currency(value, {
  49. increment: item.orderaddqty
  50. });
  51. item.qty = currency(currencyRounding(currency(detail).subtract(item.orderminqty)).format()).add(item.orderminqty).value;
  52. if (item.qty != detail) wx.showToast({
  53. title: getApp().globalData.Language.getMapText('输入数量不符合增减量规则,已为您取最接近的值'),
  54. icon: "none",
  55. mask: true
  56. })
  57. } else {
  58. item.qty = detail;
  59. }
  60. item.amount = (item.price * item.qty).toFixed(2);
  61. break;
  62. case "discountrate":
  63. /* if (detail >= 100) {
  64. item.discountrate = 100
  65. } else */
  66. if (detail <= 0) {
  67. item.discountrate = 1
  68. } else {
  69. item.discountrate = detail;
  70. }
  71. //改变折扣 重新计算现价和总价
  72. item.price = (item.marketprice * (item.discountrate / 100) - 0).toFixed(2);
  73. item.amount = (item.price * item.qty).toFixed(2);
  74. break;
  75. case "price":
  76. /* if (detail >= item.marketprice) {
  77. item.price = item.marketprice
  78. } else */
  79. if (detail <= 0) {
  80. item.discountrate = 1;
  81. item.price = (item.marketprice * (item.discountrate / 100) - 0).toFixed(2);
  82. } else {
  83. item.price = detail;
  84. }
  85. //改变现价 重新计算总价和折扣
  86. item.amount = (item.price * item.qty).toFixed(2);
  87. item.discountrate = this.getPercent(item.price, item.marketprice).toFixed(2);
  88. break;
  89. case "remarks":
  90. item.remarks = e.detail.value;
  91. break;
  92. }
  93. this.setData({
  94. [`list[${index}]`]: item
  95. })
  96. let obj = {};
  97. ["sa_contract_itemsid", "itemid", "price", "discountrate", "qty", "remarks", 'marketprice'].forEach(v => obj[v] = item[v]);
  98. obj.discountrate = (obj.discountrate / 100).toFixed(4);
  99. obj.showAmount = item.amount;
  100. this.triggerEvent("changeQueue", obj)
  101. },
  102. /* 计算百分比 */
  103. getPercent(num, total) {
  104. num = parseFloat(num);
  105. total = parseFloat(total);
  106. if (isNaN(num) || isNaN(total)) {
  107. return "-";
  108. }
  109. return total <= 0 ? "0%" : Math.round((num / total) * 10000) / 100;
  110. },
  111. deleteProduct(e) {
  112. const {
  113. sa_contract_itemsid,
  114. itemname
  115. } = e.currentTarget.dataset.item,
  116. that = this;
  117. wx.showModal({
  118. title: getApp().globalData.Language.getMapText('提示'),
  119. content: getApp().globalData.Language.getMapText('是否确认删除') + `“${itemname}”?`,
  120. cancelText: getApp().globalData.Language.getMapText('取消'),
  121. confirmText: getApp().globalData.Language.getMapText('确定'),
  122. complete: ({
  123. confirm
  124. }) => {
  125. if (confirm) that.triggerEvent("deleteItem", [sa_contract_itemsid]);
  126. }
  127. })
  128. },
  129. }
  130. })