index.js 14 KB

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