index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. const _Http = getApp().globalData.http,
  2. file = require("../../../../utils/FormatTheAttachment");
  3. let queue = [],
  4. downCounter = null,
  5. Counter = null;
  6. Component({
  7. properties: {
  8. disabled: Boolean, //禁用
  9. isAdd: {
  10. type: Boolean,
  11. value: false
  12. }
  13. },
  14. data: {
  15. sa_orderid: 0,
  16. "content": {
  17. nocache: true,
  18. "pageNumber": 1,
  19. pageTotal: 1,
  20. total: null
  21. },
  22. toolcount: 1
  23. },
  24. lifetimes: {
  25. detached: function () {
  26. if (downCounter) {
  27. clearTimeout(downCounter);
  28. this.changeItem(queue)
  29. }
  30. },
  31. },
  32. methods: {
  33. /* 获取产品列表 */
  34. getList(obj, init) {
  35. let content = this.data.content;
  36. content.sa_orderid = obj.id;
  37. if (init) content.pageNumber = 1;
  38. _Http.basic({
  39. "id": "20230116104102",
  40. content
  41. }).then(res => {
  42. console.log("工具借用列表", res)
  43. if (res.msg != '成功') return wx.showToast({
  44. title: res.msg,
  45. icon: "none"
  46. })
  47. res.data = res.data.map(value => {
  48. if (value.attinfos.length != 0) {
  49. value.attinfos = file.fileList(value.attinfos)
  50. let image = value.attinfos.find(v => v.fileType == "image");
  51. value.cover = image ? image.cover : "";
  52. }
  53. value.amount = value.amount * obj.toolcount;
  54. value.qty = value.qty * obj.toolcount;
  55. return value;
  56. })
  57. let page = getCurrentPages().find(v => v.__route__ == 'packageA/borrow/detail').data.detail;
  58. let base = {
  59. sa_orderid: page.sa_orderid,
  60. sys_enterpriseid: page.sys_enterpriseid,
  61. sa_contractid: page.sa_contractid,
  62. type: page.type,
  63. };
  64. this.setData({
  65. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  66. "content.pageNumber": res.pageNumber + 1,
  67. "content.pageSize": res.pageSize,
  68. "content.pageTotal": res.pageTotal,
  69. "content.total": res.total,
  70. sa_orderid: obj.id,
  71. toolcount: obj.toolcount,
  72. base
  73. })
  74. })
  75. },
  76. /* 统一交期 */
  77. dateChange(e) {
  78. let that = this;
  79. wx.showModal({
  80. title: '提示',
  81. content: `是否确定将当前产品列表交期统一设置为:${e.detail.value}`,
  82. complete: (res) => {
  83. if (res.confirm) _Http.basic({
  84. "id": 20230104143802,
  85. "content": {
  86. "sa_orderid": that.data.sa_orderid,
  87. "needdate": e.detail.value
  88. }
  89. }).then(res => {
  90. console.log('统一设置交期', res)
  91. wx.showToast({
  92. title: res.msg == '成功' ? '设置成功' : res.msg,
  93. icon: "none"
  94. })
  95. if (res.msg == '成功') that.setData({
  96. list: that.data.list.map(v => {
  97. v.needdate = e.detail.value;
  98. return v
  99. })
  100. })
  101. })
  102. }
  103. })
  104. },
  105. /* 修改 */
  106. changeProduct({
  107. detail
  108. }) {
  109. let obj = detail,
  110. index = this.data.list.findIndex(v => v.itemid == detail.itemid),
  111. data = this.data.list[index],
  112. calculatePrice = data.qty != obj.qty;
  113. if (data.qty == obj.qty && data.remarks == obj.remarks && data.needdate == obj.needdate) return;
  114. _Http.basic({
  115. "id": 20230116101602,
  116. "content": {
  117. ...this.data.base,
  118. "items": [detail]
  119. }
  120. }).then(res => {
  121. console.log("产品修改", res)
  122. if (res.msg != '成功') {
  123. wx.showToast({
  124. title: res.msg,
  125. icon: "none"
  126. });
  127. obj = data;
  128. };
  129. data = {
  130. ...data,
  131. ...obj
  132. };
  133. if (res.msg == '成功' && calculatePrice) {
  134. let page = getCurrentPages()[getCurrentPages().length - 1];
  135. if (page) {
  136. let amount = page.data.detail.amount - data.amount;
  137. data.amount = ((data.qty - 0) * (data.price - 0)).toFixed(2);
  138. amount = (amount + (data.amount - 0)).toFixed(2);
  139. page.setData({
  140. "detail.amount": amount - 0
  141. })
  142. }
  143. }
  144. this.setData({
  145. [`list[${index}]`]: data
  146. })
  147. })
  148. },
  149. /* 删除 */
  150. deleteItem({
  151. detail
  152. }) {
  153. let that = this;
  154. wx.showModal({
  155. title: '提示',
  156. content: `是否确认删除“${detail.itemname}”?`,
  157. complete: (res) => {
  158. if (res.confirm) _Http.basic({
  159. "id": 20230116103402,
  160. "content": {
  161. sa_orderid: detail.sa_orderid,
  162. "sa_orderitemsids": [
  163. detail.sa_orderitemsid
  164. ]
  165. }
  166. }).then(s => {
  167. if (s.msg != '成功') return wx.showToast({
  168. title: res.msg,
  169. icon: "none"
  170. });
  171. that.setData({
  172. list: that.data.list.filter(v => v.sa_orderitemsid != detail.sa_orderitemsid)
  173. });
  174. /* 更新金额 */
  175. let page = getCurrentPages()[getCurrentPages().length - 1];
  176. let amount = (page.data.detail.amount - detail.amount).toFixed(2);
  177. if (page) page.setData({
  178. "detail.amount": amount - 0
  179. })
  180. })
  181. }
  182. })
  183. },
  184. /* 去添加产品 */
  185. addProduct() {
  186. wx.navigateTo({
  187. url: `/select/product/index?params=${JSON.stringify({
  188. "id":20230116111602,
  189. "content": {
  190. nocache:true,
  191. "sa_orderid": this.data.sa_orderid, //订单ID
  192. "pageNumber": 1,
  193. "pageTotal": 1,
  194. "total": 0,
  195. "pageSize": 20,
  196. "where": {
  197. "condition": ""
  198. }
  199. }
  200. })}`
  201. });
  202. getApp().globalData.handleSelect = this.handleSelect.bind(this);
  203. },
  204. /* 处理新增产品 */
  205. handleSelect(detail) {
  206. let that = this;
  207. wx.showModal({
  208. title: '提示',
  209. content: `是否确认添加${detail.result.length}件商品?`,
  210. complete: (res) => {
  211. if (res.confirm) _Http.basic({
  212. "id": 20230116101602,
  213. "content": {
  214. ...that.data.base,
  215. "items": detail.list.map(v => {
  216. return {
  217. sa_orderitemsid: 0,
  218. "itemid": v.itemid, //商品ID
  219. "qty": 1, //数量
  220. }
  221. })
  222. }
  223. }).then(s => {
  224. console.log('新增产品', s)
  225. wx.showToast({
  226. title: s.msg == '成功' ? '添加成功' : s.msg,
  227. icon: "none"
  228. });
  229. if (s.msg == '成功') setTimeout(() => {
  230. that.getList(that.data.sa_orderid, true);
  231. wx.navigateBack();
  232. that.updateThePrice();
  233. }, 300)
  234. })
  235. }
  236. });
  237. },
  238. /* 步进器数值改变 */
  239. stepperChange(e) {
  240. switch (e.type) {
  241. case 'plus':
  242. this.data.toolcount += 1;
  243. break;
  244. case 'minus':
  245. this.data.toolcount -= 1;
  246. break;
  247. case 'blur':
  248. this.data.toolcount = e.detail.value;
  249. break;
  250. }
  251. console.log(this.data.toolcount)
  252. this.setToolcount();
  253. },
  254. /* 设置总数 */
  255. setToolcount() {
  256. clearTimeout(Counter);
  257. let page = getCurrentPages().find(v => v.__route__ == 'packageA/borrow/detail');
  258. Counter = setTimeout(() => {
  259. _Http.basic({
  260. "id": 20230116092702,
  261. "content": {
  262. "sa_orderid": this.data.sa_orderid,
  263. "sa_contractid": page.data.detail.sa_contractid,
  264. toolcount: this.data.toolcount
  265. }
  266. }).then(res => {
  267. console.log("修改套数", res)
  268. console.log(page.data.detail.toolcount)
  269. if (res.msg != '成功') {
  270. wx.showToast({
  271. title: res.msg,
  272. icon: "none"
  273. });
  274. this.setData({
  275. toolcount: page.data.detail.toolcount
  276. })
  277. } else {
  278. page.getDetail(true);
  279. }
  280. })
  281. }, 300)
  282. },
  283. /* 使用接口更新总价 */
  284. updateThePrice() {
  285. _Http.basic({
  286. "id": 20230105101102,
  287. "content": {
  288. "sa_orderid": this.data.sa_orderid
  289. },
  290. }).then(res => {
  291. console.log("获取列表总价", res)
  292. if (res.msg != '成功') return wx.showToast({
  293. title: `产品总价更新失败`,
  294. icon: "none"
  295. });
  296. let page = getCurrentPages()[getCurrentPages().length - 1];
  297. if (page) page.setData({
  298. "detail.amount": res.data.amount - 0
  299. })
  300. })
  301. }
  302. }
  303. })