detail.js 21 KB

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