shop.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <template>
  2. <view class="box">
  3. <view class="topbox">
  4. <view class="sstop">
  5. <image src="../../static/timg/icon_search@2x.png" mode="" class="sstopimg"></image>
  6. <input type="text" v-model="name" placeholder="请输入商品名称" class="sstopInput" @confirm="ssList">
  7. <image src="../../static/img/icon_close.png" mode="" @click="empty" v-if="inputChShow" class="inputCh"></image>
  8. </view>
  9. <scroll-view scroll-x="true" class="scroll-Y" >
  10. <view class="classificationBox">
  11. <view class="classification" v-for="(item,index) in categoryList" @click="topClick(index,item)">
  12. <view class="classificationName">{{item.name}}</view>
  13. <view class="classificationHx" v-if="topIndex==index"></view>
  14. </view>
  15. </view>
  16. </scroll-view>
  17. <view class="paixuBox">
  18. <view class="paixuLine" @click="defaultpx" :class="{pxActive:defaultpxActive}">
  19. 默认排序
  20. </view>
  21. <view class="paixuLine" @click="xlPx(1)">
  22. <view :class="{pxActive:salessort}">销量</view>
  23. <view class="paixuLineTbBox">
  24. <view class="paixuLineTbtop" >
  25. <image v-if="salessorts" src="../../static/timg/icon_arrow_up_pre@2x.png" mode="" class="paixuLineTbtopIcon paixuLineTbtopIcons"></image>
  26. <image v-else src="../../static/timg/icon_arrow_up_def@2x.png" mode="" class="paixuLineTbtopIcon paixuLineTbtopIcons"></image>
  27. </view>
  28. <view class="paixuLineTbtop">
  29. <image v-if="salessortx" src="../../static/timg/icon_arrow_pre@2x.png" mode="" class="paixuLineTbtopIcon paixuLineTbtopIconx"></image>
  30. <image v-else src="../../static/timg/icon_arrow_def@2x.png" mode="" class="paixuLineTbtopIcon paixuLineTbtopIconx"></image>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="paixuLine" @click="jgpx(1)">
  35. <view :class="{pxActive:pricesort}">价格</view>
  36. <view class="paixuLineTbBox">
  37. <view class="paixuLineTbtop" >
  38. <image v-if="pricesorts" src="../../static/timg/icon_arrow_up_pre@2x.png" mode="" class="paixuLineTbtopIcon paixuLineTbtopIcons"></image>
  39. <image v-else src="../../static/timg/icon_arrow_up_def@2x.png" mode="" class="paixuLineTbtopIcon paixuLineTbtopIcons"></image>
  40. </view>
  41. <view class="paixuLineTbtop">
  42. <image v-if="pricesortx" src="../../static/timg/icon_arrow_pre@2x.png" mode="" class="paixuLineTbtopIcon paixuLineTbtopIconx"></image>
  43. <image v-else src="../../static/timg/icon_arrow_def@2x.png" mode="" class="paixuLineTbtopIcon paixuLineTbtopIconx"></image>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. <scroll-view scroll-Y="true" class="scroll-Y goodsSw" >
  49. <view class="goodsBox">
  50. <view class="hotGoodsLine" v-for="(item,index) in list" @click="goDetail(item)">
  51. <view>
  52. <image :src="item.url" v-if="item.url" mode="" @error="defImg()" class="hotGoodsLineImg"></image>
  53. <image v-else src="../../static/timg/noimg.png" mode="" class="hotGoodsLineImg"></image>
  54. </view>
  55. <view class="hotGoodsLineRIght">
  56. <view class="goodsName">{{item.name}}</view>
  57. <view class="Sold" >
  58. <view v-if="item.showLabel&&item.showLabel.indexOf('2')!=-1">
  59. 已售 {{item.saleQty}}
  60. </view>
  61. </view>
  62. <view class="goodsPrice">
  63. <view class="goodsPrice1">{{item.saleLabel}}</view>
  64. <view class="goodsPrice2">¥</view>
  65. <view class="goodsPrice3">{{item.salePrice?item.salePrice:item.scribingPrice}}</view>
  66. <view class="goodsPrice4" v-if="item.salePrice&&item.scribingPrice">¥{{item.scribingPrice}}</view>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </scroll-view>
  72. </view>
  73. <!-- 手机号授权 -->
  74. <view class="authorizBox" v-if="authorizShow" @click="authorizShow=false">
  75. <view class="authorizCont" @click.stop="">
  76. <view class="authorizName">{{wxOpenData.miniAppName}}</view>
  77. <view class="authorizMs">您好,欢迎访问本店,授权手机号登录能获取我们最新的促销活动哦~</view>
  78. <button class="authorizContbutton" type="default" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">授权</button>
  79. </view>
  80. <view style="text-align: center;padding-top: 56rpx;">
  81. <image src="../../static/timg/icon_guanbi@2x.png" mode="" class="authorizCloseImg"></image>
  82. </view>
  83. </view>
  84. </view>
  85. </template>
  86. <script>
  87. export default {
  88. components: {
  89. },
  90. data() {
  91. return {
  92. userInfo:'',
  93. salessort:false,
  94. salessorts:false,
  95. salessortx:false,
  96. pricesort:false,
  97. pricesorts:false,
  98. pricesortx:false,
  99. topIndex:0,
  100. categoryList:'',
  101. page:1,
  102. limit:10,
  103. name:'',
  104. categoryID:'',
  105. order:'',
  106. orderBy:'',
  107. list:[],
  108. defaultImg: require("../../static/timg/noimg.png"),
  109. defaultpxActive:true,
  110. authorizShow:false,
  111. code:'',
  112. wxOpenData:'',
  113. shopcategoryID:'',
  114. inputChShow:false,
  115. }
  116. },
  117. watch:{
  118. name(val){
  119. console.log(val)
  120. if(val){
  121. this.inputChShow=true
  122. }
  123. },
  124. },
  125. onLoad(opt) {
  126. console.log(getApp().globalData.shopcategoryID)
  127. //this.userInfo = uni.getStorageSync("userInfo");
  128. this.shopcategoryID=getApp().globalData.shopcategoryID;
  129. if(this.shopcategoryID){
  130. this.categoryID=this.shopcategoryID
  131. }
  132. this.userInfo=this.$store.state.userInfo;
  133. this.wxOpenData=this.$store.state.wxOpenData
  134. this.getcategoryList();
  135. this.getlistOpenGoodsPage();
  136. /* uni.getLocation({
  137. type: 'gcj02',
  138. success: function(res) {
  139. console.log(res)
  140. },
  141. fail(err) {
  142. console.log(err)
  143. }
  144. }); */
  145. },
  146. onShow() {
  147. var shopcategoryID = uni.getStorageSync("shopcategoryID")
  148. if(shopcategoryID){
  149. uni.removeStorageSync('shopcategoryID');
  150. if(this.categoryList){
  151. this.categoryList.forEach((item,index)=>{
  152. //console.log(item.id)
  153. if(item.id==shopcategoryID){
  154. this.topIndex=index
  155. }
  156. })
  157. this.categoryID=shopcategoryID;
  158. this.list=[];
  159. this.page=1;
  160. this.getlistOpenGoodsPage()
  161. }
  162. }
  163. },
  164. methods: {
  165. empty(){
  166. console.log("情况")
  167. this.name='';
  168. this.inputChShow=false;
  169. },
  170. decryptPhoneNumber: function(e) {
  171. console.log(e);
  172. this.code=e.detail.code
  173. this.wxPhoneLogin()
  174. this.authorizShow=false;
  175. },
  176. wxPhoneLogin(){
  177. var that=this;
  178. this.$http('miniApp2/sys/wxPhoneLogin', {
  179. appId:'wx33053a645546ec31',
  180. unionId:'EEADACCD-8A19-499D-8AD7-6975D2C93243',
  181. code:this.code,
  182. openId:this.wxOpenData.openid
  183. },'POST').then(res => {
  184. var data = res.data;
  185. if(data.loginInfo){
  186. this.userInfo=data.loginInfo.openUser;
  187. this.wxOpenData=data.loginInfo;
  188. this.$store.commit('mutationswxOpenData', data.loginInfo)
  189. this.$store.commit('mutationsuserInfo', this.userInfo)
  190. this.topIndex=1;
  191. this.list=[];
  192. this.page=1;
  193. this.getlistOpenGoodsPage()
  194. }
  195. })
  196. },
  197. xlPx(num){
  198. this.salessort=true;
  199. this.defaultpxActive=false;
  200. this.pricesort=false;
  201. this.pricesort=false;
  202. this.pricesorts=false;
  203. this.pricesortx=false;
  204. if(this.salessorts){
  205. num=2
  206. }
  207. if(num==1){
  208. this.salessorts=true;
  209. this.salessortx=false;
  210. this.orderBy='asc';
  211. }else{
  212. this.salessorts=false;
  213. this.salessortx=true;
  214. this.orderBy='desc';
  215. }
  216. this.order='SaleQty';
  217. this.list=[];
  218. this.page=1;
  219. this.getlistOpenGoodsPage()
  220. },
  221. jgpx(type){
  222. this.salessort=false;
  223. this.defaultpxActive=false;
  224. this.pricesort=true;
  225. this.salessort=false;
  226. this.salessorts=false;
  227. this.salessortx=false;
  228. if(this.pricesorts){
  229. type=2
  230. }
  231. if(type==1){
  232. this.pricesorts=true;
  233. this.pricesortx=false;
  234. this.orderBy='asc';
  235. }else{
  236. this.pricesorts=false;
  237. this.pricesortx=true;
  238. this.orderBy='desc';
  239. }
  240. this.order='SalePrice';
  241. this.list=[];
  242. this.page=1;
  243. this.getlistOpenGoodsPage()
  244. },
  245. defaultpx(){
  246. this.order='';
  247. this.orderBy='';
  248. this.salessort=false;
  249. this.salessorts=false;
  250. this.salessortx=false;
  251. this.pricesort=false;
  252. this.pricesorts=false;
  253. this.pricesortx=false;
  254. //this.topIndex=0;
  255. this.list=[];
  256. this.page=1;
  257. this.getlistOpenGoodsPage()
  258. },
  259. defImg(event){
  260. // console.log(event)
  261. /* let img = event.srcElement;
  262. img.src = this.defaultImg;
  263. img.onerror = null; //防止闪图 */
  264. },
  265. topClick(index,item){
  266. this.topIndex=index;
  267. this.list=[];
  268. this.page=1;
  269. this.categoryID=item.id;
  270. this.getlistOpenGoodsPage()
  271. },
  272. ssList(){
  273. this.topIndex=1;
  274. this.list=[];
  275. this.page=1;
  276. this.getlistOpenGoodsPage()
  277. },
  278. goDetail(item){
  279. if(!this.userInfo){
  280. this.authorizShow=true;
  281. }else{
  282. uni.navigateTo({
  283. url:'goodsDetail?id='+item.id
  284. })
  285. }
  286. },
  287. getcategoryList(){
  288. this.$http('openMall/categoryList', {
  289. },'GET').then(res => {
  290. this.categoryList=res.data;
  291. var obj={
  292. id:'',
  293. name:'全部'
  294. }
  295. this.categoryList.unshift(obj);
  296. if(this.shopcategoryID){
  297. //console.log(this.shopcategoryID)
  298. this.categoryList.forEach((item,index)=>{
  299. //console.log(item.id)
  300. if(item.id==this.shopcategoryID){
  301. this.topIndex=index
  302. }
  303. })
  304. }
  305. })
  306. },
  307. getlistOpenGoodsPage(){
  308. uni.showLoading({ title: '加载中'});
  309. this.$http('openMall/listOpenGoodsPage', {
  310. page:this.page,
  311. limit:this.limit,
  312. name:this.name,
  313. categoryID:this.categoryID,
  314. orderBy:this.order,
  315. order:this.orderBy,
  316. },'GET').then(res => {
  317. uni.hideLoading();
  318. var data=res.data.Items;
  319. this.list=this.list.concat(data)
  320. })
  321. }
  322. },
  323. onReachBottom(){
  324. this.page++;
  325. this.getlistOpenGoodsPage()
  326. //console.log("shanglas")
  327. },
  328. onPullDownRefresh(){
  329. this.list=[];
  330. this.page=1;
  331. this.getlistOpenGoodsPage();
  332. setTimeout(() => {
  333. uni.stopPullDownRefresh(); // 关闭下拉刷新
  334. }, 2000);
  335. }
  336. }
  337. </script>
  338. <style scoped lang="less">
  339. .inputCh{
  340. width:40rpx;
  341. height: 40rpx;
  342. position: absolute;
  343. right: 40rpx;
  344. top: 40rpx;
  345. z-index: 11;
  346. }
  347. .pxActive{
  348. color: #FF0000 !important;
  349. }
  350. .paixuLineTbtopIcon{
  351. width: 16rpx;
  352. height: 8rpx;
  353. display: block;
  354. padding-left: 10rpx;
  355. }
  356. .paixuLineTbtopIconx{
  357. padding-bottom:24rpx;
  358. }
  359. .paixuLineTbtopIcons{
  360. padding-top: 8rpx;
  361. }
  362. .paixuLineTbBox{
  363. display: flex;
  364. flex-direction: column;
  365. justify-content: space-between;
  366. }
  367. .box{
  368. background: #F4F5F7;
  369. min-height: 100vh;
  370. }
  371. .sstopInput{
  372. width: 626rpx;
  373. height: 72rpx;
  374. background: #F4F5F7;
  375. border-radius: 36rpx;
  376. line-height: 72rpx;
  377. font-size: 28rpx;
  378. padding-left: 76rpx;
  379. }
  380. .sstop{
  381. position: relative;
  382. padding-top: 24rpx;
  383. padding-left: 24rpx;
  384. background: #ffffff;
  385. }
  386. .sstopimg{
  387. width: 40rpx;
  388. height: 40rpx;
  389. position: absolute;
  390. left: 44rpx;
  391. top: 40rpx;
  392. }
  393. .scroll-Y{
  394. background: #ffffff;
  395. width: 750rpx;
  396. }
  397. .classificationBox{
  398. display: flex;
  399. padding-bottom: 12rpx;
  400. }
  401. .classificationName{
  402. white-space: nowrap;
  403. font-size: 28rpx;
  404. color: #3C3C3C;
  405. line-height: 40rpx;
  406. padding:24rpx 24rpx 8rpx 24rpx;
  407. }
  408. .classificationHx{
  409. width: 40rpx;
  410. height: 4rpx;
  411. background: #FF0000;
  412. margin: 0 auto;
  413. }
  414. .paixuBox{
  415. width: 750rpx;
  416. height: 72rpx;
  417. background: #FFFFFF;
  418. margin-top: 20rpx;
  419. display: flex;
  420. justify-content: space-around;
  421. }
  422. .paixuLine{
  423. line-height: 37rpx;font-size: 26rpx;color: #666666;padding-top: 18rpx;
  424. display: flex;
  425. }
  426. .hotGoodsLine{
  427. margin-top: 20rpx;
  428. padding:0rpx 20rpx;
  429. background: #FFFFFF;
  430. border-radius: 16rpx;
  431. display: flex;
  432. }
  433. .hotGoodsLineImg{
  434. width: 208rpx;
  435. height: 194rpx;
  436. border-radius: 16rpx;
  437. border: 1px solid #EEEEEE;
  438. }
  439. .goodsName{
  440. font-size: 28rpx;
  441. font-family: PingFangSC-Regular, PingFang SC;
  442. font-weight: 400;
  443. color: #333333;
  444. line-height: 40rpx;
  445. text-overflow: -o-ellipsis-lastline;
  446. overflow: hidden;
  447. text-overflow: ellipsis;
  448. display: -webkit-box;
  449. -webkit-line-clamp: 2;
  450. line-clamp: 2;
  451. -webkit-box-orient: vertical;
  452. }
  453. .hotGoodsLineRIght{
  454. padding-left: 24rpx;
  455. }
  456. .goodsPrice{
  457. display: flex;
  458. padding-top: 10rpx;
  459. }
  460. .goodsPrice1{
  461. font-size: 24rpx;
  462. font-weight: 400;
  463. color: #FF0000;
  464. padding-top: 8rpx;
  465. }
  466. .goodsPrice2{
  467. font-size: 22rpx;
  468. font-weight: 400;
  469. color: #FF0000;
  470. padding-top: 10rpx;
  471. }
  472. .goodsPrice3{
  473. font-size: 32rpx;
  474. font-weight: 500;
  475. color: #FF0000;
  476. }
  477. .goodsPrice4{
  478. font-size: 24rpx;
  479. font-weight: 400;
  480. color: #999999;
  481. padding-top: 8rpx;
  482. text-decoration:line-through;
  483. padding-left: 10rpx;
  484. }
  485. .Sold{
  486. font-weight: 400;
  487. color: #999999;
  488. font-size: 24rpx;
  489. padding-top: 8rpx;
  490. line-height: 30rpx;
  491. height: 30rpx;
  492. }
  493. .authorizBox{
  494. width: 100vw;
  495. height: 100vh;
  496. background: rgba(0, 0, 0, 0.5);
  497. position: fixed;
  498. top: 0;
  499. left: 0;
  500. }
  501. .authorizCont{
  502. margin-top: 30vh;
  503. width: 564rpx;
  504. height: 408rpx;
  505. background: #FFFFFF;
  506. border-radius: 24rpx;
  507. margin-left: 93rpx;
  508. position: relative;
  509. }
  510. .authorizCloseImg{
  511. width: 62rpx;
  512. height: 62rpx;
  513. }
  514. .sqLogoBox{
  515. width: 180rpx;
  516. height: 180rpx;
  517. background: #FFFFFF;
  518. border-radius: 90rpx;
  519. text-align: center;
  520. position: absolute;
  521. top: -50rpx;
  522. left: 192rpx;
  523. }
  524. .authorizName{
  525. color: #333333;
  526. line-height: 42rpx;
  527. font-size: 30rpx;
  528. text-align: center;
  529. padding-top: 58rpx;
  530. }
  531. .authorizMs{
  532. color: #999999;
  533. line-height: 36rpx;
  534. font-size: 26rpx;
  535. width: 452rpx;
  536. padding-top: 24rpx;
  537. text-align: center;
  538. margin-left: 56rpx;
  539. }
  540. .authorizContbutton{
  541. width: 422rpx;
  542. height: 88rpx;
  543. background: #D53533;
  544. border-radius: 44rpx;
  545. line-height: 88rpx;
  546. text-align: center;
  547. font-size:30rpx;
  548. color: #FFFFFF;
  549. margin-top: 62rpx;
  550. margin-left:71rpx;
  551. }
  552. </style>