index.js 8.8 KB

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