detail.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. const _Http = getApp().globalData.http,
  2. currency = require("../../utils/currency"),
  3. CNY = num => currency(num, {
  4. symbol: "¥",
  5. precision: 2
  6. }).format();
  7. Page({
  8. data: {
  9. loading: true,
  10. sa_orderid: null,
  11. tabsActive: 0,
  12. tabsList: [{
  13. label: "借用工具明细",
  14. icon: "icon-tabchanpin",
  15. model: "#Product"
  16. }, {
  17. label: "附件",
  18. icon: "icon-tabfujian1",
  19. model: "#Yl_Attachment"
  20. }, {
  21. label: "订单进度",
  22. icon: "icon-tabcaozuojilu1",
  23. model: "#Progress"
  24. }],
  25. },
  26. onLoad(options) {
  27. this.setData({
  28. sa_orderid: options.id
  29. });
  30. this.getDetail(true);
  31. },
  32. onCopy() {
  33. let that = this;
  34. wx.showModal({
  35. title: '提示',
  36. content: '是否确定复制该借用单',
  37. complete: (a) => {
  38. if (a.confirm) _Http.basic({
  39. "id": "20240315131202",
  40. "content": {
  41. "sa_orderid": that.data.sa_orderid
  42. }
  43. }).then(res => {
  44. console.log("借用单复制", res)
  45. if (res.msg != '成功') return wx.showToast({
  46. title: res.msg,
  47. icon: "none"
  48. })
  49. wx.showModal({
  50. title: '提示',
  51. content: '复制成功,是否立即前往',
  52. complete: (s) => {
  53. if (s.confirm) wx.navigateTo({
  54. url: '/packageA/borrow/detail?id=' + res.data.sa_orderid,
  55. })
  56. }
  57. })
  58. })
  59. }
  60. })
  61. },
  62. /* 获取详情 */
  63. getDetail(init = false, show = true) {
  64. _Http.basic({
  65. "id": 20230114140402,
  66. "content": {
  67. nocache: true,
  68. "sa_orderid": this.data.sa_orderid
  69. }
  70. }, show).then(res => {
  71. console.log("订单详情", res)
  72. if (res.msg != '成功') return wx.showToast({
  73. title: res.msg,
  74. icon: "none"
  75. });
  76. res.data.amount = CNY(res.data.amount);
  77. this.setData({
  78. detail: res.data,
  79. loading: false
  80. });
  81. if (init) this.partialRenewal(true)
  82. })
  83. },
  84. /* 选择收货人 */
  85. selectConsignee() {
  86. if (this.isEdit()) return;
  87. wx.navigateTo({
  88. url: `/select/address/index?params=${JSON.stringify({
  89. "id":20221009155803,
  90. "content": {
  91. nocache:true,
  92. sys_enterpriseid:this.data.detail.sys_enterpriseid,
  93. "pageNumber": 1,
  94. "pageTotal": 1,
  95. "pageSize": 20,
  96. "where": {
  97. "condition": "",
  98. workaddress:1
  99. },
  100. }
  101. })}&radio=true`,
  102. });
  103. getApp().globalData.handleSelect = this.setConsignee.bind(this);
  104. },
  105. /* 设置收货人 */
  106. setConsignee({
  107. item
  108. }) {
  109. let that = this;
  110. console.log("设置收货人", item)
  111. wx.showModal({
  112. title: '提示',
  113. content: `是否确认设置"${item.name}"为收货人?`,
  114. complete: (res) => {
  115. if (res.confirm) {
  116. let rec_contactsid = that.data.detail.rec_contactsid;
  117. that.setData({
  118. "detail.rec_contactsid": item.contactsid
  119. });
  120. that.changeDetail().then(s => {
  121. if (s.msg == '成功') {
  122. wx.showToast({
  123. title: '设置成功',
  124. icon: "none"
  125. });
  126. setTimeout(() => {
  127. wx.navigateBack();
  128. that.getDetail();
  129. }, 500)
  130. } else {
  131. that.setData({
  132. "detail.rec_contactsid": rec_contactsid
  133. });
  134. }
  135. })
  136. }
  137. }
  138. })
  139. },
  140. /* 选择财务信息 */
  141. selectFinance() {
  142. if (this.isEdit()) return;
  143. wx.navigateTo({
  144. url: `/select/finance/index?params=${JSON.stringify({
  145. "id":20221013160602,
  146. "content": {
  147. nocache:true,
  148. sys_enterpriseid:this.data.detail.sys_enterpriseid,
  149. "pageNumber": 1,
  150. "pageTotal": 1,
  151. "pageSize": 20,
  152. "where": {
  153. "condition": "",
  154. },
  155. }
  156. })}&radio=true`,
  157. });
  158. getApp().globalData.handleSelect = this.setFinance.bind(this);
  159. },
  160. /* 设置财务信息 */
  161. setFinance({
  162. item
  163. }) {
  164. let that = this;
  165. console.log("设置财务信息", item)
  166. wx.showModal({
  167. title: '提示',
  168. content: `是否确认设置"${item.enterprisename}"为开票单位?`,
  169. complete: (res) => {
  170. if (res.confirm) {
  171. let sys_enterprise_financeid = that.data.detail.sys_enterprise_financeid;
  172. that.setData({
  173. "detail.sys_enterprise_financeid": item.sys_enterprise_financeid
  174. });
  175. that.changeDetail().then(s => {
  176. if (s.msg == '成功') {
  177. wx.showToast({
  178. title: '设置成功',
  179. icon: "none"
  180. });
  181. setTimeout(() => {
  182. wx.navigateBack();
  183. that.getDetail();
  184. }, 500)
  185. } else {
  186. that.setData({
  187. "detail.sys_enterprise_financeid": sys_enterprise_financeid
  188. });
  189. }
  190. })
  191. }
  192. }
  193. })
  194. },
  195. //tabs 切换
  196. tabsChange({
  197. detail
  198. }) {
  199. this.setData({
  200. tabsActive: detail
  201. });
  202. this.partialRenewal();
  203. },
  204. //局部数据更新 tabs
  205. partialRenewal(init = false) {
  206. let model = this.data.tabsList[this.data.tabsActive].model;
  207. if (model) {
  208. let Component = this.selectComponent(model),
  209. {
  210. total,
  211. pageNumber,
  212. pageTotal
  213. } = Component.data.content,
  214. id = this.data.detail.sa_orderid;
  215. if (model == '#Product') id = {
  216. id: this.data.detail.sa_orderid,
  217. toolcount: this.data.detail.toolcount || ""
  218. };
  219. if (total == null || init) {
  220. Component.getList(id, init);
  221. } else if (pageNumber <= pageTotal) {
  222. Component.getList(id, false);
  223. }
  224. }
  225. },
  226. onReachBottom() {
  227. this.partialRenewal();
  228. },
  229. /* 更新数据 */
  230. changeDetail() {
  231. let data = this.data.detail,
  232. content = {
  233. "sa_orderid": data.sa_orderid,
  234. "sys_enterpriseid": data.sys_enterpriseid, //订货企业id
  235. "sa_accountclassid": data.accountclass.sa_accountclassid || 0, //营销账户类型ID
  236. "sa_brandid": data.sa_brandid, //品牌ID
  237. "sys_enterprise_financeid": data.sys_enterprise_financeid || 0, //合作企业财务信息ID(开票信息)
  238. "rec_contactsid": data.rec_contactsid || 0, //合作企业联系人表ID(收货信息)
  239. "type": data.type, //订单类型
  240. "typemx": data.typemx, // 明细分类,可选
  241. "remarks": data.remarks,
  242. sa_contractid: data.sa_contractid,
  243. "saler_hrid": data.saler_hrid, //销售人员hrid,业务员hrid
  244. "tradefield": data.tradefield, //必选
  245. "pay_enterpriseid": data.pay_enterpriseid, //结算单位
  246. };
  247. return new Promise((resolve, reject) => {
  248. _Http.basic({
  249. "id": 20230116092702,
  250. content
  251. }).then(res => {
  252. console.log("修改订单数据", res);
  253. if (res.msg != '成功') wx.showToast({
  254. title: res.msg,
  255. icon: "none"
  256. });
  257. resolve(res)
  258. })
  259. })
  260. },
  261. /* 修改订单备注 */
  262. changeRemarks(e) {
  263. let value = e.detail.value,
  264. remarks = this.data.detail.remarks,
  265. that = this;
  266. if (value == this.data.detail.remarks) return;
  267. wx.showModal({
  268. title: '提示',
  269. content: '是否确定修改订单备注?',
  270. complete: async (res) => {
  271. if (res.cancel) that.setData({
  272. "detail.remarks": remarks
  273. })
  274. if (res.confirm) {
  275. this.data.detail.remarks = value;
  276. let res = await that.changeDetail();
  277. that.setData({
  278. "detail.remarks": res.msg == '成功' ? value : remarks
  279. })
  280. }
  281. }
  282. })
  283. },
  284. /* 删除订单 */
  285. deleteItem() {
  286. let that = this;
  287. wx.showModal({
  288. title: '提示',
  289. content: '是否确认删除订单?',
  290. complete: (res) => {
  291. if (res.confirm) _Http.basic({
  292. "id": 20230116100002,
  293. "content": {
  294. "sa_orderids": [
  295. that.data.sa_orderid
  296. ]
  297. }
  298. }).then(s => {
  299. console.log("删除订单", s)
  300. if (s.msg != '成功') return wx.showToast({
  301. title: s.msg,
  302. icon: "none"
  303. });
  304. wx.showToast({
  305. title: `成功删除${that.data.detail.sonum}订单`,
  306. icon: "none"
  307. });
  308. setTimeout(() => {
  309. /* let page = getCurrentPages().find(v => v.__route__ == 'packageA/orderForm/index');
  310. if (page) page.setData({
  311. list: page.data.list.filter(v => v.sa_orderid != that.data.sa_orderid),
  312. "content.total": page.data.content.total - 1,
  313. amount: (page.data.amount - that.data.detail.amount).toFixed(2)
  314. }); */
  315. wx.navigateBack()
  316. }, 500)
  317. })
  318. }
  319. })
  320. },
  321. /* 提交订单 */
  322. submit() {
  323. let that = this;
  324. wx.showModal({
  325. title: '提示',
  326. content: '是否确认提交订单?',
  327. complete: (res) => {
  328. if (res.confirm) _Http.basic({
  329. "id": 20230114160002,
  330. "content": {
  331. sa_orderid: that.data.sa_orderid
  332. },
  333. }).then(s => {
  334. console.log("提交订单", s)
  335. wx.showToast({
  336. title: s.msg != '成功' ? s.msg : '提交成功',
  337. icon: "none"
  338. });
  339. if (s.msg == '成功') that.setData({
  340. "detail.status": "提交"
  341. })
  342. })
  343. }
  344. })
  345. },
  346. /* 确认订单交期 */
  347. notarize() {
  348. let that = this;
  349. wx.showModal({
  350. title: '提示',
  351. content: '是否确认交期?',
  352. complete: (res) => {
  353. if (res.confirm) _Http.basic({
  354. "id": 20230129154102,
  355. "content": {
  356. sa_orderid: that.data.sa_orderid
  357. },
  358. }).then(s => {
  359. console.log("确认交期", s)
  360. wx.showToast({
  361. title: s.msg != '成功' ? s.msg : '确认成功',
  362. icon: "none"
  363. });
  364. if (s.msg == '成功') {
  365. that.setData({
  366. "detail.status": "交期确认"
  367. })
  368. }
  369. })
  370. }
  371. })
  372. },
  373. /* 判断是否可以编辑 */
  374. isEdit() {
  375. if (this.data.detail.status != '新建') wx.showToast({
  376. title: '当前订单状态不可设置!',
  377. icon: "none"
  378. });
  379. return this.data.detail.status != '新建';
  380. },
  381. /* 设置项目订单品牌领域 */
  382. setBraned() {
  383. wx.navigateTo({
  384. url: './modules/setBrand/index?id=' + this.data.sa_orderid,
  385. })
  386. },
  387. onUnload() {
  388. let page = getCurrentPages().find(v => v.__route__ == 'packageA/borrow/index');
  389. let content = JSON.parse(JSON.stringify(page.data.content));
  390. content.pageNumber = 1;
  391. content.pageSize = (page.data.content.pageNumber - 1) * page.data.content.pageSize;
  392. _Http.basic({
  393. "id": 20230114105002,
  394. content
  395. }).then(res => {
  396. console.log("更新借用单", res)
  397. page.setData({
  398. list: res.data.map(v => {
  399. v.amount = CNY(v.amount)
  400. return v
  401. }),
  402. "content.total": res.total,
  403. })
  404. /* amount: res.tips.amount || 0 */
  405. })
  406. },
  407. })