model.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. <template>
  2. <view class="content mone" v-if="baseURL">
  3. <model :modelId='mtype' :templateData='userTemplate' :isShare='isShare' :isLook='isLook' :isDefault='isDefault'
  4. :share-number='shareNumber' :honorList="honor_list"></model>
  5. <view class="fxmp flex bottom" v-if="type==2">
  6. <button class="share" type="default" open-type="share">
  7. 分享名片
  8. </button>
  9. <view class="nav-model pink" @click="payPhone" v-if="mtype ==5">
  10. 拨打电话
  11. </view>
  12. <view class="nav-model" @click="navto('/pages/user/model/model?mtype=' + mtype+'&type=0')"
  13. v-if="mtype != 3">
  14. 生成我的名片
  15. </view>
  16. <template v-else-if="mtype == 3">
  17. <view class="nav-model" @click="navto('/pages/user/model/modelrz?modelid='+userInfo.show_template_id)"
  18. v-if=" hasLogin && userInfo.info_audit_status==-2">
  19. 立即认证
  20. </view>
  21. <view class="nav-model" @click="navto('/pages/user/model/mymodellist')"
  22. v-if=" hasLogin && userInfo.info_audit_status==1">
  23. 查看我的名片
  24. </view>
  25. <view class="nav-model" v-if=" hasLogin && userInfo.info_audit_status==0">
  26. 资料审核中
  27. </view>
  28. <view class="nav-model" v-if=" !hasLogin" @click="toLogin">
  29. 生成我的名片
  30. </view>
  31. </template>
  32. </view>
  33. <view class="fxmp flex bottom" v-if="type==3">
  34. <button class="share" type="default" open-type="share">
  35. 分享名片
  36. </button>
  37. <view class="nav-model " @click="navto('/pages/user/model/modelrz?type=1&modelid=' + mtype)">
  38. 修改名片
  39. </view>
  40. <view class="nav-model pink"
  41. @click="navto('/pages/user/model/modelQr?modelid='+mtype+'&avatar='+userTemplate.avatar)">
  42. 生成海报
  43. </view>
  44. </view>
  45. <view style="height:45px;" v-if="type==3"></view>
  46. <block v-if="type==0">
  47. <view class="ljrz bottom" v-if="userInfo.work_type_id <=0&&userInfo.info_audit_status != 1"
  48. @click="navto('/pages/user/model/modelrz?modelid=' + mtype + '&type=2')">
  49. 生成我的名片
  50. </view>
  51. <view v-else class="create-model flex bottom">
  52. <view v-if="systeam!='ios'" class="price-show">
  53. 模板费用:<text class="price-show-text">{{modelInfo.price*1}}</text>
  54. </view>
  55. <view class="to-show" @click="preview">
  56. 模板预览
  57. </view>
  58. <view v-if="systeam!='ios'" class="by-now" @click="gobuy">
  59. 立即使用
  60. </view>
  61. </view>
  62. </block>
  63. <view class="yl bottom" v-if="previewShow" @click="outPreview">
  64. 结束预览
  65. </view>
  66. <view class="rightIcon">
  67. <view class="Dz" @click="onDz(1)">
  68. <uni-icons class="icon" :color="userTemplate.is_like==0?'#FFF':'#FEB8C6'" size='80rpx'
  69. type="hand-up-filled"></uni-icons>
  70. </view>
  71. <view class="ScNum">
  72. {{userTemplate.like_count||0}}
  73. </view>
  74. <view class="Sc" @click="onDz(2)">
  75. <uni-icons class="icon" :color="userTemplate.is_bookmark==0?'#FFF':'#FEB8C6'" size='80rpx'
  76. type="star-filled"></uni-icons>
  77. </view>
  78. <view class="ScNum">
  79. {{userTemplate.bookmark_count||0}}
  80. </view>
  81. <view class="Sc" @click="goPl">
  82. <uni-icons class="icon" color="#FFF" size='80rpx' type="chat-filled"></uni-icons>
  83. </view>
  84. <!-- calendar-filled -->
  85. <view class="ScNum">
  86. {{userTemplate.comment_num||0}}
  87. </view>
  88. <!-- -->
  89. <view class="Dz" @click="showDk(userTemplate.check_num)">
  90. <uni-icons class="icon" color="#FFF" size='80rpx'
  91. type="calendar-filled"></uni-icons>
  92. </view>
  93. <view class="ScNum">
  94. {{userTemplate.check_num||0}}
  95. </view>
  96. </view>
  97. <image src="/static/image/qy.png" mode="widthFix" class="qianyue" @click="goQy"
  98. v-if="!userInfo.uid || (userInfo.uid && userInfo.uid != uid)"></image>
  99. </view>
  100. </template>
  101. <script>
  102. import {
  103. mapState,
  104. mapMutations
  105. } from 'vuex';
  106. import {
  107. getUserCardInfo,
  108. getCommonUserCardInfo,
  109. getShowTemplateItem,
  110. subShowTemplateOrder,
  111. likeAndBookmark
  112. } from '@/api/model.js'
  113. import {
  114. getUser,
  115. getHonor
  116. } from '@/api/user.js';
  117. import {
  118. saveUrl,
  119. interceptor
  120. } from '@/utils/loginUtils.js';
  121. import model from '@/pages/modelData/index.vue';
  122. export default {
  123. components: {
  124. model
  125. },
  126. data() {
  127. return {
  128. honor_list: [],
  129. mtype: 1, //modelid
  130. shareId: '', //保存分享uid
  131. // 默认显示数据
  132. cardInfo: {},
  133. // 是否显示默认
  134. isDefault: true,
  135. shareNumber: 0, //浏览量
  136. userTemplate: {}, //用户展示数据
  137. modelInfo: {}, //当前模板信息
  138. payType: 'wxpay',
  139. type: 0, //0为商品页面进入1为个人中心进入修改预览2为分享查看预览,3为已购模板进入查看分享
  140. isShare: false, //是否显示分享按钮
  141. isLook: 0, //1为平台浏览量2为用户浏览量0为不显示
  142. previewShow: false, //是否显示预览
  143. uid: '', //当前载入的显示的用户uid
  144. }
  145. },
  146. onLoad(opt) {
  147. const that = this;
  148. that.getHonor(opt.uid)
  149. // #ifndef MP
  150. if (opt.spread) {
  151. // 存储其他邀请人
  152. uni.setStorageSync('spread', opt.spread);
  153. }
  154. // #endif
  155. // #ifdef MP
  156. if (opt.spread) {
  157. // 存储其他邀请人
  158. uni.setStorageSync('spread_code', opt.spread);
  159. }
  160. uni.hideShareMenu();
  161. if (opt.scene) {
  162. let arr = opt.scene.split('_')
  163. this.isLook = 2;
  164. this.type = 2;
  165. this.mtype = arr[1]
  166. this.shareId = arr[0];
  167. // 存储小程序邀请人
  168. uni.setStorage({
  169. key: 'spread_code',
  170. data: arr[0]
  171. });
  172. this.getCommonUserCardInfo(arr[0]);
  173. this.uid = arr[0];
  174. return
  175. }
  176. // #endif
  177. // 获取模板id
  178. this.mtype = +opt.mtype
  179. // 获取查看类型
  180. this.type = +opt.type
  181. // 是否商品购买页进入
  182. if (this.type === 0) {
  183. this.isLook = 1;
  184. if (this.userInfo.uid) {
  185. this.getCommonUserCardInfo(this.userInfo.uid);
  186. this.uid = this.userInfo.uid;
  187. }
  188. this.getShowTemplateItem();
  189. return
  190. } else if (this.type === 1) {
  191. //个人中心提交数据预览
  192. this.userTemplate = uni.getStorageSync('modeldata');
  193. this.isDefault = false;
  194. uni.setNavigationBarTitle({
  195. title: '名片预览'
  196. })
  197. this.uid = this.userInfo.uid;
  198. return
  199. } else
  200. if (this.type === 2) {
  201. //分享预览
  202. this.isLook = 2;
  203. this.shareId = opt.uid;
  204. this.getCommonUserCardInfo(opt.uid);
  205. this.uid = opt.uid;
  206. return
  207. } else
  208. if (this.type === 3) {
  209. //我的模板页进入预览
  210. this.isShare = true;
  211. this.isLook = 2;
  212. this.shareId = this.userInfo.uid;
  213. this.getCommonUserCardInfo(this.userInfo.uid);
  214. this.uid = this.userInfo.uid;
  215. return
  216. }
  217. // if(opt.look && opt.look == 2) {
  218. // this.islook = opt.look
  219. // this.cardInfo = uni.getStorageSync('modeldata')
  220. // this.is_yl = true
  221. // }else {
  222. // if (opt.look && opt.look == 1) {
  223. // uni.showShareMenu();
  224. // this.look = false
  225. // }
  226. // if (opt.uid) {
  227. // this.shareId = opt.uid
  228. // this.getCommonUserCardInfo(opt.uid)
  229. // } else {
  230. // this.getShowTemplateItem()
  231. // }
  232. // }
  233. },
  234. computed: {
  235. ...mapState(['baseURL']),
  236. ...mapState('user', ['userInfo', 'hasLogin']),
  237. // #ifdef MP
  238. ...mapState(['systeam']),
  239. // #endif
  240. },
  241. onShow() {
  242. // this.getUser()
  243. },
  244. // #ifdef MP
  245. onShareAppMessage(options) {
  246. // 设置菜单中的转发按钮触发转发事件时的转发内容
  247. let pages = getCurrentPages(); //获取加载的页面
  248. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  249. let url = currentPage.route; //当前页面url
  250. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  251. let shareObj = {}
  252. shareObj = {
  253. title: this.userTemplate.name + '母婴界数字名片', // 默认是小程序的名称(可以写slogan等)
  254. path: url + '?uid=' + this.shareId + '&mtype=' + this.mtype + '&type=2', // 默认是当前页面,必须是以‘/’开头的完整路径
  255. imageUrl: '',
  256. success: function(res) {
  257. // 转发成功之后的回调
  258. if (res.errMsg == 'shareAppMessage:ok') {}
  259. },
  260. fail: function() {
  261. // 转发失败之后的回调
  262. if (res.errMsg == 'shareAppMessage:fail cancel') {
  263. // 用户取消转发
  264. } else if (res.errMsg == 'shareAppMessage:fail') {
  265. // 转发失败,其中 detail message 为详细失败信息
  266. }
  267. }
  268. };
  269. // 判断是否可以邀请
  270. if (this.userInfo.uid) {
  271. shareObj.path += '&spread=' + this.userInfo.uid;
  272. }
  273. return shareObj;
  274. },
  275. // #endif
  276. onUnload() {
  277. let pages = getCurrentPages(); //获取加载的页面
  278. let currentPage = pages[pages.length - 2]; //获取当前页面的对象
  279. if (currentPage.route == 'pages/public/wxLogin') {
  280. uni.switchTab({
  281. url: '/pages/index/index'
  282. })
  283. }
  284. },
  285. methods: {
  286. ...mapMutations('user', ['setUserInfo']),
  287. showDk(num=0) {
  288. this.$api.msg('总打卡' + num + '次')
  289. },
  290. getHonor(uid) {
  291. getHonor({
  292. uid
  293. }).then(res => {
  294. console.log(res,'res');
  295. this.honor_list = res.data.honor_list
  296. })
  297. },
  298. goQy() {
  299. getUser().then(res => {
  300. uni.navigateTo({
  301. url: '/pages/user/signing/signing?id=' + this.uid
  302. })
  303. })
  304. },
  305. onDz(type) {
  306. if (type == 1) {
  307. if (this.userTemplate.is_like == 0) {
  308. this.userTemplate.is_like = 1;
  309. this.userTemplate.like_count++;
  310. } else {
  311. this.userTemplate.is_like = 0;
  312. this.userTemplate.like_count--;
  313. }
  314. }
  315. if (type == 2) {
  316. if (this.userTemplate.is_bookmark == 0) {
  317. this.userTemplate.is_bookmark = 1;
  318. this.userTemplate.bookmark_count++;
  319. } else {
  320. this.userTemplate.is_bookmark = 0;
  321. this.userTemplate.bookmark_count--;
  322. }
  323. }
  324. likeAndBookmark({
  325. uid: this.uid,
  326. type: type
  327. }).then((res) => {
  328. console.log(res)
  329. }).catch((err) => {
  330. console.log(err)
  331. })
  332. },
  333. goPl() {
  334. console.log(this.userTemplate, 'this.userTemplate');
  335. uni.navigateTo({
  336. url: '/pages/user/signing/plhis?id=' + this.uid
  337. })
  338. },
  339. payPhone() {
  340. uni.makePhoneCall({
  341. phoneNumber: this.userTemplate.mobile
  342. })
  343. },
  344. toLogin() {
  345. saveUrl();
  346. interceptor();
  347. },
  348. // 模板预览
  349. preview() {
  350. if (!this.userInfo.uid) {
  351. uni.showModal({
  352. title: '提示',
  353. content: '您未登录是否登录查看',
  354. cancelText: '取消',
  355. confirmText: '立即登录',
  356. success: res => {
  357. if (res.confirm) {
  358. saveUrl();
  359. interceptor();
  360. }
  361. },
  362. fail: () => {},
  363. complete: () => {}
  364. });
  365. return
  366. }
  367. // 判断是否显示默认数据
  368. if (this.userTemplate.id) {
  369. this.isDefault = false;
  370. } else {
  371. this.isDefault = true;
  372. }
  373. this.previewShow = true;
  374. // 隐藏浏览数量
  375. this.isLook = 0;
  376. },
  377. // 结束预览
  378. outPreview() {
  379. // 显示默认数据
  380. this.isDefault = true;
  381. this.previewShow = false;
  382. if (this.type == 0) {
  383. this.isLook = 1;
  384. return
  385. }
  386. if (this.type == 3) {
  387. this.isLook = 2;
  388. return
  389. }
  390. },
  391. navto(url) {
  392. uni.navigateTo({
  393. url
  394. })
  395. },
  396. getUser() {
  397. const that = this;
  398. getUser({}).then((e) => {
  399. that.setUserInfo(e.data)
  400. if (e.data.work_type_id > 0 && that.shareId == '') {
  401. that.getUserCardInfo()
  402. } else {
  403. that.cardInfo = {}
  404. }
  405. }).catch((e) => {})
  406. },
  407. gobuy() {
  408. let that = this
  409. subShowTemplateOrder({
  410. id: that.mtype,
  411. pay_type: that.payType
  412. }).then(res => {
  413. if (res.data.status == 1) {
  414. uni.showModal({
  415. title: '提示',
  416. content: '支付成功!',
  417. cancelText: '关闭',
  418. confirmText: '查看模板',
  419. success: res => {
  420. if (res.confirm) {
  421. uni.reLaunch({
  422. url: '/pages/user/model/model?mtype=' +
  423. that.mtype,
  424. });
  425. }
  426. },
  427. fail: () => {},
  428. complete: () => {}
  429. });
  430. } else {
  431. let da = res.data.jsApiParameters;
  432. let data = {
  433. appId: da.appId,
  434. // #ifdef H5
  435. timestamp: da.timeStamp,
  436. // #endif
  437. // #ifdef MP
  438. timeStamp: da.timeStamp + '',
  439. // #endif
  440. nonceStr: da.nonceStr,
  441. package: da.package,
  442. signType: da.signType,
  443. paySign: da.paySign,
  444. success: function(res) {
  445. // obj.paySuccessTo();
  446. // alert('支付成功')
  447. uni.showModal({
  448. title: '提示',
  449. content: '支付成功!',
  450. cancelText: '关闭',
  451. confirmText: '查看模板',
  452. success: res => {
  453. if (res.confirm) {
  454. uni.reLaunch({
  455. url: '/pages/user/model/model?mtype=' +
  456. that.mtype,
  457. });
  458. }
  459. },
  460. fail: () => {},
  461. complete: () => {}
  462. });
  463. },
  464. fail: (err) => {
  465. console.log(err)
  466. // alert('支付失败')
  467. // uni.navigateTo({
  468. // url: '/pages/order/order?state=0'
  469. // });
  470. }
  471. };
  472. if (that.payType == 'wxpay') {
  473. wx.requestPayment(data)
  474. }
  475. }
  476. })
  477. },
  478. // 获取模板详情
  479. getShowTemplateItem() {
  480. let that = this
  481. getShowTemplateItem({
  482. id: that.mtype
  483. }).then(res => {
  484. that.modelInfo = res.data;
  485. if (that.type == 0) {
  486. uni.setNavigationBarTitle({
  487. title: that.modelInfo.title
  488. })
  489. that.shareNumber = res.data.look_count
  490. }
  491. })
  492. },
  493. // 加载用户模板数据
  494. getCommonUserCardInfo(uid) {
  495. console.log('jr')
  496. let that = this
  497. getCommonUserCardInfo({
  498. uid: uid
  499. }).then(res => {
  500. let arr = []
  501. let basearr = res.data.service_area_all
  502. basearr.forEach(item => {
  503. if (item.length == 3) {
  504. arr.push(item[0].name + item[1].name + item[2].name)
  505. }
  506. if (item.length == 2) {
  507. arr.push(item[0].name + item[1].name + '市辖区')
  508. }
  509. })
  510. res.data.service_area_all = arr
  511. // 保存用户模板数据
  512. that.userTemplate = res.data
  513. // 判断是否从用户个人中心或者分享进入
  514. if (that.type == 3 || that.type == 2) {
  515. // 修改为非默认数据
  516. that.isDefault = false;
  517. that.shareNumber = res.data.card_look_count;
  518. uni.setNavigationBarTitle({
  519. title: this.userTemplate.name + '的分享名片'
  520. })
  521. }
  522. })
  523. },
  524. getUserCardInfo() {
  525. let that = this
  526. getUserCardInfo().then(res => {
  527. console.log(res)
  528. let arr = []
  529. let basearr = res.data.service_area_all
  530. basearr.forEach(item => {
  531. arr.push(item[0].name + item[1].name + item[2].name)
  532. })
  533. res.data.service_area_all = arr
  534. that.cardInfo = res.data
  535. })
  536. }
  537. }
  538. }
  539. </script>
  540. <style lang="scss" scoped>
  541. .fxmp {
  542. position: fixed;
  543. width: 750rpx;
  544. bottom: 0;
  545. padding: 0;
  546. background: #f65486;
  547. // border-radius: 5rpx;
  548. font-size: 30rpx;
  549. font-weight: 500;
  550. color: #FFFFFF;
  551. text-align: center;
  552. .share {
  553. width: 50%;
  554. padding: 0;
  555. border-radius: 0;
  556. flex-grow: 1;
  557. background-color: $base-color;
  558. color: #fff;
  559. font-size: 32rpx;
  560. }
  561. .nav-model {
  562. background-color: #FFF;
  563. color: $base-color;
  564. width: 50%;
  565. &.pink {
  566. color: #FFF;
  567. background-color: #FEB8C6;
  568. }
  569. }
  570. }
  571. .create-model {
  572. position: fixed;
  573. width: 750rpx;
  574. bottom: 0;
  575. // border-radius: 5rpx;
  576. font-size: 32rpx;
  577. font-weight: 500;
  578. text-align: center;
  579. .price-show {
  580. font-size: 32rpx;
  581. font-weight: 500;
  582. color: #333333;
  583. background-color: #fff;
  584. flex-grow: 1;
  585. .price-show-text {
  586. font-size: 48rpx;
  587. font-weight: 500;
  588. color: #FC6F6D;
  589. }
  590. }
  591. .to-show,
  592. .by-now {
  593. flex-grow: 1;
  594. width: 223rpx;
  595. background: #fa98b6;
  596. flex-shrink: 0;
  597. font-size: 34rpx;
  598. color: #fff;
  599. }
  600. .by-now {
  601. background: #f65486;
  602. }
  603. }
  604. .yl {
  605. position: fixed;
  606. bottom: 0;
  607. width: 750rpx;
  608. font-size: 32rpx;
  609. font-weight: 500;
  610. text-align: center;
  611. color: #fff;
  612. text-align: center;
  613. font-size: 34rpx;
  614. background-color: #f65486;
  615. }
  616. .ljrz {
  617. position: fixed;
  618. width: 750rpx;
  619. bottom: 0;
  620. font-size: 32rpx;
  621. font-weight: 500;
  622. text-align: center;
  623. background-color: #f65486;
  624. color: #fff;
  625. }
  626. .bottom {
  627. line-height: 45px;
  628. height: 45px;
  629. }
  630. .rightIcon {
  631. position: fixed;
  632. right: 10rpx;
  633. bottom: 300rpx;
  634. background-color: rgba(0, 0, 0, 0.1);
  635. padding: 40rpx 10rpx;
  636. border-radius: 100rpx;
  637. // border: 1px solid #fa98b6;
  638. .icon {
  639. color: #fff;
  640. }
  641. .ScNum {
  642. color: #FFF;
  643. text-align: center;
  644. }
  645. }
  646. .qianyue {
  647. width: 98rpx;
  648. height: 108rpx;
  649. position: fixed;
  650. right: 20rpx;
  651. // top:300rpx;
  652. bottom: 0;
  653. top: 500rpx;
  654. }
  655. </style>