index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <template>
  2. <view v-if="isShowView">
  3. <view class="photo" v-if="cardInfo.imageMap">
  4. <image :src="cardInfo.imageMap" mode="aspectFill" class="poster"></image>
  5. </view>
  6. <view class="infos">
  7. <view class="info dflex">
  8. <view class="flex">
  9. <view class="company">{{ cardInfo.companyName }}</view>
  10. <view class="name">{{ cardInfo.realName }}</view>
  11. <view class="job">{{ cardInfo.job }}</view>
  12. </view>
  13. <view class="logo"><image :src="cardInfo.avatar" mode="aspectFit"></image></view>
  14. </view>
  15. <view class="btns dflex" v-if="cardId">
  16. <button open-type="share" hover-class="none" class="share-ta">分享名片</button>
  17. <view class="save" @tap="addContact">保存到通讯录</view>
  18. </view>
  19. <view class="contacts" v-if="cardId || isShowContacts">
  20. <scroll-view scroll-x="true" class="contact">
  21. <view class="li" @click="goPhone()">
  22. <view class="lit dflex">
  23. <image src="../static/images/phone.png"></image>
  24. 拨打电话
  25. </view>
  26. <view class="num">{{ cardInfo.phone }}</view>
  27. </view>
  28. <view class="li" @click="copy(cardInfo.wechat, 1)">
  29. <view class="lit dflex">
  30. <image src="../static/images/wechat.png"></image>
  31. 复制微信
  32. </view>
  33. <view class="num">{{ cardInfo.wechat }}</view>
  34. </view>
  35. <view class="li" @click="copy(cardInfo.email, 2)">
  36. <view class="lit dflex">
  37. <image src="../static/images/message.png"></image>
  38. 复制邮箱
  39. </view>
  40. <view class="num">{{ cardInfo.email }}</view>
  41. </view>
  42. </scroll-view>
  43. </view>
  44. <view :class="'zhan dflex' + (isShowContacts ? ' zhan-romate':'')" v-if="!cardId" @click="showContacts()">
  45. {{isShowContacts ? '收起' : '显示全部信息'}}
  46. <image src="../static/images/bico1.png" class="bico"></image>
  47. </view>
  48. <block v-if="!cardId">
  49. <button open-type="share" hover-class="none" class="share">发名片</button>
  50. <view class="opt dflex">
  51. <view class="li" @click="jumpUrl('/card/create/create?isEdit=true&id=' + cardInfo.id)">
  52. <image src="../static/images/edit.png"></image>
  53. <view>编辑名片</view>
  54. </view>
  55. <!-- <view class="li">
  56. <image src="../static/images/fx_ico.png"></image>
  57. <view>分享图像名片</view>
  58. </view> -->
  59. <view class="li" @click="jumpUrl('/card/poster/poster?id=' + cardInfo.id)">
  60. <image src="../static/images/code.png"></image>
  61. <view>名片码</view>
  62. </view>
  63. </view>
  64. </block>
  65. <view class="datas dflex">
  66. <view class="users dflex flex">
  67. <!-- <image src="../../static/images/userimg.png" mode="aspectFill"></image>
  68. <image src="../../static/images/userimg.png" mode="aspectFill"></image>
  69. <image src="../../static/images/userimg.png" mode="aspectFill"></image> -->
  70. <view>{{ cardInfo.person }}人看过</view>
  71. </view>
  72. <view class="zan dflex" @click="userBehavior(3)">
  73. <image src="../static/images/zan_ico.png"></image>
  74. {{ cardInfo.thumbs }}
  75. </view>
  76. <!-- <view class="renqi dflex">
  77. <image src="../static/images/rqico.png"></image>
  78. {{ cardCount.viewsNo }}
  79. </view> -->
  80. </view>
  81. </view>
  82. <view class="box brief" v-if="cardInfo.brief">
  83. <view class="tit dflex">
  84. <view class="flex dflex">
  85. <image src="../static/images/jj_ico.png"></image>
  86. <view>个人简介</view>
  87. </view>
  88. <image v-if="!cardId" src="../static/images/bj_ico.png" class="edit" @tap="jumpUrl('/card/editDesc/editDesc?id=' + cardInfo.id)"></image>
  89. </view>
  90. <view class="bri"><rich-text :nodes="cardInfo.brief"></rich-text></view>
  91. </view>
  92. <view class="box" v-if="!cardId">
  93. <view class="tit dflex">
  94. <image src="../static/images/sj_ico.png"></image>
  95. <view>名片数据<text>(/人次)</text></view>
  96. </view>
  97. <view class="card-datas dflex">
  98. <view class="li">
  99. <text>{{ cardInfo.todayBrowse }}</text>
  100. 今日访问
  101. </view>
  102. <view class="li">
  103. <text>{{ cardInfo.browse }}</text>
  104. 访问总量
  105. </view>
  106. <view class="li">
  107. <text>{{ cardInfo.share }}</text>
  108. 名片分享
  109. </view>
  110. </view>
  111. </view>
  112. <view class="box videos" v-if="!cardId">
  113. <view class="tit ddflex">
  114. <view class="flex ddflex">
  115. <image src="../static/images/sp_ico.png"></image>
  116. <view>我的视频</view>
  117. </view>
  118. <!-- <image v-if="cardInfo.videoId" @click="uploadVodChangeHandle()" src="../static/images/bj_ico.png" class="edit"></image> -->
  119. <image v-if="cardInfo.videoId" @click="uploadVideo()" src="../static/images/bj_ico.png" class="edit"></image>
  120. </view>
  121. <view class="video">
  122. <!-- <video v-if="cardInfo.videoId" controls="true" class="video-sp" :src="videoInfo.playUrl"></video> -->
  123. <video v-if="cardInfo.videoId" controls="true" class="video-sp" :src="cardInfo.videoId"></video>
  124. <view v-else class="not" @click="uploadVideo()" v-else>
  125. <image src="../static/images/add_ico1.png"></image>
  126. <view>点击添加个人介绍视频</view>
  127. </view>
  128. </view>
  129. </view>
  130. <block v-else>
  131. <view class="box videos" v-if="cardInfo.videoId">
  132. <view class="tit ddflex">
  133. <view class="flex ddflex">
  134. <image src="../static/images/sp_ico.png"></image>
  135. <view>我的视频</view>
  136. </view>
  137. </view>
  138. <view class="video">
  139. <video controls="true" class="video-sp" :src="cardInfo.videoId"></video>
  140. <!-- <video controls="true" class="video-sp" :src="videoInfo.playUrl"></video> -->
  141. </view>
  142. </view>
  143. </block>
  144. <view class="box pic" v-if="cardInfo.pictures">
  145. <view class="tit dflex">
  146. <view class="flex dflex">
  147. <image src="../static/images/tp_ico.png"></image>
  148. <view>风采展示</view>
  149. </view>
  150. <image v-if="cardInfo.pictures && !cardId" @click="uploadImgs()" src="../static/images/bj_ico.png" class="edit"></image>
  151. </view>
  152. <view class="picture">
  153. <view class="pics" v-if="cardInfo.pictures">
  154. <image
  155. v-for="(item, index) in getImgList(cardInfo.pictures)"
  156. :key="index"
  157. :src="item"
  158. mode="widthFix"
  159. @tap="previewImg(getImgList(cardInfo.pictures), index)"
  160. ></image>
  161. </view>
  162. <view class="not" v-else @click="uploadImgs()">
  163. <image src="../static/images/add_ico1.png"></image>
  164. <view>点击添加图片</view>
  165. </view>
  166. </view>
  167. </view>
  168. <!-- <view class="also" v-if="cardId">我也要创建电子名片</view> -->
  169. <!-- #ifdef H5 -->
  170. <wx-share ref="wxshare" />
  171. <!-- #endif -->
  172. </view>
  173. </template>
  174. <script>
  175. const app = getApp();
  176. const req = require('../../utils/request.js');
  177. const api = require('../../utils/api.js');
  178. export default {
  179. data() {
  180. return {
  181. isShowView:false,
  182. cardId: '',
  183. cardInfo: '',
  184. cardCount: '',
  185. isShowContacts: true,
  186. zhiPicUrls: [],
  187. scene: '',
  188. isFirst: true
  189. };
  190. },
  191. onLoad(opt) {
  192. if(opt.scene) this.scene = options.scene
  193. if(opt.appId) req.setStorage('appId',opt.appId);
  194. this.cardId = opt.cardId;
  195. },
  196. async onShow() {
  197. if (this.scene) {
  198. await this.loadCodeParams();
  199. }
  200. await this.getCardInfo();
  201. },
  202. onShareAppMessage() {
  203. this.saveShareBehavior();
  204. return this.onShareMessage();
  205. },
  206. onShareTimeline() {
  207. this.saveShareBehavior();
  208. return {
  209. title: this.cardInfo.realName + ' - 电子名片',
  210. imageUrl: this.cardInfo.imageMap?this.cardInfo.imageMap:this.cardInfo.avatar,
  211. path: '/share/card/index?cardId=' + this.cardInfo.id+'&appId='+req.getStorage('appId')
  212. };
  213. },
  214. onReady() {
  215. // #ifdef H5
  216. var that = this;
  217. //初始化分享内容
  218. setTimeout(function() {
  219. var shareContent = that.onShareMessage();
  220. if (shareContent) {
  221. shareContent.path = window.location.origin + shareContent.path;
  222. }
  223. console.log('分享内容》》》》》', shareContent);
  224. that.$refs.wxshare.init(shareContent);
  225. }, 4 * 1000);
  226. // #endif
  227. },
  228. methods: {
  229. onShareMessage(){
  230. let path = '';
  231. let isSolution = '';
  232. // #ifndef H5
  233. isSolution = req.env[req.env.NODE_ENV].isSolution;
  234. // #endif
  235. // #ifdef H5
  236. isSolution = false;
  237. // #endif
  238. let userInfo = req.getStorage('userInfo');
  239. if(isSolution){
  240. path = '/share/home/index?appId='+req.getStorage('appId')+'&userId='+userInfo.id;
  241. }else{
  242. path = '/share/card/index?cardId=' + this.cardInfo.id + '&appId=' + req.getStorage('appId');
  243. }
  244. return {
  245. title: this.cardInfo.realName + ' - 电子名片',
  246. imageUrl: this.cardInfo.imageMap?this.cardInfo.imageMap:this.cardInfo.avatar,
  247. path: path
  248. };
  249. },
  250. saveShareBehavior(){
  251. let params = {
  252. behavior: 6,
  253. type: 23,
  254. bindId: this.cardInfo.id
  255. }
  256. req.saveBehavior(params,res=>{})
  257. },
  258. addContact: function() {
  259. var that = this;
  260. wx.showActionSheet({
  261. itemList: ['添加联系人'],
  262. success: function(res) {
  263. // 添加到手机通讯录
  264. uni.addPhoneContact({
  265. firstName: that.cardInfo.realName,//联系人姓名
  266. mobilePhoneNumber: that.cardInfo.phone, //联系人手机号
  267. organization: that.cardInfo.companyName,//公司
  268. weChatNumber: that.cardInfo.wechat,//微信
  269. email: that.cardInfo.email, //电子邮件
  270. })
  271. }
  272. })
  273. },
  274. loadCodeParams() {
  275. let _ts = this;
  276. return new Promise((resolve, reject) => {
  277. if (!_ts.scene) {
  278. resolve();
  279. return false;
  280. }
  281. req.getRequest(
  282. '/api/code/params',
  283. {
  284. scene: _ts.scene
  285. },
  286. data => {
  287. this.options.userId = data.userId
  288. this.cardId = data.scene
  289. resolve();
  290. }
  291. );
  292. });
  293. },
  294. getImgList(url) {
  295. var list = [];
  296. if (url) {
  297. list = url.split(',');
  298. }
  299. return list;
  300. },
  301. jumpUrl(url) {
  302. uni.navigateTo({
  303. url: url
  304. });
  305. },
  306. getCardInfo() {
  307. var url = '';
  308. var dataP = {};
  309. if (this.cardId) {
  310. url = api.card_info;
  311. dataP.id = this.cardId;
  312. } else {
  313. url = api.card_userInfo;
  314. dataP = {};
  315. }
  316. return new Promise((resolve, reject) => {
  317. req.getRequest(url, dataP, data => {
  318. // if(data.position){
  319. // data.position = JSON.parse(data.position)
  320. // }
  321. this.cardInfo = data;
  322. uni.setNavigationBarTitle({
  323. title: data.realName + '的名片'
  324. })
  325. if(this.cardId&&this.cardInfo.userId==req.getStorage('userInfo').id){
  326. this.cardId = null
  327. this.getCardInfo()
  328. }else{
  329. if(this.cardInfo.userId==req.getStorage('userInfo').id){
  330. }else{
  331. // 用户浏览
  332. if(this.isFirst){
  333. this.userBehavior(4)
  334. }
  335. }
  336. this.isFirst = false
  337. }
  338. // this.getCardCount();
  339. this.isShowView=true;
  340. resolve();
  341. });
  342. })
  343. },
  344. // 用户行为
  345. userBehavior(type){
  346. var dataP = {};
  347. dataP.type = 23 //、产品 2、活动 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 12、用户须知 13、素材 15、医院科室 16、海报 20、医生 21 新闻 23名片
  348. dataP.behavior = type; //1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、分享
  349. dataP.bindId = this.cardInfo.id;
  350. req.postRequestLoding('/api/v3/behavior/save', dataP, data => {
  351. if(type==3){
  352. if(!this.cardInfo.isThumbs) this.cardInfo.thumbs++;
  353. else this.cardInfo.thumbs--
  354. this.cardInfo.isThumbs = !this.cardInfo.isThumbs
  355. }
  356. if(type==1){
  357. this.cardInfo.follow = !this.cardInfo.follow
  358. }
  359. });
  360. },
  361. getCardCount() {
  362. req.getRequest(api.api_company_visits_count, { companyId: this.cardInfo.id }, data => {
  363. this.cardCount = data;
  364. });
  365. },
  366. showContacts() {
  367. this.isShowContacts = !this.isShowContacts;
  368. },
  369. goPhone() {
  370. uni.makePhoneCall({ phoneNumber: this.cardInfo.phone }); // 传参带入号码即可
  371. },
  372. copy(valueText, type) {
  373. uni.setClipboardData({
  374. data: valueText,
  375. success: function(res) {
  376. if (type == 1) {
  377. req.msg('微信号复制成功');
  378. } else if (type == 2) {
  379. req.msg('邮箱复制成功');
  380. }
  381. }
  382. });
  383. },
  384. uploadVideo() {
  385. let that = this;
  386. uni.chooseVideo({
  387. sourceType: ['camera', 'album'],
  388. success(res) {
  389. req.uploadFile(api.upload, res.tempFilePath, res => {
  390. that.updateCard(2, res.src);
  391. });
  392. }
  393. });
  394. },
  395. uploadImg(){
  396. let that = this;
  397. uni.chooseImage({
  398. count: 1,
  399. sizeType: ['original', 'compressed'],
  400. sourceType: ['album', 'camera'],
  401. success: function({ tempFilePaths }) {
  402. var promise = Promise.all(
  403. tempFilePaths.map(tempFilePath => {
  404. return new Promise(function(resolve, reject) {
  405. req.uploadFile(api.upload, tempFilePath, res => {
  406. that.imageMap = res.src;
  407. //上传完成,则更新保存
  408. that.updateCard(3, that.imageMap);
  409. });
  410. });
  411. })
  412. );
  413. promise
  414. .then(function(results) {
  415. console.log(results);
  416. })
  417. .catch(function(err) {
  418. console.log(err);
  419. });
  420. }
  421. });
  422. },
  423. uploadImgs() {
  424. let that = this;
  425. uni.chooseImage({
  426. count: 9,
  427. sizeType: ['original', 'compressed'],
  428. sourceType: ['album', 'camera'],
  429. success: function({ tempFilePaths }) {
  430. var promise = Promise.all(
  431. tempFilePaths.map(tempFilePath => {
  432. return new Promise(function(resolve, reject) {
  433. req.uploadFile(api.upload, tempFilePath, res => {
  434. let picUrls = that.zhiPicUrls;
  435. that.zhiPicUrls = picUrls.concat(res.src);
  436. if (tempFilePaths.length == that.zhiPicUrls.length) {
  437. //上传完成,则更新保存
  438. that.updateCard(1, that.zhiPicUrls.join(','));
  439. }
  440. });
  441. });
  442. })
  443. );
  444. promise
  445. .then(function(results) {
  446. console.log(results);
  447. })
  448. .catch(function(err) {
  449. console.log(err);
  450. });
  451. }
  452. });
  453. },
  454. //预览图片
  455. previewImg(picUrls, index) {
  456. //预览合同图片
  457. var src = picUrls[index];
  458. let imgs = picUrls;
  459. uni.previewImage({
  460. current: src, // 当前显示图片的http链接
  461. urls: imgs
  462. });
  463. },
  464. cleanimages(index) {
  465. // 删除图片
  466. let arr = this.zhiPicUrls;
  467. arr.splice(index, 1);
  468. this.zhiPicUrls = arr;
  469. },
  470. /**
  471. * @param {Object} type 1图片 2、视频
  472. * @param {Object} url 资源地址
  473. */
  474. updateCard(type, url) {
  475. var dataP = {};
  476. dataP.id = this.cardInfo.id;
  477. if (type == 1) {
  478. dataP.pictures = url;
  479. } else if (type == 2) {
  480. dataP.videoId = url;
  481. } else if (type == 3) {
  482. dataP.imageMap = url;
  483. }
  484. req.postRequest(api.card_saveOrUpdate, dataP, json => {
  485. if (type == 1) {
  486. this.cardInfo.pictures = url;
  487. this.zhiPicUrls = [];
  488. } else if (type == 2) {
  489. this.cardInfo.videoId = url;
  490. } else if (type == 3) {
  491. this.cardInfo.imageMap = url;
  492. }
  493. });
  494. },
  495. wxShare() {
  496. uni.share({
  497. provider: 'weixin',
  498. scene: 'WXSceneSession',
  499. type: 0,
  500. href: 'http://www.baidu.com',
  501. title: this.cardInfo.realName,
  502. summary: this.cardInfo.msg,
  503. imageUrl: this.cardInfo.avatar,
  504. success: function(res) {
  505. console.log('success:' + JSON.stringify(res));
  506. },
  507. fail: function(err) {
  508. console.log('fail:' + JSON.stringify(err));
  509. }
  510. });
  511. }
  512. }
  513. };
  514. </script>
  515. <style>
  516. @import './index.css';
  517. </style>