index.js 9.2 KB

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