index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. const _Http = getApp().globalData.http,
  2. file = require("../../../../utils/matchingFeilType");
  3. let Counter = null;
  4. Component({
  5. properties: {
  6. disabled: Boolean, //禁用
  7. },
  8. data: {
  9. viewIndex: 0,
  10. sa_salesforecastbillid: 0,
  11. "content": {
  12. nocache: true,
  13. pageSize: 999,
  14. total: null,
  15. "where": {
  16. "condition": ""
  17. }
  18. },
  19. param: {
  20. "id": 20220906154703,
  21. "version": 1,
  22. "content": {
  23. nocache: true,
  24. "sa_salesforecastbillid": "",
  25. pageNumber: 1,
  26. pageTotal: 1,
  27. "where": {
  28. "condition": "",
  29. "sa_projectid": ""
  30. }
  31. }
  32. },
  33. productList: [], //产品列表
  34. },
  35. methods: {
  36. /* 步进器数值改变 */
  37. stepperChange(e) {
  38. let discountrate = this.data.list[this.data.viewIndex].discountrate;
  39. switch (e.type) {
  40. case 'plus':
  41. discountrate += 1;
  42. break;
  43. case 'minus':
  44. discountrate -= 1;
  45. break;
  46. case 'blur':
  47. discountrate = e.detail.value;
  48. break;
  49. }
  50. if (discountrate > 100) discountrate = 100;
  51. if (discountrate < 0.1) discountrate = 0.1;
  52. this.data.list[this.data.viewIndex].discountrate = discountrate;
  53. this.setDiscountrate(this.data.list[this.data.viewIndex]);
  54. },
  55. /* 设置折扣 */
  56. setDiscountrate(item) {
  57. clearTimeout(Counter);
  58. let page = getCurrentPages().find(v => v.__route__ == 'packageA/salesForecasting/detail');
  59. let data = page.data.detail;
  60. Counter = setTimeout(() => {
  61. _Http.basic({
  62. id: 20220913154403,
  63. version: 1,
  64. content: {
  65. nocache: true,
  66. sa_salesforecastmodelid: data.sa_salesforecastmodelid,
  67. sa_salesforecastbillid: data.sa_salesforecastbillid,
  68. sa_projectids: [{
  69. sa_salesforecastprojectid: data.sa_salesforecastprojectid || item.sa_salesforecastprojectid,
  70. sa_projectid: item.sa_projectid,
  71. discountrate: (item.discountrate / 100).toFixed(4)
  72. }]
  73. }
  74. }).then(res => {
  75. console.log("修改折扣", res)
  76. if (res.msg != '成功') wx.showToast({
  77. title: res.msg,
  78. icon: "none"
  79. });
  80. page.getDetail(true);
  81. })
  82. }, 300)
  83. },
  84. /* 获取项目列表 */
  85. getList(id, init = false, isAdd = false) {
  86. let content = this.data.content;
  87. content.sa_salesforecastbillid = id;
  88. _Http.basic({
  89. "id": "20220916115203",
  90. "version": 1,
  91. content
  92. }).then(res => {
  93. console.log("项目清单", res)
  94. if (res.msg != '成功') return wx.showToast({
  95. title: res.data,
  96. icon: "none"
  97. })
  98. let page = getCurrentPages().find(v => v.__route__ == 'packageA/salesForecasting/detail');
  99. res.data = res.data.map(v => {
  100. v.discountrate = v.discountrate * 100;
  101. if (v.discountrate > 100) v.discountrate = 100;
  102. return v
  103. })
  104. this.setData({
  105. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  106. "content.total": res.total,
  107. sa_salesforecastbillid: id,
  108. sa_salesforecastmodelid: page.data.detail.sa_salesforecastmodelid
  109. });
  110. if (res.data.length) {
  111. this.setData({
  112. 'param.content.where.sa_projectid': res.data[isAdd ? res.data.length - 1 : this.data.viewIndex].sa_projectid,
  113. 'param.content.sa_salesforecastbillid': id,
  114. viewIndex: isAdd ? res.data.length - 1 : this.data.viewIndex
  115. })
  116. this.getProduct(true);
  117. }
  118. })
  119. },
  120. /* 获取产品清单 */
  121. getProduct(init = false) {
  122. let param = this.data.param;
  123. if (init) param.content.pageNumber = 1;
  124. if (param.content.pageNumber > param.content.pageTotal) return;
  125. _Http.basic(param).then(res => {
  126. console.log("产品列表", res)
  127. if (res.msg != '成功') return wx.showToast({
  128. title: res.msg,
  129. icon: "none"
  130. });
  131. if (res.data.length == 1 && !res.data[0].itemname) {
  132. res.data = []
  133. } else {
  134. res.data = res.data.map(value => {
  135. if (value.attinfos.length != 0) {
  136. value.attinfos = file.fileList(value.attinfos)
  137. let image = value.attinfos.find(v => v.fileType == "image");
  138. value.cover = image ? image.cover : "";
  139. }
  140. value.className = [];
  141. value.brandName = [];
  142. if (value.temclass.length != 0) value.temclass.forEach(v => {
  143. if (v.brandname != "") value.brandName.push(v.brandname);
  144. if (v.itemclassname != "") value.className.push(v.itemclassname);
  145. })
  146. return value;
  147. })
  148. }
  149. this.setData({
  150. productList: res.pageNumber == 1 ? res.data : this.data.productList.concat(res.data),
  151. "param.content.pageNumber": res.pageNumber + 1,
  152. "param.content.pageTotal": res.pageTotal,
  153. })
  154. })
  155. },
  156. /* 切换tab */
  157. onChange(e) {
  158. this.setData({
  159. "param.content.where.sa_projectid": e.detail.name,
  160. viewIndex: e.detail.index,
  161. });
  162. this.getProduct(true);
  163. },
  164. /* 添加产品 */
  165. addProduct() {
  166. wx.navigateTo({
  167. url: `/packageA/select/product/select?params=${JSON.stringify({
  168. id: 20221208105403,
  169. version: 1,
  170. content: {
  171. nocache:true,
  172. sa_projectid: this.data.param.content.where.sa_projectid,
  173. sa_salesforecastbillid: this.data.sa_salesforecastbillid,
  174. "where": {
  175. "condition": ""
  176. }
  177. }
  178. })}`
  179. });
  180. getApp().globalData.handleSelect = this.handleaddProduct.bind(this);
  181. },
  182. handleaddProduct({
  183. list
  184. }) {
  185. const that = this;
  186. wx.showModal({
  187. title: '提示',
  188. content: `是否确认添加${list.length}件产品`,
  189. complete: ({
  190. confirm
  191. }) => {
  192. if (confirm) _Http.basic({
  193. "id": 20220906155003,
  194. "version": 1,
  195. "content": {
  196. "sa_salesforecastmodelid": that.data.sa_salesforecastmodelid,
  197. "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
  198. "sa_projectid": that.data.param.content.where.sa_projectid,
  199. itemclassinfos: list.map(v => {
  200. return {
  201. "sa_salesforecastid": 0,
  202. "itemid": v.itemid,
  203. "orderqty": 0,
  204. "orderamount": 0,
  205. "invoiceqty": 0,
  206. "invoiceamount": 0,
  207. "outqty": v.qty,
  208. "price": v.price
  209. }
  210. })
  211. }
  212. }).then(res => {
  213. console.log("项目添加产品", res)
  214. wx.showToast({
  215. title: res.msg == '成功' ? '添加成功' : res.msg,
  216. icon: "none"
  217. })
  218. if (res.msg == '成功') setTimeout(() => {
  219. wx.navigateBack();
  220. that.getProduct(true);
  221. that.setAmount();
  222. }, 300)
  223. })
  224. }
  225. })
  226. },
  227. /* 生成修改队列 */
  228. changeQueue({
  229. detail
  230. }) {
  231. const that = this;
  232. _Http.basic({
  233. "id": 20220906155003,
  234. "version": 1,
  235. "content": {
  236. "sa_salesforecastmodelid": that.data.sa_salesforecastmodelid,
  237. "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
  238. "sa_projectid": that.data.param.content.where.sa_projectid,
  239. itemclassinfos: [detail]
  240. }
  241. }).then(res => {
  242. console.log("项目修改产品", res)
  243. if (res.msg != '成功') return wx.showToast({
  244. title: res.msg,
  245. icon: "none"
  246. })
  247. that.setData({
  248. [`productList[0].sumamount`]: res.data[0].sumamount,
  249. })
  250. this.setAmount();
  251. })
  252. },
  253. /* 删除 */
  254. deleteItem({
  255. detail
  256. }) {
  257. _Http.basic({
  258. "id": 20220906155103,
  259. "version": 1,
  260. "content": detail
  261. }).then(res => {
  262. console.log("删除产品", res);
  263. if (res.msg != '成功') return wx.showToast({
  264. title: res.msg,
  265. icon: "none"
  266. });
  267. this.setData({
  268. productList: this.data.productList.filter(v => v.sa_salesforecastid != detail.sa_salesforecastid)
  269. });
  270. this.setAmount();
  271. wx.showToast({
  272. title: '删除成功',
  273. icon: "none"
  274. })
  275. })
  276. },
  277. setAmount() {
  278. let page = getCurrentPages().find(v => v.__route__ == 'packageA/salesForecasting/detail');
  279. if (page) page.getDetail(true)
  280. },
  281. }
  282. })