model.vue 17 KB

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