index.js 11 KB

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