detail.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. const _Http = getApp().globalData.http;
  2. let figure = null; //免运费额度
  3. import currency from "../../utils/currency";
  4. Page({
  5. data: {
  6. hidePrice: wx.getStorageSync('hidePrice'),
  7. loading: true,
  8. sa_orderid: null,
  9. tabsActive: 0,
  10. tabsList: [{
  11. label: "产品明细",
  12. icon: "icon-tabchanpin",
  13. model: "#Product"
  14. }, {
  15. label: "附件",
  16. icon: "icon-tabfujian1",
  17. model: "#Yl_Attachment"
  18. }, {
  19. label: "订单进度",
  20. icon: "icon-tabcaozuojilu1",
  21. model: "#Progress"
  22. }]
  23. },
  24. onLoad(options) {
  25. this.setData({
  26. sa_orderid: options.id,
  27. order_rebate_used: wx.getStorageSync('siteP').order_rebate_used,
  28. userrole: wx.getStorageSync('userrole')
  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. defaultamount: currency(res.data.defaultamount, {
  50. symbol: "¥",
  51. precision: 2
  52. }).format()
  53. });
  54. if (init) {
  55. this.partialRenewal(true)
  56. let content = wx.getStorageSync('userrole') == '业务员' ? {
  57. sys_enterpriseid: this.data.detail.sys_enterpriseid
  58. } : {};
  59. //业务员根据指定经销商的免运费
  60. _Http.basic({
  61. "id": 20220920084001,
  62. content
  63. }, false).then(res => {
  64. console.log("查询企业档案获取企业免邮额度", res)
  65. if (res.msg != '成功') return wx.showToast({
  66. title: res.msg,
  67. icon: "none"
  68. })
  69. figure = res.data.freefreightamount;
  70. this.setLogisticsMsg();
  71. })
  72. } else {
  73. this.setLogisticsMsg();
  74. }
  75. })
  76. },
  77. /* 免运费信息 */
  78. setLogisticsMsg() {
  79. let logistics = null;
  80. if (figure == -1) {
  81. logistics = '到付'
  82. } else if (figure == 0) {
  83. logistics = '预付'
  84. } else {
  85. let defaultamount = this.data.detail.defaultamount;
  86. logistics = defaultamount >= figure ? '免运费' : '差' + currency(figure).subtract(defaultamount).value + '元免运费';
  87. }
  88. this.setData({
  89. logistics
  90. })
  91. },
  92. /* 选择结算人 */
  93. selectAgent() {
  94. if (this.isEdit()) return;
  95. if (this.data.detail.type == '项目订单') return;
  96. wx.navigateTo({
  97. url: `/select/agent/index?params=${JSON.stringify({
  98. "id":20230104103702,
  99. "content": {
  100. "pageNumber": 1,
  101. "pageTotal": 1,
  102. "pageSize": 20,
  103. "where": {
  104. "condition": "",
  105. },
  106. }
  107. })}&radio=true`,
  108. });
  109. getApp().globalData.handleSelect = this.setAgeant.bind(this);
  110. },
  111. /* 设置结算人 */
  112. setAgeant({
  113. item
  114. }) {
  115. let that = this;
  116. console.log("选择经销商", item)
  117. wx.showModal({
  118. title: '提示',
  119. content: `是否确认设置"${item.enterprisename}"为结算人?`,
  120. complete: (res) => {
  121. if (res.confirm) {
  122. let pay_enterpriseid = that.data.detail.pay_enterpriseid,
  123. sys_enterprise_financeid = that.data.detail.sys_enterprise_financeid,
  124. sa_accountclassid = that.data.detail.accountclass.sa_accountclassid;
  125. that.setData({
  126. "detail.pay_enterpriseid": item.sys_enterpriseid,
  127. "detail.sys_enterprise_financeid": item.finance[0] ? item.finance[0].sys_enterprise_financeid : 0,
  128. "detail.accountclass.sa_accountclassid": item.accounts[0] ? item.accounts[0].sa_accountclassid : 0,
  129. });
  130. that.changeDetail().then(s => {
  131. if (s.msg == '成功') {
  132. wx.showToast({
  133. title: '设置成功',
  134. icon: "none"
  135. });
  136. setTimeout(() => {
  137. wx.navigateBack();
  138. that.getDetail();
  139. }, 500)
  140. } else {
  141. that.setData({
  142. "detail.pay_enterpriseid": pay_enterpriseid,
  143. "detail.sys_enterprise_financeid": sys_enterprise_financeid,
  144. "detail.sa_accountclassid": sa_accountclassid
  145. });
  146. }
  147. })
  148. }
  149. }
  150. })
  151. },
  152. /* 选择财务信息 */
  153. selectFinance() {
  154. if (this.isEdit()) return;
  155. wx.navigateTo({
  156. url: `/select/finance/index?params=${JSON.stringify({
  157. "id":20221013160602,
  158. "content": {
  159. nocache:true,
  160. sys_enterpriseid:this.data.detail.sys_enterpriseid,
  161. "pageNumber": 1,
  162. "pageTotal": 1,
  163. "pageSize": 20,
  164. "where": {
  165. "condition": "",
  166. },
  167. }
  168. })}&radio=true`,
  169. });
  170. getApp().globalData.handleSelect = this.setFinance.bind(this);
  171. },
  172. /* 设置财务信息 */
  173. setFinance({
  174. item
  175. }) {
  176. let that = this;
  177. console.log("设置财务信息", item)
  178. wx.showModal({
  179. title: '提示',
  180. content: `是否确认设置"${item.enterprisename}"为开票单位?`,
  181. complete: (res) => {
  182. if (res.confirm) {
  183. let sys_enterprise_financeid = that.data.detail.sys_enterprise_financeid;
  184. that.setData({
  185. "detail.sys_enterprise_financeid": item.sys_enterprise_financeid
  186. });
  187. that.changeDetail().then(s => {
  188. if (s.msg == '成功') {
  189. wx.showToast({
  190. title: '设置成功',
  191. icon: "none"
  192. });
  193. setTimeout(() => {
  194. wx.navigateBack();
  195. that.getDetail();
  196. }, 500)
  197. } else {
  198. that.setData({
  199. "detail.sys_enterprise_financeid": sys_enterprise_financeid
  200. });
  201. }
  202. })
  203. }
  204. }
  205. })
  206. },
  207. //tabs 切换
  208. tabsChange({
  209. detail
  210. }) {
  211. this.setData({
  212. tabsActive: detail
  213. });
  214. this.partialRenewal();
  215. },
  216. //局部数据更新 tabs
  217. partialRenewal(init = false) {
  218. let model = this.data.tabsList[this.data.tabsActive].model;
  219. if (model) {
  220. let Component = this.selectComponent(model),
  221. {
  222. total,
  223. pageNumber,
  224. pageTotal
  225. } = Component.data.content,
  226. id = this.data.detail.sa_orderid;
  227. if (total == null || init) {
  228. Component.getList(id, init);
  229. } else if (pageNumber < pageTotal) {
  230. Component.getList(id, false);
  231. }
  232. }
  233. },
  234. onReachBottom() {
  235. this.partialRenewal();
  236. },
  237. /* 更新数据 */
  238. changeDetail() {
  239. let data = this.data.detail,
  240. content = {
  241. "sa_orderid": data.sa_orderid,
  242. "sys_enterpriseid": data.sys_enterpriseid, //订货企业id
  243. "sa_accountclassid": data.sa_accountclassid || 0, //营销账户类型ID
  244. "sa_brandid": data.sa_brandid, //品牌ID
  245. "sys_enterprise_financeid": data.sys_enterprise_financeid || 0, //合作企业财务信息ID(开票信息)
  246. //"sa_logiscompid": data.logiscomp.sa_logiscompid || 0, 物流公司档案ID
  247. "rec_contactsid": data.rec_contactsid || 0, //合作企业联系人表ID(收货信息)
  248. "type": data.type, //订单类型
  249. "typemx": data.typemx, // 明细分类,可选
  250. "remarks": data.remarks,
  251. "saler_hrid": data.saler_hrid, //销售人员hrid,业务员hrid
  252. "tradefield": data.tradefield, //必选
  253. "pay_enterpriseid": data.pay_enterpriseid, //结算单位
  254. "rebate_userate": data.accountclass.rebate_userate, //返利金使用比例
  255. };
  256. return new Promise((resolve, reject) => {
  257. _Http.basic({
  258. "id": 20221108111402,
  259. content
  260. }).then(res => {
  261. console.log("修改订单数据", res);
  262. if (res.msg != '成功') wx.showToast({
  263. title: res.msg,
  264. icon: "none"
  265. });
  266. resolve(res)
  267. })
  268. })
  269. },
  270. /* 修改订单备注 */
  271. changeRemarks(e) {
  272. let value = e.detail.value,
  273. remarks = this.data.detail.remarks,
  274. that = this;
  275. if (value == this.data.detail.remarks) return;
  276. wx.showModal({
  277. title: '提示',
  278. content: '是否确定修改订单备注?',
  279. complete: async (res) => {
  280. if (res.cancel) that.setData({
  281. "detail.remarks": remarks
  282. })
  283. if (res.confirm) {
  284. this.data.detail.remarks = value;
  285. let res = await that.changeDetail();
  286. that.setData({
  287. "detail.remarks": res.msg == '成功' ? value : remarks
  288. })
  289. }
  290. }
  291. })
  292. },
  293. /* 设置是否使用返利金 */
  294. changeRebateUsed() {
  295. if (this.isEdit()) return this.setData({
  296. detail: this.data.detail
  297. })
  298. let amount = (this.data.detail.order_rebate_userate * this.data.detail.defaultamount).toFixed(2); //最大可用金额
  299. let rebatebalance = this.data.detail.rebatebalance; //返利金账户余额
  300. _Http.basic({
  301. "id": 20230218225002,
  302. "content": {
  303. "sa_orderid": this.data.sa_orderid, //订单金额
  304. "isused": this.data.detail.rebate_used == 1 ? 0 : 1, //是否使用
  305. "rebateamount": rebatebalance > amount ? amount : rebatebalance //返利金使用金额
  306. }
  307. }, false).then(res => {
  308. console.log('设置启用返利金', res)
  309. if (res.msg != '成功') {
  310. wx.showToast({
  311. title: res.msg,
  312. icon: "none"
  313. });
  314. this.setData({
  315. "detail.rebate_used": this.data.detail.rebate_used
  316. })
  317. return;
  318. }
  319. this.getDetail(true, false)
  320. })
  321. },
  322. /* 修改返利金 */
  323. setRebate_amount(e = 0) {
  324. let value = e.detail.value;
  325. let rebatebalance = this.data.detail.rebatebalance; //返利金账户余额
  326. value = value > rebatebalance ? rebatebalance : value;
  327. let amount = (this.data.detail.order_rebate_userate * this.data.detail.defaultamount).toFixed(2); //最大可用金额
  328. _Http.basic({
  329. "id": 20230218225002,
  330. "content": {
  331. "sa_orderid": this.data.sa_orderid, //订单金额
  332. "isused": 1, //是否使用
  333. "rebateamount": value > amount ? amount : value
  334. }
  335. }, false).then(res => {
  336. console.log('设置返利金', res)
  337. if (res.msg != '成功') {
  338. wx.showToast({
  339. title: res.msg,
  340. icon: "none",
  341. mask: true
  342. });
  343. this.setData({
  344. "detail.accountclass.rebate_amount": this.data.detail.accountclass.rebate_amount
  345. })
  346. } else {
  347. this.setData({
  348. "detail.accountclass.rebate_amount": value
  349. })
  350. if (value > amount || amount == 0) wx.showToast({
  351. title: "返利金最大可使用" + amount + "元",
  352. icon: "none"
  353. })
  354. this.getDetail(true, false)
  355. }
  356. })
  357. },
  358. /* 删除订单 */
  359. deleteItem() {
  360. let that = this;
  361. wx.showModal({
  362. title: '提示',
  363. content: '是否确认删除订单?',
  364. complete: (res) => {
  365. if (res.confirm) _Http.basic({
  366. "id": 20221108152102,
  367. "content": {
  368. "sa_orderids": [
  369. that.data.sa_orderid
  370. ]
  371. }
  372. }).then(s => {
  373. console.log("删除订单", s)
  374. if (s.msg != '成功') return wx.showToast({
  375. title: s.msg,
  376. icon: "none"
  377. });
  378. wx.showToast({
  379. title: `成功删除${that.data.detail.sonum}订单`,
  380. icon: "none"
  381. });
  382. setTimeout(() => {
  383. wx.navigateBack()
  384. }, 500)
  385. })
  386. }
  387. })
  388. },
  389. /* 提交订单 */
  390. submit() {
  391. let that = this;
  392. wx.showModal({
  393. title: '提示',
  394. content: '是否确认提交订单?',
  395. complete: (res) => {
  396. if (res.confirm) _Http.basic({
  397. "id": 20221108153402,
  398. "content": {
  399. sa_orderid: that.data.sa_orderid
  400. },
  401. }).then(s => {
  402. console.log("提交订单", s)
  403. wx.showToast({
  404. title: s.msg != '成功' ? s.msg : '提交成功',
  405. icon: "none"
  406. });
  407. if (s.msg == '成功') that.setData({
  408. "detail.status": "提交"
  409. })
  410. })
  411. }
  412. })
  413. },
  414. /* 判断是否可以编辑 */
  415. isEdit() {
  416. if (this.data.detail.status != '新建') wx.showToast({
  417. title: '当前订单状态不可设置!',
  418. icon: "none"
  419. });
  420. if (this.data.detail.type == '特殊订单') wx.showToast({
  421. title: '特殊订单不可设置!',
  422. icon: "none"
  423. });
  424. return this.data.detail.status != '新建' || this.data.detail.type == '特殊订单';
  425. },
  426. /* 拷贝订单 */
  427. copyItem() {
  428. let item = this.data.detail;
  429. wx.showModal({
  430. title: '提示',
  431. content: `是否确认复制${item.type}“${item.sonum}”`,
  432. complete: (res) => {
  433. if (res.confirm) _Http.basic({
  434. "id": 20230102144502,
  435. "content": {
  436. "sa_orderid": item.sa_orderid
  437. }
  438. }).then(res => {
  439. console.log("复制订单", res)
  440. if (res.msg != '成功') return wx.showToast({
  441. title: res.msg,
  442. icon: "none"
  443. });
  444. wx.showModal({
  445. title: '提示',
  446. content: `${item.type}复制成功 是否立即前往`,
  447. complete: (s) => {
  448. if (s.confirm) wx.redirectTo({
  449. url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
  450. })
  451. }
  452. })
  453. })
  454. }
  455. })
  456. },
  457. /* 设置项目订单品牌领域 */
  458. setBraned() {
  459. wx.navigateTo({
  460. url: './modules/setBrand/index?id=' + this.data.sa_orderid,
  461. })
  462. },
  463. onUnload() {
  464. let page = getCurrentPages().find(v => v.__route__ == "packageA/orderForm/index")
  465. if (page) page.updateList && page.updateList()
  466. }
  467. })