index.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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: Boolean,
  14. signamount_due: String,
  15. discountrate: 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(true);
  71. })
  72. }, 300)
  73. },
  74. /* 获取产品列表 */
  75. getList(id, init) {
  76. let content = this.data.content;
  77. content.sa_projectid = id;
  78. if (init) content.pageNumber = 1
  79. _Http.basic({
  80. "id": "20221021145702",
  81. content
  82. }).then(res => {
  83. console.log("项目清单列表", res)
  84. if (res.msg != '成功') return wx.showToast({
  85. title: res.data,
  86. icon: "none"
  87. })
  88. res.data = res.data.map(value => {
  89. if (value.attinfos.length == 0) return value;
  90. value.attinfos = file.fileList(value.attinfos)
  91. let image = value.attinfos.find(v => v.fileType == "image");
  92. value.cover = image ? image.cover : "";
  93. value.amount = CNY(value.amount);
  94. value.className = value.itemclass.length == 0 ? "暂无类目" : value.itemclass.map(v => v.itemclassname);
  95. value.brandName = value.brand.length == 0 ? "暂无品牌" : value.brand.map(v => v.brandname);
  96. value.discountrate = value.discountrate * 100;
  97. return value;
  98. })
  99. this.setData({
  100. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  101. "content.pageNumber": res.pageNumber + 1,
  102. "content.pageSize": res.pageSize,
  103. "content.pageTotal": res.pageTotal,
  104. "content.total": res.total,
  105. sa_projectid: id
  106. })
  107. })
  108. },
  109. /* 去选择产品 */
  110. addProduct() {
  111. wx.navigateTo({
  112. url: '/packageA/select/product/select?params=' + JSON.stringify({
  113. "id": 20221021171802,
  114. "version": 1,
  115. "content": {
  116. nocache: true,
  117. pageNumber: 1,
  118. pageTotal: 1,
  119. total: null,
  120. sa_projectid: this.data.sa_projectid,
  121. where: {
  122. condition: ""
  123. }
  124. }
  125. })
  126. });
  127. getApp().globalData.handleSelect = this.handleSelect.bind(this);
  128. },
  129. /* 处理选择产品 */
  130. handleSelect({
  131. list
  132. }) {
  133. let that = this,
  134. discountrate = this.data.discountrate / 100;
  135. wx.showModal({
  136. title: '提示',
  137. content: `是否确认添加${list.length}件产品?`,
  138. complete: ({
  139. confirm
  140. }) => {
  141. if (confirm) {
  142. _Http.basic({
  143. "id": 20221021145502,
  144. "content": {
  145. "sa_projectid": that.data.sa_projectid,
  146. "items": list.map(v => {
  147. return {
  148. "sa_project_itemsid": 0,
  149. "itemid": v.itemid,
  150. "qty": 1,
  151. "remarks": "",
  152. "marketprice": v.marketprice, //市场价
  153. "price": (v.marketprice * discountrate).toFixed(2) //单价
  154. }
  155. })
  156. }
  157. }).then(res => {
  158. console.log("项目商机添加产品", res);
  159. wx.showToast({
  160. title: res.msg != '成功' ? res.msg : '添加成功!',
  161. icon: "none"
  162. });
  163. if (res.msg == '成功') setTimeout(() => {
  164. wx.navigateBack()
  165. that.getList(that.data.sa_projectid, true)
  166. this.setAmount();
  167. }, 300)
  168. })
  169. }
  170. }
  171. })
  172. },
  173. /* 删除产品 */
  174. deleteItems({
  175. detail
  176. }) {
  177. _Http.basic({
  178. "id": 20221021145602,
  179. "content": {
  180. sa_projectid: this.data.sa_projectid,
  181. "deletereason": "",
  182. "sa_project_itemsids": detail
  183. }
  184. }).then(res => {
  185. console.log("批量删除产品", res);
  186. wx.showToast({
  187. title: res.msg == '成功' ? '删除成功!' : res.msg,
  188. icon: "none"
  189. })
  190. if (res.msg == '成功') {
  191. this.setData({
  192. list: this.data.list.filter(v => detail.indexOf(v.sa_project_itemsid) == -1)
  193. })
  194. this.setAmount();
  195. }
  196. })
  197. },
  198. /* 生成修改队列 */
  199. changeQueue({
  200. detail
  201. }) {
  202. let i = queue.findIndex(v => v.sa_project_itemsid == detail.sa_project_itemsid);
  203. if (i == -1) {
  204. queue.push(detail)
  205. } else {
  206. queue[i] = detail;
  207. };
  208. clearTimeout(downCounter)
  209. downCounter = setTimeout(() => {
  210. this.changeItem()
  211. }, 300);
  212. },
  213. changeItem() {
  214. _Http.basic({
  215. "id": 20221021145502,
  216. "content": {
  217. "sa_projectid": this.data.sa_projectid,
  218. items: queue
  219. }
  220. }, false).then(res => {
  221. console.log("批量修改产品清单", res)
  222. queue = [];
  223. downCounter = null;
  224. if (res.msg == '成功') {
  225. this.setAmount();
  226. } else {
  227. wx.showToast({
  228. title: res.msg,
  229. icon: "none"
  230. })
  231. that.getList(that.data.sa_projectid, true)
  232. }
  233. })
  234. },
  235. setAmount() {
  236. getCurrentPages().find(v => v.__route__ == 'packageA/project/detail').getDetail();
  237. },
  238. }
  239. })