model.vue 15 KB

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