index.js 9.7 KB

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