detail.js 23 KB

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