index.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. Counter = null;
  11. Component({
  12. properties: {
  13. disabled: {
  14. type: Boolean
  15. },
  16. signamount_due: {
  17. type: String
  18. },
  19. discountrate: {
  20. type: Number
  21. }, //折扣
  22. },
  23. data: {
  24. sa_projectid: 0,
  25. content: {
  26. nocache: true,
  27. pageNumber: 1,
  28. pageTotal: 1,
  29. total: null
  30. }
  31. },
  32. lifetimes: {
  33. detached: function () {
  34. if (downCounter) {
  35. clearTimeout(downCounter);
  36. this.changeItem()
  37. }
  38. },
  39. attached: function () {
  40. getApp().globalData.Language.getLanguagePackage(this)
  41. }
  42. },
  43. methods: {
  44. /* 步进器数值改变 */
  45. stepperChange(e) {
  46. switch (e.type) {
  47. case 'plus':
  48. this.data.discountrate += 1;
  49. break;
  50. case 'minus':
  51. this.data.discountrate -= 1;
  52. break;
  53. case 'blur':
  54. this.data.discountrate = e.detail.value;
  55. break;
  56. }
  57. if (this.data.discountrate > 100) this.data.discountrate = 100;
  58. if (this.data.discountrate < 0.5) this.data.discountrate = 0.5;
  59. this.setDiscountrate();
  60. },
  61. /* 设置折扣 */
  62. setDiscountrate() {
  63. clearTimeout(Counter);
  64. let page = getCurrentPages().find(v => v.__route__ == 'packageA/project/detail');
  65. let data = page.data.detail;
  66. Counter = setTimeout(() => {
  67. _Http.basic({
  68. "id": 20230207090702,
  69. "content": {
  70. "sa_projectid": data.sa_projectid,
  71. "discountrate": (this.data.discountrate / 100).toFixed(4) //预计折扣率
  72. }
  73. }).then(res => {
  74. console.log("修改折扣", res)
  75. if (res.code != '1') wx.showToast({
  76. title: res.msg,
  77. icon: "none"
  78. });
  79. page.getDetail();
  80. this.getList(this.data.sa_projectid, true)
  81. })
  82. }, 300)
  83. },
  84. /* 获取产品列表 */
  85. getList(id, init) {
  86. let content = this.data.content;
  87. content.sa_projectid = id;
  88. if (init) content.pageNumber = 1
  89. _Http.basic({
  90. "id": "20221021145702",
  91. content
  92. }).then(res => {
  93. console.log("项目清单列表", res)
  94. if (res.code != '1') return wx.showToast({
  95. title: res.data,
  96. icon: "none"
  97. })
  98. res.data = res.data.map(value => {
  99. if (value.attinfos.length == 0) return value;
  100. value.attinfos = file.fileList(value.attinfos)
  101. let image = value.attinfos.find(v => v.fileType == "image");
  102. value.cover = image ? image.cover : "";
  103. value.amount = CNY(value.amount);
  104. value.className = value.itemclass.length == 0 ? "暂无类目" : value.itemclass.map(v => v.itemclassname);
  105. value.brandName = value.brand.length == 0 ? "暂无品牌" : value.brand.map(v => v.brandname);
  106. value.discountrate = value.discountrate * 100;
  107. return value;
  108. })
  109. this.setData({
  110. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  111. "content.pageNumber": res.pageNumber + 1,
  112. "content.pageSize": res.pageSize,
  113. "content.pageTotal": res.pageTotal,
  114. "content.total": res.total,
  115. sa_projectid: id
  116. })
  117. })
  118. },
  119. /* 去选择产品 */
  120. addProduct() {
  121. wx.navigateTo({
  122. url: '/packageA/select/product/select?params=' + JSON.stringify({
  123. "id": 20221021171802,
  124. "version": 1,
  125. "content": {
  126. nocache: true,
  127. pageNumber: 1,
  128. pageTotal: 1,
  129. total: null,
  130. sa_projectid: this.data.sa_projectid,
  131. where: {
  132. condition: ""
  133. }
  134. }
  135. })
  136. });
  137. getApp().globalData.handleSelect = this.handleSelect.bind(this);
  138. },
  139. /* 处理选择产品 */
  140. handleSelect({
  141. list
  142. }) {
  143. let that = this,
  144. discountrate = this.data.discountrate / 100;
  145. wx.showModal({
  146. title: getApp().globalData.Language.getMapText('提示'),
  147. content: getApp().globalData.Language.getMapText('是否确认添加') + list.length + getApp().globalData.Language.getMapText('件产品') + `?`,
  148. cancelText: getApp().globalData.Language.getMapText('取消'),
  149. confirmText: getApp().globalData.Language.getMapText('确定'),
  150. complete: ({
  151. confirm
  152. }) => {
  153. if (confirm) {
  154. _Http.basic({
  155. "id": 20221021145502,
  156. "content": {
  157. "sa_projectid": that.data.sa_projectid,
  158. "items": list.map(v => {
  159. return {
  160. "sa_project_itemsid": 0,
  161. "itemid": v.itemid,
  162. "qty": v.orderminqty || 1, //依照起订量添加初始数量
  163. "remarks": "",
  164. "marketprice": v.marketprice, //市场价
  165. "price": (v.marketprice * discountrate).toFixed(2) //单价
  166. }
  167. })
  168. }
  169. }).then(res => {
  170. console.log("项目商机添加产品", res);
  171. wx.showToast({
  172. title: res.code != '1' ? res.msg : getApp().globalData.Language.getMapText('添加成功'),
  173. icon: "none"
  174. });
  175. if (res.code == '1') setTimeout(() => {
  176. wx.navigateBack()
  177. that.getList(that.data.sa_projectid, true)
  178. this.setAmount();
  179. }, 300)
  180. })
  181. }
  182. }
  183. })
  184. },
  185. /* 删除产品 */
  186. deleteItems({
  187. detail
  188. }) {
  189. _Http.basic({
  190. "id": 20221021145602,
  191. "content": {
  192. sa_projectid: this.data.sa_projectid,
  193. "deletereason": "",
  194. "sa_project_itemsids": detail
  195. }
  196. }).then(res => {
  197. console.log("批量删除产品", res);
  198. wx.showToast({
  199. title: res.code == '1' ? getApp().globalData.Language.getMapText('删除成功') : res.msg,
  200. icon: "none"
  201. })
  202. if (res.code == '1') {
  203. this.setData({
  204. list: this.data.list.filter(v => detail.indexOf(v.sa_project_itemsid) == -1)
  205. })
  206. this.setAmount();
  207. }
  208. })
  209. },
  210. /* 生成修改队列 */
  211. changeQueue({
  212. detail
  213. }) {
  214. let i = queue.findIndex(v => v.sa_project_itemsid == detail.sa_project_itemsid);
  215. if (i == -1) {
  216. queue.push(detail)
  217. } else {
  218. queue[i] = detail;
  219. };
  220. clearTimeout(downCounter)
  221. downCounter = setTimeout(() => {
  222. this.changeItem()
  223. }, 300);
  224. },
  225. changeItem() {
  226. _Http.basic({
  227. "id": 20221021145502,
  228. "content": {
  229. "sa_projectid": this.data.sa_projectid,
  230. items: queue
  231. }
  232. }, false).then(res => {
  233. console.log("批量修改产品清单", res)
  234. queue = [];
  235. downCounter = null;
  236. if (res.code == '1') {
  237. this.setAmount();
  238. } else {
  239. wx.showToast({
  240. title: res.msg,
  241. icon: "none"
  242. })
  243. that.getList(that.data.sa_projectid, true)
  244. }
  245. })
  246. },
  247. setAmount() {
  248. getCurrentPages().find(v => v.__route__ == 'packageA/project/detail').getDetail();
  249. },
  250. }
  251. })