category.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <template>
  2. <view style="height:100vh;overflow: hidden;background-color: #FFFFFF;">
  3. <view class="head">
  4. <view class="search" @tap="tapSearch">
  5. <image class="search_icon" src="http://139.9.103.171:1888/img/image/search_icon.png"></image>
  6. <input class="search_input" placeholder="请输入搜索的商品" placeholder-style="color:#ccc;" disabled />
  7. </view>
  8. <ScrollMenu></ScrollMenu>
  9. </view>
  10. <view class="category">
  11. <scroll-view scroll-y class="left_scroll_view" :style="calcLeftHeight" show-scrollbar="false">
  12. <view :class="['tab-item',index==current?'active':'']" v-for="(item,index) in tabList" :key="index" @tap="tapTabItem(index)" style="display: flex;justify-content: center;align-items: center;">
  13. <view v-if="index==0||index==1||index==2" style="margin-right: 5upx;width:24upx;height: 24upx;font-size: 18upx;color: #fff;text-align: center;line-height: 24upx;border-radius: 4upx;background-color: #DB4444;">荐</view>
  14. <view>{{item.name}}</view>
  15. </view>
  16. <view class="seize"></view>
  17. </scroll-view>
  18. <view style="width: 100%;">
  19. <DtCateGoryGoodsListNew ref="goodList" :adsList="adsList" :menuList="childrenCategorys"></DtCateGoryGoodsListNew>
  20. <!-- <DtCateGorySeries :dataList="childrenCategorys" @tapitem="onTapItem"/> -->
  21. </view>
  22. <!-- <view class="right_box" :style="calcLeftHeight">
  23. <view class="top" v-if="current==0 ||current==1">
  24. <view class="tip">
  25. <view>促销商品不享受现金券以外其他任何优惠!</view>
  26. </view>
  27. <view class="condition">
  28. <view class="item">
  29. <view>销量</view>
  30. </view>
  31. <view class="item">
  32. <view>价格</view>
  33. </view>
  34. <view class="item" @tap="switchShowStyle">
  35. <view>{{showStyle?'大图':'列表'}}</view>
  36. </view>
  37. </view>
  38. </view>
  39. <scroll-view scroll-y class="right_scroll_view" :style="calcRightHeight" show-scrollbar="false">
  40. <view class="center">
  41. <DtCateGoryGoodsList :showStyle="showStyle" v-if="current==0 || current==1" />
  42. <DtCateGorySeries v-else />
  43. </view>
  44. </scroll-view>
  45. </view> -->
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import ScrollMenu from "../comps/scroll_menu.vue"
  51. import DtCateGoryGoodsList from '../comps/dt_category_goods_list'
  52. import DtCateGorySeries from '../comps/dt_category_series'
  53. import DtCateGoryGoodsListNew from '../comps/dt_category_goods_list_new.vue'
  54. export default {
  55. components: {
  56. ScrollMenu,
  57. DtCateGoryGoodsList,
  58. DtCateGorySeries,
  59. DtCateGoryGoodsListNew
  60. },
  61. data() {
  62. return {
  63. winLeftHeight: 0,
  64. winRightHeight: 0,
  65. current: 0,
  66. tabList: [],
  67. showStyle: true,
  68. childrenCategorys: [],
  69. adsList:[],
  70. adsobj:null,
  71. }
  72. },
  73. computed: {
  74. calcLeftHeight() {
  75. return "height:" + this.winLeftHeight + "px;";
  76. },
  77. calcRightHeight() {
  78. return "height:" + this.winLeftHeight + "px;";
  79. }
  80. },
  81. onLoad() {
  82. wx.showShareMenu({
  83. withShareTicket: true
  84. })
  85. },
  86. onShareAppMessage(res) {
  87. let pages = getCurrentPages(); //获取加载的页面
  88. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  89. let inviteCode = null;
  90. let resp = this.$auth.getMemberInfo();
  91. if(this.$auth.isPromoter(true)){
  92. inviteCode = this.$auth.getMemberId();
  93. }
  94. let path = `/pages/index/index?type=share&path=${currentPage.route}&inviteCode=${inviteCode}`;
  95. console.error('path = ' + path);
  96. return {
  97. path: path,
  98. success(res) {
  99. console.log('转发成功');
  100. },
  101. fail(res) {
  102. console.log('转发失败');
  103. }
  104. };
  105. },
  106. methods: {
  107. onTapItem({item,index}){
  108. console.log(75,item,index)
  109. let params=[{
  110. k: 'productCategory.id',
  111. t: 1,
  112. v: item.id
  113. }]
  114. uni.navigateTo({
  115. url: "/pagesM/pages/goods_list?params="+JSON.stringify(params)
  116. })
  117. },
  118. autoHeight() {
  119. let res = uni.getSystemInfoSync();
  120. let clientHeight = res.windowHeight;
  121. let clientWidth = res.windowWidth;
  122. let upxR = 750 / clientWidth;
  123. let left = clientHeight * upxR - 105;
  124. let leftHeight = uni.upx2px(left);
  125. let right = clientHeight * upxR - 215;
  126. let rightHeight = uni.upx2px(right)
  127. this.winLeftHeight = leftHeight;
  128. this.winRightHeight = rightHeight;
  129. },
  130. tapSearch(){
  131. uni.navigateTo({
  132. url:'/pagesM/pages/search'
  133. })
  134. },
  135. tapTabItem(index) {
  136. if(this.current == index) return
  137. this.current = index;
  138. if(this.tabList[index] && this.tabList[index].childrens && this.tabList[index].childrens.children){
  139. let list = this.tabList[index].childrens.children
  140. this.childrenCategorys = Array.isArray(list) ? list : [];
  141. this.$refs.goodList.tapActive(0,this.childrenCategorys[0]);
  142. }
  143. // this.getProductChildrenCategorys();
  144. this.getAdList(index)
  145. },
  146. getAdList(index){
  147. if(this.adsobj==null||this.adsobj=="{}"){return}
  148. this.adsList.length = 0;
  149. Object.keys(this.adsobj).forEach((key)=>{
  150. if(this.tabList[index].id==key){
  151. this.adsList = this.adsobj[key].slice(0)
  152. }
  153. })
  154. this.$refs.goodList.getswipHeight(this.adsList)
  155. },
  156. // switchShowStyle() {
  157. // this.showStyle = !this.showStyle
  158. // },
  159. // 查找子分类
  160. // async getProductChildrenCategorys(id) {
  161. // let data = {};
  162. // data.id = this.tabList[this.current].id;
  163. // let childrenCategorys = await this.$api.getProductChildrenCategorys(data);
  164. // this.childrenCategorys = childrenCategorys;
  165. // },
  166. //查找店铺商品分类
  167. // async getStoreProductCategorys() {
  168. // let productCategoryList = await this.$api.getStoreProductCategorys();
  169. // this.tabList = productCategoryList;
  170. // this.getProductChildrenCategorys();
  171. // },
  172. async queryDataList() {
  173. let resp = await this.$api.getProductCategorys({
  174. _isShowLoading:true
  175. });
  176. resp.map((item,index)=>{
  177. let allObj = {
  178. icon:'',
  179. id:item.id,
  180. name:item.name
  181. }
  182. resp[index].childrens.children.unshift(allObj)
  183. })
  184. this.tabList = resp;
  185. if(resp[0] && resp[0].childrens && resp[0].childrens.children){
  186. let list = resp[0].childrens.children
  187. this.childrenCategorys = Array.isArray(list) ? list : []
  188. }
  189. this.$refs.goodList.tapActive(0,this.childrenCategorys[0]);
  190. },
  191. async queryAdList() {
  192. let resp = await this.$api.getProductCategorysAd({
  193. _isShowLoading:true
  194. });
  195. this.adsobj = resp
  196. },
  197. onLoadPage(options) {
  198. // wx.hideShareMenu();
  199. this.autoHeight();
  200. // this.getStoreProductCategorys();
  201. let list = [];
  202. let queryDataList = this.queryDataList();
  203. let queryAdList = this.queryAdList();
  204. list.push(queryDataList);
  205. list.push(queryAdList);
  206. let that = this;
  207. Promise.all(list).then(()=>{
  208. this.getAdList(0);
  209. this.categoryPosition();//第一次加载需在列表数据出来之后执行
  210. }).catch((err)=>{
  211. console.log(err)
  212. })
  213. },
  214. categoryPosition(){
  215. let id = uni.getStorageSync("categoryId");
  216. if(this.tabList.length>0&&id){
  217. this.tabList.forEach((item,index)=>{
  218. if(item.id==id){
  219. this.tapTabItem(index)
  220. return;
  221. }
  222. })
  223. uni.removeStorage({
  224. key: 'categoryId'
  225. })
  226. }
  227. }
  228. },
  229. onShow() {
  230. this.categoryPosition()
  231. }
  232. }
  233. </script>
  234. <style lang="scss" scoped>
  235. .head {
  236. padding: 20upx 30upx 5upx;
  237. background-color: $dt-color-primary;
  238. .search {
  239. height: 60upx;
  240. border-radius: 25px;
  241. display: flex;
  242. flex-direction: row;
  243. align-items: center;
  244. background: #fff;
  245. font-size: 30upx;
  246. .search_icon {
  247. width: 26upx;
  248. height: 26upx;
  249. padding: 20upx;
  250. }
  251. .search_input {
  252. flex: 1;
  253. height: 60upx;
  254. padding-right: 20upx;
  255. }
  256. }
  257. }
  258. .category {
  259. display: flex;
  260. flex-direction: row;
  261. .left_scroll_view {
  262. width: 200upx;
  263. text-align: center;
  264. font-size: 24upx;
  265. background-color: $dt-bg-color-grey;
  266. .tab-item {
  267. white-space: nowrap;
  268. overflow: hidden;
  269. text-overflow: ellipsis;
  270. width: 100%;
  271. padding: 20upx 0;
  272. height: 50upx;
  273. line-height: 50upx;
  274. display: inline-block;
  275. color: #3A3A3A;
  276. font-weight: bold;
  277. text-align: center;
  278. }
  279. .tab-item.active {
  280. color: $dt-color-primary;
  281. position: relative;
  282. background-color: #fff;
  283. }
  284. .tab-item.active:after {
  285. content: "";
  286. display: block;
  287. height: 50upx;
  288. width: 8upx;
  289. background: $dt-color-primary;
  290. position: absolute;
  291. top: 20upx;
  292. right: 1upx;
  293. border-radius: 16upx;
  294. }
  295. }
  296. .right_box {
  297. width: 600upx;
  298. .top {
  299. position: relative;
  300. top: 0;
  301. left: 0;
  302. .tip {
  303. background: #f2f2f2;
  304. display: flex;
  305. flex-direction: row;
  306. font-size: 20upx;
  307. align-items: center;
  308. color: #666666;
  309. height: 50upx;
  310. }
  311. .condition {
  312. display: flex;
  313. flex-direction: row;
  314. align-items: center;
  315. height: 60upx;
  316. justify-content: space-around;
  317. border-bottom: 1upx solid rgb(238, 238, 238);
  318. .item {
  319. font-size: 24upx;
  320. color: #333333;
  321. display: flex;
  322. flex-direction: row;
  323. align-items: center;
  324. image {
  325. width: 20upx;
  326. height: 20upx;
  327. }
  328. }
  329. }
  330. }
  331. .right_scroll_view {
  332. width: 100%;
  333. }
  334. }
  335. }
  336. .seize {
  337. // padding: 20upx 0;
  338. height: 140upx;
  339. }
  340. </style>