goodsList.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <view class="container">
  3. <view class="header flex flex-y-center">
  4. <view :class="['item','flex','flex-center',typeActive == 1 ? 'active' : '']" @click="onTypeChange(1)">
  5. <view class="title">全部商品</view>
  6. </view>
  7. <view :class="['item','flex','flex-center',typeActive == 2 ? 'active' : '']" @click="onTypeChange(2)">
  8. <view class="title">售卖中</view>
  9. </view>
  10. <view :class="['item','flex','flex-center',typeActive == 3 ? 'active' : '']" @click="onTypeChange(3)">
  11. <view class="title">已下架</view>
  12. </view>
  13. <!-- <view :class="['item','flex','flex-center',typeActive == 4 ? 'active' : '']" @click="onTypeChange(4)">
  14. <view class="title">已售罄</view>
  15. </view> -->
  16. </view>
  17. <view class="main-block flex box-pack-between">
  18. <scroll-view scroll-y class="left-bar">
  19. <view class="item" :class="[catIndex == -1?'active':'']" @click="onCatChange(-1)">全部</view>
  20. <view class="item" :class="[catIndex == index?'active':'']" v-for="(item,index) in catList" :key="index" @click="onCatChange(index)">{{item.title}}</view>
  21. </scroll-view>
  22. <scroll-view scroll-y class="right-bar" @scrolltolower="scrollTolower" >
  23. <view class="cat-name">{{catIndex == -1?'全部':catList[catIndex].title}}</view>
  24. <view class="goods-list">
  25. <view class="item flex" v-for="(item,index) in list" :key="index" @click="toDetail(index)">
  26. <view class="goods-img-block">
  27. <image :src="getImgPath(item.thumb)" mode="aspectFill" class="goods-img"></image>
  28. <view class="goods-tips" v-if="item.stock == 0">已售罄</view>
  29. </view>
  30. <view class="info-block">
  31. <view class="goods-name text-1 flex flex-y-center box-pack-between arr-r">{{item.name}}</view>
  32. <view class="stock box-pack-between">
  33. <text>库存:{{item.stock}}</text>
  34. <text>总销量:{{item.fictitious}}</text>
  35. </view>
  36. <view class="goods-btm flex flex-y-center box-pack-between">
  37. <view class="price">¥{{item.price}}</view>
  38. <view class="btn-block flex flex-y-center">
  39. <view class="btn" v-if="item.status == 0" @click.stop="onStatusChange(index,1)">上架</view>
  40. <view class="btn" v-if="item.status == 1" @click.stop="onStatusChange(index,0)">下架</view>
  41. <view class="btn" style="margin-left:24rpx;" @click.stop="onDel(index)">删除</view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="no-more" v-if="list.length>0">---没有更多了---</view>
  48. </scroll-view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. export default {
  54. data() {
  55. return {
  56. store_id:"",
  57. typeActive: 1,
  58. catIndex: -1, //选中分类
  59. page:1,
  60. list:[],
  61. is_bottom:false,
  62. catList:[]
  63. }
  64. },
  65. onLoad(options) {
  66. this.store_id = uni.getStorageSync("store_id");
  67. this.getData(1)
  68. this.getCatList()
  69. },
  70. onReachBottom() {
  71. },
  72. methods: {
  73. scrollTolower(){
  74. // console.log("ree",this.is_bottom)
  75. if (!this.is_bottom) {
  76. this.getData(this.page + 1)
  77. }
  78. },
  79. getImgPath(path) {
  80. return this.$siteroot + path
  81. },
  82. onTypeChange(index) {
  83. if (index != this.typeActive) {
  84. this.typeActive = index
  85. this.getData(1)
  86. }
  87. },
  88. onCatChange(index) {
  89. if (index != this.catIndex) {
  90. this.catIndex = index
  91. this.getData(1)
  92. }
  93. },
  94. getData(page) {
  95. if (page == 1) {
  96. this.list = []
  97. this.page = 1
  98. this.is_bottom = false
  99. }
  100. let params = {
  101. page,
  102. limit: 10,
  103. store_id: this.store_id,
  104. category_id: this.catIndex == -1?'':this.catList[this.catIndex].id,
  105. }
  106. if(this.typeActive == 2){
  107. params.status = 1
  108. }else if(this.typeActive == 3){
  109. params.status = 0
  110. }else{
  111. params.status = ""
  112. }
  113. this.request({
  114. url: 'Smdcshop/goods_lists',
  115. data: params
  116. }).then(res => {
  117. if (res.code == '200' && res.data.length>0) {
  118. this.list = this.list.concat(res.data)
  119. this.page = page
  120. } else {
  121. this.is_bottom = true
  122. }
  123. })
  124. },
  125. getCatList(){
  126. this.request({
  127. url:'Smdcshop/cygoods_category_index',
  128. data:{
  129. store_id:this.store_id
  130. }
  131. }).then(res=>{
  132. this.catList = res.data
  133. })
  134. },
  135. onStatusChange(index,status){
  136. this.request({
  137. url:'Smdcshop/goods_state',
  138. data:{
  139. id:this.list[index].id,
  140. is_show:status
  141. }
  142. }).then(res=>{
  143. this.list[index].status = status == 1 ?1:0
  144. })
  145. },
  146. onDel(index){
  147. uni.showModal({
  148. content:"确定删除该商品",
  149. success: (r) => {
  150. if(r.confirm){
  151. this.request({
  152. url:"Smdcshop/goods_delect",
  153. data:{
  154. id:this.list[index].id
  155. }
  156. }).then(res=>{
  157. if(res.code == 200){
  158. this.getData(1)
  159. }
  160. })
  161. }
  162. }
  163. })
  164. },
  165. toDetail(index){
  166. let id=this.list[index].id;
  167. uni.navigateTo({
  168. url:`/saomaDiancan/editGoods/editGoods?id=${id}`
  169. })
  170. },
  171. }
  172. }
  173. </script>
  174. <style>
  175. page {}
  176. .header {
  177. height: 96rpx;
  178. background-color: #fff;
  179. position: sticky;
  180. top: 0;
  181. z-index: 100;
  182. box-sizing: border-box;
  183. border-bottom: 8rpx solid #F4F5F7;
  184. }
  185. .header .item {
  186. width: 33.33vw;
  187. box-sizing: border-box;
  188. flex: none;
  189. height: 88rpx;
  190. position: relative;
  191. }
  192. .header .item.active .title {
  193. color: #247EFF;
  194. font-size: 32rpx;
  195. font-weight: 600;
  196. }
  197. .header .item.active::after {
  198. content: "";
  199. display: block;
  200. width: 40rpx;
  201. height: 4rpx;
  202. border-radius: 2rpx;
  203. background-color: #247EFF;
  204. position: absolute;
  205. bottom: 8rpx;
  206. left: 50%;
  207. transform: translateX(-50%);
  208. }
  209. .header .item .title {
  210. font-size: 28rpx;
  211. color: #666;
  212. }
  213. .main-block {
  214. width: 100%;
  215. height: calc(100vh - 96rpx);
  216. }
  217. .main-block .left-bar {
  218. width: 176rpx;
  219. flex: none;
  220. height: 100%;
  221. background-color: #F4F5F7;
  222. /*兼容 IOS<11.2*/
  223. padding-bottom: constant(safe-area-inset-bottom);
  224. /*兼容 IOS>11.2*/
  225. padding-bottom: env(safe-area-inset-bottom);
  226. }
  227. .main-block .item {
  228. padding: 30rpx 15rpx;
  229. font-size: 28rpx;
  230. color: #666;
  231. font-weight: 500;
  232. line-height: 40rpx; text-align: center;
  233. }
  234. .main-block .item.active {
  235. color: #247EFF;
  236. font-weight: 600;
  237. background-color: #fff;
  238. }
  239. .main-block .right-bar {
  240. width: 574rpx;
  241. flex: none;
  242. height: 100%;
  243. background-color: #fff;
  244. box-sizing: border-box;
  245. padding: 30rpx 0 30rpx 25rpx;
  246. position: relative;
  247. /*兼容 IOS<11.2*/
  248. padding-bottom: constant(safe-area-inset-bottom);
  249. /*兼容 IOS>11.2*/
  250. padding-bottom: env(safe-area-inset-bottom);
  251. }
  252. .main-block .right-bar .cat-name {
  253. font-size: 30rpx;
  254. font-weight: 600;
  255. color: #333;
  256. line-height: 42rpx;
  257. background-color: #fff;
  258. }
  259. .main-block .right-bar .item {
  260. padding: 40rpx 30rpx 40rpx 0;
  261. border-bottom: 1rpx solid #f5f5f5;
  262. }
  263. .main-block .right-bar .item .goods-img-block {
  264. flex: none;
  265. width: 120rpx;
  266. height: 120rpx;
  267. overflow: hidden;
  268. border-radius: 8rpx;
  269. position: relative;
  270. }
  271. .main-block .right-bar .item .goods-img-block .goods-img {
  272. display: block;
  273. width: 120rpx;
  274. height: 120rpx;
  275. }
  276. .main-block .right-bar .item .goods-img-block .goods-tips {
  277. background-color: rgba(0, 0, 0, 0.5);
  278. width: 100%;
  279. height: 35rpx;
  280. position: absolute;
  281. left: 0;
  282. bottom: 0;
  283. color: #fff;
  284. line-height: 35rpx;
  285. text-align: center;
  286. font-size: 20rpx;
  287. }
  288. .main-block .right-bar .item .info-block {
  289. padding-left: 24rpx;
  290. width: 405rpx;
  291. box-sizing: border-box;
  292. }
  293. .main-block .right-bar .item .info-block .goods-name {
  294. padding-right: 15rpx;
  295. font-size: 30rpx;
  296. font-weight: 600;
  297. color: #333;
  298. line-height: 1;
  299. }
  300. .main-block .right-bar .item .arr-r::after {
  301. border-color: #333 #333 transparent transparent;
  302. }
  303. .main-block .right-bar .item .info-block .stock {
  304. font-size: 24rpx;
  305. color: #999;
  306. line-height: 1;
  307. margin-top: 16rpx;
  308. }
  309. .main-block .right-bar .item .info-block .goods-btm {
  310. margin-top: 12rpx;
  311. }
  312. .main-block .right-bar .item .info-block .goods-btm .price {
  313. font-size: 30rpx;
  314. color: #FD3939;
  315. font-weight: 600;
  316. }
  317. .main-block .right-bar .item .info-block .goods-btm .btn {
  318. width: 100rpx;
  319. height: 38rpx;
  320. font-size: 20rpx;
  321. line-height: 38rpx;
  322. text-align: center;
  323. color: #666;
  324. border: 1rpx solid #DBDDE1;
  325. background-color: #F4F5F7;
  326. }
  327. </style>