猎豆优选小程序

clipboard.vue 13KB

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