index.js 13 KB

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