index.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. lifetimes: {
  35. attached: function () {
  36. getApp().globalData.Language.getLanguagePackage(this)
  37. }
  38. },
  39. methods: {
  40. getList(id, init) {
  41. let content = this.data.content;
  42. content.sa_salesforecastbillid = id;
  43. if (init) content.pageNumber = 1
  44. _Http.basic({
  45. "id": 20230705145504,
  46. content
  47. }).then(res => {
  48. console.log("预测项目列表", res)
  49. if (res.code != '1') return wx.showToast({
  50. title: res.data,
  51. icon: "none"
  52. })
  53. content.total = res.total;
  54. content.pageNumber = res.pageNumber + 1;
  55. content.pageTotal = res.pageTotal;
  56. res.data = res.data.map(v => {
  57. v.signamount_due = CNY(v.signamount_due);
  58. return v
  59. })
  60. this.setData({
  61. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  62. sa_salesforecastbillid: id,
  63. content
  64. });
  65. if (res.data.length) {
  66. this.setData({
  67. allinvoiceamount: CNY(res.data[0].allinvoiceamount),
  68. alloutamount: CNY(res.data[0].alloutamount),
  69. })
  70. }
  71. })
  72. },
  73. add() {
  74. wx.navigateTo({
  75. url: `/packageA/select/project/select2?params=${JSON.stringify({
  76. "id": 20230705145604,
  77. "content": {
  78. nocache: true,
  79. "sa_salesforecastbillid": this.data.sa_salesforecastbillid,
  80. "where": {
  81. "condition": ""
  82. }
  83. }
  84. })}`,
  85. })
  86. getApp().globalData.handleSelect = this.handleAdd.bind(this);
  87. },
  88. handleAdd({
  89. result
  90. }) {
  91. const that = this;
  92. wx.showModal({
  93. title: getApp().globalData.Language.getMapText('提示'),
  94. content: getApp().globalData.Language.joint([{
  95. t: 1,
  96. v: '是否确认添加',
  97. r: " "
  98. }, {
  99. v: result.length,
  100. r: " "
  101. }, {
  102. t: 1,
  103. v: '个项目',
  104. r: "?"
  105. }]),
  106. cancelText: getApp().globalData.Language.getMapText('取消'),
  107. confirmText: getApp().globalData.Language.getMapText('确定'),
  108. complete: (res) => {
  109. if (res.confirm) _Http.basic({
  110. "id": 20230705145104,
  111. "content": {
  112. "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
  113. "ownertable": "sa_project", // sa_order 订单 sa_project 项目 sa_customers 客户
  114. "salesforecastproject": result.map(v => {
  115. return {
  116. "sa_salesforecastprojectid": 0,
  117. "ownerid": v,
  118. discountrate: 1
  119. }
  120. })
  121. }
  122. }).then(res => {
  123. console.log("添加项目", res)
  124. wx.showToast({
  125. title: res.code == '1' ? getApp().globalData.Language.getMapText('添加成功') : res.msg,
  126. icon: "none"
  127. });
  128. getCurrentPages()[getCurrentPages().length - 2].getDetail();
  129. if (res.code == '1') {
  130. that.getList(that.data.sa_salesforecastbillid, true)
  131. setTimeout(() => {
  132. wx.navigateBack()
  133. }, 300)
  134. }
  135. })
  136. }
  137. })
  138. },
  139. deleteItem(e) {
  140. const {
  141. item
  142. } = e.currentTarget.dataset,
  143. that = this;
  144. wx.showModal({
  145. title: getApp().globalData.Language.getMapText('提示'),
  146. content: getApp().globalData.Language.getMapText('是否确定删除') + `"${item.projectname}"` + getApp().globalData.Language.getMapText('项目'),
  147. cancelText: getApp().globalData.Language.getMapText('取消'),
  148. confirmText: getApp().globalData.Language.getMapText('确定'),
  149. complete: (res) => {
  150. if (res.confirm) _Http.basic({
  151. "id": 20230705145304,
  152. "content": {
  153. "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
  154. "sa_salesforecastprojectids": [item.sa_salesforecastprojectid]
  155. }
  156. }).then(res => {
  157. console.log("删除项目", res)
  158. wx.showToast({
  159. title: res.code == '1' ? getApp().globalData.Language.getMapText('删除成功') : res.msg,
  160. icon: "none"
  161. });
  162. if (res.code == '1') that.updateList()
  163. })
  164. }
  165. })
  166. },
  167. updateList(projectnum) {
  168. let content = JSON.parse(JSON.stringify(this.data.content));
  169. if (projectnum) {
  170. content.where.condition = projectnum;
  171. content.pageSize = 1;
  172. } else {
  173. content.pageSize = (content.pageNumber - 1) * content.pageNumber;
  174. }
  175. content.pageNumber = 1;
  176. _Http.basic({
  177. "id": 20230705145504,
  178. content
  179. }).then(res => {
  180. console.log("更新数据", res)
  181. if (res.code != '1') return wx.showToast({
  182. title: res.msg,
  183. icon: "none"
  184. })
  185. res.data = res.data.map(v => {
  186. v.signamount_due = CNY(v.signamount_due);
  187. return v
  188. })
  189. if (projectnum) {
  190. let index = this.data.list.findIndex(v => v.projectnum == projectnum);
  191. if (index != -1) this.setData({
  192. [`list[${index}]`]: res.data[0]
  193. })
  194. } else {
  195. this.setData({
  196. list: res.data
  197. })
  198. }
  199. this.setData({
  200. allinvoiceamount: res.data.length ? CNY(res.data[0].allinvoiceamount) : "¥0.00",
  201. alloutamount: res.data.length ? CNY(res.data[0].alloutamount) : "¥0.00"
  202. })
  203. })
  204. getCurrentPages()[getCurrentPages().length - 1].getDetail();
  205. },
  206. onBlur(e) {
  207. const {
  208. item,
  209. name
  210. } = e.currentTarget.dataset;
  211. let value = e.detail.value;
  212. if (item[name] == value) return;
  213. item[name] = Number((value - 0).toFixed(2))
  214. _Http.basic({
  215. "id": 20230705145104,
  216. "content": {
  217. "sa_salesforecastbillid": this.data.sa_salesforecastbillid,
  218. "ownertable": "sa_project", // sa_order 订单 sa_project 项目 sa_customers 客户
  219. "salesforecastproject": [{
  220. "sa_salesforecastprojectid": item.sa_salesforecastprojectid,
  221. "ownerid": item.sa_projectid,
  222. "outamount": item.outamount,
  223. "invoiceamount": item.invoiceamount
  224. }]
  225. }
  226. }).then(res => {
  227. console.log("修改项目", res);
  228. wx.showToast({
  229. title: res.code == '1' ? getApp().globalData.Language.getMapText('修改成功') : res.msg,
  230. icon: "none"
  231. });
  232. if (res.code == '1') this.updateList(item.projectnum)
  233. })
  234. }
  235. }
  236. })