model.vue 17 KB

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