index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. <template>
  2. <view>
  3. <u-navbar title="商品列表" back-icon-color="#2D405E" :title-bold="true" title-color="#2D405E" title-size="32" :border-bottom="false" :is-back="false"></u-navbar>
  4. <block v-if="$accessCheck($Access.PublishGoods)">
  5. <view class="keyword-view clearfix">
  6. <view class="float_left">
  7. <u-search
  8. @clear="searchList"
  9. @search="searchList"
  10. :show-action="false"
  11. :clearabled="true"
  12. placeholder="商品名称/编码/条码进行搜索"
  13. v-model="keyword"
  14. height="72"
  15. placeholder-color="#879BBA"
  16. color="#879BBA"
  17. bg-color="#ECF0F7"
  18. ></u-search>
  19. </view>
  20. <!-- <view class="float_right" v-if="$accessCheck($Access.PublishGoodsSearch)" @click="openSel('search_show')">
  21. <text class="custom-icon custom-icon-shaixuan"></text>
  22. </view> -->
  23. <view class="tabs-view">
  24. <view class="search-view clearfix">
  25. <view class="title ellipsis" @click="openSel('salesStatus_show')">
  26. <u-icon
  27. size="12"
  28. label-pos="left"
  29. label-color="#62738e"
  30. color="#b8c0c8"
  31. label-size="26"
  32. :label="salesStatus_name"
  33. name="arrow-down-fill"
  34. class="ico"
  35. ></u-icon>
  36. </view>
  37. <view class="title ellipsis" @click="goPage('/pagesT/brand/selBrand')">
  38. <u-icon
  39. size="12"
  40. label-pos="left"
  41. label-color="#62738e"
  42. color="#b8c0c8"
  43. label-size="26"
  44. :label="brand_name"
  45. name="arrow-down-fill"
  46. class="ico"
  47. ></u-icon>
  48. </view>
  49. <view class="title ellipsis" @click="goPage('/pagesT/shop/selShop')">
  50. <u-icon size="12" label-pos="left" label-color="#62738e" color="#b8c0c8" label-size="26" :label="shop_name" name="arrow-down-fill" class="ico"></u-icon>
  51. </view>
  52. <view class="title ellipsis" style="line-height: 116rpx;color: #62738e;" @click="clearValue()"><text>重置</text></view>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="catet-view"><u-tabs name="title" :list="cateT_list" height="70" font-size="28" :current="cateT_current" @change="cateTchange"></u-tabs></view>
  57. <view class="main-view clearfix" :style="{ height: height }">
  58. <view class="left-view float_left">
  59. <scroll-view scroll-y="true" class="left-scroll">
  60. <view class="cate-li ellipsis" :class="[!category_id ? 'cate-on' : '']" @click="changeCate()">全部</view>
  61. <view
  62. class="cate-li ellipsis"
  63. v-for="(item, index) in category_list"
  64. :key="index"
  65. @click="changeCate(item)"
  66. :class="[category_id === item.id ? 'cate-on' : '']"
  67. >
  68. {{ item.title }}
  69. </view>
  70. </scroll-view>
  71. </view>
  72. <view class="rigth-view float_left">
  73. <scroll-view
  74. scroll-y="true"
  75. class="rigth-scroll"
  76. @scrolltolower="moreGoods"
  77. :scroll-top="scrollTop"
  78. @refresherrefresh="refresherrefresh"
  79. :refresher-enabled="true"
  80. :refresher-triggered="refresher_triggered"
  81. >
  82. <view class="goods-li" v-for="(item, index) in goods_list" :key="index">
  83. <view @click="goPage(`/pages/goods/SaleGoodsDetail?id=${item.id}&basicGoodsId=${item.basicGoodsId}`)">
  84. <view class="goods-main clearfix">
  85. <image class="goods-img float_left" :src="item.images[0]" mode="aspectFill"></image>
  86. <view class="goods-info float_left">
  87. <view class="goods-name">{{ item.title }}</view>
  88. <view class="goods-code">{{ item.code }}</view>
  89. </view>
  90. </view>
  91. <view class="goods-tag clearfix">
  92. <view class="tag-li" :class="[item.enableStatus === 5 ? 'green' : 'red']">{{ item.enableStatus === 5 ? '上架' : '下架' }}</view>
  93. <view class="tag-li brand">{{ item.categoryName }}</view>
  94. <view v-if="item.brandName" class="tag-li else">{{ item.brandName }}</view>
  95. </view>
  96. </view>
  97. <view class="handel-btn">
  98. <view v-if="$accessCheck($Access.PublishGoodsUpdateEnableStatus)" class="btn-li" @click="GoodsUpdateEnableStatus(item)">
  99. {{ item.enableStatus === 5 ? '下架' : '上架' }}
  100. </view>
  101. <view v-if="$accessCheck($Access.PublishGoodsEditGoods)" class="btn-li" style="border-left: 1rpx solid #ECF0F7;" @click="editGoods(item)">
  102. 编辑
  103. </view>
  104. <!-- <view v-if="$accessCheck($Access.PublishGoodsGetGoodsInfo)" class="btn-li"
  105. style="border-left: 1rpx solid #ECF0F7;"
  106. @click="goPage(`/pages/goods/SaleGoodsDetail?id=${item.id}&basicGoodsId=${item.basicGoodsId}`)">
  107. 查看
  108. </view> -->
  109. </view>
  110. </view>
  111. <u-loadmore v-if="goods_list.length" :status="load_status" />
  112. <view v-if="!goods_list.length" class="empty-view"><u-empty text="暂无商品" mode="favor"></u-empty></view>
  113. </scroll-view>
  114. </view>
  115. </view>
  116. <addBtn @click="addBtnClick"></addBtn>
  117. </block>
  118. <view v-else class="empty-view"><u-empty text="没有权限" mode="order"></u-empty></view>
  119. <u-popup v-model="search_show" mode="right">
  120. <view class="search-pop">
  121. <uniStatusBar></uniStatusBar>
  122. <view class="form-view" style="padding-top: 45px;">
  123. <u-form label-width="160rpx" label-position="left">
  124. <u-form-item label-position="top" label="销售状态">
  125. <text
  126. v-for="(item, index) in status_list"
  127. :key="index"
  128. class="check-li"
  129. :class="[enableStatus === item.value ? 'active' : '']"
  130. @click="statusChange(item)"
  131. >
  132. {{ item.label }}
  133. </text>
  134. </u-form-item>
  135. <u-form-item label="品牌">
  136. <view class="clearfix form-val" @click="goPage('/pagesT/brand/selBrand')">
  137. <text class="float_left ellipsis">{{ brandId ? brand_name : '请选择' }}</text>
  138. <view class="float_right" @click.stop="clearValue('brandId')">
  139. <u-icon :name="!brandId ? 'arrow-right' : 'close-circle-fill'" size="28" color="#999999"></u-icon>
  140. </view>
  141. </view>
  142. </u-form-item>
  143. <u-form-item label="所属店铺">
  144. <view class="clearfix form-val" @click="goPage('/pagesT/shop/selShop')">
  145. <text class="float_left ellipsis">{{ shopId ? shop_name : '请选择' }}</text>
  146. <view class="float_right" @click.stop="clearValue('shopId')">
  147. <u-icon :name="!shopId ? 'arrow-right' : 'close-circle-fill'" size="28" color="#999999"></u-icon>
  148. </view>
  149. </view>
  150. </u-form-item>
  151. </u-form>
  152. </view>
  153. <view class="search-btn">
  154. <view class="btn-li" @click="clearValue()">重置</view>
  155. <view class="btn-li" @click="searchList">确定</view>
  156. </view>
  157. </view>
  158. </u-popup>
  159. <u-modal
  160. v-model="tip_show"
  161. @confirm="goPage('/pages/goods/AddSelGoods', $accessCheck($Access.AddBaseData))"
  162. @cancel="goPage('/pagesT/goods/addGoods', $accessCheck($Access.PublishGoodsAddGoods))"
  163. :show-cancel-button="true"
  164. cancel-text="商品资料"
  165. confirm-text="销售商品"
  166. content=" "
  167. title="请选择"
  168. ></u-modal>
  169. <u-select @confirm="salesStatusChange" v-model="salesStatus_show" :list="status_list"></u-select>
  170. <!-- 底部tabbar -->
  171. <Tabbar v-model="tabbar_current"></Tabbar>
  172. </view>
  173. </template>
  174. <script>
  175. import uniStatusBar from '../../components/uni-status-bar.vue';
  176. export default {
  177. components: {
  178. uniStatusBar
  179. },
  180. data() {
  181. return {
  182. refresher_triggered: false, //设置当前下拉刷新状态,true 表示下拉刷新已经被触发,false 表示下拉刷新未被触发
  183. tabbar_current:2,
  184. cateT_current: 0,
  185. cateT_list: [],
  186. tip_show: false,
  187. brandData: '',
  188. shopData: '',
  189. status_list: [{
  190. value: 5,
  191. label: '上架'
  192. },
  193. {
  194. value: 4,
  195. label: '下架'
  196. }
  197. ],
  198. search_show: false,
  199. load_status: 'nomore',
  200. tab_current: 0,
  201. category_list: [], // 分类列表
  202. category_id: '', // 分类id
  203. category_t_id: '', // 分类二级id
  204. auditStatus: 2, // 审核状态
  205. isOption: '', // 是否是自选商品
  206. page: 1,
  207. pageSize: 10,
  208. total: 0,
  209. goods_list: [],
  210. brandId: '', //品牌
  211. brand_name: '所属品牌',
  212. keyword: '', //关键词
  213. enableStatus: '', //上下架
  214. shopId: '',
  215. shop_name: '所属店铺',
  216. scrollTop: -1,
  217. salesStatus_show: false,
  218. salesStatus_name: '全部商品'
  219. };
  220. },
  221. watch: {
  222. brandData(val) {
  223. if (val.id) {
  224. this.brandId = val.id;
  225. this.brand_name = val.title;
  226. this.searchList()
  227. }
  228. },
  229. shopData(val) {
  230. if (val) {
  231. this.shopId = val.id;
  232. this.shop_name = val.name;
  233. this.searchList()
  234. }
  235. }
  236. },
  237. computed: {
  238. height() {
  239. return this.cateT_list.length ? 'calc(100vh - 388rpx)' : 'calc(100vh - 308rpx)';
  240. },
  241. enterprise() {
  242. return this.$store.state.enterprise;
  243. }
  244. },
  245. onLoad(options) {
  246. this.getAllCategory();
  247. },
  248. onShow() {
  249. this.page = 1;
  250. this.getData();
  251. },
  252. methods: {
  253. cateTchange(index) {
  254. this.cateT_current = index;
  255. this.category_t_id = index ? this.cateT_list[index].id : '';
  256. this.scrollTop = 0;
  257. this.$nextTick(() => {
  258. this.scrollTop = -1;
  259. });
  260. this.page = 1;
  261. this.getData();
  262. },
  263. addBtnClick() {
  264. if (this.enterprise.scope === 4) {
  265. this.goPage('/pages/goods/AddGoodsOneStore', this.$accessCheck(this.$Access
  266. .PublishGoodsAddBasicAndPublishGoods));
  267. } else {
  268. this.tip_show = true;
  269. }
  270. },
  271. editGoods(item) {
  272. if (this.enterprise.scope === 4) {
  273. this.goPage('/pages/goods/AddGoodsOneStore?id=' + item.id);
  274. } else {
  275. this.goPage('/pages/goods/AddSelGoods?id=' + item.id);
  276. }
  277. },
  278. statusChange(row) {
  279. this.enableStatus = row.value;
  280. },
  281. GoodsUpdateEnableStatus(row) {
  282. uni.showModal({
  283. title: '提示',
  284. content: `确定要${row.enableStatus === 5 ? '下架' : '上架'}该商品吗?`,
  285. success: res => {
  286. if (res.confirm) {
  287. this.$u.api
  288. .GoodsUpdateEnableStatus({
  289. enableStatus: row.enableStatus === 5 ? 4 : 5,
  290. id: row.id
  291. })
  292. .then(res => {
  293. this.$u.toast('操作成功');
  294. this.searchList();
  295. });
  296. }
  297. }
  298. });
  299. },
  300. morehandel(item) {
  301. item.is_more = !item.is_more;
  302. },
  303. // 获取所有商品分类
  304. getAllCategory() {
  305. this.$u.api
  306. .getAllCategory({
  307. enableStatus: 5
  308. })
  309. .then(res => {
  310. this.category_list = res.data;
  311. });
  312. },
  313. // 切换分类
  314. changeCate(row) {
  315. this.scrollTop = 0;
  316. this.$nextTick(() => {
  317. this.scrollTop = -1;
  318. });
  319. if (row) {
  320. this.category_id = row.id;
  321. if (row.children) {
  322. const children = this.$u.deepClone(row.children);
  323. children.unshift({
  324. title: '全部',
  325. id: 0
  326. });
  327. this.cateT_list = children;
  328. } else {
  329. this.cateT_list = [];
  330. }
  331. } else {
  332. this.category_id = 0;
  333. this.cateT_list = [];
  334. }
  335. this.category_t_id = '';
  336. this.cateT_current = 0;
  337. this.page = 1;
  338. this.getData();
  339. },
  340. // 滚动到底部,触发上拉加载
  341. moreGoods() {
  342. if (this.total / this.pageSize > this.page) {
  343. this.page += 1;
  344. this.getData();
  345. }
  346. },
  347. // 下拉刷新
  348. refresherrefresh() {
  349. this.refresher_triggered = true;
  350. this.page = 1;
  351. this.getData();
  352. },
  353. searchList() {
  354. this.search_show = false;
  355. this.page = 1;
  356. this.getData();
  357. },
  358. // 判断当前使用方法为列表接口还是搜索引擎接口 获取列表数据
  359. getData() {
  360. let categoryPath = '';
  361. if (this.category_id && this.category_t_id) {
  362. categoryPath = this.category_id + ',' + this.category_t_id;
  363. } else if (this.category_id) {
  364. categoryPath = this.category_id;
  365. } else {
  366. categoryPath = '';
  367. }
  368. // 搜索参数规整
  369. const obj = {
  370. keyword: this.keyword,
  371. brandId: this.brandId,
  372. categoryPath: categoryPath,
  373. enableStatus: this.enableStatus,
  374. shopId: this.shopId
  375. };
  376. const isKey = this.$utils.isSerch(obj);
  377. if (isKey) {
  378. this.getAllGoodsSearch(obj);
  379. } else {
  380. this.getAllGoods();
  381. }
  382. },
  383. // 获取商品列表
  384. getAllGoods() {
  385. this.load_status = 'loading';
  386. let params = {
  387. page: this.page,
  388. pageSize: this.pageSize
  389. };
  390. this.$u.api.getAllGoods(params).then(res => {
  391. // 设置当前下拉刷新状态为false
  392. this.refresher_triggered = false;
  393. if (this.page === 1) {
  394. this.goods_list = res.data;
  395. } else {
  396. this.goods_list = this.goods_list.concat(res.data);
  397. }
  398. this.total = res.pageTotal;
  399. this.load_status = this.$utils.loadStatus(this.page, this.pageSize, this.total);
  400. }).catch(err => {
  401. // 设置当前下拉刷新状态为false
  402. this.refresher_triggered = false;
  403. });
  404. },
  405. // 商品搜索
  406. getAllGoodsSearch(obj) {
  407. this.load_status = 'loading';
  408. let params = {
  409. ...obj,
  410. page: this.page,
  411. pageSize: this.pageSize
  412. };
  413. this.$u.api.getAllGoodsSearch(params).then(res => {
  414. // 设置当前下拉刷新状态为false
  415. this.refresher_triggered = false;
  416. if (this.page === 1) {
  417. this.goods_list = res.data;
  418. } else {
  419. this.goods_list = this.goods_list.concat(res.data);
  420. }
  421. this.total = res.pageTotal;
  422. this.load_status = this.$utils.loadStatus(this.page, this.pageSize, this.total);
  423. }).catch(err => {
  424. // 设置当前下拉刷新状态为false
  425. this.refresher_triggered = false;
  426. });;
  427. },
  428. enableStatusConfirm(arr) {
  429. this.enableStatus = arr[0].value;
  430. this.enableStatus_name = arr[0].value ? arr[0].label : '';
  431. this.searchList();
  432. },
  433. clearProp(key) {
  434. this[key] = '';
  435. this[key + '_name'] = '';
  436. this.searchList();
  437. },
  438. openSel(key) {
  439. this[key] = true;
  440. },
  441. clearValue(key) {
  442. // if (!key) {
  443. // this.keyword = '';
  444. // this.brandId = '';
  445. // this.category_id = '';
  446. // this.enableStatus = '';
  447. // this.shopId = '';
  448. // this.searchList();
  449. // } else {
  450. // this[key] = '';
  451. // }
  452. this.keyword = '';
  453. this.brandId = '';
  454. this.category_id = '';
  455. this.enableStatus = '';
  456. this.shopId = '';
  457. this.salesStatus_name = '全部商品'
  458. this.brand_name = '所属品牌'
  459. this.shop_name = '所属店铺'
  460. this.searchList();
  461. },
  462. salesStatusChange(e) {
  463. this.enableStatus = e[0].value
  464. this.salesStatus_name = e[0].label
  465. this.searchList();
  466. }
  467. }
  468. };
  469. </script>
  470. <style scoped lang="scss">
  471. .tabs-view {
  472. width: 100%;
  473. background-color: #ffffff;
  474. .search-view {
  475. width: 100%;
  476. display: flex;
  477. .title {
  478. flex: 5;
  479. height: 102rpx;
  480. text-align: center;
  481. font-weight: 400;
  482. line-height: 102rpx;
  483. }
  484. }
  485. }
  486. .catet-view {
  487. border-bottom: 1px solid #f5f5f5;
  488. }
  489. .keyword-view {
  490. background-color: #ffffff;
  491. padding: 0 24rpx 0;
  492. .float_left {
  493. width: 100%;
  494. }
  495. .float_right {
  496. line-height: 64rpx;
  497. width: 50rpx;
  498. text-align: center;
  499. color: #666666;
  500. }
  501. }
  502. .main-view {
  503. height: calc(100vh - 106rpx);
  504. .left-view {
  505. width: 200rpx;
  506. background-color: #ffffff;
  507. height: 100%;
  508. .left-scroll {
  509. width: 100%;
  510. height: 100%;
  511. .cate-li {
  512. width: 100%;
  513. line-height: 80rpx;
  514. padding-left: 36rpx;
  515. color: #4b4b4b;
  516. background-color: #ffffff;
  517. font-size: 26rpx;
  518. font-weight: 400;
  519. }
  520. .cate-on {
  521. background-color: rgb(235, 240, 248);
  522. color: #000000;
  523. position: relative;
  524. font-weight: 600;
  525. font-size: 28rpx;
  526. &::before {
  527. content: '';
  528. display: block;
  529. width: 6rpx;
  530. height: 20rpx;
  531. background-color: $uni-color-primary;
  532. position: absolute;
  533. left: 14rpx;
  534. top: 50%;
  535. transform: translateY(-50%);
  536. }
  537. }
  538. }
  539. }
  540. .rigth-view {
  541. width: calc(100% - 200rpx);
  542. background-color: #ffffff;
  543. height: 100%;
  544. .rigth-scroll {
  545. width: 100%;
  546. height: 100%;
  547. background-color: #f5f5f6;
  548. .goods-li {
  549. padding: 16rpx 0 0;
  550. margin: 20rpx 16rpx;
  551. border-bottom: 1px solid #f5f5f5;
  552. position: relative;
  553. background-color: #ffffff;
  554. border-radius: 8rpx;
  555. .goods-tag {
  556. // padding: 16rpx 0;
  557. margin: 16rpx 0 24rpx 16rpx;
  558. .tag-li {
  559. float: left;
  560. margin-right: 8rpx;
  561. min-width: 104rpx;
  562. height: 32rpx;
  563. font-size: 20rpx;
  564. text-align: center;
  565. line-height: 32rpx;
  566. border-radius: 4rpx;
  567. padding: 0 6rpx;
  568. }
  569. .brand {
  570. line-height: 28rpx;
  571. border-radius: 4rpx;
  572. border: 1rpx solid #4076d6;
  573. color: #4076d6;
  574. }
  575. .else {
  576. background-color: rgb(206, 242, 255);
  577. color: #32c5ff;
  578. }
  579. .red {
  580. background-color: rgb(255, 237, 238);
  581. color: #f67778;
  582. }
  583. .green {
  584. background-color: rgb(218, 248, 242);
  585. color: #00c395;
  586. }
  587. }
  588. .goods-main {
  589. margin-left: 16rpx;
  590. .goods-img {
  591. border-radius: 8rpx;
  592. width: 114rpx;
  593. height: 114rpx;
  594. margin-right: 16rpx;
  595. }
  596. .goods-info {
  597. width: 348rpx;
  598. .goods-name {
  599. -webkit-line-clamp: 1;
  600. font-size: 28rpx;
  601. color: #2d405e;
  602. font-family: PingFangSC-Medium, PingFang SC;
  603. font-weight: 500;
  604. }
  605. .goods-code {
  606. font-size: 22rpx;
  607. padding-top: 6rpx;
  608. color: #62738e;
  609. }
  610. .goods-num {
  611. color: #999999;
  612. font-size: 22rpx;
  613. text {
  614. padding-right: 10rpx;
  615. }
  616. }
  617. }
  618. }
  619. .handel-btn {
  620. display: flex;
  621. height: 76rpx;
  622. border-top: 1px solid #ecf0f7;
  623. .btn-li {
  624. color: #879bba;
  625. font-size: 28rpx;
  626. line-height: 76rpx;
  627. flex: 3;
  628. text-align: center;
  629. // border: 1px solid #dddddd;
  630. // margin: 20rpx 10rpx 0;
  631. // border-radius: 8rpx;
  632. }
  633. }
  634. .more-btn {
  635. position: absolute;
  636. right: 20rpx;
  637. bottom: -120rpx;
  638. background-color: #ffffff;
  639. border-radius: 10rpx;
  640. padding: 0 20rpx;
  641. z-index: 9;
  642. box-shadow: 0px 3px 24rpx rgba(0, 0, 0, 0.1);
  643. .more-btn-li {
  644. font-size: 24rpx;
  645. line-height: 60rpx;
  646. text-align: center;
  647. border-bottom: 1px solid #f5f5f5;
  648. &:last-child {
  649. border: 0 none;
  650. }
  651. }
  652. }
  653. }
  654. }
  655. }
  656. }
  657. </style>