model.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  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="bottom_padding" v-if="type!=1">
  6. </view>
  7. <view class="fxmp flex bottom" v-if="type==2">
  8. <button class="share" type="default" open-type="share">
  9. 分享名片
  10. </button>
  11. </view>
  12. <view class="fxmp flex bottom" v-if="type==3">
  13. <button class="share" type="default" open-type="share">
  14. 分享名片
  15. </button>
  16. <view class="nav-model " @click="navto('/pages/user/model/modelrz?type=1&modelid=' + mtype)">
  17. 修改名片
  18. </view>
  19. </view>
  20. <block v-if="type==0">
  21. <view class="ljrz bottom" v-if="userInfo.work_type_id <=0"
  22. @click="navto('/pages/user/model/modelrz?modelid=' + mtype + '&type=2')">
  23. 生成我的名片
  24. </view>
  25. <view v-else class="create-model flex bottom">
  26. <view class="price-show">
  27. 模板费用:<text>{{modelInfo.price*1}}</text>
  28. </view>
  29. <view class="to-show" @click="preview">
  30. 模板预览
  31. </view>
  32. <view class="by-now" @click="gobuy">
  33. 购买使用
  34. </view>
  35. </view>
  36. </block>
  37. <view class="yl bottom" v-if="previewShow" @click="outPreview">
  38. 结束预览
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import {
  44. mapState,
  45. mapMutations
  46. } from 'vuex';
  47. import {
  48. getUserCardInfo,
  49. getCommonUserCardInfo,
  50. getShowTemplateItem,
  51. subShowTemplateOrder
  52. } from '@/api/model.js'
  53. import {
  54. getUser
  55. } from '@/api/user.js';
  56. import {
  57. saveUrl,
  58. interceptor
  59. } from '@/utils/loginUtils.js';
  60. import model from '@/pages/modelData/index.vue';
  61. export default {
  62. components: {
  63. model
  64. },
  65. data() {
  66. return {
  67. mtype: 1, //modelid
  68. shareId: '', //保存分享uid
  69. // 默认显示数据
  70. cardInfo: {},
  71. // 是否显示默认
  72. isDefault: false,
  73. shareNumber: 0, //浏览量
  74. userTemplate: {}, //用户展示数据
  75. modelInfo: {}, //当前模板信息
  76. payType: 'wxpay',
  77. type: 0, //0为商品页面进入1为个人中心进入修改预览2为分享查看预览,3为已购模板进入查看分享
  78. isShare: false, //是否显示分享按钮
  79. isLook: 0, //1为平台浏览量2为用户浏览量0为不显示
  80. previewShow: false, //是否显示预览
  81. }
  82. },
  83. onLoad(opt) {
  84. // #ifndef MP
  85. if (opt.spread) {
  86. // 存储其他邀请人
  87. uni.setStorageSync('spread', opt.spread);
  88. }
  89. // #endif
  90. // #ifdef MP
  91. if (opt.scene) {
  92. // 存储小程序邀请人
  93. uni.setStorage({
  94. key: 'spread_code',
  95. data: opt.scene
  96. });
  97. }
  98. uni.hideShareMenu();
  99. // #endif
  100. // 获取模板id
  101. this.mtype = +opt.mtype
  102. // 获取查看类型
  103. this.type = +opt.type
  104. // 是否首页进入
  105. if (this.type === 0) {
  106. this.isLook = 1;
  107. this.getShowTemplateItem();
  108. if (this.userInfo.uid) {
  109. this.getCommonUserCardInfo(this.userInfo.uid);
  110. }else{
  111. // 展示默认数据
  112. this.isDefault = true;
  113. }
  114. return
  115. }
  116. //个人中心提交数据预览
  117. if (this.type === 1) {
  118. this.templateData = uni.getStorageSync('modeldata');
  119. return
  120. }
  121. //分享预览
  122. if (this.type === 2) {
  123. console.log(opt.type, 'opt.type');
  124. this.isLook = 2;
  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. shareObj = {
  170. title: this.templateData.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. that.shareNumber = res.data.look_count
  348. }
  349. })
  350. },
  351. // 加载用户模板数据
  352. getCommonUserCardInfo(uid) {
  353. let that = this
  354. getCommonUserCardInfo({
  355. uid: uid
  356. }).then(res => {
  357. let arr = []
  358. let basearr = res.data.service_area_all
  359. basearr.forEach(item => {
  360. arr.push(item[0].name + item[1].name + item[2].name)
  361. })
  362. res.data.service_area_all = arr
  363. // 保存用户模板数据
  364. that.userTemplate = res.data
  365. // 判断是否从用户个人中心或者分享进入
  366. if (that.type == 3 || that.type == 2) {
  367. // 修改为非默认数据
  368. that.isDefault = false;
  369. that.shareNumber = res.data.card_look_count;
  370. }
  371. })
  372. },
  373. getUserCardInfo() {
  374. let that = this
  375. getUserCardInfo().then(res => {
  376. console.log(res)
  377. let arr = []
  378. let basearr = res.data.service_area_all
  379. basearr.forEach(item => {
  380. arr.push(item[0].name + item[1].name + item[2].name)
  381. })
  382. res.data.service_area_all = arr
  383. that.cardInfo = res.data
  384. })
  385. }
  386. }
  387. }
  388. </script>
  389. <style lang="scss" scoped>
  390. .bottom_padding {
  391. height: 45px;
  392. width: 100%;
  393. }
  394. .m-card {
  395. width: 640rpx;
  396. background: #fcf4f1;
  397. border-radius: 20rpx;
  398. position: relative;
  399. // min-height: 270rpx;
  400. margin: 0 auto 46rpx;
  401. .card-tit {
  402. width: 219rpx;
  403. height: 57rpx;
  404. background: #F46C85;
  405. border-radius: 20rpx 28rpx 29rpx 0rpx;
  406. justify-content: flex-start;
  407. align-items: center;
  408. padding: 0 20rpx;
  409. font-size: 32rpx;
  410. font-weight: bold;
  411. color: #FFFFFF;
  412. .tit-logo {
  413. width: 32rpx;
  414. height: 32rpx;
  415. margin-right: 18rpx;
  416. }
  417. }
  418. .card-bg {
  419. width: 100%;
  420. height: 270rpx;
  421. position: absolute;
  422. bottom: 0rpx;
  423. }
  424. .card-content {
  425. padding: 25rpx 35rpx;
  426. font-size: 26rpx;
  427. font-weight: 500;
  428. color: #2C2E35;
  429. position: relative;
  430. }
  431. .img-list {
  432. justify-content: space-between;
  433. flex-wrap: wrap;
  434. margin: auto;
  435. padding: 30rpx 30rpx 0;
  436. position: relative;
  437. image {
  438. width: 270rpx;
  439. height: 270rpx;
  440. background-color: #fff;
  441. margin-bottom: 30rpx;
  442. box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.6);
  443. }
  444. }
  445. .fw {
  446. font-size: 26rpx;
  447. font-weight: 500;
  448. color: #2C2E35;
  449. padding: 10rpx 0;
  450. .fw-tit {
  451. color: #F46C85;
  452. display: flex;
  453. align-items: center;
  454. .yg {
  455. background-color: #F46C85;
  456. display: inline-block;
  457. width: 10rpx;
  458. height: 10rpx;
  459. border-radius: 50%;
  460. margin-right: 10rpx;
  461. }
  462. }
  463. .fw-content {
  464. padding-top: 10rpx;
  465. padding-left: 18rpx;
  466. text-align: justify;
  467. }
  468. }
  469. .user-info {
  470. flex-wrap: wrap;
  471. font-size: 26rpx;
  472. font-weight: 500;
  473. color: #000000;
  474. position: relative;
  475. .info-item-b,
  476. .info-item-q {
  477. padding: 10rpx 0;
  478. color: #000000;
  479. position: relative;
  480. padding-left: 20rpx;
  481. &::before {
  482. display: inline-block;
  483. content: '';
  484. width: 10rpx;
  485. height: 10rpx;
  486. border-radius: 50%;
  487. background-color: #F46C85;
  488. position: absolute;
  489. top: 22rpx;
  490. left: 0;
  491. }
  492. .qianger {
  493. width: 2em;
  494. display: inline-block;
  495. }
  496. .laner {
  497. width: 0.5em;
  498. display: inline-block;
  499. }
  500. }
  501. .info-item-b {
  502. width: 50%;
  503. }
  504. .info-item-q {
  505. width: 100%;
  506. display: flex;
  507. align-items: flex-start;
  508. justify-content: start;
  509. .fwdz {
  510. flex-direction: column;
  511. align-items: flex-start;
  512. }
  513. .gzt {
  514. width: 312rpx;
  515. height: 24rpx;
  516. padding-top: 10rpx;
  517. position: relative;
  518. image {
  519. width: 312rpx;
  520. height: 24rpx;
  521. position: relative;
  522. }
  523. .gzt-price,
  524. .gzt-price-b {
  525. width: 200rpx;
  526. text-align: center;
  527. position: absolute;
  528. padding-top: 20rpx;
  529. &::after {
  530. content: '';
  531. width: 0px;
  532. height: 0rpx;
  533. // background: #FEB8C6;
  534. border: 14rpx solid;
  535. border-color: transparent transparent #FEB8C6;
  536. // border-top:transparent;
  537. // border-left: transparent;
  538. // border-right: transparent;
  539. position: absolute;
  540. top: -14rpx;
  541. left: 0;
  542. right: 0;
  543. margin: auto;
  544. }
  545. text {
  546. color: #F46C85;
  547. }
  548. }
  549. .gzt-price {
  550. left: -100rpx;
  551. }
  552. .gzt-price-b {
  553. right: -100rpx;
  554. }
  555. }
  556. .rz {
  557. margin-top: 10rpx;
  558. margin-left: 10rpx;
  559. width: 87rpx;
  560. height: 26rpx;
  561. }
  562. }
  563. }
  564. }
  565. .m-btm {
  566. width: 660rpx;
  567. height: 384rpx;
  568. }
  569. .hua2 {
  570. position: relative;
  571. &::before {
  572. content: '';
  573. width: 199rpx;
  574. height: 298rpx;
  575. background: url($base-url + '/resource/icon/model1/hua2.png') no-repeat;
  576. position: absolute;
  577. bottom: -100rpx;
  578. right: 0;
  579. background-size: 100% 100%;
  580. }
  581. }
  582. .hua3 {
  583. position: relative;
  584. &::before {
  585. content: '';
  586. width: 192rpx;
  587. height: 223rpx;
  588. background: url($base-url + '/resource/icon/model1/hua3.png') no-repeat;
  589. position: absolute;
  590. top: 0;
  591. bottom: 0;
  592. left: 0;
  593. margin: auto;
  594. background-size: 100% 100%;
  595. }
  596. }
  597. .hua4 {
  598. position: relative;
  599. &::before {
  600. content: '';
  601. width: 128rpx;
  602. height: 145rpx;
  603. background: url($base-url + '/resource/icon/model1/hua4.png') no-repeat;
  604. position: absolute;
  605. bottom: -70rpx;
  606. right: 0;
  607. background-size: 100% 100%;
  608. }
  609. }
  610. .hua5 {
  611. position: relative;
  612. &::before {
  613. content: '';
  614. width: 199rpx;
  615. height: 298rpx;
  616. background: url($base-url + '/resource/icon/model1/hua2.png') no-repeat;
  617. position: absolute;
  618. bottom: -100rpx;
  619. left: 0;
  620. background-size: 100% 100%;
  621. transform: rotateY(180deg);
  622. }
  623. }
  624. .hua6 {
  625. position: relative;
  626. &::before {
  627. content: '';
  628. width: 192rpx;
  629. height: 223rpx;
  630. background: url($base-url + '/resource/icon/model1/hua3.png') no-repeat;
  631. position: absolute;
  632. bottom: -110rpx;
  633. right: 0;
  634. background-size: 100% 100%;
  635. transform: rotateY(180deg);
  636. }
  637. }
  638. .fxmp {
  639. width: 750rpx;
  640. .share {
  641. width: 50%;
  642. padding: 0;
  643. border-radius: 0;
  644. flex-grow: 1;
  645. &::after {
  646. border: none;
  647. }
  648. }
  649. .nav-model {
  650. background-color: #FFF;
  651. color: $base-color;
  652. width: 50%;
  653. }
  654. }
  655. .fxmp {
  656. position: fixed;
  657. width: 750rpx;
  658. bottom: 0;
  659. padding: 0;
  660. background: #f65486;
  661. // border-radius: 5rpx;
  662. font-size: 30rpx;
  663. font-weight: 500;
  664. color: #FFFFFF;
  665. text-align: center;
  666. }
  667. .create-model {
  668. position: fixed;
  669. width: 750rpx;
  670. bottom: 0;
  671. // border-radius: 5rpx;
  672. font-size: 32rpx;
  673. font-weight: 500;
  674. text-align: center;
  675. .price-show {
  676. font-size: 32rpx;
  677. font-weight: 500;
  678. color: #333333;
  679. background-color: #fff;
  680. flex-grow: 1;
  681. text {
  682. font-size: 48rpx;
  683. font-weight: 500;
  684. color: #FC6F6D;
  685. }
  686. }
  687. .to-show,
  688. .by-now {
  689. width: 223rpx;
  690. background: #fa98b6;
  691. flex-shrink: 0;
  692. font-size: 34rpx;
  693. color: #fff;
  694. }
  695. .by-now {
  696. background: #f65486;
  697. }
  698. }
  699. .yl {
  700. position: fixed;
  701. bottom: 0;
  702. width: 750rpx;
  703. font-size: 32rpx;
  704. font-weight: 500;
  705. text-align: center;
  706. color: #fff;
  707. text-align: center;
  708. font-size: 34rpx;
  709. background-color: #f65486;
  710. }
  711. .ljrz {
  712. position: fixed;
  713. width: 750rpx;
  714. bottom: 0;
  715. font-size: 32rpx;
  716. font-weight: 500;
  717. text-align: center;
  718. background-color: #f65486;
  719. color: #fff;
  720. }
  721. .bottom {
  722. line-height: 45px;
  723. height: 45px;
  724. }
  725. </style>