detail.js 11 KB

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