index.js 11 KB

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