model.vue 15 KB

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