index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. const _Http = getApp().globalData.http,
  2. file = require("../../../../utils/FormatTheAttachment"),
  3. currency = require("../../../../utils/currency");
  4. let queue = [],
  5. downCounter = null,
  6. sa_orderid = 0,
  7. CNY = num => currency(num, {
  8. symbol: "¥",
  9. precision: 2
  10. }).format();
  11. Component({
  12. properties: {
  13. sa_order_v: {
  14. type: String
  15. },
  16. disabled: {
  17. type: Boolean
  18. }, //禁用
  19. returnProductCount: {
  20. type: Function
  21. },
  22. privacyFieldC: {
  23. type: Array
  24. },
  25. packagetype: {
  26. type: String
  27. },
  28. },
  29. data: {
  30. content: {
  31. nocache: true,
  32. pageNumber: 1,
  33. pageTotal: 1,
  34. total: null
  35. }
  36. },
  37. lifetimes: {
  38. detached: function () {
  39. if (downCounter) {
  40. clearTimeout(downCounter);
  41. this.changeItem(queue)
  42. }
  43. },
  44. },
  45. methods: {
  46. /* 获取产品列表 */
  47. getList(id, init) {
  48. let content = this.data.content;
  49. content.sa_orderid = id;
  50. sa_orderid = id;
  51. if (init) content.pageNumber = 1;
  52. _Http.basic({
  53. "id": "20221109093902",
  54. content
  55. }).then(res => {
  56. console.log("订货清单列表", res)
  57. if (res.msg != '成功') return wx.showToast({
  58. title: res.msg,
  59. icon: "none"
  60. })
  61. res.data = res.data.map(v => {
  62. if (v.attinfos.length != 0) {
  63. v.attinfos = file.fileList(v.attinfos)
  64. let image = v.attinfos.find(v => v.fileType == "image");
  65. v.cover = image ? image.cover : "";
  66. };
  67. v.showPrice = CNY(v.price)
  68. // v.marketprice = CNY(v.marketprice)
  69. v.showAmount = CNY(v.amount)
  70. return v;
  71. })
  72. let page = getCurrentPages().find(v => v.__route__ == 'packageA/orderForm/detail').data.detail;
  73. let base = {
  74. sa_orderid: page.sa_orderid,
  75. sys_enterpriseid: page.sys_enterpriseid,
  76. sa_contractid: page.sa_contractid,
  77. type: page.type,
  78. };
  79. this.triggerEvent("returnProductCount", res.total)
  80. this.setData({
  81. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  82. "content.pageNumber": res.pageNumber + 1,
  83. "content.pageSize": res.pageSize,
  84. "content.pageTotal": res.pageTotal,
  85. "content.total": res.total,
  86. base
  87. })
  88. })
  89. },
  90. /* 修改 */
  91. changeProduct({
  92. detail
  93. }) {
  94. let obj = detail,
  95. index = obj.index,
  96. data = this.data.list[index];
  97. if (data.qty == obj.qty && data.remarks == obj.remarks && data.needdate == obj.needdate) return;
  98. detail.sa_order_v = this.data.sa_order_v - 0;
  99. _Http.basic({
  100. "id": 20221109093602,
  101. "content": {
  102. ...this.data.base,
  103. "items": [detail],
  104. sa_order_v: this.data.sa_order_v - 0
  105. }
  106. }).then(res => {
  107. console.log("产品修改", res)
  108. if (res.msg != '成功') {
  109. wx.showToast({
  110. title: res.msg,
  111. icon: "none"
  112. });
  113. obj = data;
  114. };
  115. data = {
  116. ...data,
  117. ...obj
  118. };
  119. data.showAmount = CNY(currency(data.price).multiply(data.qty).format());
  120. data.showPrice = CNY(data.price)
  121. this.setData({
  122. [`list[${index}]`]: data
  123. })
  124. this.updateThePrice();
  125. })
  126. },
  127. /* 删除 */
  128. deleteItem({
  129. detail
  130. }) {
  131. let that = this;
  132. wx.showModal({
  133. title: '提示',
  134. content: that.data.packagetype ? '该商品为套餐商品,删除后该套餐下的商品会全部删除,确定删除嘛?' : `是否确认删除“${detail.itemname}”?`,
  135. complete: (res) => {
  136. if (res.confirm) _Http.basic({
  137. "id": 20221109093702,
  138. "content": {
  139. sa_orderid,
  140. "sa_orderitemsids": [
  141. detail.sa_orderitemsid
  142. ],
  143. sa_order_v: that.data.sa_order_v
  144. }
  145. }).then(s => {
  146. if (s.msg != '成功') return wx.showToast({
  147. title: res.msg,
  148. icon: "none"
  149. });
  150. if (that.data.packagetype) {
  151. that.getList(sa_orderid, true)
  152. } else {
  153. that.setData({
  154. list: that.data.list.filter(v => v.sa_orderitemsid != detail.sa_orderitemsid)
  155. });
  156. that.triggerEvent("returnProductCount", that.data.content.total - 1)
  157. }
  158. that.updateThePrice();
  159. })
  160. }
  161. })
  162. },
  163. /* 去添加产品 */
  164. addProduct() {
  165. if (this.data.packagetype) {
  166. wx.navigateTo({
  167. url: '/packageA/activity/bindingProduct/index?params=' + JSON.stringify({
  168. "id": 20230107182302,
  169. "version": 1,
  170. "content": {
  171. nocache: true,
  172. sa_orderid, //订单ID
  173. packagetype: this.data.packagetype,
  174. "where": {
  175. "condition": "",
  176. packagetypemx: "",
  177. }
  178. }
  179. }) + "&butText=添加套餐&getListPa=" + JSON.stringify({
  180. "id": "20221109093902",
  181. content: this.data.content
  182. }),
  183. });
  184. getApp().globalData.handleSelect = this.handleInsert.bind(this);
  185. } else {
  186. let detail = getCurrentPages().find(v => v.__route__ == 'packageA/orderForm/detail').data.detail,
  187. id = '';
  188. switch (detail.type) {
  189. case '促销订单':
  190. id = 20230107182302;
  191. break;
  192. case '标准订单':
  193. id = 20221109153502;
  194. break;
  195. case '特殊订单':
  196. id = 20221109153502;
  197. break;
  198. }
  199. wx.navigateTo({
  200. url: `${detail.type=='促销订单'?'/packageA/activity/selectProduct/index':'/select/product/index'}?params=${JSON.stringify({
  201. "id":id,
  202. "content": {
  203. nocache:true,
  204. sa_orderid, //订单ID
  205. "total": 0,
  206. "where": {
  207. "condition": ""
  208. }
  209. }
  210. })}&butText=添加产品`
  211. });
  212. this.setData({
  213. type: detail.type
  214. })
  215. getApp().globalData.handleSelect = this.handleSelect.bind(this);
  216. }
  217. },
  218. /* 处理新增产品 */
  219. handleSelect(detail) {
  220. let that = this;
  221. _Http.basic({
  222. "id": 2024020201095102,
  223. "content": {
  224. ...that.data.base,
  225. "items": detail.list
  226. },
  227. }).then(res => {
  228. console.log("查询重复产品", res)
  229. if (res.msg != '成功') return wx.showToast({
  230. title: res.msg,
  231. icon: "none"
  232. });
  233. if (res.data.items.length) {
  234. if (res.data.isrepeat) {
  235. wx.showModal({
  236. title: '提示',
  237. content: `本单已存在【${res.data.items[0].itemname}】商品,确认继续添加吗?`,
  238. complete: (res) => {
  239. if (res.confirm) handle()
  240. }
  241. })
  242. } else {
  243. wx.showModal({
  244. title: '提示',
  245. content: `本单已存在【${res.data.items[0].itemname}】商品,禁止重复添加!`,
  246. showCancel: false
  247. })
  248. }
  249. } else {
  250. handle()
  251. }
  252. })
  253. function handle() {
  254. wx.showModal({
  255. title: '提示',
  256. content: `是否确认添加${detail.result.length}件商品?`,
  257. complete: (res) => {
  258. if (res.confirm) that.handleInsert(detail).bind(that)
  259. }
  260. });
  261. }
  262. },
  263. handleInsert({
  264. list
  265. }) {
  266. return new Promise((resolve) => {
  267. _Http.basic({
  268. "id": 20221109093602,
  269. content: {
  270. ...this.data.base,
  271. "items": list.map(v => {
  272. return {
  273. sa_orderitemsid: v.sa_orderitemsid || 0,
  274. itemid: v.itemid, //商品ID
  275. qty: v.qty, //数量
  276. width: v.width || 0,
  277. length: v.length || 0,
  278. cheek: v.cheek,
  279. color: v.color,
  280. material: v.material,
  281. spec: v.spec,
  282. custom: v.custom,
  283. price: this.data.type == '工具订单' ? v.marketprice : v.contractprice,
  284. sa_promotion_itemsid: v.sa_promotion_itemsid || 0
  285. }
  286. })
  287. }
  288. }).then(s => {
  289. console.log('新增产品', s)
  290. resolve(s.msg == '成功')
  291. wx.showToast({
  292. title: s.msg == '成功' ? '操作成功' : s.msg,
  293. icon: "none",
  294. mask: s.msg == '成功'
  295. });
  296. if (s.msg == '成功') {
  297. this.getList(sa_orderid, true);
  298. this.updateThePrice();
  299. setTimeout(() => {
  300. wx.navigateBack();
  301. }, 300)
  302. }
  303. })
  304. })
  305. },
  306. /* 使用接口更新总价 */
  307. updateThePrice() {
  308. getCurrentPages().find(v => v.__route__ == 'packageA/orderForm/detail').getDetail();
  309. }
  310. }
  311. })