index.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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.unoutamount = CNY(v.unoutamount);
  55. v.uninvoiceamount = 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. })}`,
  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. if (res.msg == '成功') {
  112. that.getList(that.data.sa_salesforecastbillid, true)
  113. setTimeout(() => {
  114. wx.navigateBack()
  115. }, 300)
  116. }
  117. })
  118. }
  119. })
  120. },
  121. deleteItem(e) {
  122. const {
  123. item
  124. } = e.currentTarget.dataset,
  125. that = this;
  126. wx.showModal({
  127. title: '提示',
  128. content: `是否确定删除"${item.sonum}"订单`,
  129. complete: (res) => {
  130. if (res.confirm) _Http.basic({
  131. "id": 20230705145304,
  132. "content": {
  133. "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
  134. "sa_salesforecastprojectids": [item.sa_salesforecastprojectid]
  135. }
  136. }).then(res => {
  137. console.log("删除订单行", res)
  138. wx.showToast({
  139. title: res.msg == '成功' ? '删除成功' : res.msg,
  140. icon: "none"
  141. });
  142. if (res.msg == '成功') that.updateList()
  143. })
  144. }
  145. })
  146. },
  147. updateList(sonum) {
  148. let content = JSON.parse(JSON.stringify(this.data.content));
  149. if (sonum) {
  150. content.where.condition = sonum;
  151. content.pageSize = 1;
  152. } else {
  153. content.pageSize = (content.pageNumber - 1) * content.pageNumber;
  154. }
  155. content.pageNumber = 1;
  156. _Http.basic({
  157. "id": 20230705145504,
  158. content
  159. }).then(res => {
  160. console.log("更新数据", res)
  161. if (res.msg != '成功') return wx.showToast({
  162. title: res.msg,
  163. icon: "none"
  164. })
  165. res.data = res.data.map(v => {
  166. v.defaultamount = CNY(v.defaultamount);
  167. v.amount = CNY(v.amount);
  168. return v
  169. })
  170. if (sonum) {
  171. let index = this.data.list.findIndex(v => v.sonum == sonum);
  172. if (index != -1) this.setData({
  173. [`list[${index}]`]: res.data[0]
  174. })
  175. } else {
  176. this.setData({
  177. list: res.data
  178. })
  179. }
  180. if (res.data.length) this.setData({
  181. allinvoiceamount: CNY(res.data[0].allinvoiceamount),
  182. alloutamount: CNY(res.data[0].alloutamount),
  183. })
  184. })
  185. getCurrentPages()[getCurrentPages().length - 1].getDetail();
  186. },
  187. onBlur(e) {
  188. const {
  189. item,
  190. name
  191. } = e.currentTarget.dataset;
  192. let value = e.detail.value;
  193. if (item[name] == value) return;
  194. item[name] = Number((value - 0).toFixed(2))
  195. _Http.basic({
  196. "id": 20230705145204,
  197. "content": {
  198. "sa_salesforecastbillid": this.data.sa_salesforecastbillid,
  199. "sa_salesforecastprojectid": item.sa_salesforecastprojectid,
  200. "salesforecast": [{
  201. "sa_salesforecastid": item.sa_salesforecastid,
  202. "outamount": item.outamount,
  203. "invoiceamount": item.invoiceamount
  204. }]
  205. }
  206. }).then(res => {
  207. console.log("修改行", res);
  208. wx.showToast({
  209. title: res.msg == '成功' ? '修改成功' : res.msg,
  210. icon: "none"
  211. });
  212. if (res.msg == '成功') this.updateList(item.sonum)
  213. })
  214. }
  215. }
  216. })