index.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. {extend name="public/container"}
  2. {block name="head_top"}
  3. <script type="text/javascript" src="{__WAP_PATH}crmeb/js/base.js"></script>
  4. {/block}
  5. {block name="title"}{$category ? $category['cate_name'] : '全部产品'}{/block}
  6. {block name="content"}
  7. <body style="background:#f7f7f7; overflow: hidden;">
  8. <div id="product-list" class="product-sort">
  9. <section>
  10. <div class="search-wrapper" ref="head" @touchmove.prevent :class="{active:movingDirectionY == 1}">
  11. <form action="" method="post" @submit.prevent="searchProduct">
  12. <input type="text" v-model="keyword" placeholder="商品搜索: 请输入商品关键词"/>
  13. </form>
  14. <div class="menu"><a href="{:url('store/category')}"></a></div>
  15. </div>
  16. <div class="price-select flex" @touchmove.prevent ref="nav">
  17. <div class="item" :class="{ on:search.priceOrder =='' && search.salesOrder == '' && search.news == false}" @click="changeDefault">默认</div>
  18. <div class="item" :class="{'selected-up':search.priceOrder == 'asc','selected-down':search.priceOrder == 'desc','on':search.priceOrder!=''}" @click="changePriceOrder">价格<i class="icon"></i></div>
  19. <div class="item" :class="{'selected-up':search.salesOrder == 'asc','selected-down':search.salesOrder == 'desc','on':search.salesOrder!=''}" @click="changeSalesOrder">销量<i class="icon"></i></div>
  20. <div class="item" :class="{on:search.news == true}" @click="changeNews">新品</div>
  21. <div class="layout-vertical" :class="{on:vertical != true}" @click="vertical = !vertical"><span></span></div>
  22. </div>
  23. <div class="product-list" ref="bsDom" style="-webkit-overflow-scrolling: touch;">
  24. <div>
  25. <ul class="list-layout flex" :class="{vertical:vertical == true}">
  26. <li class="flex" v-for="item in group.list" v-cloak="">
  27. <a class="flex" :href="productUrl(item.id)">
  28. <div class="img"><img :src="item.image" /></div>
  29. <div class="info-txt">
  30. <p class="name" v-text="item.store_name"></p>
  31. <span class="count">已售{{item.sales}}</span>
  32. <p class="price">¥{{item.price}}</p>
  33. </div>
  34. </a>
  35. <div class="buy-car" @click="shopCard(item)"></div>
  36. </li>
  37. </ul>
  38. <p class="loading-line" v-show="loading == true"><i></i><span>正在加载中</span><i></i></p>
  39. <p class="loading-line" v-show="loading == false && group.loaded == false" v-cloak="" @click="getList"><i></i><span>点击加载</span><i></i></p>
  40. <p class="loading-line" v-show="loading == false && group.loaded == true" v-cloak=""><i></i><span>没有更多了</span><i></i></p>
  41. </div>
  42. </div>
  43. </section>
  44. <div class="model-bg"></div>
  45. <div class="child-alink-bg" @touchmove.prevent v-show="showCategoryList == true" @click="showCategoryList = false" v-cloak=""></div>
  46. {include file="public/store_menu"}
  47. </div>
  48. <script>
  49. var base = new Base64();
  50. requirejs(['vue','store','better-scroll','helper','{__WAP_PATH}crmeb/module/store/shop-card.js'],function(Vue,storeApi,BScroll,$h,shopCard){
  51. shopCard.install(Vue);
  52. var cid = "{$cid}";
  53. new Vue({
  54. el:"#product-list",
  55. components:{
  56. 'shop-card':shopCard
  57. },
  58. data:{
  59. keyword:'{$keyword}',
  60. categoryList:[],
  61. showCategoryList:false,
  62. childCategoryList:[],
  63. search:{
  64. cInfo:{},
  65. sInfo:{},
  66. priceOrder:'',
  67. salesOrder:'',
  68. news:0,
  69. keyword:'{$keyword}'
  70. },
  71. group:{
  72. first:0,
  73. limit:20,
  74. list:[],
  75. loaded:false
  76. },
  77. loading: false,
  78. scroll:null,
  79. templateCategory:{},
  80. vertical:false,
  81. movingDirectionY:0,
  82. cid:'{$cid}',
  83. sid:'{$sid}'
  84. },
  85. watch:{
  86. movingDirectionY:function(n){
  87. var that = this;
  88. if(n == 1){
  89. this.$refs.bsDom.style.height = (
  90. document.documentElement.clientHeight -
  91. this.$refs.nav.offsetHeight -
  92. this.$refs.storeMenu.offsetHeight
  93. )+'px';
  94. }else{
  95. this.$refs.bsDom.style.height = (
  96. document.documentElement.clientHeight -
  97. this.$refs.head.offsetHeight -
  98. this.$refs.nav.offsetHeight -
  99. this.$refs.storeMenu.offsetHeight
  100. )+'px';
  101. }
  102. // setTimeout(function(){
  103. // that.$nextTick(function(){
  104. // that.scroll.refresh();
  105. // });
  106. // },400);
  107. },
  108. vertical:function(){
  109. // this.$nextTick(function(){
  110. // this.scroll.refresh();
  111. // });
  112. },
  113. search:{
  114. handler:function(v){
  115. this.group = {
  116. first:0,
  117. limit:20,
  118. list:[],
  119. loaded:false
  120. };
  121. this.loading = false;
  122. this.getList();
  123. },
  124. deep:true
  125. }
  126. },
  127. computed:{
  128. cate_name:function(){
  129. if(this.search.sInfo.id != undefined && this.search.sInfo.id != 0)
  130. return this.search.sInfo.cate_name;
  131. else if(this.search.sInfo.id === 0 && this.search.cInfo.id != undefined)
  132. return this.search.cInfo.cate_name;
  133. else
  134. return '默认';
  135. }
  136. },
  137. methods:{
  138. shopCard:function(product){
  139. var that = this;
  140. $h.loadFFF();
  141. storeApi.getProductAttr(product.id,function(res){
  142. var productValue = res.data.data.productValue;
  143. $h.loadClear();
  144. that.$shopCard({
  145. product:product,
  146. show:true,
  147. onChange:function(values){
  148. var checkedAttr = productValue[values.sort().join(',')];
  149. if(undefined != checkedAttr){
  150. this.changeProduct({
  151. stock:checkedAttr.stock,
  152. price:checkedAttr.price,
  153. image:checkedAttr.image
  154. });
  155. }
  156. },
  157. onCart:function(values,cartNum){
  158. var checkedAttr = productValue[values.sort().join(',')];
  159. storeApi.setCart({
  160. cartNum:cartNum,
  161. uniqueId:checkedAttr === undefined ? '' : checkedAttr.unique,
  162. productId:product.id
  163. },function () {
  164. $h.pushMsg('加入购物车成功!');
  165. });
  166. this.close();
  167. },
  168. onBuy:function(values,cartNum){
  169. var checkedAttr = productValue[values.sort().join(',')];
  170. storeApi.goBuy({
  171. cartNum:cartNum,
  172. uniqueId:checkedAttr === undefined ? '' : checkedAttr.unique,
  173. productId:product.id
  174. },function(cartId){
  175. location.href = $h.U({
  176. c:'store',
  177. a:'confirm_order',
  178. p:{cartId:cartId}
  179. });
  180. });
  181. this.close();
  182. },
  183. attrList:res.data.data.productAttr,
  184. onClose:function(){
  185. setTimeout(this.remove,550);
  186. }
  187. });
  188. },function(){ $h.loadClear(); return true});
  189. },
  190. goCart:function(){
  191. location.href = $h.U({
  192. c:'store',
  193. a:'cart'
  194. });
  195. },
  196. productUrl:function(id){
  197. return $h.U({c:'store',a:'detail',p:{id:id}});
  198. },
  199. searchProduct:function(){
  200. if(this.keywrod == '') return;
  201. if(this.keywrod == this.search.keyword) return;
  202. this.search.keyword = this.keyword;
  203. this.search.cInfo = {};
  204. this.search.sInfo = {};
  205. this.search.news = 0;
  206. // this.scroll.scrollTo(0,0);
  207. },
  208. getList:function(){
  209. if(this.loading) return;
  210. var that = this,type = 'group',group = that.group;
  211. if(group.loaded) return ;
  212. this.loading = true;
  213. storeApi.getProductList({
  214. keyword:base.encode(this.search.keyword) || 0,
  215. cId:this.cid || 0,
  216. sId:this.sid || 0,
  217. priceOrder:this.search.priceOrder || 0,
  218. salesOrder:this.search.salesOrder || 0,
  219. news:this.search.news || 0,
  220. first:group.first,
  221. limit:group.limit
  222. },function(res){
  223. var list = res.data.data,groupLength = group.list.length;
  224. // that.scroll.stop();
  225. group.loaded = list.length < group.limit;
  226. group.first += list.length;
  227. group.list = group.list.concat(list);
  228. that.$set(that,type,group);
  229. that.loading = false;
  230. // that.$nextTick(function(){
  231. // if(list.length || !groupLength) that.scroll.refresh();
  232. // if(!groupLength) setTimeout(function(){that.scroll.scrollTo(0,0,300);},0);
  233. // that.scroll.finishPullUp();
  234. // });
  235. },function(){that.loading = false});
  236. },
  237. bScrollInit:function () {
  238. var that = this;
  239. this.$refs.bsDom.style.height = (
  240. document.documentElement.clientHeight -
  241. this.$refs.head.offsetHeight -
  242. this.$refs.nav.offsetHeight -
  243. this.$refs.storeMenu.offsetHeight
  244. )+'px';
  245. this.$refs.bsDom.style.overflow = 'scroll';
  246. // this.$refs.bsDom.getElementsByTagName('div')[0].style.position = 'relative';
  247. // this.scroll = new BScroll(this.$refs.bsDom,{bounce:false,observeDOM:false,click:true,probeType:1,cancelable:false,snapThreshold:0.01,deceleration:0.0018, useTransform:false});
  248. // this.movingDirectionY = this.scroll.movingDirectionY;
  249. // this.scroll.on('pullingUp',function(){
  250. // that.loading == false && that.getList();
  251. // });
  252. // this.scroll.on('flick',function(){
  253. // that.movingDirectionY = that.scroll.movingDirectionY;
  254. // });
  255. },
  256. changeDefault:function () {
  257. this.search.salesOrder = '';
  258. this.search.priceOrder = '';
  259. this.search.news = false;
  260. },
  261. changeNews:function(){
  262. this.search.salesOrder = '';
  263. this.search.priceOrder = '';
  264. this.search.news = !this.search.news;
  265. },
  266. changePriceOrder:function(){
  267. if(this.search.priceOrder == '')
  268. this.search.priceOrder = 'desc';
  269. else if(this.search.priceOrder == 'desc')
  270. this.search.priceOrder = 'asc';
  271. else if(this.search.priceOrder == 'asc')
  272. this.search.priceOrder = '';
  273. this.search.salesOrder = '';
  274. this.search.news = false;
  275. },
  276. changeSalesOrder:function(){
  277. if(this.search.salesOrder == '')
  278. this.search.salesOrder = 'desc';
  279. else if(this.search.salesOrder == 'desc')
  280. this.search.salesOrder = 'asc';
  281. else if(this.search.salesOrder == 'asc')
  282. this.search.salesOrder = '';
  283. this.search.priceOrder = '';
  284. this.search.news = false;
  285. },
  286. selectAll:function(){
  287. if(!this.templateCategory.id) return ;
  288. this.search.cInfo = {};
  289. this.search.sInfo = {};
  290. this.templateCategory = {};
  291. this.childCategoryList = [];
  292. this.showCategoryList = false;
  293. },
  294. changeCategory:function (category,index) {
  295. this.templateCategory = category;
  296. this.childCategoryList = [{'cate_name':'全部商品','id':0}];
  297. this.childCategoryList = this.childCategoryList.concat(category.child);
  298. },
  299. changeChild:function(child){
  300. this.search.sInfo = child;
  301. this.search.cInfo = this.templateCategory;
  302. this.showCategoryList = false;
  303. this.search.keyword = this.keyword = '';
  304. }
  305. },
  306. mounted:function(){
  307. var that = this;
  308. this.bScrollInit();
  309. this.getList();
  310. }
  311. });
  312. });
  313. </script>
  314. {/block}