index.js 11 KB

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