detail.js 22 KB

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