detail.js 23 KB

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