model.vue 17 KB

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