detail.js 15 KB

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