shop.vue 13 KB

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