index.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. const _Http = getApp().globalData.http,
  2. currency = require("../../../../utils/currency"),
  3. file = require("../../../../utils/matchingFeilType"),
  4. CNY = value => currency(value, {
  5. symbol: "¥",
  6. precision: 2
  7. }).format();
  8. Component({
  9. properties: {
  10. disabled: {
  11. type: Boolean
  12. },
  13. toAdd: {
  14. type: Function
  15. }
  16. },
  17. options: {
  18. addGlobalClass: true
  19. },
  20. data: {
  21. sa_salesforecastbillid: 0,
  22. list: [],
  23. sa_projectid: 0,
  24. "content": {
  25. "nocache": true,
  26. pageSize: 9999,
  27. "total": null,
  28. "where": {
  29. "condition": ""
  30. }
  31. },
  32. project: null
  33. },
  34. methods: {
  35. getList(id, init, update = false) {
  36. let content = this.data.content;
  37. content.sa_salesforecastbillid = id;
  38. content.where.condition = update ? this.data.project.projectnum : "";
  39. _Http.basic({
  40. "id": 20230705144904,
  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. res.data = res.data.map(v => {
  49. v.zk = currency(v.discountrate).multiply(100).value;
  50. v.shouAmount = CNY(v.sumprojectamount)
  51. return v
  52. });
  53. if (update) {
  54. const index = this.data.list.findIndex(v => v.projectnum == this.data.project.projectnum);
  55. if (index != -1) {
  56. this.setData({
  57. [`list[${index}]`]: res.data[0],
  58. project: res.data[0]
  59. });
  60. this.getProduct();
  61. }
  62. } else {
  63. content.total = res.total;
  64. this.setData({
  65. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  66. content
  67. });
  68. if (res.data.length) {
  69. this.setData({
  70. sa_projectid: res.data[0].sa_projectid,
  71. project: res.data[0]
  72. });
  73. this.getProduct();
  74. } else {
  75. this.setData({
  76. sa_projectid: 0,
  77. project: null
  78. })
  79. }
  80. }
  81. this.setData({
  82. sa_salesforecastbillid: id
  83. })
  84. })
  85. },
  86. onChange({
  87. detail
  88. }) {
  89. this.setData({
  90. sa_projectid: detail.name,
  91. project: this.data.list[detail.index]
  92. });
  93. this.getProduct();
  94. },
  95. addProject() {
  96. this.triggerEvent("toAdd")
  97. },
  98. /* 折扣失焦 */
  99. onBlur(e) {
  100. let zk = e.detail.value,
  101. project = JSON.parse(JSON.stringify(this.data.project));
  102. if (zk > 100) {
  103. zk = 100
  104. } else if (zk < 0.01) {
  105. zk = project.zk;
  106. wx.showToast({
  107. title: '折扣过小',
  108. icon: "none"
  109. })
  110. }
  111. if (zk == project.zk) return;
  112. project.zk = currency(zk).multiply(1).value;
  113. project.discountrate = currency(zk, {
  114. precision: 4
  115. }).divide(100).value;
  116. _Http.basic({
  117. id: 20230705145104,
  118. content: {
  119. sa_salesforecastbillid: this.data.sa_salesforecastbillid,
  120. "ownertable": "sa_project",
  121. salesforecastproject: [{
  122. ownerid: project.sa_projectid,
  123. ownertable: "sa_project",
  124. discountrate: project.discountrate,
  125. sa_salesforecastprojectid: project.sa_salesforecastprojectid
  126. }]
  127. }
  128. }).then(res => {
  129. console.log("修改项目折扣", res)
  130. wx.showToast({
  131. title: res.msg == '成功' ? '折扣修改成功' : res.msg,
  132. icon: "none"
  133. })
  134. if (res.msg == '成功') this.updateAmount();
  135. })
  136. },
  137. getProduct() {
  138. _Http.basic({
  139. "id": 20230705145004,
  140. "content": {
  141. nocache: true,
  142. "sa_salesforecastprojectid": this.data.project.sa_salesforecastprojectid,
  143. "sa_salesforecastbillid": this.data.project.sa_salesforecastbillid,
  144. pageSize: 9999,
  145. "where": {
  146. "condition": ""
  147. }
  148. }
  149. }).then(res => {
  150. if (res.msg != '成功') return wx.showToast({
  151. title: res.data,
  152. icon: "none"
  153. })
  154. console.log("产品", res)
  155. this.setData({
  156. productList: res.data.map(value => {
  157. if (value.attinfos.length != 0) {
  158. value.attinfos = file.fileList(value.attinfos)
  159. let image = value.attinfos.find(v => v.fileType == "image");
  160. value.cover = image ? image.cover : "";
  161. }
  162. value.className = value.itemclass.length == 0 ? "暂无类目" : value.itemclass.map(v => v.itemclassname);
  163. value.brandName = value.brand.length == 0 ? "暂无品牌" : value.brand.map(v => v.brandname);
  164. value.showMP = CNY(value.marketprice)
  165. value.showOrderamount = CNY(value.orderamount)
  166. return value
  167. })
  168. })
  169. })
  170. },
  171. toAddProduct() {
  172. let project = this.data.project;
  173. wx.navigateTo({
  174. url: `/packageA/select/product/select?params=${JSON.stringify({
  175. "accesstoken": "1ede5d2594d778a5e652b5a267c90308",
  176. "id": 20230705145704,
  177. "content": {
  178. "pageNumber": 1,
  179. "pageSize": 20,
  180. "sa_salesforecastbillid":project.sa_salesforecastbillid,
  181. "sa_salesforecastprojectid":project.sa_salesforecastprojectid,
  182. "sa_projectid":project.sa_projectid,
  183. "where": {
  184. "condition": ""
  185. }
  186. }
  187. })}`,
  188. });
  189. getApp().globalData.handleSelect = this.handleAdd.bind(this);
  190. },
  191. handleAdd({
  192. list
  193. }) {
  194. let that = this,
  195. project = this.data.project;
  196. console.log(list)
  197. wx.showModal({
  198. title: '提示',
  199. content: `是否确认添加${list.length}件产品`,
  200. complete: (res) => {
  201. if (res.confirm) _Http.basic({
  202. "id": 20230705145204,
  203. "content": {
  204. "sa_salesforecastbillid": project.sa_salesforecastbillid,
  205. "sa_salesforecastprojectid": project.sa_salesforecastprojectid,
  206. "salesforecast": list.map(v => {
  207. return {
  208. "itemid": v.itemid,
  209. "orderqty": v.qty,
  210. "orderamount": v.qty * v.price,
  211. "price": v.price,
  212. "sa_salesforecastid": 0
  213. }
  214. })
  215. }
  216. }).then(res => {
  217. console.log("添加产品", res)
  218. if (res.msg != '成功') return wx.showToast({
  219. title: res.data,
  220. icon: "none"
  221. });
  222. wx.showToast({
  223. title: '添加成功',
  224. icon: "none",
  225. mask: true
  226. });
  227. setTimeout(() => {
  228. wx.navigateBack()
  229. that.updateAmount()
  230. }, 300)
  231. })
  232. }
  233. })
  234. },
  235. /* 更新金额 */
  236. updateAmount() {
  237. const page = getCurrentPages().find(v => v.__route__ == 'packageA/finishforecast/detail');
  238. if (page) page.getDetail();
  239. this.getList(this.data.sa_salesforecastbillid, true, true)
  240. },
  241. }
  242. })