猎豆优选小程序

clipboard.vue 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <template>
  2. <u-mask :show="show">
  3. <view class="clipboard-container">
  4. <image @click="maskClipboardClose" class="close" src="https://ld.726p.com/ldyx_static/imgs/close.png" mode="widthFix"></image>
  5. <image src="https://ld.726p.com/ldyx_static/imgs/clipboard_icon.png" mode="widthFix" class="clipboard_img"></image>
  6. <view class="content">
  7. <view class="mask-title">
  8. <text>{{search_goods.goods_id ? '猜你喜欢' : '智能搜索'}}</text>
  9. </view>
  10. <block v-if="search_goods.goods_id">
  11. <view class="goods-container" @click="onClickGoodsItem()">
  12. <image class="goods-img" :src="search_goods.img" mode="widthFix"></image>
  13. <view class="goods-info">
  14. <view class="goods-title">{{search_goods.title}}</view>
  15. <view class="goods-price">¥{{search_goods.discount_price}}</view>
  16. <view class="goods-quan">
  17. <view class="coupon-wrap" v-if="search_goods.is_coupon == 1">
  18. <text class="label">券</text>
  19. <text class="value">{{ search_goods.coupon_price }}元</text>
  20. </view>
  21. <view class="coupon-wrap coupon-fan" v-if="search_goods.commission_price > 0">
  22. <text class="label">返</text>
  23. <text class="value">{{ search_goods.commission_price }}元</text>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="clipbpard-buttones">
  29. <view class="clipbpard-button" @click="onClickGoodsItem()">查看详情</view>
  30. <!--
  31. <view class="clipbpard-button share" @click="onClickShare(search_goods)">
  32. <block v-if="search_goods.commission_price > 0">
  33. 分享奖<text>{{search_goods.commission_price}}</text>
  34. </block>
  35. <block v-else>分享</block>
  36. </view>
  37. <view class="clipbpard-button" @click="onClickGoodsItem()">
  38. <block v-if="search_goods.economize > 0">
  39. 购买省<text>{{search_goods.economize}}</text>
  40. </block>
  41. <block v-else>领券购买</block>
  42. </view>
  43. -->
  44. </view>
  45. </block>
  46. <block v-else>
  47. <view class="search_con">{{search_con}}</view>
  48. <u-divider color="#AAAAAA" half-width="52" border-color="#D8D8D8" bg-color="transparent" margin-bottom="36" margin-top="58">选择搜索</u-divider>
  49. <view class="clipbpard-buttones">
  50. <view class="shopItem" @click="goSearchPage(1)">
  51. <image src="https://ld.726p.com/ldyx_static/imgs/clipboard_tb.png" mode="widthFix"></image>
  52. <text>淘宝</text>
  53. </view>
  54. <!-- <view class="shopItem" @click="goSearchPage(2)">
  55. <image src="https://ld.726p.com/ldyx_static/imgs/clipboard_jd.png" mode="widthFix"></image>
  56. <text>京东</text>
  57. </view> -->
  58. <!-- <view class="shopItem" @click="goSearchPage(3)">
  59. <image src="https://ld.726p.com/ldyx_static/imgs/icon-dy.png" mode="widthFix"></image>
  60. <text>抖音</text>
  61. </view> -->
  62. <view class="shopItem" @click="goSearchPage(4)">
  63. <image src="https://ld.726p.com/ldyx_static/imgs/pdd-icon.png" mode="widthFix"></image>
  64. <text>拼多多</text>
  65. </view>
  66. <!-- <view class="shopItem" @click="goSearchPage(5)">
  67. <image src="https://ld.726p.com/ldyx_static/imgs/icon-wph.png" mode="widthFix" style="border-radius:10rpx;"></image>
  68. <text>唯品会</text>
  69. </view> -->
  70. <!-- <view class="clipbpard-button share" @click="maskClipboardClose">取消</view>
  71. <view class="clipbpard-button" @click="goSearchPage">搜索</view> -->
  72. </view>
  73. </block>
  74. </view>
  75. </view>
  76. <!-- 淘宝授权弹框 -->
  77. <tbAuthorize v-if="isShowTbAuth" :tb_show="isShowTbAuth" @closeTask='isShowTbAuth = false' />
  78. </u-mask>
  79. </template>
  80. <script>
  81. import tbAuthorize from '../pages/commonMoudle/tbAuthorize.vue'
  82. const router = require('@/utils/router')
  83. export default {
  84. name: 'invite',
  85. components: {
  86. tbAuthorize,
  87. },
  88. data() {
  89. return {
  90. search_goods:{},
  91. search_con: '',
  92. show:false,
  93. isLogin: false,
  94. isShowTbAuth: false, // 控制是否展示淘宝授权弹框
  95. refreshCanvas: true, // 更新canvas
  96. canvasImg: '', // 海报图片
  97. qrcodeVal: '', // 二维码链接
  98. qrcodeImg: '', // 二维码图片
  99. posterInfo: {}, // 海报信息
  100. goodsParams: {}, // 当前商品参数
  101. }
  102. },
  103. mounted(){
  104. // 获取用户登录状态
  105. this.handleGetUserIsLogin()
  106. this.getClipboard()
  107. },
  108. methods:{
  109. // 去商品详情
  110. onClickGoodsItem() {
  111. const { img = '', goods_id = '', coupon_price = '', discount_price = '', price = '', is_coupon = '', commission_rate = '', is_high_commission = '', coupon_end_time = '', coupon_start_time = '' } = this.search_goods;
  112. if (this.search_goods.shop_type == 4) { // 京东
  113. uni.navigateTo({
  114. url: `/pages/subPackages/home/jdGoodsDetail?goods_id=${encodeURIComponent(goods_id)}`
  115. })
  116. } else if (this.search_goods.shop_type == 5) { // 抖音
  117. uni.navigateTo({
  118. url: `/pages/subPackages/dy/goodsDetail?goods_id=${encodeURIComponent(goods_id)}`
  119. })
  120. }else if (this.search_goods.shop_type == 6) { // 拼多多
  121. uni.navigateTo({
  122. url: `/pages/subPackages/pdd/goodsDetail?goods_id=${encodeURIComponent(goods_id)}`
  123. })
  124. } else if (this.search_goods.shop_type == 7) { // 唯品会
  125. uni.navigateTo({
  126. url: `/pages/subPackages/wph/goodsDetail?goods_id=${encodeURIComponent(goods_id)}`
  127. })
  128. }else {
  129. uni.navigateTo({
  130. url: `/pages/subPackages/home/goodsDetail?img=${encodeURIComponent(img)}&goods_id=${encodeURIComponent(goods_id)}&coupon_price=${encodeURIComponent(coupon_price)}&discount_price=${encodeURIComponent(discount_price)}&price=${encodeURIComponent(price)}&is_coupon=${encodeURIComponent(is_coupon)}&commission_rate=${encodeURIComponent(commission_rate)}&is_high_commission=${encodeURIComponent(is_high_commission)}&coupon_end_time=${encodeURIComponent(coupon_end_time)}&coupon_start_time=${encodeURIComponent(coupon_start_time)}`
  131. })
  132. }
  133. uni.setStorageSync('is_clipbpard', false)
  134. },
  135. // 去搜索页
  136. goSearchPage(type){
  137. uni.navigateTo({
  138. url:`/pages/subPackages/home/search?type=${type}&keyword=${this.search_con}`
  139. })
  140. uni.setStorageSync('is_clipbpard', false)
  141. },
  142. // 点击关闭弹框
  143. maskClipboardClose(){
  144. this.$emit('close')
  145. },
  146. // 获取剪切板内容
  147. getClipboard(){
  148. let clipbpard_con = uni.getStorageSync('clipbpard_con') //clipbpard_con剪切板内容
  149. if ( clipbpard_con ) {
  150. // 判断复制的文案是否包含链接
  151. const pattern = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&amp;//=]*)/;
  152. let clipbpard_link_result = pattern.test(clipbpard_con);
  153. if ( clipbpard_link_result ) { // 包含链接
  154. this.cliboard_get_goods(clipbpard_con.trim())
  155. } else { // 不包含链接
  156. this.show = true;
  157. this.search_con = clipbpard_con.trim();
  158. }
  159. // uni.setStorageSync('clipboard','no') // 已经获取并弹出过剪切板内容
  160. }
  161. },
  162. // 获取剪切板搜索商品列表
  163. async cliboard_get_goods(keyword) {
  164. try {
  165. const url = this.$api_jd.searchV2
  166. const params = {
  167. page: 1,
  168. keyword: keyword,
  169. sort: 1,
  170. is_has_coupon: 0,
  171. type: 0, //type 0:全网 1:淘宝 2:京东
  172. }
  173. uni.showLoading({ title: '加载中...', mask: true })
  174. const { data: res = {} } = await this.$postJSON(url, params)
  175. uni.hideLoading()
  176. this.show = true;
  177. if (res && res.errno == 0 && Array.isArray(res.rst.data)) {
  178. if (res.rst.data && res.rst.data.length > 0) {
  179. this.search_goods = res.rst.data[0];
  180. this.search_goods.economize = Number(this.search_goods.commission_price) + Number(this.search_goods.coupon_price);
  181. } else {
  182. this.search_con = keyword;
  183. }
  184. } else {
  185. this.search_con = keyword;
  186. // uni.showToast({ title: res.err || '操作失败', icon: 'none' })
  187. }
  188. } catch (error) { }
  189. },
  190. // 获取用户登录状态
  191. handleGetUserIsLogin() {
  192. const userInfo = uni.getStorageSync('userInfo') || ''
  193. const user_id = uni.getStorageSync('user_id') || ''
  194. if (userInfo && user_id) {
  195. this.isLogin = true
  196. } else {
  197. this.isLogin = false
  198. }
  199. },
  200. // 获取是否已完成淘宝授权
  201. async handleGetIsAuthOrNo () {
  202. try {
  203. const url = this.$api.relationAuth_isAuthOrNo;
  204. const params = {}
  205. uni.showLoading({ title: '加载中...', mask: true })
  206. const { data: res } = await this.$postJSON(url, params)
  207. uni.hideLoading()
  208. if (res && res.errno == 0) {
  209. return Promise.resolve(res.rst.flag)
  210. } else {
  211. uni.showToast({ title: res.err || '操作失败', icon: 'none' })
  212. return Promise.reject('获取失败')
  213. }
  214. } catch (error) {
  215. console.log('error => ', error)
  216. return Promise.reject(error)
  217. }
  218. },
  219. // 监听点击分享按钮
  220. async onClickShare(goodsItem) {
  221. try {
  222. // 未登录 => 去登录
  223. if (!this.isLogin) {
  224. router.navigateTo({
  225. url: '/pages/subPackages/login/loginPhone'
  226. })
  227. return false
  228. }
  229. // 已登录 => 判断是否授权
  230. const isAuth = await this.handleGetIsAuthOrNo()
  231. if (isAuth == 0) { // 未授权 => 显示授权弹框
  232. this.isShowTbAuth = true
  233. } else if (isAuth == 1) { // 已授权 => 生成图片 => 分享图片
  234. // this.goodsParams = {...goodsItem}
  235. // this.handleShareGoods()
  236. const { goods_id = '', coupon_price = '', discount_price = '', price = '', is_coupon = '', commission_rate = '', is_high_commission = '', coupon_end_time = '', coupon_start_time = '', shop_type = '' } = goodsItem
  237. uni.navigateTo({
  238. url: `/pages/subPackages/home/shareDetail?shop_type=${shop_type}&goods_id=${encodeURIComponent(goods_id)}&coupon_price=${encodeURIComponent(coupon_price)}&discount_price=${encodeURIComponent(discount_price)}&price=${encodeURIComponent(price)}&is_coupon=${encodeURIComponent(is_coupon)}&commission_rate=${encodeURIComponent(commission_rate)}&is_high_commission=${encodeURIComponent(is_high_commission)}&coupon_end_time=${encodeURIComponent(coupon_end_time)}&coupon_start_time=${encodeURIComponent(coupon_start_time)}`
  239. })
  240. }
  241. } catch (error) {
  242. console.log('error => ', error)
  243. }
  244. },
  245. }
  246. }
  247. </script>
  248. <style scoped lang='scss'>
  249. .clipboard-container {
  250. position: absolute;
  251. top: 50%;
  252. left: 50%;
  253. transform: translate(-50%, -50%);
  254. width: 648rpx;
  255. min-height: 400rpx;
  256. padding: 52rpx 28rpx;
  257. border-radius: 120rpx 120rpx 32rpx 32rpx;
  258. background: url('https://ld.726p.com/ldyx_static/imgs/loginReindBg.png') #FFFFFF no-repeat;
  259. background-size: 100% auto;
  260. z-index: 999;
  261. .clipbpard_bg{
  262. border-radius: 120rpx 120rpx 0 0;
  263. position: absolute;
  264. top: 0;
  265. left: 0;
  266. width: 100%;
  267. }
  268. .content{
  269. position: relative;
  270. z-index: 9;
  271. }
  272. .mask-title{
  273. display: flex;
  274. align-items: center;
  275. justify-content: center;
  276. color: #181818;
  277. font-size: 40rpx;
  278. line-height: 56rpx;
  279. font-weight: bold;
  280. letter-spacing: 2rpx;
  281. margin-top: 70rpx;
  282. }
  283. .close {
  284. position: absolute;
  285. bottom: -100rpx;
  286. left: 0;
  287. right: 0;
  288. margin: auto;
  289. width: 60rpx;
  290. height: 60rpx;
  291. }
  292. .goods-container{
  293. display: flex;
  294. align-items: center;
  295. margin-top: 50rpx;
  296. margin-bottom: 50rpx;
  297. .goods-img{
  298. width: 200rpx;
  299. height: 200rpx;
  300. border-radius: 18rpx;
  301. }
  302. .goods-info{
  303. flex: 1;
  304. margin-left: 20rpx;
  305. .goods-title{
  306. font-size: 28rpx;
  307. color: #181818;
  308. line-height: 40rpx;
  309. /* // 超出两行省略号 */
  310. word-break: break-all;
  311. overflow: hidden;
  312. -webkit-line-clamp: 2;
  313. text-overflow: ellipsis;
  314. display: -webkit-box;
  315. -webkit-box-orient: vertical;
  316. }
  317. .goods-price{
  318. color: #FF4040;
  319. font-size: 36rpx;
  320. line-height: 50rpx;
  321. margin-top: 14rpx;
  322. }
  323. .goods-quan{
  324. display: flex;
  325. align-items: center;
  326. margin-top: 14rpx;
  327. .coupon-wrap {
  328. margin-right: 30rpx;
  329. display: flex;
  330. align-items: center;
  331. width: 155rpx;
  332. height: 36rpx;
  333. background-image: url("https://ld.726p.com/ldyx_static/imgs/quan.png");
  334. background-repeat: no-repeat;
  335. background-size: 100% 100%;
  336. color: #FF4040;
  337. font-size: 26rpx;
  338. &.coupon-fan{
  339. background-image: url("https://ld.726p.com/ldyx_static/imgs/fan.png");
  340. color: #AE4300;
  341. }
  342. .label {
  343. width: 48rpx;
  344. text-align: center;
  345. }
  346. .value {
  347. flex: 1;
  348. text-align: center;
  349. }
  350. }
  351. }
  352. }
  353. }
  354. .clipbpard-buttones{
  355. display: flex;
  356. align-items: center;
  357. justify-content: space-around;
  358. padding: 0 20rpx;
  359. .clipbpard-button{
  360. width: 100%;
  361. height: 80rpx;
  362. background: linear-gradient(90deg, #FF9048 0%, #FB3F3C 100%);
  363. border-radius: 40rpx;
  364. color: #FFFFFF;
  365. font-size: 32rpx;
  366. line-height: 80rpx;
  367. text-align: center;
  368. margin: 0 10rpx;
  369. &.share{
  370. background: #FFEED9;
  371. color: #AE4300;
  372. }
  373. text{
  374. margin-left: 10rpx;
  375. }
  376. }
  377. .shopItem{
  378. text-align: center;
  379. //width: 88rpx;
  380. image{
  381. width: 88rpx;
  382. height: 88rpx;
  383. display: block;
  384. }
  385. text{
  386. font-size: 24rpx;
  387. font-weight: 400;
  388. color: #333333;
  389. line-height: 34rpx;
  390. margin-top: 8rpx;
  391. }
  392. }
  393. }
  394. .search_con{
  395. color: #181818;
  396. font-size: 28rpx;
  397. line-height: 40rpx;
  398. padding: 54rpx 24rpx 0;
  399. text-overflow: ellipsis;
  400. display: -webkit-box;
  401. -webkit-line-clamp: 6;
  402. overflow: hidden;
  403. /*! autoprefixer: off */
  404. -webkit-box-orient: vertical;
  405. /*! autoprefixer: on */
  406. word-break: break-all ;
  407. }
  408. }
  409. .clipboard_img{
  410. width: 260rpx;
  411. height: 260rpx;
  412. position: absolute;
  413. top: -50rpx;
  414. left: 0;
  415. right: 0;
  416. margin: auto;
  417. }
  418. </style>