goodsList.vue 7.2 KB

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