index.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. 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.projectname}"项目`,
  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(projectnum) {
  149. let content = JSON.parse(JSON.stringify(this.data.content));
  150. if (projectnum) {
  151. content.where.condition = projectnum;
  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.signamount_due = CNY(v.signamount_due);
  168. return v
  169. })
  170. if (projectnum) {
  171. let index = this.data.list.findIndex(v => v.projectnum == projectnum);
  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. this.setData({
  181. allinvoiceamount: res.data.length ? CNY(res.data[0].allinvoiceamount) : "¥0.00",
  182. alloutamount: res.data.length ? CNY(res.data[0].alloutamount) : "¥0.00"
  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": 20230705145104,
  197. "content": {
  198. "sa_salesforecastbillid": this.data.sa_salesforecastbillid,
  199. "ownertable": "sa_project", // sa_order 订单 sa_project 项目 sa_customers 客户
  200. "salesforecastproject": [{
  201. "sa_salesforecastprojectid": item.sa_salesforecastprojectid,
  202. "ownerid": item.sa_projectid,
  203. "outamount": item.outamount,
  204. "invoiceamount": item.invoiceamount
  205. }]
  206. }
  207. }).then(res => {
  208. console.log("修改项目", res);
  209. wx.showToast({
  210. title: res.msg == '成功' ? '修改成功' : res.msg,
  211. icon: "none"
  212. });
  213. if (res.msg == '成功') this.updateList(item.projectnum)
  214. })
  215. }
  216. }
  217. })