index.js 10 KB

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