model.vue 16 KB

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