index.js 12 KB

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