index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. const _Http = getApp().globalData.http,
  2. file = require("../../../../utils/matchingFeilType"),
  3. currency = require("../../../../utils/currency"),
  4. CNY = value => currency(value, {
  5. symbol: "¥",
  6. precision: 2
  7. }).format();
  8. let queue = [],
  9. downCounter = null,
  10. sa_quotedpriceid = 0;
  11. Component({
  12. properties: {
  13. disabled: Boolean, //禁用
  14. sa_projectid: Number,
  15. type: String, //报价单类型
  16. savePage: null, //保存页面
  17. },
  18. observers: {
  19. sumamount(newData) {
  20. let savePage = this.data.savePage;
  21. let i = savePage.data.list1.findIndex(v => v.label == '总金额');
  22. if (i != -1 && savePage.data.list1[i].value != newData) savePage.setData({
  23. [`list1[${i}].value`]: newData
  24. })
  25. }
  26. },
  27. data: {
  28. "content": {
  29. nocache: true,
  30. "pageNumber": 1,
  31. pageTotal: 1,
  32. total: null
  33. },
  34. actionShow: false,
  35. actions: [{
  36. name: "自项目产品添加"
  37. }, {
  38. name: "自产品档案添加"
  39. }]
  40. },
  41. lifetimes: {
  42. detached: function () {
  43. if (downCounter) {
  44. clearTimeout(downCounter);
  45. this.changeItem(queue)
  46. }
  47. },
  48. },
  49. methods: {
  50. /* 获取产品列表 */
  51. getList(id, init) {
  52. let content = this.data.content;
  53. content.sa_quotedpriceid = id;
  54. sa_quotedpriceid = id;
  55. if (init) content.pageNumber = 1;
  56. _Http.basic({
  57. "id": "20221021095503",
  58. content
  59. }).then(res => {
  60. console.log("项目清单列表", res)
  61. if (res.msg != '成功') return wx.showToast({
  62. title: res.data,
  63. icon: "none"
  64. })
  65. res.data = res.data.map(value => {
  66. if (value.attinfos.length != 0) {
  67. value.attinfos = file.fileList(value.attinfos)
  68. let image = value.attinfos.find(v => v.fileType == "image");
  69. value.cover = image ? image.cover : "";
  70. }
  71. //最低价 = 牌价*最低折扣
  72. value.minPrice = currency(value.marketprice).multiply(value.mindiscountrate).value;
  73. value.mindiscountrate = currency(value.mindiscountrate).multiply(100).value;
  74. value.discountrate = currency(value.discountrate).multiply(100).value;
  75. value.price = currency(value.price).value;
  76. //显示格式化金额
  77. value.showMarketprice = CNY(value.marketprice);
  78. value.discountDifferenceAmount = CNY(value.discountDifferenceAmount)
  79. value.showAmount = CNY(value.amount)
  80. value.className = value.itemclass.length == 0 ? "暂无类目" : value.itemclass.map(v => v.itemclassname);
  81. value.brandName = value.brand.length == 0 ? "暂无品牌" : value.brand.map(v => v.brandname);
  82. return value;
  83. })
  84. this.setData({
  85. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  86. "content.pageNumber": res.pageNumber + 1,
  87. "content.pageSize": res.pageSize,
  88. "content.pageTotal": res.pageTotal,
  89. "content.total": res.total,
  90. savePage: getCurrentPages().find(v => v.__route__ == 'packageA/offers/detail'),
  91. })
  92. if (res.pageNumber == 1) this.setData({
  93. sumamount: CNY(res.data[0].rowstotal[0].sumamount || 0)
  94. })
  95. })
  96. },
  97. /* 去选择产品 */
  98. addProduct() {
  99. console.log("添加产品", this.data.type, this.data.sa_projectid)
  100. if (this.data.type == '项目报价') {
  101. this.setData({
  102. actionShow: true
  103. })
  104. } else {
  105. this.toSelected(0);
  106. }
  107. },
  108. cancelSelector() {
  109. this.setData({
  110. actionShow: false
  111. })
  112. },
  113. selectorMode({
  114. detail
  115. }) {
  116. this.toSelected(detail.name == '自项目产品添加' ? this.data.sa_projectid : 0);
  117. this.cancelSelector();
  118. },
  119. /* 去挑选 */
  120. toSelected(sa_projectid) {
  121. wx.navigateTo({
  122. url: '/packageA/select/product/select?params=' + JSON.stringify({
  123. "id": 20221020164903,
  124. "version": 1,
  125. "content": {
  126. nocache: true,
  127. total: null,
  128. sa_projectid,
  129. sa_quotedpriceid,
  130. where: {
  131. condition: ""
  132. }
  133. }
  134. })
  135. });
  136. getApp().globalData.handleSelect = sa_projectid == 0 ? this.selectProduct.bind(this) : this.projectProduct.bind(this)
  137. },
  138. /* 项目产品 */
  139. projectProduct({
  140. list
  141. }) {
  142. console.log('项目产品添加', list)
  143. let that = this;
  144. wx.showModal({
  145. title: '提示',
  146. content: `是否确认添加${list.length}件产品?`,
  147. complete: ({
  148. confirm
  149. }) => {
  150. if (confirm) _Http.basic({
  151. "id": 20221021095403,
  152. "version": 1,
  153. "content": {
  154. sa_quotedpriceid,
  155. items: list.map(v => {
  156. return {
  157. "sa_quotedprice_itemsid": 0,
  158. "itemid": v.itemid,
  159. "price": v.price,
  160. "discountrate": currency(v.price).divide(v.marketprice).value,
  161. "qty": v.qty
  162. }
  163. })
  164. }
  165. }).then(res => {
  166. console.log("报价单添加产品", res);
  167. wx.showToast({
  168. title: res.msg != '成功' ? res.msg : '添加成功!',
  169. icon: "none"
  170. });
  171. if (res.msg == '成功') setTimeout(() => {
  172. that.getList(sa_quotedpriceid, true)
  173. wx.navigateBack()
  174. }, 300)
  175. })
  176. }
  177. })
  178. },
  179. /* 产品档案添加 */
  180. selectProduct({
  181. list
  182. }) {
  183. console.log('产品档案添加', list)
  184. let that = this;
  185. wx.showModal({
  186. title: '提示',
  187. content: `是否确认添加${list.length}件产品?`,
  188. complete: ({
  189. confirm
  190. }) => {
  191. if (confirm) _Http.basic({
  192. "id": 20221021095403,
  193. "version": 1,
  194. "content": {
  195. sa_quotedpriceid,
  196. items: list.map(v => {
  197. return {
  198. "sa_quotedprice_itemsid": 0,
  199. "itemid": v.itemid,
  200. "price": v.marketprice,
  201. "discountrate": 1,
  202. "qty": 1
  203. }
  204. })
  205. }
  206. }).then(res => {
  207. console.log("报价单添加产品", res);
  208. wx.showToast({
  209. title: res.msg != '成功' ? res.msg : '添加成功!',
  210. icon: "none"
  211. });
  212. if (res.msg == '成功') setTimeout(() => {
  213. that.getList(sa_quotedpriceid, true)
  214. wx.navigateBack()
  215. }, 300)
  216. })
  217. }
  218. })
  219. },
  220. /* 删除产品 */
  221. deleteItems({
  222. detail
  223. }) {
  224. _Http.basic({
  225. "id": 20221021095603,
  226. "version": 1,
  227. "content": {
  228. "sa_quotedprice_itemsids": detail
  229. }
  230. }).then(res => {
  231. console.log("批量删除产品", res);
  232. wx.showToast({
  233. title: res.msg == '成功' ? '删除成功!' : res.msg,
  234. icon: "none"
  235. })
  236. if (res.msg == '成功') {
  237. let i = this.data.list.findIndex(v => v.sa_quotedprice_itemsid == detail);
  238. let sumamount = CNY(currency(this.data.sumamount).subtract(this.data.list[i].amount));
  239. this.data.list.splice(i, 1);
  240. this.setData({
  241. list: this.data.list,
  242. sumamount
  243. })
  244. }
  245. })
  246. },
  247. /* 生成修改队列 */
  248. changeQueue({
  249. detail
  250. }) {
  251. let i = queue.findIndex(v => v.sa_quotedprice_itemsid == detail.sa_quotedprice_itemsid);
  252. i == -1 ? queue.push(detail) : queue[i] = detail;
  253. clearTimeout(downCounter)
  254. downCounter = setTimeout(() => {
  255. this.changeItem(queue)
  256. }, 300);
  257. },
  258. changeItem(items) {
  259. console.log(items)
  260. if (items.length == 0) return;
  261. _Http.basic({
  262. "id": 20221021095403,
  263. "version": 1,
  264. "content": {
  265. sa_quotedpriceid,
  266. items
  267. }
  268. }, false).then(res => {
  269. console.log("批量修改产品清单", res)
  270. queue = [];
  271. downCounter = null;
  272. let list = this.data.list;
  273. if (res.msg != '成功') {
  274. wx.showToast({
  275. title: res.msg,
  276. icon: "none"
  277. })
  278. return;
  279. } else {
  280. items.forEach(v => {
  281. let i = list.findIndex(value => v.sa_quotedprice_itemsid == value.sa_quotedprice_itemsid);
  282. if (i != -1) {
  283. v.discountrate = (v.discountrate * 100).toFixed(2);
  284. this.setData({
  285. sumamount: CNY(currency(this.data.sumamount).subtract(list[i].amount).add(v.amount))
  286. })
  287. v.showAmount = CNY(v.amount)
  288. this.data.list[i] = Object.assign(list[i], v);
  289. }
  290. });
  291. }
  292. this.setData({
  293. list
  294. })
  295. let page = getCurrentPages().find(v => v.__route__ == 'packageA/offers/detail');
  296. if (page) {
  297. let index = page.data.list1.findIndex(v => v.label == '总金额');
  298. if (index != -1) page.setData({
  299. [`list1[${index}].value`]: this.data.sumamount
  300. })
  301. }
  302. })
  303. }
  304. }
  305. })