detail.js 19 KB

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