detail.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. const _Http = getApp().globalData.http;
  2. let figure = null; //免运费额度
  3. import currency from "../../utils/currency";
  4. Page({
  5. data: {
  6. hidePrice: wx.getStorageSync('hidePrice'),
  7. loading: true,
  8. sa_orderid: null,
  9. tabsActive: 0,
  10. tabsList: [{
  11. label: "产品明细",
  12. icon: "icon-tabchanpin",
  13. model: "#Product"
  14. }, {
  15. label: "附件",
  16. icon: "icon-tabfujian1",
  17. model: "#Yl_Attachment"
  18. }, {
  19. label: "订单进度",
  20. icon: "icon-tabcaozuojilu1",
  21. model: "#Progress"
  22. }, {
  23. label: "出库单",
  24. icon: "icon-tabrenwu",
  25. model: "#Consignment"
  26. }, {
  27. label: "物流单",
  28. icon: "icon-shouhuo",
  29. model: "#Shipments"
  30. }]
  31. },
  32. onLoad(options) {
  33. this.setData({
  34. options: wx.getStorageSync('auth').worderform.options,
  35. sa_orderid: options.id,
  36. order_rebate_used: wx.getStorageSync('siteP').order_rebate_used,
  37. userrole: wx.getStorageSync('userrole')
  38. });
  39. this.getDetail(true);
  40. },
  41. /* 获取详情 */
  42. getDetail(init = false, show = true) {
  43. _Http.basic({
  44. "id": 20221108151302,
  45. "content": {
  46. nocache: true,
  47. "sa_orderid": this.data.sa_orderid
  48. }
  49. }, show).then(res => {
  50. console.log("订单详情", res.data)
  51. if (res.msg != '成功') return wx.showToast({
  52. title: res.msg,
  53. icon: "none"
  54. });
  55. let CNY = value => currency(value, {
  56. symbol: "¥",
  57. precision: 2
  58. }).format();
  59. if (res.data.sa_accountclassinfos) res.data.sa_accountclassinfos = res.data.sa_accountclassinfos.map(v => {
  60. v.amount = CNY(v.amount)
  61. v.text = `\n(余额:${CNY(v.balance)},信用额度:${CNY(v.creditquota)})`
  62. return v
  63. })
  64. this.setData({
  65. detail: res.data,
  66. loading: false,
  67. amount: CNY(res.data.amount)
  68. });
  69. if (init) {
  70. this.partialRenewal(true)
  71. let content = wx.getStorageSync('userrole') == '业务员' ? {
  72. sys_enterpriseid: this.data.detail.sys_enterpriseid
  73. } : {};
  74. //业务员根据指定经销商的免运费
  75. _Http.basic({
  76. "id": 20220920084001,
  77. content
  78. }, false).then(res => {
  79. console.log("查询企业档案获取企业免邮额度", res)
  80. if (res.msg != '成功') return wx.showToast({
  81. title: res.msg,
  82. icon: "none"
  83. })
  84. figure = res.data.freefreightamount;
  85. this.setLogisticsMsg();
  86. })
  87. } else {
  88. this.setLogisticsMsg();
  89. }
  90. })
  91. },
  92. /* 免运费信息 */
  93. setLogisticsMsg() {
  94. let logistics = null;
  95. if (figure == -1) {
  96. logistics = '到付'
  97. } else if (figure == 0) {
  98. logistics = '预付'
  99. } else {
  100. let amount = this.data.detail.amount;
  101. logistics = amount >= figure ? '免运费' : '差' + currency(figure).subtract(amount).value + '元免运费';
  102. }
  103. this.setData({
  104. logistics
  105. })
  106. },
  107. /* 选择结算人 */
  108. selectAgent() {
  109. if (this.isEdit()) return;
  110. if (this.data.detail.type == '项目订单') return;
  111. wx.navigateTo({
  112. url: `/select/agent/index?params=${JSON.stringify({
  113. "id":20230104103702,
  114. "content": {
  115. "pageNumber": 1,
  116. "pageTotal": 1,
  117. "pageSize": 20,
  118. "where": {
  119. "condition": "",
  120. },
  121. }
  122. })}&radio=true`,
  123. });
  124. getApp().globalData.handleSelect = this.setAgeant.bind(this);
  125. },
  126. /* 设置结算人 */
  127. setAgeant({
  128. item
  129. }) {
  130. let that = this;
  131. console.log("选择经销商", item)
  132. wx.showModal({
  133. title: '提示',
  134. content: `是否确认设置"${item.enterprisename}"为结算人?`,
  135. complete: (res) => {
  136. if (res.confirm) {
  137. let pay_enterpriseid = that.data.detail.pay_enterpriseid,
  138. sys_enterprise_financeid = that.data.detail.sys_enterprise_financeid,
  139. sa_accountclassid = that.data.detail.accountclass.sa_accountclassid;
  140. that.setData({
  141. "detail.pay_enterpriseid": item.sys_enterpriseid,
  142. "detail.sys_enterprise_financeid": item.finance[0] ? item.finance[0].sys_enterprise_financeid : 0,
  143. "detail.accountclass.sa_accountclassid": item.accounts[0] ? item.accounts[0].sa_accountclassid : 0,
  144. });
  145. that.changeDetail().then(s => {
  146. if (s.msg == '成功') {
  147. wx.showToast({
  148. title: '设置成功',
  149. icon: "none"
  150. });
  151. setTimeout(() => {
  152. wx.navigateBack();
  153. that.getDetail();
  154. }, 500)
  155. } else {
  156. that.setData({
  157. "detail.pay_enterpriseid": pay_enterpriseid,
  158. "detail.sys_enterprise_financeid": sys_enterprise_financeid,
  159. "detail.sa_accountclassid": sa_accountclassid
  160. });
  161. }
  162. })
  163. }
  164. }
  165. })
  166. },
  167. /* 修改支付账户 */
  168. changeAccount(e) {
  169. if (this.isEdit()) return;
  170. wx.navigateTo({
  171. url: `/select/account/index?params=${JSON.stringify({
  172. "id":20221008134803,
  173. "version": 1,
  174. "content": {
  175. "pageNumber": 1,
  176. "pageTotal": 1,
  177. "pageSize": 20,
  178. "where": {
  179. "condition": "",
  180. "isused": 1,
  181. "isnotspecialfund": this.data.detail.type == '标准订单' ? 0 : 1, //是否专用
  182. },
  183. }
  184. })}&radio=true`,
  185. });
  186. getApp().globalData.handleSelect = this.setAccount.bind(this);
  187. },
  188. setAccount({
  189. item
  190. }) {
  191. let that = this;
  192. wx.showModal({
  193. title: '提示',
  194. content: `是否确认设置"${item.accountname}"为结算人?`,
  195. complete: (res) => {
  196. if (res.confirm) {
  197. that.setData({
  198. "detail.sa_accountclassid": item.sa_accountclassid,
  199. });
  200. that.changeDetail().then(s => {
  201. if (s.msg == '成功') {
  202. wx.showToast({
  203. title: '设置成功',
  204. icon: "none"
  205. });
  206. setTimeout(() => {
  207. wx.navigateBack();
  208. that.getDetail();
  209. }, 500)
  210. }
  211. })
  212. }
  213. }
  214. })
  215. },
  216. /* 选择财务信息 */
  217. selectFinance() {
  218. if (this.isEdit()) return;
  219. wx.navigateTo({
  220. url: `/select/finance/index?params=${JSON.stringify({
  221. "id":20221013160602,
  222. "content": {
  223. nocache:true,
  224. sys_enterpriseid:this.data.detail.sys_enterpriseid,
  225. "pageNumber": 1,
  226. "pageTotal": 1,
  227. "pageSize": 20,
  228. "where": {
  229. "condition": "",
  230. },
  231. }
  232. })}&radio=true`,
  233. });
  234. getApp().globalData.handleSelect = this.setFinance.bind(this);
  235. },
  236. /* 设置财务信息 */
  237. setFinance({
  238. item
  239. }) {
  240. let that = this;
  241. console.log("设置财务信息", item)
  242. wx.showModal({
  243. title: '提示',
  244. content: `是否确认设置"${item.enterprisename}"为开票单位?`,
  245. complete: (res) => {
  246. if (res.confirm) {
  247. let sys_enterprise_financeid = that.data.detail.sys_enterprise_financeid;
  248. that.setData({
  249. "detail.sys_enterprise_financeid": item.sys_enterprise_financeid
  250. });
  251. that.changeDetail().then(s => {
  252. if (s.msg == '成功') {
  253. wx.showToast({
  254. title: '设置成功',
  255. icon: "none"
  256. });
  257. setTimeout(() => {
  258. wx.navigateBack();
  259. that.getDetail();
  260. }, 500)
  261. } else {
  262. that.setData({
  263. "detail.sys_enterprise_financeid": sys_enterprise_financeid
  264. });
  265. }
  266. })
  267. }
  268. }
  269. })
  270. },
  271. //tabs 切换
  272. tabsChange({
  273. detail
  274. }) {
  275. this.setData({
  276. tabsActive: detail
  277. });
  278. this.partialRenewal();
  279. },
  280. //局部数据更新 tabs
  281. partialRenewal(init = false) {
  282. let model = this.data.tabsList[this.data.tabsActive].model;
  283. if (model) {
  284. let Component = this.selectComponent(model),
  285. {
  286. total,
  287. pageNumber,
  288. pageTotal
  289. } = Component.data.content,
  290. id = this.data.detail.sa_orderid;
  291. if (total == null || init) {
  292. Component.getList(id, init);
  293. } else if (pageNumber <= pageTotal) {
  294. Component.getList(id, false);
  295. }
  296. }
  297. },
  298. onReachBottom() {
  299. this.partialRenewal();
  300. },
  301. /* 更新数据 */
  302. changeDetail() {
  303. let data = this.data.detail,
  304. content = {
  305. "sa_orderid": data.sa_orderid,
  306. "sys_enterpriseid": data.sys_enterpriseid, //订货企业id
  307. "sa_accountclassid": data.sa_accountclassid || 0, //营销账户类型ID
  308. "sa_brandid": data.sa_brandid, //品牌ID
  309. "sys_enterprise_financeid": data.sys_enterprise_financeid || 0, //合作企业财务信息ID(开票信息)
  310. //"sa_logiscompid": data.logiscomp.sa_logiscompid || 0, 物流公司档案ID
  311. "rec_contactsid": data.rec_contactsid || 0, //合作企业联系人表ID(收货信息)
  312. "type": data.type, //订单类型
  313. "typemx": data.typemx, // 明细分类,可选
  314. "remarks": data.remarks,
  315. "saler_hrid": data.saler_hrid, //销售人员hrid,业务员hrid
  316. "tradefield": data.tradefield, //必选
  317. "pay_enterpriseid": data.pay_enterpriseid, //结算单位
  318. "rebate_userate": data.accountclass.rebate_userate, //返利金使用比例
  319. sa_order_v: data.sa_order_v || ""
  320. };
  321. return new Promise((resolve, reject) => {
  322. _Http.basic({
  323. "id": 20221108111402,
  324. content
  325. }).then(res => {
  326. console.log("修改订单数据", res);
  327. if (res.msg != '成功') wx.showToast({
  328. title: res.msg,
  329. icon: "none"
  330. });
  331. resolve(res)
  332. })
  333. })
  334. },
  335. /* 修改订单备注 */
  336. changeRemarks(e) {
  337. let value = e.detail.value,
  338. remarks = this.data.detail.remarks,
  339. that = this;
  340. if (value == this.data.detail.remarks) return;
  341. wx.showModal({
  342. title: '提示',
  343. content: '是否确定修改订单备注?',
  344. complete: async (res) => {
  345. if (res.cancel) that.setData({
  346. "detail.remarks": remarks
  347. })
  348. if (res.confirm) {
  349. this.data.detail.remarks = value;
  350. let res = await that.changeDetail();
  351. that.setData({
  352. "detail.remarks": res.msg == '成功' ? value : remarks
  353. })
  354. }
  355. }
  356. })
  357. },
  358. /* 设置是否使用返利金 */
  359. changeRebateUsed() {
  360. if (this.isEdit()) return this.setData({
  361. detail: this.data.detail
  362. })
  363. let amount = (this.data.detail.order_rebate_userate * this.data.detail.amount).toFixed(2); //最大可用金额
  364. let rebatebalance = this.data.detail.rebatebalance; //返利金账户余额
  365. _Http.basic({
  366. "id": 20230218225002,
  367. "content": {
  368. "sa_orderid": this.data.sa_orderid, //订单金额
  369. "isused": this.data.detail.rebate_used == 1 ? 0 : 1, //是否使用
  370. "rebateamount": rebatebalance > amount ? amount : rebatebalance, //返利金使用金额
  371. "sa_order_v": this.data.detail.sa_order_v || '',
  372. }
  373. }, false).then(res => {
  374. console.log('设置启用返利金', res)
  375. if (res.msg != '成功') {
  376. wx.showToast({
  377. title: res.msg,
  378. icon: "none"
  379. });
  380. this.setData({
  381. "detail.rebate_used": this.data.detail.rebate_used
  382. })
  383. return;
  384. }
  385. this.getDetail(true, false)
  386. })
  387. },
  388. /* 修改返利金 */
  389. setRebate_amount(e = 0) {
  390. let value = e.detail.value;
  391. let rebatebalance = this.data.detail.rebatebalance; //返利金账户余额
  392. value = value > rebatebalance ? rebatebalance : value;
  393. let amount = (this.data.detail.order_rebate_userate * this.data.detail.amount).toFixed(2); //最大可用金额
  394. _Http.basic({
  395. "id": 20230218225002,
  396. "content": {
  397. "sa_orderid": this.data.sa_orderid, //订单金额
  398. "isused": 1, //是否使用
  399. "rebateamount": value > amount ? amount : value,
  400. "sa_order_v": this.data.detail.sa_order_v || '',
  401. }
  402. }, false).then(res => {
  403. console.log('设置返利金', res)
  404. if (res.msg != '成功') {
  405. wx.showToast({
  406. title: res.msg,
  407. icon: "none",
  408. mask: true
  409. });
  410. this.setData({
  411. "detail.accountclass.rebate_amount": this.data.detail.accountclass.rebate_amount
  412. })
  413. } else {
  414. this.setData({
  415. "detail.accountclass.rebate_amount": value
  416. })
  417. if (value > amount || amount == 0) wx.showToast({
  418. title: "返利金最大可使用" + amount + "元",
  419. icon: "none"
  420. })
  421. this.getDetail(true, false)
  422. }
  423. })
  424. },
  425. /* 删除订单 */
  426. deleteItem() {
  427. let that = this;
  428. wx.showModal({
  429. title: '提示',
  430. content: '是否确认删除订单?',
  431. complete: (res) => {
  432. if (res.confirm) _Http.basic({
  433. "id": 20221108152102,
  434. "content": {
  435. "sa_orderids": [
  436. that.data.sa_orderid
  437. ]
  438. }
  439. }).then(s => {
  440. console.log("删除订单", s)
  441. if (s.msg != '成功') return wx.showToast({
  442. title: s.msg,
  443. icon: "none"
  444. });
  445. wx.showToast({
  446. title: `成功删除${that.data.detail.sonum}订单`,
  447. icon: "none"
  448. });
  449. setTimeout(() => {
  450. wx.navigateBack()
  451. }, 500)
  452. })
  453. }
  454. })
  455. },
  456. /* 特殊订单预提交 */
  457. presubmission(e) {
  458. let that = this;
  459. let isrecheck = e.currentTarget.dataset.isrecheck == 1;
  460. wx.showModal({
  461. title: '提示',
  462. content: `是否确认${isrecheck?'预提交订单':'撤回预提交'}?`,
  463. complete: (res) => {
  464. if (res.confirm) _Http.basic({
  465. "id": 20230331152503,
  466. "content": {
  467. isrecheck,
  468. sa_orderid: that.data.sa_orderid,
  469. sa_order_v: that.data.detail.sa_order_v,
  470. },
  471. }).then(s => {
  472. console.log("预提交订单", s)
  473. wx.showToast({
  474. title: s.msg != '成功' ? s.msg : isrecheck ? '预提交成功' : '撤回预提交成功',
  475. icon: "none"
  476. });
  477. if (s.msg == '成功') that.setData({
  478. "detail.status": isrecheck ? "预提交" : '新建'
  479. })
  480. })
  481. }
  482. })
  483. },
  484. /* 提交订单 */
  485. submit() {
  486. let that = this;
  487. wx.showModal({
  488. title: '提示',
  489. content: '是否确认提交订单?',
  490. complete: (res) => {
  491. if (res.confirm) _Http.basic({
  492. "id": 20221108153402,
  493. "content": {
  494. sa_orderid: that.data.sa_orderid,
  495. sa_order_v: that.data.detail.sa_order_v,
  496. },
  497. }).then(s => {
  498. console.log("提交订单", s)
  499. wx.showToast({
  500. title: s.msg != '成功' ? s.msg : '提交成功',
  501. icon: "none"
  502. });
  503. if (s.msg == '成功') that.setData({
  504. "detail.status": "提交"
  505. })
  506. })
  507. }
  508. })
  509. },
  510. /* 判断是否可以编辑 */
  511. isEdit() {
  512. if (this.data.detail.status != '新建') wx.showToast({
  513. title: '当前订单状态不可设置!',
  514. icon: "none"
  515. });
  516. return this.data.detail.status != '新建' || this.data.detail.type == '特殊订单';
  517. },
  518. /* 拷贝订单 */
  519. copyItem() {
  520. let item = this.data.detail;
  521. wx.showModal({
  522. title: '提示',
  523. content: `是否确认复制${item.type}“${item.sonum}”`,
  524. complete: (res) => {
  525. if (res.confirm) _Http.basic({
  526. "id": 20230102144502,
  527. "content": {
  528. "sa_orderid": item.sa_orderid
  529. }
  530. }).then(res => {
  531. console.log("复制订单", res)
  532. if (res.msg != '成功') return wx.showToast({
  533. title: res.msg,
  534. icon: "none"
  535. });
  536. wx.showModal({
  537. title: '提示',
  538. content: `${item.type}复制成功 是否立即前往`,
  539. complete: (s) => {
  540. if (s.confirm) wx.redirectTo({
  541. url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
  542. })
  543. }
  544. })
  545. })
  546. }
  547. })
  548. },
  549. /* 设置项目订单品牌领域 */
  550. setBraned() {
  551. wx.navigateTo({
  552. url: './modules/setBrand/index?id=' + this.data.sa_orderid,
  553. })
  554. },
  555. onUnload() {
  556. let page = getCurrentPages().find(v => v.__route__ == "packageA/orderForm/index")
  557. if (page) page.updateList && page.updateList()
  558. }
  559. })