detail.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. isAdmin: getApp().globalData.auth.wcontract.options.some(v => v == "admin"), //是否具有管理权限
  5. isLeader: false, //是否为负责人
  6. options: getApp().globalData.auth.wcontract.options, //权限列表
  7. tabsActive: 0, //tabs 选中项
  8. sa_contractid: "",
  9. tabsList: [{
  10. label: "详细信息",
  11. num: 132
  12. }],
  13. tabbarList: [{
  14. icon: "icon-genjin",
  15. label: "跟进"
  16. }],
  17. },
  18. onLoad(options) {
  19. this.setData({
  20. sa_contractid: options.sa_contractid
  21. });
  22. this.getDetail();
  23. },
  24. getDetail() {
  25. _Http.basic({
  26. "id": 20221121195102,
  27. "content": {
  28. nocache: true,
  29. "sa_contractid": this.data.sa_contractid
  30. },
  31. }).then(res => {
  32. console.log("合同详情", res)
  33. if (res.msg != '成功') return wx.showToast({
  34. title: res.msg,
  35. icon: "none"
  36. });
  37. let isLeader = res.data.leader.some(some => some.userid == wx.getStorageSync('userMsg').userid),
  38. tabbarList = this.data.tabbarList;
  39. if (this.data.isAdmin) tabbarList = [{
  40. icon: "icon-genjin",
  41. label: "审核"
  42. }, {
  43. icon: "icon-genjin",
  44. label: "反审核"
  45. }].concat(tabbarList);
  46. if (isLeader || this.data.isAdmin) tabbarList = tabbarList.concat([{
  47. icon: "icon-genjin",
  48. label: "提交"
  49. }, {
  50. icon: "icon-genjin",
  51. label: "终止"
  52. }, {
  53. icon: "icon-zhuanyi",
  54. label: "更换负责人"
  55. }, {
  56. icon: "icon-shanchu",
  57. label: "作废"
  58. }])
  59. let data = res.data,
  60. tabsList = this.data.tabsList,
  61. tabsActive = 0;
  62. switch (data.type) {
  63. case "框架":
  64. data.type = '经销商合作协议'
  65. tabsList = tabsList.concat([{
  66. label: "产品明细折扣",
  67. num: 132
  68. }, {
  69. label: "产品类型折扣",
  70. num: 132
  71. }, {
  72. label: "跟进动态",
  73. num: 132
  74. }]);
  75. tabsActive = 1;
  76. break;
  77. case "工具借用":
  78. data.type = '工具使用(借出)协议'
  79. tabsList = tabsList.concat([{
  80. label: "工具清单",
  81. num: 132
  82. }, {
  83. label: "跟进动态",
  84. num: 132
  85. }]);
  86. tabsActive = 1;
  87. break;
  88. case "居间":
  89. data.type = '居间协议'
  90. break;
  91. case "项目":
  92. /* {
  93. label: "合同条款",
  94. num: 132
  95. }, */
  96. data.type = data.typemx + '项目协议'
  97. tabsList = tabsList.concat([{
  98. label: "产品清单",
  99. num: 132
  100. }, {
  101. label: "跟进动态",
  102. num: 132
  103. }]);
  104. tabsActive = 1;
  105. break;
  106. default:
  107. result = '--'
  108. break;
  109. };
  110. this.setDetail(data);
  111. this.setData({
  112. isLeader,
  113. tabbarList,
  114. detail: data,
  115. list2: [{
  116. label: "创建人",
  117. value: data.createby
  118. }, {
  119. label: "创建时间",
  120. value: data.createdate
  121. }, {
  122. label: "最近编辑人",
  123. value: data.changeby
  124. }, {
  125. label: "最近编辑时间",
  126. value: data.changedate
  127. }, {
  128. label: "最近跟进人",
  129. value: data.followby
  130. }, {
  131. label: "最近跟进时间",
  132. value: data.followdate
  133. }],
  134. tabsList,
  135. tabsActive
  136. });
  137. /* 更新列表数据 */
  138. let page = getCurrentPages().find(v => v.__route__ == 'packageA/contract/index');
  139. if (page) {
  140. let i = page.data.list.findIndex(v => v.sa_contractid == this.data.sa_contractid);
  141. if (i != -1) page.setData({
  142. [`list[${i}].status`]: res.data.status
  143. })
  144. }
  145. this.getTags();
  146. this.getGroup();
  147. this.partialRenewal();
  148. })
  149. },
  150. /* 设置详情信息 */
  151. setDetail(data) {
  152. let briefs = [{
  153. label: "合同编号",
  154. value: data.billno
  155. }, {
  156. label: "合同类型",
  157. value: data.type
  158. }, {
  159. label: "经销商",
  160. value: data.enterprisename
  161. }, {
  162. label: "整体折扣",
  163. value: data.discountrate
  164. }, {
  165. label: "签约时间",
  166. value: data.signdate
  167. }, {
  168. label: "状态",
  169. value: data.status
  170. }],
  171. list1 = [{
  172. label: "合同标题",
  173. value: data.title
  174. }, {
  175. label: "合同编号",
  176. value: data.billno
  177. }, {
  178. label: "合同类型",
  179. value: data.type
  180. }, {
  181. label: "合同模板",
  182. value: data.type
  183. }, {
  184. label: "负责人",
  185. value: data.leader[0].name
  186. },
  187. {
  188. label: "合同有效期",
  189. value: data.begdate + ' 至 ' + data.enddate
  190. }, {
  191. label: "签约时间",
  192. value: data.signdate
  193. }, {
  194. label: "合同描述",
  195. value: data.remarks
  196. }
  197. ];
  198. if (data.typemx) {
  199. briefs.splice(5, 0, {
  200. label: "签约金额",
  201. value: data.signamount
  202. })
  203. briefs.splice(4, 0, {
  204. label: "关联项目",
  205. value: data.projectname
  206. })
  207. list1.splice(4, 0, {
  208. label: "关联项目",
  209. value: data.projectname
  210. })
  211. list1.splice(7, 0, {
  212. label: "签约金额",
  213. value: data.signamount
  214. })
  215. } else {
  216. switch (data.type) {
  217. case "居间协议":
  218. briefs.splice(2, 1, {
  219. label: "居间服务商",
  220. value: data.enterprisename
  221. })
  222. briefs.splice(3, 0, {
  223. label: "关联项目",
  224. value: data.projectname
  225. })
  226. briefs.splice(5, 0, {
  227. label: "佣金比例",
  228. value: data.kickback + '%'
  229. })
  230. list1.splice(4, 0, {
  231. label: "居间服务商",
  232. value: data.enterprisename
  233. })
  234. list1.splice(5, 0, {
  235. label: "关联项目",
  236. value: data.projectname
  237. })
  238. list1.splice(8, 0, {
  239. label: "佣金比例",
  240. value: data.kickback + '%'
  241. })
  242. break;
  243. case "工具使用(借出)协议":
  244. briefs.splice(2, 1, {
  245. label: "客户",
  246. value: data.enterprisename
  247. })
  248. briefs.splice(3, 1)
  249. briefs.splice(4, 0, {
  250. label: "单套价格",
  251. value: data.signamount
  252. })
  253. list1.splice(5, 0, {
  254. label: "客户",
  255. value: data.enterprisename
  256. })
  257. list1.splice(8, 0, {
  258. label: "单套价格",
  259. value: data.signamount
  260. })
  261. break;
  262. }
  263. }
  264. this.setData({
  265. briefs,
  266. list1
  267. })
  268. },
  269. //tabs 切换
  270. tabsChange({
  271. detail
  272. }) {
  273. this.setData({
  274. tabsActive: detail
  275. });
  276. this.partialRenewal();
  277. },
  278. //更新标签
  279. getTags() {
  280. this.selectComponent("#Tags").getTags();
  281. },
  282. //更新团队成员
  283. getGroup() {
  284. this.selectComponent("#Group").getList();
  285. },
  286. //局部数据更新 tabs
  287. partialRenewal(init = false) {
  288. let id = this.data.detail.sa_contractid;
  289. let model = '';
  290. let name = this.data.tabsList[this.data.tabsActive].label;
  291. console.log(name)
  292. switch (name) {
  293. case "跟进动态":
  294. model = '#Trace'
  295. break;
  296. case "产品清单":
  297. model = '#Product'
  298. break;
  299. case "工具清单":
  300. model = '#Product'
  301. break;
  302. case "产品明细折扣":
  303. model = '#PiscountProduct'
  304. break;
  305. case "产品类型折扣":
  306. model = '#PiscountType'
  307. break;
  308. };
  309. if (model) {
  310. // 确定好模块ID total = null 是第一次加载 加载数据
  311. // init是新增或修改需要清数据
  312. let Component = this.selectComponent(model);
  313. const {
  314. total,
  315. pageNumber,
  316. pageTotal
  317. } = Component.data.content;
  318. if (total == null || init) {
  319. Component.getList(id, init);
  320. } else if (pageNumber <= pageTotal) {
  321. Component.getList(id, false);
  322. } else {
  323. //用来判断 在搜索页面修改,与tabs选项不一致 但是切换到该选项 重置数据
  324. }
  325. }
  326. },
  327. onReachBottom() {
  328. this.partialRenewal();
  329. },
  330. //详情按钮回调
  331. tabbarOnClick({
  332. detail
  333. }) {
  334. let data = this.data.detail,
  335. that = this;
  336. switch (detail.label) {
  337. case "终止":
  338. wx.showModal({
  339. title: '提示',
  340. content: `是否确定终止当前协议`,
  341. complete: (res) => {
  342. if (res.confirm) _Http.basic({
  343. "id": 20221212102802,
  344. "content": {
  345. "sa_contractid": that.data.sa_contractid
  346. }
  347. }).then(res => {
  348. console.log("提交报价单", res)
  349. wx.showToast({
  350. title: res.msg == '成功' ? "已终止" : res.msg,
  351. icon: "none"
  352. })
  353. if (res.msg == '成功') setTimeout(() => {
  354. that.getDetail();
  355. }, 300)
  356. })
  357. }
  358. })
  359. break;
  360. case "提交":
  361. if (data.status != '新建') return wx.showToast({
  362. title: '当前状态不可提交!',
  363. icon: "none"
  364. })
  365. wx.showModal({
  366. title: '提示',
  367. content: `是否确定提交当前协议,提交后禁止使用部分功能`,
  368. complete: (res) => {
  369. if (res.confirm) _Http.basic({
  370. "id": 20221121202802,
  371. "content": {
  372. "sa_contractids": [that.data.sa_contractid]
  373. }
  374. }).then(res => {
  375. console.log("提交报价单", res)
  376. wx.showToast({
  377. title: res.msg == '成功' ? "提交成功" : res.msg,
  378. icon: "none"
  379. })
  380. if (res.msg == '成功') setTimeout(() => {
  381. that.getDetail();
  382. }, 300)
  383. })
  384. }
  385. })
  386. break;
  387. case "审核":
  388. if (data.status != '已提交') return wx.showToast({
  389. title: '当前状态不可审核!',
  390. icon: "none"
  391. })
  392. wx.showModal({
  393. title: '提示',
  394. content: `是否通过当前协议`,
  395. complete: (res) => {
  396. if (res.confirm) _Http.basic({
  397. "id": 20221121203102,
  398. "version": 1,
  399. "content": {
  400. "type": 1, //0:不通过,1:通过
  401. "sa_contractids": [that.data.sa_contractid]
  402. }
  403. }).then(res => {
  404. console.log("审核合同", res)
  405. wx.showToast({
  406. title: res.msg == '成功' ? "审核成功" : res.msg,
  407. icon: "none"
  408. })
  409. if (res.msg == '成功') setTimeout(() => {
  410. that.getDetail();
  411. }, 300)
  412. })
  413. }
  414. })
  415. break;
  416. case "反审核":
  417. if (data.status == '新建') return wx.showToast({
  418. title: '当前状态不可反审核!',
  419. icon: "none"
  420. })
  421. wx.showModal({
  422. title: '提示',
  423. content: `是否退回当前协议`,
  424. complete: (res) => {
  425. if (res.confirm) _Http.basic({
  426. "id": 20221212135402,
  427. "content": {
  428. "sa_contractid": that.data.sa_contractid,
  429. }
  430. }).then(res => {
  431. console.log("反审核合同", res)
  432. wx.showToast({
  433. title: res.msg == '成功' ? "反审核成功" : res.msg,
  434. icon: "none"
  435. })
  436. if (res.msg == '成功') setTimeout(() => {
  437. that.getDetail();
  438. }, 300)
  439. })
  440. }
  441. })
  442. break;
  443. case "跟进":
  444. wx.navigateTo({
  445. url: `/packageA/setclient/modules/trace/add/index?ownertable=sa_contract&ownerid=${data.sa_contractid}`,
  446. })
  447. break;
  448. case "作废":
  449. wx.showModal({
  450. title: '提示',
  451. content: '是否确认作废该协议?',
  452. complete: ({
  453. confirm
  454. }) => {
  455. if (confirm) _Http.basic({
  456. "id": 20221121202502,
  457. "version": 1,
  458. "content": {
  459. "sa_contractids": [this.data.detail.sa_contractid]
  460. }
  461. }).then(res => {
  462. wx.showToast({
  463. title: res.msg == '成功' ? '已作废协议' : res.msg,
  464. icon: "none"
  465. });
  466. if (res.msg == '成功') {
  467. setTimeout(() => {
  468. getCurrentPages().forEach(v => {
  469. if (v.__route__ == 'packageA/contract/index') {
  470. v.setData({
  471. list: v.data.list.filter(value => value.sa_contractid != this.data.detail.sa_contractid),
  472. 'content.total': v.data.content.total - 1
  473. })
  474. }
  475. })
  476. wx.navigateBack();
  477. }, 300)
  478. }
  479. })
  480. }
  481. })
  482. break;
  483. case "更换负责人":
  484. wx.navigateTo({
  485. url: `/pages/group/select?data=${JSON.stringify({
  486. ownertable:"sa_contract",
  487. ownerid:data.sa_contractid,
  488. })}&radio=true&principal=true`,
  489. })
  490. break;
  491. }
  492. },
  493. /* 更换负责人 */
  494. handelSubmit(arr) {
  495. const that = this;
  496. wx.showModal({
  497. title: '提示',
  498. content: '是否确认更换负责人',
  499. complete: ({
  500. confirm
  501. }) => {
  502. if (confirm) _Http.basic({
  503. "id": 20220930103701,
  504. "content": {
  505. ownertable: "sa_contract",
  506. ownerid: that.data.detail.sa_contractid,
  507. userid: arr[0]
  508. }
  509. }).then(res => {
  510. console.log("更换负责人", res)
  511. if (res.msg != '成功') return wx.showToast({
  512. title: res.data,
  513. icon: "none"
  514. });
  515. wx.showToast({
  516. title: '更换成功!',
  517. icon: "none"
  518. });
  519. setTimeout(() => {
  520. that.getDetail();
  521. wx.navigateBack();
  522. }, 300)
  523. })
  524. }
  525. })
  526. },
  527. onShareAppMessage() {}
  528. })