index.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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": 3, // 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. return v
  53. })
  54. this.setData({
  55. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  56. sa_salesforecastbillid: id,
  57. content
  58. });
  59. if (res.data.length) this.setData({
  60. allinvoiceamount: CNY(res.data[0].allinvoiceamount),
  61. alloutamount: CNY(res.data[0].alloutamount),
  62. })
  63. })
  64. },
  65. add() {
  66. wx.navigateTo({
  67. url: `/packageA/invoiceforecast/modules/client/select?params=${JSON.stringify({
  68. "id": 20230706092404,
  69. "content": {
  70. nocache:true,
  71. "sa_salesforecastbillid": this.data.sa_salesforecastbillid,
  72. "where": {
  73. "condition": ""
  74. }
  75. }
  76. })}`,
  77. })
  78. getApp().globalData.handleSelect = this.handleAdd.bind(this);
  79. },
  80. handleAdd({
  81. result
  82. }) {
  83. const that = this;
  84. wx.showModal({
  85. title: '提示',
  86. content: `是否确定添加${result.length}个客户`,
  87. complete: (res) => {
  88. if (res.confirm) _Http.basic({
  89. "id": 20230705145104,
  90. "content": {
  91. "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
  92. "ownertable": "sa_customers", // sa_order 订单 sa_project 项目 客户
  93. "salesforecastproject": result.map(v => {
  94. return {
  95. "sa_salesforecastprojectid": 0,
  96. "ownerid": v,
  97. discountrate: 1
  98. }
  99. })
  100. }
  101. }).then(res => {
  102. console.log("添加订单", res)
  103. wx.showToast({
  104. title: res.msg == '成功' ? '添加成功' : res.msg,
  105. icon: "none"
  106. });
  107. if (res.msg == '成功') {
  108. that.getList(that.data.sa_salesforecastbillid, true)
  109. setTimeout(() => {
  110. wx.navigateBack()
  111. }, 300)
  112. }
  113. })
  114. }
  115. })
  116. },
  117. deleteItem(e) {
  118. const {
  119. item
  120. } = e.currentTarget.dataset,
  121. that = this;
  122. wx.showModal({
  123. title: '提示',
  124. content: `是否确定删除"${item.enterprisename}"客户`,
  125. complete: (res) => {
  126. if (res.confirm) _Http.basic({
  127. "id": 20230705145304,
  128. "content": {
  129. "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
  130. "sa_salesforecastprojectids": [item.sa_salesforecastprojectid]
  131. }
  132. }).then(res => {
  133. console.log("删除客户", res)
  134. wx.showToast({
  135. title: res.msg == '成功' ? '删除成功' : res.msg,
  136. icon: "none"
  137. });
  138. if (res.msg == '成功') that.updateList()
  139. })
  140. }
  141. })
  142. },
  143. updateList(sa_customersid) {
  144. let content = JSON.parse(JSON.stringify(this.data.content));
  145. if (sa_customersid) {
  146. content.where.sa_customersid = sa_customersid;
  147. content.pageSize = 1;
  148. } else {
  149. content.pageSize = (content.pageNumber - 1) * content.pageNumber;
  150. }
  151. content.pageNumber = 1;
  152. _Http.basic({
  153. "id": 20230705145504,
  154. content
  155. }).then(res => {
  156. console.log("更新数据", res)
  157. if (res.msg != '成功') return wx.showToast({
  158. title: res.msg,
  159. icon: "none"
  160. })
  161. res.data = res.data.map(v => {
  162. return v
  163. })
  164. if (sa_customersid) {
  165. let index = this.data.list.findIndex(v => v.sa_customersid == sa_customersid);
  166. if (index != -1) this.setData({
  167. [`list[${index}]`]: res.data[0]
  168. })
  169. } else {
  170. this.setData({
  171. list: res.data
  172. })
  173. }
  174. if (res.data.length) this.setData({
  175. allinvoiceamount: CNY(res.data[0].allinvoiceamount),
  176. alloutamount: CNY(res.data[0].alloutamount),
  177. })
  178. })
  179. getCurrentPages()[getCurrentPages().length - 1].getDetail();
  180. },
  181. onBlur(e) {
  182. const {
  183. item,
  184. name
  185. } = e.currentTarget.dataset;
  186. let value = e.detail.value;
  187. if (item[name] == value) return;
  188. item[name] = Number((value - 0).toFixed(2))
  189. _Http.basic({
  190. "id": 20230705145204,
  191. "content": {
  192. "sa_salesforecastbillid": this.data.sa_salesforecastbillid,
  193. "sa_salesforecastprojectid": item.sa_salesforecastprojectid,
  194. "salesforecast": [{
  195. "sa_salesforecastid": item.sa_salesforecastid,
  196. "outamount": item.outamount,
  197. "invoiceamount": item.invoiceamount
  198. }]
  199. }
  200. }).then(res => {
  201. console.log("修改行", res);
  202. wx.showToast({
  203. title: res.msg == '成功' ? '修改成功' : res.msg,
  204. icon: "none"
  205. });
  206. if (res.msg == '成功') this.updateList(item.sa_customersid)
  207. })
  208. }
  209. }
  210. })