index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <template>
  2. <view>
  3. <view :class="'top-fixed' + (skinNotColor ? ' not-color' : '')" :style="'height: '+ systems.barHeight + 'rpx;'">
  4. <view :class="'bgcolor' + (isTop == 1 ? ' opacity' : '')" :style="'height:' + systems.barHeight + 'rpx'"></view>
  5. <view class="top-fixed-c" :style="'height: '+ systems.navigationHeight + 'rpx;margin-top:' + systems.ktxStatusHeight + 'rpx;'">
  6. <navigator url="" hover-class="none" open-type="navigateBack" class="back"><image :src="picUrlss+'back_black.png'"></image></navigator>
  7. <view class="top-title tover" :style="'line-height: '+ systems.navigationHeight + 'rpx;'" v-if="isTop == 1">{{params.title}}</view>
  8. </view>
  9. </view>
  10. <block v-for="(item,index) in params.params.jsonContent" :key="index">
  11. <view class="ban" v-if="item.key == 'banner'">
  12. <swiper class="swiper" @change="swiperChange" autoplay="true" interval="5000" duration="300">
  13. <block v-for="(it, idx) in item.value.imageList" :key="idx">
  14. <swiper-item>
  15. <image lazy-load="true" :src="it.src" mode="aspectFill" @click="clickBanner(item)"></image>
  16. </swiper-item>
  17. </block>
  18. </swiper>
  19. <view class="dots ddflex">
  20. <block v-for="(it, idx) in item.value.imageList" :key="idx"><view :class="['dot', idx == swiperCurrent ? 'active' : '']"></view></block>
  21. </view>
  22. </view>
  23. <view class="form" v-if="item.key == 'applicationForm'">
  24. <view class="form-title" v-if="item.value.title.isShow">{{item.value.title.value}}</view>
  25. <view class="form-list">
  26. <view class="li" v-for="(it,idx) in item.value.formItemList" :key="idx">
  27. <view class="label">{{it.label}}</view>
  28. <block v-if="it.type == 1">
  29. <button open-type="getPhoneNumber" hover-class="none" @getphonenumber="getPhoneNumber" :class="'phone-ipt fflex' + (it.fieldValue?'':' placeholder')" v-if="it.dataType == 1">
  30. <block v-if="it.fieldValue">{{it.fieldValue}}</block>
  31. <block v-else>请填写{{it.label}}</block>
  32. </button>
  33. <input v-model="it.fieldValue" :placeholder="'请填写' + it.label" placeholder-class="placeholder" class="ipt fflex" v-else />
  34. </block>
  35. <textarea v-model="it.fieldValue" :placeholder="'请填写' + it.label" placeholder-class="placeholder" class="textarea fflex" v-else-if="it.type == 4"></textarea>
  36. <picker :range="it.option" class="pickers fflex" @change="changeOptions($event,idx)" v-else-if="it.type == 5">
  37. <view v-if="it.fieldValue">{{it.fieldValue}}</view>
  38. <view class="placeholder" v-else>请选择{{it.label}}</view>
  39. </picker>
  40. </view>
  41. </view>
  42. <view class="form-btn" @click="formSubmit(item.value)">{{item.value.buttonName}}</view>
  43. </view>
  44. <view class="richText" v-if="item.key == 'text'">
  45. <rich-text :nodes="item.value.content"></rich-text>
  46. </view>
  47. <block v-if="item.key == 'product'">
  48. <view class="product" v-if="item.value.layoutNum == 1">
  49. <view class="li ddflex" v-for="(it,idx) in item.value.productList" :key="idx" @click="jumpUrl('/product/detail/detail?id=' + it.id)">
  50. <image :src="it.pic" mode="aspectFill" class="pro-img"></image>
  51. <view class="pro-info fflex">
  52. <view class="pro-name tovers">{{it.title}}</view>
  53. <view class="pro-bri tover" v-if="it.brief">{{it.brief}}</view>
  54. <view class="pro-opt ddflex">
  55. <view class="money">¥{{it.minSalePrice}}<text>/起</text></view>
  56. <view class="pro-btn">立即购买</view>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <view class="product2 ddflex" v-if="item.value.layoutNum == 2">
  62. <view class="li" v-for="(it,idx) in item.value.productList" :key="idx" @click="jumpUrl('/product/detail/detail?id=' + it.id)">
  63. <image :src="it.pic" mode="aspectFill" class="pro-img"></image>
  64. <view class="pro-info fflex">
  65. <view class="pro-name tovers">{{it.title}}</view>
  66. <view class="pro-opt ddflex">
  67. <view class="money">¥{{it.minSalePrice}}<text>/起</text></view>
  68. <view class="pro-cart"><image src="../../static/pages/images/jia.png"></image></view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. <view class="product product3" v-if="item.value.layoutNum == 3">
  74. <scroll-view scroll-x="true">
  75. <view class="li" v-for="(it,idx) in item.value.productList" :key="idx" @click="jumpUrl('/product/detail/detail?id=' + it.id)">
  76. <view class="ddflex">
  77. <image :src="it.pic" mode="aspectFill" class="pro-img"></image>
  78. <view class="pro-info fflex">
  79. <view class="pro-name tovers">{{it.title}}</view>
  80. <view class="pro-bri tover" v-if="it.brief">{{it.brief}}</view>
  81. <view class="pro-opt ddflex">
  82. <view class="money">¥{{it.minSalePrice}}<text>/起</text></view>
  83. <view class="pro-btn">立即购买</view>
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. </scroll-view>
  89. </view>
  90. </block>
  91. <view class="images" v-if="item.key == 'images'">
  92. <image :src="item.value.src" mode="widthFix"></image>
  93. </view>
  94. <block v-if="item.key == 'customerService'"></block>
  95. <button open-type="contact" class="contact ddflex" v-if="item.value.type == '0'">
  96. <image src="../../static/pages/images/kfico.png"></image>客服
  97. </button>
  98. <view class="contact ddflex" @click="customerServiceChat(item.value)" v-if="item.value.type == '1'">
  99. <image src="../../static/pages/images/kfico.png"></image>客服
  100. </view>
  101. <view class="contact ddflex" @click="jumpHref(item.value)" v-if="item.value.type == '2'">
  102. <image src="../../static/pages/images/kfico.png"></image>客服
  103. </view>
  104. </block>
  105. <view class="share ddflex" @click="showShare">
  106. <image src="../../static/pages/images/fxico1_1.png"></image>分享
  107. </view>
  108. <v-share :hide-toast="hideShare" :product="params" type="market" :code-url="codeUrl" @onFather="click"></v-share>
  109. <!-- #ifdef H5 -->
  110. <wx-share ref="wxshare" />
  111. <!-- #endif -->
  112. </view>
  113. </template>
  114. <script>
  115. const app = getApp();
  116. const req = require("../../utils/request.js");
  117. import vShare from "../../components/share/share";
  118. export default {
  119. components: {
  120. vShare
  121. },
  122. data() {
  123. return {
  124. picUrlss: req.public.picUrls,
  125. systems: {},
  126. isTop: 0,
  127. options:{},
  128. params: '',
  129. swiperCurrent: 0,
  130. hideShare: true,
  131. codeUrl: '',
  132. sessionKey: '',
  133. openid: '',
  134. userInfo: {},
  135. saveId: ''
  136. };
  137. },
  138. async onLoad(options) {
  139. if(options.appId) req.setStorage('appId',options.appId);
  140. this.options = options;
  141. if(options.userId){
  142. req.setStorage('pidCode',options.userId)
  143. }
  144. if(options.saveBehaviorId){
  145. this.saveId = options.saveBehaviorId
  146. }
  147. app.globalData.getCheckSessoin(json => {
  148. this.sessionKey = json.session_key;
  149. this.openid = json.openid;
  150. });
  151. req.silenceLogin(options.userId, '');
  152. if(options.scene){
  153. await this.loadCodeParams();
  154. }
  155. await this.getParams();
  156. await this.saveBehavior(4);
  157. },
  158. onShow() {
  159. this.userInfo = req.getStorage('userInfo');
  160. },
  161. onUnload() {
  162. this.updateBehavior()
  163. },
  164. onShareAppMessage() {
  165. this.saveBehavior(6)
  166. return this.onShareMessage();
  167. },
  168. onShareTimeline() {
  169. this.saveBehavior(6)
  170. let path = {
  171. code: this.params.code,
  172. appId: req.getStorage('appId')
  173. }
  174. if(req.getStorage('userInfo').id){
  175. path.userId = req.getStorage('userInfo').id
  176. }
  177. if(this.saveId){
  178. path += '&saveBehaviorId=' + this.saveId
  179. }
  180. return {
  181. title: this.params.title,
  182. query: path,
  183. imageUrl: this.params.pic
  184. };
  185. },
  186. onReady() {
  187. // #ifdef H5
  188. var that = this;
  189. //初始化分享内容
  190. setTimeout(function() {
  191. var shareContent = that.onShareMessage();
  192. if (shareContent) {
  193. shareContent.path = window.location.origin + shareContent.path;
  194. }
  195. console.log('分享内容》》》》》', shareContent);
  196. that.$refs.wxshare.init(shareContent);
  197. }, 4 * 1000);
  198. // #endif
  199. },
  200. methods: {
  201. onShareMessage(){
  202. let path = '/leaflet/detail/index?code=' + this.params.code+'&appId='+req.getStorage('appId')
  203. if(req.getStorage('userInfo').id){
  204. path += '&userId=' + req.getStorage('userInfo').id
  205. }
  206. if(this.saveId){
  207. path += '&saveBehaviorId=' + this.saveId
  208. }
  209. return {
  210. title: this.params.title,
  211. path: path,
  212. imageUrl: this.params.pic
  213. };
  214. },
  215. getParams() {
  216. let that = this;
  217. let params = {
  218. code: this.options.code
  219. }
  220. return new Promise((resolve, reject) => {
  221. req.getRequest('/api/v3/material/library/detail', params, data => {
  222. data.params.jsonContent.map(item=>{
  223. if(item.key == 'applicationForm'){
  224. item.value.formItemList.map(it=>{
  225. if(it.label.indexOf('姓名')>-1){
  226. if(that.userInfo.nickName){
  227. it.fieldValue = that.userInfo.nickName
  228. }
  229. }
  230. if(it.dataType == 1){
  231. if(that.userInfo.mobile){
  232. it.fieldValue = that.userInfo.mobile
  233. }
  234. }
  235. if(it.type == 5){
  236. it.option = ['大健康','快销品']
  237. }
  238. })
  239. }
  240. return item
  241. })
  242. that.params = data
  243. uni.setNavigationBarTitle({
  244. title: data.title
  245. })
  246. console.log('data.title==',data.title)
  247. resolve();
  248. });
  249. });
  250. },
  251. saveBehavior(behavior){
  252. let params = {
  253. behavior: behavior,
  254. type: 7,
  255. bindId: this.params.libraryId
  256. }
  257. if(req.getStorage('pidCode')){
  258. params.pid = req.getStorage('pidCode')
  259. }
  260. if(this.saveId){
  261. params.parentId = this.saveId
  262. }
  263. req.saveBehavior(params,data=>{
  264. if(behavior != 6){
  265. this.saveId = data
  266. }
  267. })
  268. },
  269. updateBehavior(){
  270. let params = {
  271. id: this.saveId
  272. }
  273. req.getBehaviorUpdate(params,data=>{})
  274. },
  275. swiperChange(e) {
  276. this.swiperCurrent = e.detail.current;
  277. },
  278. jumpUrl(url){
  279. uni.navigateTo({
  280. url: url
  281. })
  282. },
  283. customerServiceChat(item) {
  284. wx.openCustomerServiceChat({
  285. extInfo: {
  286. url: item.target
  287. },
  288. corpId: item.id,
  289. success(res) {
  290. console.log('调用微信客服')
  291. }
  292. })
  293. },
  294. jumpHref(item){
  295. window.location.href = item.target
  296. },
  297. showShare() {
  298. // #ifdef H5
  299. this.hideShare = false
  300. // #endif
  301. // #ifndef H5
  302. req.isLogin().then(success => {
  303. if (success) {
  304. this.getCodeUrl()
  305. this.hideShare = false
  306. }
  307. });
  308. // #endif
  309. },
  310. click(e) {
  311. this.hideShare = e
  312. },
  313. getCodeUrl() {
  314. let that = this;
  315. let scene = that.params.code;
  316. if(req.getStorage('appId')) scene += '_'+ req.getStorage('appId');
  317. const params = {
  318. page: 'leaflet/detail/index',
  319. scene: scene
  320. };
  321. req.getRequest('/api/program/codev', params, url => {
  322. that.codeUrl = url
  323. });
  324. },
  325. loadCodeParams() {
  326. let _ts = this;
  327. return new Promise((resolve, reject) => {
  328. let form = {
  329. scene: _ts.options.scene
  330. };
  331. if (!_ts.options.scene) {
  332. resolve();
  333. return false;
  334. }
  335. req.getRequest('/api/code/params', form, data => {
  336. let res = data.scene.split('_');
  337. this.options.code = res[0];
  338. req.setStorage('pidCode', data.userId);
  339. req.silenceLogin(data.userId, '');
  340. req.setStorage('appId',res[res.length-1]);
  341. resolve();
  342. });
  343. });
  344. },
  345. getPhoneNumber(e) {
  346. console.log('获取手机号',e)
  347. let that = this;
  348. let _params = {
  349. sessionKey: that.sessionKey,
  350. iv: e.detail.iv,
  351. encryptedData: e.detail.encryptedData
  352. };
  353. if (req.getStorage('pidCode')) {
  354. _params.parentId = req.getStorage('pidCode');
  355. }
  356. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  357. req.postRequest('/api/weixin/mobile', _params, json => {
  358. // console.log(json);
  359. if (json.mobile) {
  360. var userInfo = req.getStorage('userInfo');
  361. userInfo.mobile = json.mobile;
  362. req.setStorage('userInfo', userInfo);
  363. that.params.params.jsonContent.map(item=>{
  364. if(item.key == 'applicationForm'){
  365. item.value.formItemList.map(it=>{
  366. if(it.dataType == 1){
  367. it.fieldValue = json.mobile
  368. }
  369. })
  370. }
  371. return item
  372. })
  373. that.$forceUpdate();
  374. }
  375. });
  376. }
  377. },
  378. changeOptions(e,idx){
  379. console.log('选择==',e)
  380. console.log('idx==',idx)
  381. this.params.params.jsonContent.map(item=>{
  382. if(item.key == 'applicationForm'){
  383. item.value.formItemList.map((it,index)=>{
  384. if(it.type == 5&&idx==index){
  385. it.fieldValue = it.option[e.detail.value]
  386. }
  387. })
  388. }
  389. return item
  390. })
  391. this.$forceUpdate()
  392. },
  393. checkRequire(formItemList){
  394. for(var i = 0; i < formItemList.length; i++){
  395. if(formItemList[i].required){
  396. if(!formItemList[i].fieldValue){
  397. req.msg('请填写' + formItemList[i].label);
  398. return false;
  399. }
  400. }
  401. }
  402. return true;
  403. },
  404. formSubmit(datas){
  405. let params = {
  406. formId: datas.database,
  407. libraryId: this.params.libraryId
  408. }
  409. if(req.getStorage('userInfo').id){
  410. params.belongUid = req.getStorage('userInfo').id
  411. }
  412. let formItemList = datas.formItemList
  413. let valueList = []
  414. if(!this.checkRequire(formItemList)) return false
  415. formItemList.map(it=>{
  416. let obj = {
  417. fieldId: it.databaseLabel,
  418. fieldName: it.label,
  419. fieldType: it.type,
  420. fieldValue: it.fieldValue
  421. }
  422. valueList.push(obj)
  423. })
  424. params.valueList = valueList;
  425. console.log('表单提交==',params)
  426. req.postRequest('/api/v3/custom/form/submit',params,data=>{
  427. req.alertMsg('你的信息已成功提交,会有专业人员联系你,请耐心等待',suc=>{
  428. this.getParams();
  429. })
  430. })
  431. },
  432. callPhone(phone){
  433. uni.makePhoneCall({
  434. phoneNumber: phone
  435. })
  436. }
  437. },
  438. mounted() {
  439. const systemInfo = uni.getSystemInfoSync();
  440. // px转换到rpx的比例
  441. let pxToRpxScale = 750 / systemInfo.windowWidth;
  442. let systems = {
  443. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  444. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  445. };
  446. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  447. this.systems = systems;
  448. },
  449. onPageScroll: function(e) {
  450. if (e.scrollTop > this.systems.barHeight) {
  451. this.isTop = 1;
  452. } else {
  453. this.isTop = 0;
  454. }
  455. }
  456. };
  457. </script>
  458. <style>
  459. @import './index.css';
  460. </style>