index.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. const _Http = getApp().globalData.http,
  2. file = require("../../../../utils/matchingFeilType");
  3. Component({
  4. properties: {
  5. refresh: Function, //更新数据
  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. getList(id) {
  38. let content = this.data.content;
  39. content.sa_salesforecastbillid = id;
  40. _Http.basic({
  41. "id": "20220916115203",
  42. "version": 1,
  43. content
  44. }).then(res => {
  45. console.log("项目清单", res)
  46. if (res.msg != '成功') return wx.showToast({
  47. title: res.data,
  48. icon: "none"
  49. })
  50. this.setData({
  51. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  52. "content.total": res.total,
  53. sa_salesforecastbillid: id
  54. });
  55. if (res.data.length) {
  56. this.setData({
  57. 'param.content.where.sa_projectid': res.data[0].sa_projectid,
  58. 'param.content.sa_salesforecastbillid': id,
  59. viewIndex: 0
  60. })
  61. this.getProduct(true);
  62. }
  63. })
  64. },
  65. /* 获取产品清单 */
  66. getProduct(init = false) {
  67. let param = this.data.param;
  68. if (init) param.content.pageNumber = 1;
  69. if (param.content.pageNumber > param.content.pageTotal) return;
  70. _Http.basic(param).then(res => {
  71. console.log("产品列表", res)
  72. if (res.msg != '成功') return wx.showToast({
  73. title: res.msg,
  74. icon: "none"
  75. });
  76. if (res.data.length == 1 && !res.data[0].itemname) {
  77. res.data = []
  78. } else {
  79. res.data = res.data.map(value => {
  80. if (value.attinfos.length != 0) {
  81. value.attinfos = file.fileList(value.attinfos)
  82. let image = value.attinfos.find(v => v.fileType == "image");
  83. value.cover = image ? image.cover : "";
  84. }
  85. value.className = [];
  86. value.brandName = [];
  87. if (value.temclass.length != 0) value.temclass.forEach(v => {
  88. if (v.brandname != "") value.brandName.push(v.brandname);
  89. if (v.itemclassname != "") value.className.push(v.itemclassname);
  90. })
  91. return value;
  92. })
  93. }
  94. this.setData({
  95. productList: res.pageNumber == 1 ? res.data : this.data.productList.concat(res.data),
  96. "param.content.pageNumber": res.pageNumber + 1,
  97. "param.content.pageTotal": res.pageTotal,
  98. })
  99. })
  100. },
  101. /* 切换tab */
  102. onChange(e) {
  103. this.setData({
  104. "param.content.where.sa_projectid": e.detail.name,
  105. viewIndex: e.detail.index,
  106. });
  107. this.getProduct(true);
  108. },
  109. /* 添加产品 */
  110. addProduct() {
  111. wx.navigateTo({
  112. url: `/packageA/select/product/select?params=${JSON.stringify({
  113. id: 20221208105403,
  114. version: 1,
  115. model:'#Project',
  116. content: {
  117. nocache:true,
  118. sa_projectid: this.data.param.content.where.sa_projectid,
  119. sa_salesforecastbillid: this.data.sa_salesforecastbillid,
  120. pageSize: 20,
  121. pageNumber: 1,
  122. pageTotal: 1
  123. }
  124. })}`
  125. });
  126. },
  127. handleSelectProduct(itemclassinfos, oldList) {
  128. const that = this,
  129. page = getCurrentPages().find(v => v.__route__ == 'packageA/salesForecasting/detail')
  130. wx.showModal({
  131. title: '提示',
  132. content: '是否确认添加产品',
  133. complete: ({
  134. confirm
  135. }) => {
  136. if (confirm) _Http.basic({
  137. "id": 20220906155003,
  138. "version": 1,
  139. "content": {
  140. "sa_salesforecastmodelid": page.data.detail.sa_salesforecastmodelid,
  141. "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
  142. "sa_projectid": that.data.param.content.where.sa_projectid,
  143. itemclassinfos
  144. }
  145. }).then(res => {
  146. console.log("项目添加产品", res)
  147. wx.showToast({
  148. title: res.msg == '成功' ? '添加成功' : res.msg,
  149. icon: "none"
  150. })
  151. if (res.msg != '成功') return;
  152. setTimeout(() => {
  153. that.getProduct(true);
  154. wx.navigateBack();
  155. that.triggerEvent("refresh")
  156. }, 300)
  157. })
  158. }
  159. })
  160. },
  161. /* 生成修改队列 */
  162. changeQueue({
  163. detail
  164. }) {
  165. const that = this,
  166. page = getCurrentPages().find(v => v.__route__ == 'packageA/salesForecasting/detail')
  167. _Http.basic({
  168. "id": 20220906155003,
  169. "version": 1,
  170. "content": {
  171. "sa_salesforecastmodelid": page.data.detail.sa_salesforecastmodelid,
  172. "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
  173. "sa_projectid": that.data.param.content.where.sa_projectid,
  174. itemclassinfos: detail
  175. }
  176. }).then(res => {
  177. console.log("项目修改产品", res)
  178. if (res.msg != '成功') return wx.showToast({
  179. title: res.msg,
  180. icon: "none"
  181. })
  182. let index = that.data.productList.findIndex(v => v.sa_salesforecastid == detail[0].sa_salesforecastid);
  183. if (index != -1) that.data.productList[index] = {
  184. ...that.data.productList[index],
  185. ...detail[0]
  186. }
  187. that.setData({
  188. [`productList[${index}]`]: that.data.productList[index],
  189. [`productList[0].sumamount`]: res.data[0].sumamount,
  190. })
  191. that.triggerEvent("refresh")
  192. })
  193. },
  194. /* 删除 */
  195. deleteItem({
  196. detail
  197. }) {
  198. _Http.basic({
  199. "id": 20220906155103,
  200. "version": 1,
  201. "content": detail
  202. }).then(res => {
  203. console.log("删除产品", res);
  204. if (res.msg != '成功') return wx.showToast({
  205. title: res.msg,
  206. icon: "none"
  207. });
  208. this.setData({
  209. productList: this.data.productList.filter(v => v.sa_salesforecastid != detail.sa_salesforecastid)
  210. });
  211. this.triggerEvent("refresh")
  212. wx.showToast({
  213. title: '删除成功',
  214. icon: "none"
  215. })
  216. })
  217. }
  218. }
  219. })