index.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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": 2, // 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.signamount_due = CNY(v.signamount_due);
  53. return v
  54. })
  55. this.setData({
  56. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  57. sa_salesforecastbillid: id,
  58. content
  59. });
  60. if (res.data.length) {
  61. this.setData({
  62. allinvoiceamount: CNY(res.data[0].allinvoiceamount),
  63. alloutamount: CNY(res.data[0].alloutamount),
  64. })
  65. }
  66. })
  67. },
  68. add() {
  69. wx.navigateTo({
  70. url: `/packageA/select/project/select2?params=${JSON.stringify({
  71. "accesstoken": "aed8bd216339ced8fd8a7018bf63effc",
  72. "id": 20230705145604,
  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_project", // 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.projectname}"项目`,
  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(projectnum) {
  148. let content = JSON.parse(JSON.stringify(this.data.content));
  149. if (projectnum) {
  150. content.where.condition = projectnum;
  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.signamount_due = CNY(v.signamount_due);
  167. return v
  168. })
  169. if (projectnum) {
  170. let index = this.data.list.findIndex(v => v.projectnum == projectnum);
  171. if (index != -1) this.setData({
  172. [`list[${index}]`]: res.data[0]
  173. })
  174. } else {
  175. this.setData({
  176. list: res.data
  177. })
  178. }
  179. if (res.data.length) this.setData({
  180. allinvoiceamount: CNY(res.data[0].allinvoiceamount),
  181. alloutamount: CNY(res.data[0].alloutamount),
  182. })
  183. })
  184. getCurrentPages()[getCurrentPages().length - 1].getDetail();
  185. },
  186. onBlur(e) {
  187. const {
  188. item,
  189. name
  190. } = e.currentTarget.dataset;
  191. let value = e.detail.value;
  192. if (item[name] == value) return;
  193. item[name] = Number((value - 0).toFixed(2))
  194. _Http.basic({
  195. "id": 20230705145204,
  196. "content": {
  197. "sa_salesforecastbillid": this.data.sa_salesforecastbillid,
  198. "sa_salesforecastprojectid": item.sa_salesforecastprojectid,
  199. "salesforecast": [{
  200. "sa_salesforecastid": item.sa_salesforecastid,
  201. "outamount": item.outamount,
  202. "invoiceamount": item.invoiceamount
  203. }]
  204. }
  205. }).then(res => {
  206. console.log("修改项目", res);
  207. wx.showToast({
  208. title: res.msg == '成功' ? '修改成功' : res.msg,
  209. icon: "none"
  210. });
  211. if (res.msg == '成功') this.updateList(item.projectnum)
  212. })
  213. }
  214. }
  215. })