index.js 9.7 KB

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