index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <template>
  2. <view class="content" style="background: #F4F5F7;">
  3. <view class="top">
  4. <view>
  5. <image class="logo" :src="userDetail.avatar"></image>
  6. </view>
  7. <view class="topRight">
  8. <view class="wxName">{{userDetail.name}}</view>
  9. <view class="titleBox">
  10. <view class="title" v-for="(item,index) in customerInfo.lables">{{item.name}}</view>
  11. </view>
  12. </view>
  13. </view>
  14. <view class="tabBox">
  15. <view class="tabline" :class="{tabActive:tabIndex==1}" @click="tabFn(1)">客户信息</view>
  16. <view class="tabline" :class="{tabActive:tabIndex==2}" @click="tabFn(2)">车辆信息</view>
  17. <view class="tabline" :class="{tabActive:tabIndex==3}" @click="tabFn(3)">套餐余额</view>
  18. <view class="tabline" :class="{tabActive:tabIndex==4}" @click="tabFn(4)">优惠券</view>
  19. <view class="tabline" :class="{tabActive:tabIndex==5}" @click="tabFn(5)">消费历史</view>
  20. </view>
  21. <custom ref="customView" :token="token" v-show="tabIndex==1"></custom>
  22. <car ref="carView" :token="token" v-show="tabIndex==2"></car>
  23. <packageV ref="packageView" v-show="tabIndex==3"></packageV>
  24. <coupon ref="couponView" v-show="tabIndex==4"></coupon>
  25. <consumption ref="consumptionView" v-show="tabIndex==5"></consumption>
  26. <!-- <view>{{code}}</view>
  27. <view @click="copy(code)">复制code</view> -->
  28. <!--<view style="color: red;">{{userId}}</view>
  29. <view @click="copy(userId)">复制userId</view>
  30. <view @click="copy(token)">{{token}}</view>
  31. <view>{{agentId}}</view> -->
  32. <!-- <view @click="oAuth">重新授权</view> -->
  33. <!-- <view style="color: red;">{{userId}}</view>
  34. <view @click="copy(userId)">复制userId</view>
  35. <view>{{token}}</view>
  36. <view @click="copy(token)">复制token</view> -->
  37. </view>
  38. </template>
  39. <script>
  40. import custom from './custom.vue'
  41. import car from './car.vue'
  42. import packageV from './package.vue'
  43. import coupon from './coupon.vue'
  44. import consumption from './consumption.vue'
  45. export default {
  46. components: {
  47. custom,car,packageV,coupon,consumption
  48. },
  49. data() {
  50. return {
  51. title: 'Hello',
  52. tabIndex:1,
  53. token:'',
  54. code:'',
  55. userId:'',
  56. userDetail:'',
  57. customerInfo:'',
  58. corpID:'',
  59. agentId:'',
  60. unionID:'',
  61. }
  62. },
  63. onLoad() {
  64. var that=this
  65. this.code=uni.getStorageSync('code')
  66. this.token=uni.getStorageSync('token')
  67. this.corpID=uni.getStorageSync('corpID')
  68. this.agentId=uni.getStorageSync('agentId')
  69. //this.userId='wmMGjbBgAA0JAbGD5Vu8BzEuYgZhvhOA'
  70. //this.token='26AF53EA2DC528681ABD7B3AC46072E96F0A964431A2453CF0F1DA1C28732A1EAF945459643F62A3A6FD87751E6880BB'
  71. //this.userId='wmMGjbBgAALroygkoaVBN4-W2O1daIkg'
  72. //this.token='065BAA93971FEB1A37A08D682FCDB41CC69E76FC36BB038790FB99C5CD71C28EAF945459643F62A3A6FD87751E6880BB'
  73. this.userId='wmMGjbBgAAeKTdCmEN0CLKPNwJ4ACTxw'
  74. this.token='0A809B6077F4044EDECFC49762B59668E9508B2CA4C6C4791C8894B2B1A7338AAF945459643F62A3A6FD87751E6880BB'
  75. uni.setStorage({
  76. key: 'token',
  77. data: that.token,
  78. success: function () {
  79. that.extCustomerInfo()
  80. that.extUserDetail()
  81. }
  82. });
  83. uni.setStorage({
  84. key: 'userId',
  85. data: that.userId,
  86. success: function () {
  87. }
  88. });
  89. /* this.code='aSBU0ums_4Z3ofjrfgSlYppwI9Cku5qtIg45ECkJTYY'
  90. */
  91. /* if(!this.token){
  92. this.authUserInfo()
  93. }else{
  94. this.extCustomerInfo()
  95. //this.$refs.customView.getdata()
  96. this.extUserDetail()
  97. //this.init()
  98. }
  99. */
  100. // this.authUserInfo()
  101. //this.extUserDetail()
  102. },
  103. methods: {
  104. tabFn(num){
  105. this.tabIndex=num
  106. if(num==1){
  107. this.$refs.customView.getdata()
  108. }
  109. if(num==2){
  110. this.$refs.carView.getdata()
  111. }
  112. if(num == 3){
  113. this.$refs.packageView.getdata()
  114. }
  115. if(num==4){
  116. this.$refs.couponView.getdata()
  117. }
  118. if(num==5){
  119. this.$refs.consumptionView.getdata()
  120. }
  121. },
  122. extCustomerInfo(){
  123. var that=this;
  124. this.$http('enterprise/wechat/extCustomerInfo', {
  125. corpID:'wpMGjbBgAA_zIu6wbKy48zFSbGiGeP8g',
  126. // extUserId:'wmMGjbBgAA0JAbGD5Vu8BzEuYgZhvhOA',
  127. extUserId:this.userId,
  128. token:this.token
  129. }, 'GET').then(res => {
  130. this.customerInfo=res.data.customerInfo
  131. uni.setStorage({
  132. key: 'integral',
  133. data: that.customerInfo.integral,
  134. success: function () { }
  135. });
  136. uni.setStorage({
  137. key: 'levelName',
  138. data: that.customerInfo.levelName,
  139. success: function () { }
  140. });
  141. var map=res.data.map
  142. var arr=[]
  143. if(map.length){
  144. map.forEach(item=>{
  145. arr.push(item.PlateNumber)
  146. })
  147. }
  148. uni.setStorage({
  149. key: 'PlateNumberArr',
  150. data: arr,
  151. success: function () { }
  152. });
  153. })
  154. },
  155. extUserDetail(){
  156. var that=this;
  157. this.$http('enterpriseWechat/auth/extUserDetail', {
  158. corpID:'wpMGjbBgAA_zIu6wbKy48zFSbGiGeP8g',
  159. // extUserId:'wmMGjbBgAA0JAbGD5Vu8BzEuYgZhvhOA'
  160. extUserId:this.userId
  161. }, 'GET').then(res => {
  162. uni.hideLoading();
  163. this.userDetail=res.data
  164. this.$refs.customView.getdata()
  165. })
  166. },
  167. authUserInfo(){
  168. var that=this;
  169. uni.showLoading({
  170. title: '加载中'
  171. });
  172. this.$http('enterpriseWechat/auth/authUserInfo', {
  173. corpID:'wpMGjbBgAA_zIu6wbKy48zFSbGiGeP8g',
  174. code: this.code
  175. }, 'GET').then(res => {
  176. this.token=res.data.token
  177. uni.setStorage({
  178. key: 'token',
  179. data: that.token,
  180. success: function () {
  181. that.init()
  182. }
  183. });
  184. //that.extUserDetail()
  185. //that.extCustomerInfo()
  186. })
  187. },
  188. init(){
  189. /* if(this.$wx.agentConfig){
  190. uni.showToast({
  191. title: 'agentConfig',
  192. icon: 'none',
  193. duration: 3000
  194. });
  195. }else{
  196. uni.showToast({
  197. title: 'agentConfig失败',
  198. icon: 'none',
  199. duration: 3000
  200. });
  201. } */
  202. var that=this
  203. this.$http('enterpriseWechat/auth/getAgentConfig', {
  204. corpID:'wpMGjbBgAA_zIu6wbKy48zFSbGiGeP8g',
  205. url:'http://qw.66km.com.cn/'
  206. }, 'GET').then(res => {
  207. console.log(11)
  208. that.$wx.agentConfig({
  209. corpid: 'wpMGjbBgAA_zIu6wbKy48zFSbGiGeP8g', // 必填,企业微信的corpid,必须与当前登录的企业一致
  210. agentid:that.agentId, // 必填,企业微信的应用id (e.g. 1000247)
  211. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  212. nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
  213. signature: res.data.signature,// 必填,签名,见附录-JS-SDK使用权限签名算法
  214. jsApiList: ['getCurExternalContact','getContext'], //必填,传入需要使用的接口名称
  215. success: function(res) {
  216. console.log(res)
  217. /* uni.showToast({
  218. title: 'agentConfig成功',
  219. icon: 'none',
  220. duration: 3000
  221. }); */
  222. // 回调
  223. that.getContext()
  224. },
  225. fail: function(err) {
  226. console.log(err)
  227. uni.showToast({
  228. title: 'agentConfig失败11',
  229. icon: 'none',
  230. duration: 3000
  231. });
  232. if(res.errMsg.indexOf('function not exist') > -1){
  233. alert('版本过低请升级')
  234. }
  235. }
  236. });
  237. })
  238. },
  239. getContext(){
  240. var that=this;
  241. this.$wx.invoke('getContext', {
  242. }, function(res){
  243. if(res.err_msg == "getContext:ok"){
  244. // entry = res.entry ; //返回进入H5页面的入口类型,目前有normal、contact_profile、single_chat_tools、group_chat_tools、chat_attachment
  245. //shareTicket = res.shareTicket; //可用于调用getShareInfo接口
  246. that.getCurExternalContact()
  247. }else {
  248. //错误处理
  249. uni.showToast({
  250. title: '入口不对',
  251. icon: 'none',
  252. duration: 3000
  253. });
  254. }
  255. });
  256. },
  257. getCurExternalContact(){
  258. var that=this;
  259. this.$wx.invoke('getCurExternalContact', {
  260. }, function(res){
  261. if(res.err_msg == "getCurExternalContact:ok"){
  262. that.userId = res.userId ; //返回当前外部联系人userId
  263. uni.setStorage({
  264. key: 'userId',
  265. data: that.userId,
  266. success: function () {
  267. }
  268. });
  269. that.extUserDetail()
  270. that.extCustomerInfo()
  271. }else {
  272. //错误处理
  273. uni.showToast({
  274. title: 'userId获取失败',
  275. icon: 'none',
  276. duration: 3000
  277. });
  278. }
  279. });
  280. },
  281. init2(){
  282. var that=this;
  283. console.log(this.$wx.config)
  284. if(this.code){
  285. if(that.$wx.config){
  286. }else{
  287. uni.showToast({
  288. title: 'agentConfig失败',
  289. icon: 'none',
  290. duration: 3000
  291. });
  292. }
  293. }else{
  294. uni.navigateTo({
  295. url:'auto'
  296. })
  297. }
  298. uni.showLoading({
  299. title: '加载中'
  300. });
  301. /* this.$http('enterpriseWechat/auth/oAuth2', {
  302. corpID:'wpMGjbBgAA_zIu6wbKy48zFSbGiGeP8g',
  303. redirectUri:'http://qw.66km.com.cn/#/',
  304. agentId:'1000036'
  305. }, 'GET').then(res => {
  306. uni.hideLoading();
  307. console.log(res.data)
  308. }).catch(err=>{
  309. uni.hideLoading();
  310. }) */
  311. this.$http('enterpriseWechat/auth/getAgentConfig', {
  312. corpID:'wpMGjbBgAA_zIu6wbKy48zFSbGiGeP8g',
  313. url:'http://qw.66km.com.cn/'
  314. }, 'GET').then(res => {
  315. uni.hideLoading();
  316. console.log(this.$wx)
  317. this.$wx.config({
  318. debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  319. appId: 'wpMGjbBgAA_zIu6wbKy48zFSbGiGeP8g', // 必填,公众号的唯一标识
  320. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  321. nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
  322. signature: res.data.signature,// 必填,签名
  323. jsApiList: [getCurExternalContact] // 必填,需要使用的JS接口列表
  324. });
  325. that.$wx.ready(() => {
  326. if(that.$wx.agentConfig){
  327. }else{
  328. uni.showToast({
  329. title: 'agentConfig失败',
  330. icon: 'none',
  331. duration: 3000
  332. });
  333. }
  334. // that.agentConfigFn()
  335. that.$wx.agentConfig({
  336. corpid: 'wpMGjbBgAA_zIu6wbKy48zFSbGiGeP8g', // 必填,企业微信的corpid,必须与当前登录的企业一致
  337. agentid: '1000051', // 必填,企业微信的应用id (e.g. 1000247)
  338. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  339. nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
  340. signature: res.data.signature,// 必填,签名,见附录-JS-SDK使用权限签名算法
  341. jsApiList: ['getCurExternalContact'], //必填,传入需要使用的接口名称
  342. success: function(res) {
  343. console.log(res)
  344. uni.showToast({
  345. title: 'agentConfig成功',
  346. icon: 'none',
  347. duration: 3000
  348. });
  349. // 回调
  350. taht.getContext()
  351. },
  352. fail: function(res) {
  353. console.log(res)
  354. uni.showToast({
  355. title: 'agentConfig失败',
  356. icon: 'none',
  357. duration: 3000
  358. });
  359. if(res.errMsg.indexOf('function not exist') > -1){
  360. alert('版本过低请升级')
  361. }
  362. }
  363. });
  364. })
  365. }).catch(err=>{
  366. uni.hideLoading();
  367. })
  368. },
  369. agentConfigFn(){
  370. },
  371. oAuth(){
  372. uni.navigateTo({
  373. url:'auto?appid='+this.agentId+'&agentid='+this.agentId
  374. })
  375. },
  376. copy(e){
  377. uni.setClipboardData({
  378. data: e,
  379. success: function () {
  380. uni.showToast({
  381. title: '复制成功',
  382. icon: 'success',
  383. duration: 2000
  384. });
  385. },
  386. fail: function () {
  387. console.log('复制失败');
  388. }
  389. });
  390. }
  391. }
  392. }
  393. </script>
  394. <style scoped>
  395. .top{
  396. background: #fff;
  397. }
  398. .top{
  399. display: flex;
  400. padding: 30rpx 24rpx;
  401. }
  402. .logo{
  403. width: 98rpx;height: 98rpx;
  404. }
  405. .topRight{
  406. padding-left: 20rpx;
  407. }
  408. .wxName{
  409. font-weight: 500;
  410. font-size: 32rpx;
  411. color: #333333;
  412. line-height: 45rpx;
  413. }
  414. .titleBox{
  415. display: flex;
  416. padding-top: 10rpx;
  417. display: flex; flex-wrap: wrap;
  418. width: 500rpx;
  419. }
  420. .title{
  421. height: 36rpx;
  422. border-radius: 4rpx;
  423. border: 1px solid #FF8113;
  424. line-height: 34rpx;
  425. font-size: 24rpx;
  426. color: #FF8113;
  427. padding: 0 8rpx;
  428. margin-right: 10rpx;
  429. margin-bottom: 10rpx;
  430. }
  431. .tabBox{
  432. display: flex;justify-content: space-between;
  433. background: #fff;
  434. margin-top: 16rpx;
  435. padding: 30rpx 24rpx;
  436. font-size: 30rpx;
  437. color: #333333;
  438. line-height: 42rpx;
  439. }
  440. .tabActive{
  441. color: #FF8113;font-weight: 500;
  442. border-bottom: 2px solid #FF8113;
  443. }
  444. .tabline{
  445. padding-bottom: 8rpx;
  446. }
  447. </style>