detail.js 14 KB

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