viewcase.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. // index/pages/viewcase/viewcase.js
  2. const app = getApp();
  3. var utils = require("../../../utils/http");
  4. var designTimer = null;
  5. var time = 0;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. cid: '',
  12. dscDataMsg: '',
  13. detail: {},
  14. companyobj: {},
  15. loginFlag: false,
  16. canIUseGetUserProfile: false,
  17. designPlan: false,
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad(options) {
  23. if (wx.getUserProfile) {
  24. this.setData({
  25. canIUseGetUserProfile: true
  26. })
  27. }
  28. if (!!options.cid) {
  29. this.setData({
  30. cid: options.cid
  31. })
  32. if (options.type == 1) {
  33. this.devCaseDetail();
  34. } else {
  35. if (!!options.ctp) {
  36. app.globalData.clientype = options.ctp;
  37. }
  38. if (!!options.uid) {
  39. app.globalData.shareuserid = options.uid;
  40. }
  41. this.login();
  42. }
  43. }
  44. wx.hideHomeButton();
  45. },
  46. login: function () {
  47. var that = this;
  48. wx.login({
  49. success: function (data) {
  50. if (data.errMsg == 'login:ok') {
  51. utils.$post({
  52. url: app.globalData.webUrl + 'api/users/code2session',
  53. data: {
  54. code: data.code,
  55. share: app.globalData.shareuserid,
  56. client_type:app.globalData.clientype
  57. },
  58. success: function (r) {
  59. if (r.data.code == '0') {
  60. app.globalData.sharepersonobj = r.data.share;
  61. app.globalData.token = r.data.token;
  62. that.sharecompany();
  63. that.setData({
  64. sharepersonMsg: app.globalData.sharepersonobj,
  65. })
  66. if (r.data.user != null && (!!r.data.user.headimgurl && r.data.user.headimgurl != "" || !!r.data.user.nickname && r.data.user.nickname != "" && r.data.user.nickname != '游客')) {
  67. that.setData({
  68. loginFlag: false,
  69. employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false
  70. })
  71. app.globalData.personMsg = r.data.user;
  72. app.globalData.use_id = r.data.user.id;
  73. app.globalData.userflag = false;//有个人信息
  74. var nickname = r.data.user.nickname;
  75. var phone = r.data.user.phone;
  76. app.globalData.phone = false;//没有手机号
  77. if (r.data.user.phone == '') {
  78. wx.hideLoading();
  79. app.globalData.phone = false;//没有手机号
  80. that.setData({
  81. phoneFlag: true,
  82. })
  83. designTimer = setTimeout(() => {
  84. that.setData({
  85. designPlan: true
  86. })
  87. },3000)
  88. that.devClientCaseDetail();
  89. } else {
  90. app.globalData.phone = true;//有手机号
  91. that.setData({
  92. phoneFlag: false,
  93. })
  94. var obj = {
  95. detail: 1
  96. }
  97. that.devClientCaseDetail(obj);
  98. }
  99. } else {
  100. wx.hideLoading();
  101. that.setData({
  102. loginFlag: true,
  103. phoneFlag: true
  104. })
  105. }
  106. } else {
  107. setTimeout(function () {
  108. wx.hideLoading()
  109. }, 500)
  110. }
  111. }
  112. })
  113. }
  114. }
  115. })
  116. },
  117. sharecompany:function (){
  118. const that=this;
  119. utils.$post({
  120. url: app.globalData.webUrl + 'client/index/content_belong_company',
  121. header: {
  122. 'Authorization':'bearer '+app.globalData.token
  123. },
  124. data:{
  125. client_type:app.globalData.clientype,
  126. uid: app.globalData.shareuserid
  127. },
  128. success: function (res) {
  129. if(res.data.code=='0'){
  130. app.globalData.currentUserId = res.data.data.employee_id;
  131. that.setData({
  132. companyobj:res.data.data
  133. })
  134. }
  135. },
  136. complete(res) {
  137. wx.hideLoading()
  138. }
  139. })
  140. },
  141. devCaseDetail() {
  142. var that = this;
  143. utils.$get({
  144. url: app.globalData.webUrl + 'api/building/dev_case_detail',
  145. header: {
  146. 'Authorization': 'bearer ' + app.globalData.token
  147. },
  148. data: {
  149. id: that.data.cid,
  150. },
  151. success: function (res) {
  152. if (res.data.code == '0') {
  153. wx.setNavigationBarTitle({
  154. title: res.data.data.name,
  155. })
  156. that.setData({
  157. dscDataMsg: res.data.data.content,
  158. detail: res.data.data
  159. })
  160. } else {
  161. wx.showToast({
  162. title: res.data.msg,
  163. icon: 'none',
  164. duration: 1500
  165. })
  166. }
  167. }
  168. })
  169. },
  170. devClientCaseDetail() {
  171. var that = this;
  172. utils.$get({
  173. url: app.globalData.webUrl + 'client/building/dev_case_detail',
  174. header: {
  175. 'Authorization': 'bearer ' + app.globalData.token
  176. },
  177. data: {
  178. id: that.data.cid,
  179. },
  180. success: function (res) {
  181. if (res.data.code == '0') {
  182. wx.setNavigationBarTitle({
  183. title: res.data.data.name,
  184. })
  185. that.setData({
  186. dscDataMsg: res.data.data.content,
  187. detail: res.data.data
  188. })
  189. } else {
  190. wx.showToast({
  191. title: res.data.msg,
  192. icon: 'none',
  193. duration: 1500
  194. })
  195. }
  196. }
  197. })
  198. },
  199. closeDesigntap(e) {
  200. if (designTimer) {
  201. clearTimeout(designTimer);
  202. }
  203. if (e.detail.type == 'success') {
  204. this.setData({
  205. designPlan: false
  206. })
  207. } else {
  208. this.setData({
  209. designPlan: false
  210. })
  211. }
  212. },
  213. visitimefun() {
  214. const that = this;
  215. utils.$post({
  216. url: app.globalData.webUrl + 'client/index/visit_due_time',
  217. header: {
  218. 'Authorization': 'bearer ' + app.globalData.token
  219. },
  220. data: {
  221. id: that.data.cid,
  222. pipe_type: 'devcase',
  223. time: time,
  224. },
  225. success: function (res) {}
  226. })
  227. },
  228. /**
  229. * 生命周期函数--监听页面初次渲染完成
  230. */
  231. onReady() {
  232. },
  233. /**
  234. * 生命周期函数--监听页面显示
  235. */
  236. onShow() {
  237. time = 0;
  238. setInterval(() => {
  239. time++;
  240. },1000)
  241. },
  242. /**
  243. * 生命周期函数--监听页面隐藏
  244. */
  245. onHide() {
  246. this.visitimefun();
  247. },
  248. /**
  249. * 生命周期函数--监听页面卸载
  250. */
  251. onUnload() {
  252. this.visitimefun();
  253. },
  254. /**
  255. * 页面相关事件处理函数--监听用户下拉动作
  256. */
  257. onPullDownRefresh() {
  258. },
  259. /**
  260. * 页面上拉触底事件的处理函数
  261. */
  262. onReachBottom() {
  263. },
  264. /**
  265. * 用户点击右上角分享
  266. */
  267. onShareAppMessage() {
  268. var that = this;
  269. return {
  270. title: that.data.detail.name,
  271. path: '/index/pages/viewcase/viewcase?cid=' + that.data.cid + '&uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype + '&type=2'
  272. }
  273. }
  274. })