classify.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <!-- #ifdef H5 -->
  3. <zj-page-layout>
  4. <template slot="header">
  5. <view class="search-container">
  6. <u-search
  7. shape="round"
  8. :showAction="false"
  9. placeholder="输入分类名称进行搜索"
  10. v-model="keyword"
  11. @search="searchData"
  12. @clear="searchData">
  13. </u-search>
  14. </view>
  15. <view class="brand-container">
  16. <u-tabs
  17. :list="brandList"
  18. @change="chooseBrand"
  19. :current="curTab"
  20. keyName="brandName"
  21. lineWidth="0"
  22. lineHeight="0"
  23. activeStyle="padding: 0 24rpx; border-radius: 24rpx; background: #E7EFFF; color: #3D8FFD;"
  24. inactiveStyle="padding: 0 24rpx; border-radius: 24rpx;"
  25. itemStyle="height: 72rpx; line-height: 72rpx; padding: 0; border-radius: 24rpx; color: #7A8BA7; margin-right: 16rpx; font-size: 28rpx; background: #f5f5f5;">
  26. </u-tabs>
  27. </view>
  28. </template>
  29. <view class="main-container">
  30. <view class="left">
  31. <block v-for="(item, index) in leftList" :key='index'>
  32. <view class="item ellipsis" :class="leftCurrent == item.categoryId ? 'current':''" @tap="changeLeft(item.categoryId)">{{item.name}}</view>
  33. </block>
  34. </view>
  35. <view class="right">
  36. <block v-for="(item, index) in rightList" :key='index'>
  37. <view class="item" @tap="submitChoess(item)">
  38. <image :src="item.imgUrl" mode="aspectFill"></image>
  39. <text class="name ellipsis">{{item.name}}</text>
  40. </view>
  41. </block>
  42. <Loading :type="2" :loadStatus="loadStatus" :dataList="rightList" />
  43. </view>
  44. </view>
  45. </zj-page-layout>
  46. <!-- #endif -->
  47. <!-- #ifndef H5 -->
  48. <web-view :src="webViewHref(`/packageWorkorder/pages/create/classify`, pam,crossPagePam)" @message="crossPage.$listener"></web-view>
  49. <!-- #endif -->
  50. </template>
  51. <script>
  52. // #ifdef H5
  53. export default {
  54. data() {
  55. return {
  56. keyword: '',
  57. brandList: [],
  58. brand: null,
  59. leftList: [],
  60. leftCurrent: 0,
  61. rightList: [],
  62. loadStatus: 0,
  63. }
  64. },
  65. computed:{
  66. curTab() {
  67. return this.brandList.map(item => item.id).indexOf(this.brand && this.brand.id) || 0;
  68. }
  69. },
  70. onLoad() {
  71. this.geBrandList();
  72. this.getLeftList();
  73. },
  74. methods: {
  75. // 获取品牌
  76. geBrandList() {
  77. this.$api.get('/charging/brand/list')
  78. .then(res => {
  79. this.brandList = res.data;
  80. if(res.data && res.data.length > 0) {
  81. this.brand = res.data[0];
  82. }
  83. })
  84. },
  85. // 获取一级菜单
  86. getLeftList() {
  87. this.$api.get('/goods/category/list', {
  88. type: 2
  89. }).then(res => {
  90. this.leftList = res.data;
  91. this.leftCurrent = res.data.length > 0 ? res.data[0].categoryId : 0;
  92. this.getRightList();
  93. })
  94. },
  95. // 获取二级菜单
  96. getRightList() {
  97. this.loadStatus = 1;
  98. this.$api.get('/goods/category/list', {
  99. parentId: this.leftCurrent,
  100. name: this.keyword,
  101. type: 2
  102. }).then(res => {
  103. this.loadStatus = 0;
  104. let list = res.data;
  105. if(list.length < 1){
  106. this.loadStatus = 2;
  107. }
  108. this.rightList = list;
  109. }).catch(() => {
  110. this.loadStatus = 2;
  111. })
  112. },
  113. // 切换一级菜单
  114. changeLeft(pid) {
  115. this.leftCurrent = pid;
  116. this.getRightList();
  117. },
  118. // 搜索
  119. searchSubmit() {
  120. this.getRightList();
  121. },
  122. // 选择品牌
  123. chooseBrand(item) {
  124. this.brand = item;
  125. },
  126. submitChoess(item) {
  127. if(!this.brand) return this.$toast('请先选择品牌');
  128. this.crossPage.$emit('chooseClassify', {
  129. brandId: this.brand.id,
  130. brandName: this.brand.brandName,
  131. imgUrl: item.imgUrl,
  132. mainId: item.parentId,
  133. smallId: item.categoryId,
  134. smallName: item.name,
  135. num: 1,
  136. });
  137. this.$navToPage({
  138. delta: 1
  139. }, 'navigateBack')
  140. }
  141. }
  142. }
  143. // #endif
  144. // #ifndef H5
  145. export default {
  146. data() {
  147. return {
  148. pam: {},
  149. }
  150. },
  151. onLoad(pam) {
  152. this.pam = pam;
  153. },
  154. }
  155. // #endif
  156. </script>
  157. <style lang="scss" scoped>
  158. .search-container {
  159. background: #ffffff;
  160. padding: 0 20rpx 20rpx;
  161. ::v-deep .u-search {
  162. height: 60rpx;
  163. input {
  164. background: #F7F8FF !important;
  165. }
  166. .u-search__content {
  167. background: #F7F8FF !important;
  168. height: 60rpx;
  169. }
  170. }
  171. }
  172. .brand-container {
  173. background: #ffffff;
  174. padding: 0 20rpx 20rpx;
  175. }
  176. .main-container {
  177. display: flex;
  178. height: 100%;
  179. padding-top: 20rpx;
  180. box-sizing: border-box;
  181. .left {
  182. width: 200rpx;
  183. height: 100%;
  184. overflow-y: scroll;
  185. box-sizing: border-box;
  186. flex-shrink: 0;
  187. .item {
  188. position: relative;
  189. display: flex;
  190. align-items: center;
  191. justify-content: center;
  192. height: 100rpx;
  193. font-size: 28rpx;
  194. color: $sec-font;
  195. border-radius: 12rpx;
  196. padding: 0 20rpx;
  197. &.current {
  198. color: $main-font;
  199. background: #ffffff;
  200. font-weight: 500;
  201. &::after {
  202. content: '';
  203. background: $theme-color;
  204. border-radius: 0 8rpx 8rpx 0;
  205. width: 8rpx;
  206. height: 40rpx;
  207. position: absolute;
  208. left: 0;
  209. top: 50%;
  210. margin-top: -20rpx;
  211. }
  212. }
  213. }
  214. }
  215. .right {
  216. flex: 1;
  217. margin: 0 20rpx auto 20rpx;
  218. background: #FFFFFF;
  219. border-radius: 10rpx;
  220. display: flex;
  221. flex-wrap: wrap;
  222. padding: 0 20rpx 20rpx 20rpx;
  223. max-height: calc(100% - 20rpx);
  224. overflow-y: scroll;
  225. box-sizing: border-box;
  226. .item {
  227. display: flex;
  228. flex-direction: column;
  229. align-items: center;
  230. margin-right: 20rpx;
  231. margin-top: 20rpx;
  232. width: 140rpx;
  233. font-size: 24rpx;
  234. image {
  235. width: 140rpx;
  236. height: 140rpx;
  237. margin-bottom: 5rpx;
  238. }
  239. .name {
  240. width: 150rpx;
  241. text-align: center;
  242. }
  243. &:nth-child(3n) {
  244. margin-right: 0;
  245. }
  246. }
  247. }
  248. }
  249. </style>