detail.js 15 KB

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