BaseGoodslist.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <view>
  3. <view class="keyword-view clearfix">
  4. <view class="float_left">
  5. <u-search @clear="searchList" @search="searchList" :show-action="false" :clearabled="true" placeholder="商品名称/编码/条码" v-model="keyword"></u-search>
  6. </view>
  7. <view v-if="$accessCheck($Access.BaseDataListSearch)" class="float_right" @click="openSel('search_show')"><text class="custom-icon custom-icon-shaixuan"></text></view>
  8. </view>
  9. <view class="main-view clearfix">
  10. <view class="left-view float_left">
  11. <scroll-view scroll-y="true" class="left-scroll">
  12. <view class="cate-li" :class="[!category_id ? 'cate-on' : '']" @click="changeCate(0)">全部</view>
  13. <view class="cate-li" v-for="(item, index) in category_list" :key="index" @click="changeCate(item.id)" :class="[category_id === item.id ? 'cate-on' : '']">
  14. {{ item.title }}
  15. </view>
  16. </scroll-view>
  17. </view>
  18. <view class="rigth-view float_left">
  19. <scroll-view scroll-y="true" class="rigth-scroll" @scrolltolower="moreGoods" :scroll-top="scrollTop">
  20. <view class="goods-li" v-for="(item, index) in goods_list" :key="index">
  21. <view class="goods-main clearfix">
  22. <image class="goods-img float_left" :src="item.images[0]" mode="aspectFill"></image>
  23. <view class="goods-info float_left">
  24. <view class="goods-name ellipsis">{{ item.title }}</view>
  25. <view class="goods-code">{{ item.code }}</view>
  26. <view class="goods-tag">
  27. <u-tag class="tag-li" mode="plain" size="mini" :text="item.categoryTitle" />
  28. <u-tag class="tag-li" size="mini" :text="item.enableStatus === 5 ? '启用' : '禁用'" />
  29. <u-tag class="tag-li" v-if="item.brandTitle" size="mini" type="success" :text="item.brandTitle" />
  30. </view>
  31. </view>
  32. </view>
  33. <view class="handel-btn">
  34. <view class="btn-li" v-if="$accessCheck($Access.BaseDataListUpdateEnableStatus)" @click="updateEnableStatusGoods(item)">
  35. {{ item.enableStatus === 5 ? '禁用' : '启用' }}
  36. </view>
  37. <view class="btn-li" @click="goPage('/pagesT/goods/addGoods?id=' + item.id)" v-if="$accessCheck($Access.EditBaseData)">编辑</view>
  38. <view v-if="$accessCheck($Access.BaseDataListDetail)" class="btn-li" @click="goPage('/pages/goods/goodsDetail?id=' + item.id)">查看</view>
  39. <!-- <view class="btn-li" @click="goPage('/pages/goods/goodsDetail?id=' + item.id)">发布</view> -->
  40. </view>
  41. </view>
  42. <u-loadmore v-if="goods_list.length" :status="load_status" />
  43. <view v-if="!goods_list.length" class="empty-view"><u-empty text="暂无商品" mode="favor"></u-empty></view>
  44. </scroll-view>
  45. </view>
  46. </view>
  47. <addBtn v-if="$accessCheck($Access.AddBaseData)" url="/pagesT/goods/addGoods"></addBtn>
  48. <u-popup v-model="search_show" mode="right">
  49. <view class="search-pop">
  50. <view class="form-view">
  51. <u-form label-width="160rpx" label-position="left">
  52. <u-form-item label-position="top" label="销售状态">
  53. <text
  54. v-for="(item, index) in status_list"
  55. :key="index"
  56. class="check-li"
  57. :class="[enableStatus === item.value ? 'active' : '']"
  58. @click="statusChange(item)"
  59. >
  60. {{ item.label }}
  61. </text>
  62. </u-form-item>
  63. <u-form-item label="品牌">
  64. <view class="clearfix form-val" @click="goPage('/pagesT/brand/selBrand')">
  65. <text class="float_left ellipsis">{{ brandId ? brand_name : '请选择' }}</text>
  66. <view class="float_right" @click.stop="clearValue('brandId')">
  67. <u-icon :name="!brandId ? 'arrow-right' : 'close-circle-fill'" size="28" color="#999999"></u-icon>
  68. </view>
  69. </view>
  70. </u-form-item>
  71. </u-form>
  72. </view>
  73. <view class="search-btn">
  74. <view class="btn-li" @click="clearValue()">重置</view>
  75. <view class="btn-li" @click="searchList">确定</view>
  76. </view>
  77. </view>
  78. </u-popup>
  79. </view>
  80. </template>
  81. <script>
  82. export default {
  83. data() {
  84. return {
  85. load_status: 'nomore',
  86. tab_current: 0,
  87. status_list: [
  88. {
  89. label: '启用',
  90. value: 5
  91. },
  92. {
  93. label: '禁用',
  94. value: 4
  95. }
  96. ],
  97. category_list: [], // 分类列表
  98. category_id: '', // 分类id
  99. auditStatus: 2, // 审核状态
  100. isOption: '', // 是否是自选商品
  101. page: 1,
  102. pageSize: 10,
  103. total: 0,
  104. goods_list: [],
  105. brandId: '', //品牌
  106. brand_name: '',
  107. keyword: '', //关键词
  108. enableStatus: '', //上下架
  109. brandData: {},
  110. search_show: false,
  111. scrollTop: -1
  112. };
  113. },
  114. watch: {
  115. brandData(val) {
  116. if (val.id) {
  117. this.brandId = val.id;
  118. this.brand_name = val.title;
  119. }
  120. }
  121. },
  122. onLoad() {
  123. this.getAllCategory();
  124. },
  125. onShow() {
  126. this.page = 1;
  127. this.getData();
  128. },
  129. methods: {
  130. updateEnableStatusGoods(row) {
  131. uni.showModal({
  132. title: '提示',
  133. content: `确定要${row.enableStatus === 5 ? '禁用' : '启用'}该商品吗?`,
  134. success: res => {
  135. if (res.confirm) {
  136. this.$u.api
  137. .updateEnableStatusGoods({
  138. enableStatus: row.enableStatus === 5 ? 4 : 5,
  139. id: [row.id]
  140. })
  141. .then(res => {
  142. this.$u.toast('操作成功');
  143. this.searchList();
  144. });
  145. }
  146. }
  147. });
  148. },
  149. // 获取所有商品分类
  150. getAllCategory() {
  151. this.$u.api
  152. .getAllCategory({
  153. enableStatus: 5
  154. })
  155. .then(res => {
  156. this.category_list = res.data;
  157. });
  158. },
  159. // 切换分类
  160. changeCate(id) {
  161. this.scrollTop = 0;
  162. this.$nextTick(() => {
  163. this.scrollTop = -1;
  164. });
  165. this.category_id = id;
  166. this.searchList();
  167. },
  168. // 滚动到底部,触发上拉加载
  169. moreGoods() {
  170. if (this.total / this.pageSize > this.page) {
  171. this.page += 1;
  172. this.getData();
  173. }
  174. },
  175. searchList() {
  176. this.search_show = false;
  177. this.page = 1;
  178. this.getData();
  179. },
  180. // 判断当前使用方法为列表接口还是搜索引擎接口 获取列表数据
  181. getData() {
  182. // 搜索参数规整
  183. const obj = {
  184. keyword: this.keyword,
  185. brandId: this.brandId,
  186. categoryPath: this.category_id,
  187. enableStatus: this.enableStatus
  188. };
  189. const isKey = this.$utils.isSerch(obj);
  190. if (isKey) {
  191. this.searchGoods();
  192. } else {
  193. this.getAllGoodsBasic();
  194. }
  195. },
  196. // 获取商品列表
  197. getAllGoodsBasic() {
  198. this.load_status = 'loading';
  199. let params = {
  200. page: this.page,
  201. pageSize: this.pageSize
  202. };
  203. this.$u.api.getAllGoodsBasic(params).then(res => {
  204. if (this.page === 1) {
  205. this.goods_list = res.data;
  206. } else {
  207. this.goods_list = this.goods_list.concat(res.data);
  208. }
  209. this.total = res.pageTotal;
  210. this.load_status = this.$utils.loadStatus(this.page, this.pageSize, this.total);
  211. });
  212. },
  213. // 商品搜索
  214. searchGoods() {
  215. this.load_status = 'loading';
  216. let params = {
  217. keyword: this.keyword,
  218. brandId: this.brandId,
  219. categoryPath: this.category_id,
  220. enableStatus: this.enableStatus,
  221. page: this.page,
  222. pageSize: this.pageSize
  223. };
  224. this.$u.api.searchGoods(params).then(res => {
  225. if (this.page === 1) {
  226. this.goods_list = res.data;
  227. } else {
  228. this.goods_list = this.goods_list.concat(res.data);
  229. }
  230. this.total = res.pageTotal;
  231. this.load_status = this.$utils.loadStatus(this.page, this.pageSize, this.total);
  232. });
  233. },
  234. statusChange(val) {
  235. this.enableStatus = val;
  236. },
  237. clearValue(key) {
  238. if (!key) {
  239. this.keyword = '';
  240. this.brandId = '';
  241. this.category_id = '';
  242. this.enableStatus = '';
  243. this.searchList();
  244. } else {
  245. this[key] = '';
  246. }
  247. },
  248. openSel(key) {
  249. this[key] = true;
  250. }
  251. }
  252. };
  253. </script>
  254. <style scoped lang="scss">
  255. .keyword-view {
  256. background-color: #ffffff;
  257. padding: 20rpx 24rpx;
  258. .float_left {
  259. width: 640rpx;
  260. }
  261. .float_right {
  262. line-height: 64rpx;
  263. width: 50rpx;
  264. text-align: center;
  265. color: #666666;
  266. }
  267. }
  268. .main-view {
  269. .left-view {
  270. width: 168rpx;
  271. background-color: #f7f8fa;
  272. .left-scroll {
  273. width: 100%;
  274. height: calc(100vh - 106rpx);
  275. .cate-li {
  276. line-height: 90rpx;
  277. padding-left: 36rpx;
  278. color: #666666;
  279. }
  280. .cate-on {
  281. background-color: #ffffff;
  282. color: #000000;
  283. position: relative;
  284. &::before {
  285. content: '';
  286. display: block;
  287. width: 6rpx;
  288. height: 20rpx;
  289. background-color: $uni-color-primary;
  290. position: absolute;
  291. left: 14rpx;
  292. top: 50%;
  293. transform: translateY(-50%);
  294. }
  295. }
  296. }
  297. }
  298. .rigth-view {
  299. width: calc(100% - 168rpx);
  300. background-color: #ffffff;
  301. .rigth-scroll {
  302. width: 100%;
  303. height: calc(100vh - 106rpx);
  304. .goods-li {
  305. padding: 20rpx;
  306. border-bottom: 1px solid #f5f5f5;
  307. position: relative;
  308. .goods-main {
  309. .goods-img {
  310. border-radius: 10rpx;
  311. width: 156rpx;
  312. height: 156rpx;
  313. margin-right: 20rpx;
  314. }
  315. .goods-info {
  316. width: 366rpx;
  317. .goods-name {
  318. -webkit-line-clamp: 1;
  319. }
  320. .goods-code {
  321. font-size: 24rpx;
  322. padding-top: 6rpx;
  323. }
  324. .goods-tag {
  325. padding: 10rpx 0;
  326. .tag-li {
  327. margin-right: 14rpx;
  328. }
  329. }
  330. .goods-num {
  331. color: #999999;
  332. font-size: 22rpx;
  333. text {
  334. padding-right: 10rpx;
  335. }
  336. }
  337. }
  338. }
  339. .handel-btn {
  340. display: flex;
  341. .btn-li {
  342. font-size: 24rpx;
  343. line-height: 50rpx;
  344. flex: 3;
  345. text-align: center;
  346. border: 1px solid #dddddd;
  347. margin: 20rpx 10rpx 0;
  348. border-radius: 8rpx;
  349. }
  350. }
  351. .more-btn {
  352. position: absolute;
  353. right: 20rpx;
  354. bottom: -120rpx;
  355. background-color: #ffffff;
  356. border-radius: 10rpx;
  357. padding: 0 20rpx;
  358. z-index: 9;
  359. box-shadow: 0px 3px 24rpx rgba(0, 0, 0, 0.1);
  360. .more-btn-li {
  361. font-size: 24rpx;
  362. line-height: 60rpx;
  363. text-align: center;
  364. border-bottom: 1px solid #f5f5f5;
  365. &:last-child {
  366. border: 0 none;
  367. }
  368. }
  369. }
  370. }
  371. }
  372. }
  373. }
  374. </style>