index.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. const _Http = getApp().globalData.http,
  2. currency = require("../../../../utils/currency"),
  3. CNY = value => currency(value, {
  4. symbol: "¥",
  5. precision: 2
  6. }).format();
  7. Component({
  8. properties: {
  9. disabled: {
  10. type: Boolean
  11. }, //禁用
  12. },
  13. options: {
  14. addGlobalClass: true
  15. },
  16. data: {
  17. sa_salesforecastbillid: 0,
  18. list: [],
  19. sa_projectid: 0,
  20. allinvoiceamount: "",
  21. alloutamount: "",
  22. "content": {
  23. "nocache": true,
  24. "pageNumber": 1,
  25. "pageTotal": 1,
  26. "pageSize": 20,
  27. "type": 1, // 1 订单 2项目 3客户
  28. "total": null,
  29. "where": {
  30. "condition": ""
  31. }
  32. },
  33. },
  34. methods: {
  35. getList(id, init) {
  36. let content = this.data.content;
  37. content.sa_salesforecastbillid = id;
  38. if (init) content.pageNumber = 1
  39. _Http.basic({
  40. "id": 20230705145504,
  41. content
  42. }).then(res => {
  43. console.log("预测订单列表", res)
  44. if (res.msg != '成功') return wx.showToast({
  45. title: res.data,
  46. icon: "none"
  47. })
  48. content.total = res.total;
  49. content.pageNumber = res.pageNumber + 1;
  50. content.pageTotal = res.pageTotal;
  51. res.data = res.data.map(v => {
  52. v.defaultamount = CNY(v.defaultamount);
  53. v.amount = CNY(v.amount);
  54. v.showunoutamount = CNY(v.unoutamount);
  55. v.showuninvoiceamount = CNY(v.uninvoiceamount);
  56. return v
  57. })
  58. this.setData({
  59. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  60. sa_salesforecastbillid: id,
  61. content
  62. });
  63. if (res.data.length) this.setData({
  64. allinvoiceamount: CNY(res.data[0].allinvoiceamount),
  65. alloutamount: CNY(res.data[0].alloutamount),
  66. })
  67. })
  68. },
  69. add() {
  70. wx.navigateTo({
  71. url: `/packageA/select/orderForm/select?params=${JSON.stringify({
  72. "id": 20230706090904,
  73. "content": {
  74. nocache: true,
  75. "sa_salesforecastbillid": this.data.sa_salesforecastbillid,
  76. "where": {
  77. "condition": ""
  78. }
  79. }
  80. })}&aitText=暂无数据,请添加订单明细`,
  81. })
  82. getApp().globalData.handleSelect = this.handleAdd.bind(this);
  83. },
  84. handleAdd({
  85. result
  86. }) {
  87. const that = this;
  88. wx.showModal({
  89. title: '提示',
  90. content: `是否确定添加${result.length}个订单`,
  91. complete: (res) => {
  92. if (res.confirm) _Http.basic({
  93. "id": 20230705145104,
  94. "content": {
  95. "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
  96. "ownertable": "sa_order", // sa_order 订单 sa_project 项目 sa_customers 客户
  97. "salesforecastproject": result.map(v => {
  98. return {
  99. "sa_salesforecastprojectid": 0,
  100. "ownerid": v,
  101. discountrate: 1
  102. }
  103. })
  104. }
  105. }).then(res => {
  106. console.log("添加订单", res)
  107. wx.showToast({
  108. title: res.msg == '成功' ? '添加成功' : res.msg,
  109. icon: "none"
  110. });
  111. getCurrentPages()[getCurrentPages().length - 2].getDetail();
  112. if (res.msg == '成功') {
  113. that.getList(that.data.sa_salesforecastbillid, true)
  114. setTimeout(() => {
  115. wx.navigateBack()
  116. }, 300)
  117. }
  118. })
  119. }
  120. })
  121. },
  122. deleteItem(e) {
  123. const {
  124. item
  125. } = e.currentTarget.dataset,
  126. that = this;
  127. wx.showModal({
  128. title: '提示',
  129. content: `是否确定删除"${item.sonum}"订单`,
  130. complete: (res) => {
  131. if (res.confirm) _Http.basic({
  132. "id": 20230705145304,
  133. "content": {
  134. "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
  135. "sa_salesforecastprojectids": [item.sa_salesforecastprojectid]
  136. }
  137. }).then(res => {
  138. console.log("删除订单行", res)
  139. wx.showToast({
  140. title: res.msg == '成功' ? '删除成功' : res.msg,
  141. icon: "none"
  142. });
  143. if (res.msg == '成功') that.updateList()
  144. })
  145. }
  146. })
  147. },
  148. updateList(sonum) {
  149. let content = JSON.parse(JSON.stringify(this.data.content));
  150. if (sonum) {
  151. content.where.condition = sonum;
  152. content.pageSize = 1;
  153. } else {
  154. content.pageSize = (content.pageNumber - 1) * content.pageNumber;
  155. }
  156. content.pageNumber = 1;
  157. _Http.basic({
  158. "id": 20230705145504,
  159. content
  160. }).then(res => {
  161. console.log("更新数据", res)
  162. if (res.msg != '成功') return wx.showToast({
  163. title: res.msg,
  164. icon: "none"
  165. })
  166. res.data = res.data.map(v => {
  167. v.defaultamount = CNY(v.defaultamount);
  168. v.amount = CNY(v.amount);
  169. v.showunoutamount = CNY(v.unoutamount);
  170. v.showuninvoiceamount = CNY(v.uninvoiceamount);
  171. return v
  172. })
  173. if (sonum) {
  174. let index = this.data.list.findIndex(v => v.sonum == sonum);
  175. if (index != -1) this.setData({
  176. [`list[${index}]`]: res.data[0]
  177. })
  178. } else {
  179. this.setData({
  180. list: res.data
  181. })
  182. }
  183. this.setData({
  184. allinvoiceamount: res.data.length ? CNY(res.data[0].allinvoiceamount) : CNY(0),
  185. alloutamount: res.data.length ? CNY(res.data[0].alloutamount) : CNY(0),
  186. })
  187. })
  188. getCurrentPages()[getCurrentPages().length - 1].getDetail();
  189. },
  190. onBlur(e) {
  191. const {
  192. item,
  193. name
  194. } = e.currentTarget.dataset;
  195. let value = e.detail.value;
  196. if (item[name] == value) return;
  197. item[name] = Number((value - 0).toFixed(2))
  198. _Http.basic({
  199. "id": 20230705145104,
  200. "content": {
  201. "sa_salesforecastbillid": this.data.sa_salesforecastbillid,
  202. "ownertable": "sa_order", // sa_order 订单 sa_project 项目 sa_customers 客户
  203. "salesforecastproject": [{
  204. "sa_salesforecastprojectid": item.sa_salesforecastprojectid || 0,
  205. "sa_salesforecastid": item.sa_salesforecastid || 0,
  206. "outamount": item.outamount,
  207. "ownerid": item.sa_orderid,
  208. "invoiceamount": item.invoiceamount
  209. }]
  210. }
  211. }).then(res => {
  212. console.log("修改行", res);
  213. wx.showToast({
  214. title: res.msg == '成功' ? '修改成功' : res.msg,
  215. icon: "none"
  216. });
  217. if (res.msg == '成功') this.updateList(item.sonum)
  218. })
  219. }
  220. }
  221. })