index.js 13 KB

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