index.vue 13 KB

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