detail.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. const _Http = getApp().globalData.http,
  2. currency = require("../../utils/currency"),
  3. CNY = value => currency(value, {
  4. symbol: "¥",
  5. precision: 2
  6. }).format();
  7. Page({
  8. data: {
  9. isLeader: false, //是否为负责人
  10. tabsActive: 0, //tabs 选中项
  11. sa_contractid: "",
  12. tabsList: [{
  13. label: "详细信息",
  14. icon: "icon-tabxiangxixinxi1"
  15. }],
  16. tabbarList: [],
  17. },
  18. onLoad(options) {
  19. this.setData({
  20. sa_contractid: options.id,
  21. isAdmin: wx.getStorageSync('auth').wcontract.options.some(v => v == "admin"), //是否具有管理权限
  22. options: wx.getStorageSync('auth').wcontract.options, //权限列表
  23. });
  24. this.getDetail();
  25. },
  26. getDetail() {
  27. _Http.basic({
  28. "id": 20221121195102,
  29. "content": {
  30. nocache: true,
  31. "sa_contractid": this.data.sa_contractid
  32. },
  33. }).then(res => {
  34. console.log("合同详情", res)
  35. if (res.msg != '成功') return wx.showToast({
  36. title: res.msg,
  37. icon: "none"
  38. });
  39. let isLeader = res.data.leader.some(some => some.userid == wx.getStorageSync('userMsg').userid),
  40. tabbarList = [{
  41. icon: "icon-genjin",
  42. label: "跟进"
  43. }];
  44. if (this.data.isAdmin) tabbarList = [{
  45. icon: "icon-genjin",
  46. label: "审核"
  47. }, {
  48. icon: "icon-genjin",
  49. label: "反审核"
  50. }].concat(tabbarList);
  51. if (isLeader || this.data.isAdmin) {
  52. tabbarList = [{
  53. icon: "icon-zhuanyi",
  54. label: "更换负责人"
  55. }, {
  56. icon: "icon-genjin",
  57. label: "终止"
  58. }, {
  59. icon: "icon-shanchu",
  60. label: "作废"
  61. }].concat(tabbarList)
  62. if (res.data.status == '新建') tabbarList.push({
  63. icon: "icon-bianji",
  64. label: "编辑"
  65. });
  66. if (isLeader && res.data.status == '已提交') {
  67. tabbarList.unshift({
  68. icon: "icon-genjin",
  69. label: '撤回'
  70. })
  71. } else {
  72. tabbarList.unshift({
  73. icon: "icon-genjin",
  74. label: '提交'
  75. })
  76. }
  77. };
  78. let data = res.data,
  79. tabsList = this.data.tabsList,
  80. tabsActive = 0;
  81. switch (data.type) {
  82. case "框架":
  83. data.type = '经销商合作协议'
  84. tabsList = tabsList.concat([{
  85. label: "产品明细折扣",
  86. icon: "icon-tabchanpin",
  87. model: '#PiscountProduct'
  88. }, {
  89. label: "产品类别折扣",
  90. icon: "icon-tabchanpinleibie",
  91. model: '#PiscountType'
  92. }, {
  93. label: "业绩目标",
  94. icon: "icon-tabrenwu",
  95. model: '#Objective'
  96. }, {
  97. label: "跟进动态",
  98. icon: "icon-tabgenjindongtai1",
  99. model: '#Trace'
  100. }]);
  101. tabsActive = 1;
  102. break;
  103. case "工具借用":
  104. data.type = '工具使用(借用)协议'
  105. tabsList = tabsList.concat([{
  106. label: "工具清单",
  107. icon: "icon-tabgongjuqingdan",
  108. model: '#Product'
  109. }, {
  110. label: "跟进动态",
  111. icon: "icon-tabgenjindongtai1",
  112. model: '#Trace'
  113. }])
  114. tabsActive = 1;
  115. break;
  116. case "居间":
  117. data.type = '居间协议'
  118. break;
  119. case "项目":
  120. /* {
  121. label: "合同条款",
  122. num: 132
  123. }, */
  124. data.type = data.typemx + '项目协议'
  125. tabsList = tabsList.concat([{
  126. label: "产品明细折扣",
  127. icon: "icon-tabchanpin",
  128. model: '#Product'
  129. }, {
  130. label: "产品类别折扣",
  131. icon: "icon-tabchanpinleibie",
  132. model: '#PiscountType'
  133. }, {
  134. label: "跟进动态",
  135. icon: "icon-tabgenjindongtai1"
  136. }]);
  137. tabsActive = 1;
  138. break;
  139. };
  140. tabsList.push({
  141. label: "任务",
  142. icon: "icon-tabrenwu",
  143. model: "#Work"
  144. })
  145. this.setDetail(data);
  146. this.setData({
  147. isLeader,
  148. tabbarList,
  149. detail: data,
  150. list2: [{
  151. label: "创建人",
  152. value: data.createby
  153. }, {
  154. label: "创建时间",
  155. value: data.createdate
  156. }, {
  157. label: "最近编辑人",
  158. value: data.changeby
  159. }, {
  160. label: "最近编辑时间",
  161. value: data.changedate
  162. }, {
  163. label: "提交人",
  164. value: data.submitby
  165. }, {
  166. label: "提交时间",
  167. value: data.submitdate
  168. }, {
  169. label: "审核人",
  170. value: data.checkby
  171. }, {
  172. label: "审核时间",
  173. value: data.checkdate
  174. }, {
  175. label: "作废原因",
  176. value: data.leader.deletereason
  177. }, {
  178. label: "转手次数",
  179. value: data.leader[0].leadernum
  180. }],
  181. tabsList,
  182. tabsActive
  183. });
  184. /* 更新列表数据 */
  185. let page = getCurrentPages().find(v => v.__route__ == 'packageA/contract/index');
  186. if (page) {
  187. let i = page.data.list.findIndex(v => v.sa_contractid == this.data.sa_contractid);
  188. if (i != -1) page.setData({
  189. [`list[${i}].status`]: res.data.status
  190. })
  191. }
  192. this.getTags();
  193. this.getGroup();
  194. this.partialRenewal();
  195. })
  196. },
  197. /* 设置详情信息 */
  198. setDetail(data) {
  199. let briefs = [{
  200. label: "合同编号",
  201. value: data.billno
  202. }, {
  203. label: "合同类型",
  204. value: data.type
  205. }, {
  206. label: "经销商",
  207. value: data.enterprisename
  208. }, {
  209. label: "整体折扣",
  210. value: data.discountrate * 100 + "%"
  211. }, {
  212. label: "签约日期",
  213. value: data.signdate
  214. }, {
  215. label: "状态",
  216. value: data.status
  217. }],
  218. list1 = [{
  219. label: "合同标题",
  220. value: data.title
  221. }, {
  222. label: "合同编号",
  223. value: data.billno
  224. }, {
  225. label: "合同类型",
  226. value: data.type
  227. }, {
  228. label: "签约日期",
  229. value: data.signdate
  230. }, {
  231. label: "合同有效期",
  232. value: data.begdate + ' 至 ' + data.enddate
  233. }, {
  234. label: "合同模板",
  235. value: data.type
  236. }, {
  237. label: "合同描述",
  238. value: data.remarks
  239. }, {
  240. label: "负责人",
  241. value: data.leader[0].name
  242. }, {
  243. label: "状态",
  244. value: data.status
  245. }];
  246. if (data.typemx) {
  247. console.log(data)
  248. briefs.splice(3, 0, {
  249. label: "项目",
  250. value: data.projectname
  251. })
  252. briefs.splice(4, 0, {
  253. label: "项目编号",
  254. value: data.projectnum
  255. })
  256. briefs.splice(5, 0, {
  257. label: "有效期",
  258. value: data.begdate + ' 至 ' + data.enddate
  259. })
  260. briefs.splice(6, 1)
  261. briefs.splice(7, 0, {
  262. label: "签约金额(元)",
  263. value: CNY(data.signamount)
  264. })
  265. briefs.splice(7, 0, {
  266. label: "折扣(%)",
  267. value: data.discountrate * 100 + "%"
  268. })
  269. list1.splice(3, 0, {
  270. label: data.typemx == '直销' ? '客户' : "经销商",
  271. value: data.enterprisename
  272. })
  273. list1.splice(4, 0, {
  274. label: "项目",
  275. value: data.projectname
  276. })
  277. list1.splice(5, 0, {
  278. label: "品牌",
  279. value: data.brandname
  280. })
  281. list1.splice(6, 0, {
  282. label: "领域",
  283. value: data.tradefields
  284. })
  285. list1.splice(7, 0, {
  286. label: "项目编号",
  287. value: data.projectnum
  288. })
  289. list1.splice(8, 0, {
  290. label: "项目地址",
  291. value: data.address
  292. })
  293. list1.splice(9, 0, {
  294. label: "收货人",
  295. value: data.name
  296. })
  297. list1.splice(10, 0, {
  298. label: "收货人电话",
  299. value: data.phonenumber
  300. })
  301. list1.splice(11, 0, {
  302. label: "业务员",
  303. value: data.salername
  304. })
  305. list1.splice(12, 0, {
  306. label: "签约金额",
  307. value: CNY(data.signamount)
  308. })
  309. list1.splice(13, 0, {
  310. label: "折扣(%)",
  311. value: data.discountrate * 100 + "%"
  312. })
  313. if (data.typemx == '直销') briefs[2].label = '客户';
  314. } else {
  315. switch (data.type) {
  316. case "居间协议":
  317. briefs.splice(2, 1, {
  318. label: "居间服务商",
  319. value: data.enterprisename
  320. })
  321. briefs.splice(3, 0, {
  322. label: "项目",
  323. value: data.projectname
  324. })
  325. briefs.splice(4, 0, {
  326. label: "项目编号",
  327. value: data.projectnum
  328. })
  329. briefs.splice(5, 1, {
  330. label: data.calculatemodel == 1 ? '订单金额比例' : '产品折扣',
  331. value: data.calculatemodel == 1 ? data.orderratio * 100 + '%' : data.productdiscount * 100 + '%'
  332. })
  333. briefs.splice(3, 0, {
  334. label: "项目合同",
  335. value: data.ascription_title
  336. })
  337. briefs.splice(7, 0, {
  338. label: "合同有效期",
  339. value: data.begdate + "-" + data.enddate
  340. })
  341. list1.splice(3, 0, {
  342. label: "居间服务商",
  343. value: data.enterprisename
  344. })
  345. list1.splice(4, 0, {
  346. label: "项目合同",
  347. value: data.ascription_title
  348. })
  349. list1.splice(5, 0, {
  350. label: "项目",
  351. value: data.projectname
  352. })
  353. list1.splice(6, 0, {
  354. label: "项目编号",
  355. value: data.projectnum
  356. })
  357. list1.splice(8, 0, {
  358. label: data.calculatemodel == 1 ? '订单金额比例' : '居间产品折扣',
  359. value: data.calculatemodel == 1 ? data.orderratio * 100 + '%' : data.productdiscount * 100 + '%'
  360. })
  361. break;
  362. case "工具使用(借用)协议":
  363. briefs.splice(2, 1, {
  364. label: "客户",
  365. value: data.enterprisename
  366. })
  367. briefs.splice(3, 1, {
  368. label: "单套价格",
  369. value: data.signamount
  370. })
  371. briefs.splice(5, 0, {
  372. label: "合同有效期",
  373. value: data.begdate + ' 至 ' + data.enddate
  374. })
  375. list1.splice(3, 0, {
  376. label: "客户",
  377. value: data.enterprisename
  378. })
  379. list1.splice(4, 0, {
  380. label: "单套价格",
  381. value: data.signamount
  382. })
  383. break;
  384. case "经销商合作协议":
  385. briefs[3].label = '折扣(%)';
  386. briefs.splice(3, 0, {
  387. label: "签约金额(元)",
  388. value: CNY(data.signamount)
  389. })
  390. list1.splice(3, 0, {
  391. label: "经销商",
  392. value: data.enterprisename
  393. })
  394. list1.splice(4, 0, {
  395. label: "签约金额(元)",
  396. value: CNY(data.signamount)
  397. })
  398. list1.splice(5, 0, {
  399. label: "折扣(%)",
  400. value: data.discountrate * 100 + "%"
  401. })
  402. list1.splice(6, 0, {
  403. label: "品牌",
  404. value: data.brandname
  405. })
  406. list1.splice(7, 0, {
  407. label: "领域",
  408. value: data.tradefields
  409. })
  410. break;
  411. }
  412. }
  413. this.setData({
  414. briefs,
  415. list1
  416. })
  417. },
  418. //tabs 切换
  419. tabsChange({
  420. detail
  421. }) {
  422. this.setData({
  423. tabsActive: detail
  424. });
  425. this.partialRenewal();
  426. },
  427. //更新标签
  428. getTags() {
  429. this.selectComponent("#Tags").getTags();
  430. },
  431. //更新团队成员
  432. getGroup() {
  433. this.selectComponent("#Group").getList();
  434. },
  435. //局部数据更新 tabs
  436. partialRenewal(init = false) {
  437. let model = this.data.tabsList[this.data.tabsActive].model;
  438. if (model) {
  439. let Component = this.selectComponent(model),
  440. {
  441. total,
  442. pageNumber,
  443. pageTotal
  444. } = Component.data.content,
  445. id = this.data.sa_contractid;
  446. if (total == null || init) {
  447. Component.getList(id, init);
  448. } else if (pageNumber < pageTotal) {
  449. Component.getList(id, false);
  450. }
  451. }
  452. },
  453. onReachBottom() {
  454. this.partialRenewal();
  455. },
  456. //详情按钮回调
  457. tabbarOnClick({
  458. detail
  459. }) {
  460. let data = this.data.detail,
  461. that = this;
  462. switch (detail.label) {
  463. case "终止":
  464. wx.showModal({
  465. title: '提示',
  466. content: `是否确定终止当前协议`,
  467. complete: (res) => {
  468. if (res.confirm) _Http.basic({
  469. "id": 20221212102802,
  470. "content": {
  471. "sa_contractid": that.data.sa_contractid
  472. }
  473. }).then(res => {
  474. console.log("提交报价单", res)
  475. wx.showToast({
  476. title: res.msg == '成功' ? "已终止" : res.msg,
  477. icon: "none"
  478. })
  479. if (res.msg == '成功') setTimeout(() => {
  480. that.getDetail();
  481. }, 300)
  482. })
  483. }
  484. })
  485. break;
  486. case "提交":
  487. if (data.status != '新建') return wx.showToast({
  488. title: '当前状态不可提交!',
  489. icon: "none"
  490. })
  491. wx.showModal({
  492. title: '提示',
  493. content: `是否确定提交当前协议,提交后禁止使用部分功能`,
  494. complete: (res) => {
  495. if (res.confirm) _Http.basic({
  496. "id": 20221121202802,
  497. "content": {
  498. "sa_contractids": [that.data.sa_contractid]
  499. }
  500. }).then(res => {
  501. console.log("提交报价单", res)
  502. wx.showToast({
  503. title: res.msg == '成功' ? "提交成功" : res.msg,
  504. icon: "none"
  505. })
  506. if (res.msg == '成功') setTimeout(() => {
  507. that.getDetail();
  508. }, 300)
  509. })
  510. }
  511. })
  512. break;
  513. case "审核":
  514. if (data.status != '已提交') return wx.showToast({
  515. title: '当前状态不可审核!',
  516. icon: "none"
  517. })
  518. wx.showModal({
  519. title: '提示',
  520. content: `是否通过当前协议`,
  521. complete: (res) => {
  522. if (res.confirm) _Http.basic({
  523. "id": 20221121203102,
  524. "version": 1,
  525. "content": {
  526. "type": 1, //0:不通过,1:通过
  527. "sa_contractids": [that.data.sa_contractid]
  528. }
  529. }).then(res => {
  530. console.log("审核合同", res)
  531. wx.showToast({
  532. title: res.msg == '成功' ? "审核成功" : res.msg,
  533. icon: "none"
  534. })
  535. if (res.msg == '成功') setTimeout(() => {
  536. that.getDetail();
  537. }, 300)
  538. })
  539. }
  540. })
  541. break;
  542. case "撤回":
  543. if (data.status != '已提交') return wx.showToast({
  544. title: '当前状态不可撤回!',
  545. icon: "none"
  546. })
  547. wx.showModal({
  548. title: '提示',
  549. content: `是否撤回审核当前协议`,
  550. complete: (res) => {
  551. if (res.confirm) _Http.basic({
  552. "id": 20230130091502,
  553. "content": {
  554. "sa_contractid": that.data.sa_contractid,
  555. }
  556. }).then(res => {
  557. console.log("撤回审核合同", res)
  558. wx.showToast({
  559. title: res.msg == '成功' ? "撤回审核成功" : res.msg,
  560. icon: "none"
  561. })
  562. if (res.msg == '成功') setTimeout(() => {
  563. that.getDetail();
  564. }, 300)
  565. })
  566. }
  567. })
  568. break;
  569. case "反审核":
  570. if (data.status == '新建') return wx.showToast({
  571. title: '当前状态不可反审核!',
  572. icon: "none"
  573. })
  574. wx.showModal({
  575. title: '提示',
  576. content: `是否反审核当前协议`,
  577. complete: (res) => {
  578. if (res.confirm) _Http.basic({
  579. "id": 20221212135402,
  580. "content": {
  581. "sa_contractid": that.data.sa_contractid,
  582. }
  583. }).then(res => {
  584. console.log("反审核合同", res)
  585. wx.showToast({
  586. title: res.msg == '成功' ? "反审核成功" : res.msg,
  587. icon: "none"
  588. })
  589. if (res.msg == '成功') setTimeout(() => {
  590. that.getDetail();
  591. }, 300)
  592. })
  593. }
  594. })
  595. break;
  596. case "跟进":
  597. wx.navigateTo({
  598. url: `/packageA/setclient/modules/trace/add/index?ownertable=sa_contract&ownerid=${data.sa_contractid}`,
  599. })
  600. break;
  601. case "作废":
  602. wx.showModal({
  603. title: '提示',
  604. content: '是否确认作废该协议?',
  605. complete: ({
  606. confirm
  607. }) => {
  608. if (confirm) _Http.basic({
  609. "id": 20221121202502,
  610. "version": 1,
  611. "content": {
  612. "sa_contractids": [this.data.detail.sa_contractid]
  613. }
  614. }).then(res => {
  615. wx.showToast({
  616. title: res.msg == '成功' ? '已作废协议' : res.msg,
  617. icon: "none"
  618. });
  619. if (res.msg == '成功') {
  620. setTimeout(() => {
  621. getCurrentPages().forEach(v => {
  622. if (v.__route__ == 'packageA/contract/index') {
  623. v.setData({
  624. list: v.data.list.filter(value => value.sa_contractid != this.data.detail.sa_contractid),
  625. 'content.total': v.data.content.total - 1
  626. })
  627. }
  628. })
  629. wx.navigateBack();
  630. }, 300)
  631. }
  632. })
  633. }
  634. })
  635. break;
  636. case "编辑":
  637. this.toEdit();
  638. break;
  639. case "更换负责人":
  640. wx.navigateTo({
  641. url: `/pages/group/select?data=${JSON.stringify({
  642. ownertable:"sa_contract",
  643. ownerid:data.sa_contractid,
  644. })}&radio=true&principal=true`,
  645. })
  646. break;
  647. }
  648. },
  649. toEdit() {
  650. let data = this.data.detail,
  651. type = null;
  652. data.invaliddate = [data.begdate, data.enddate]
  653. data.sys_enterpriseid = [data.enterprisename, [data.sys_enterpriseid]];
  654. data.sa_projectid = [data.projectname, [data.sa_projectid]];
  655. switch (data.type) {
  656. case "经销商合作协议":
  657. type = "type1"
  658. break;
  659. case "经销项目协议":
  660. type = "type2"
  661. break;
  662. case "直销项目协议":
  663. type = "type3"
  664. break;
  665. case "居间协议":
  666. data.ascription_contractid = [data.ascription_title, [data.ascription_contractid]];
  667. data.radios = data.calculatemodel + "";
  668. type = "type4"
  669. break;
  670. case "工具使用(借用)协议":
  671. type = "type5"
  672. break;
  673. };
  674. if (type) wx.navigateTo({
  675. url: `/packageA/contract/add/${type}/index?data=${JSON.stringify(data)}`,
  676. })
  677. },
  678. /* 更换负责人 */
  679. handelSubmit(arr) {
  680. const that = this;
  681. wx.showModal({
  682. title: '提示',
  683. content: '是否确认更换负责人',
  684. complete: ({
  685. confirm
  686. }) => {
  687. if (confirm) _Http.basic({
  688. "id": 20220930103701,
  689. "content": {
  690. ownertable: "sa_contract",
  691. ownerid: that.data.detail.sa_contractid,
  692. userid: arr[0]
  693. }
  694. }).then(res => {
  695. console.log("更换负责人", res)
  696. if (res.msg != '成功') return wx.showToast({
  697. title: res.data,
  698. icon: "none"
  699. });
  700. wx.showToast({
  701. title: '更换成功!',
  702. icon: "none"
  703. });
  704. setTimeout(() => {
  705. that.getDetail();
  706. wx.navigateBack();
  707. }, 300)
  708. })
  709. }
  710. })
  711. },
  712. onUnload() {
  713. let page = getCurrentPages().find(v => v.__route__ == 'packageA/contract/index');
  714. if (!page) return;
  715. let content = JSON.parse(JSON.stringify(page.data.content));
  716. content.pageSize = (content.pageNumber - 1) * content.pageSize;
  717. content.pageNumber = 1;
  718. _Http.basic({
  719. id: 20221121201502,
  720. content
  721. }).then(res => {
  722. console.log("更新合同列表", res);
  723. if (res.msg == '成功') page.setData({
  724. list: res.data,
  725. "content.total": res.total
  726. })
  727. })
  728. }
  729. })