goods.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. <template>
  2. <app-layout>
  3. <view v-if="id" class="screen" @click='id=null'></view>
  4. <view class="search main-between">
  5. <view @click='beSearch' v-if="!toSearch" class="main-center search-content cross-center">
  6. <image class="search-icon" src="/static/image/icon/icon-search.png"></image>
  7. <text class="search-text">请输入商品名称搜索</text>
  8. </view>
  9. <view v-else class="dir-left-nowrap" style="position: relative">
  10. <input focus placeholder="请输入商品名称搜索" class="box-grow-1 t-small search-content" @confirm='reload' confirm-type='search' @focus="getFocus=true;id=null" v-model='keyword'></input>
  11. <image v-if="getFocus && keyword.length > 0" @click="clearSearch" class="search-clear" src="../image/clear.png"></image>
  12. </view>
  13. <view @click="toAdd">
  14. <view class='add-goods dir-left-nowrap'>
  15. <image src='./../image/add.png'></image>
  16. <view>添加商品</view>
  17. </view>
  18. </view>
  19. </view>
  20. <app-tab-nav setTop="88" :tabList="tabList" padding="0" :activeItem="activeTab" @click="tabStatus" :theme="theme"></app-tab-nav>
  21. <view class="top-place"></view>
  22. <view>
  23. <view class="msg-item" @click='id=null' v-for="item in list" :key="item.id">
  24. <image class="msg-img" :src='item.goodsWarehouse.cover_pic'></image>
  25. <view class="out-dialog" v-if="item.goods_stock == 0 && appSetting.is_show_stock == '1'">
  26. <image :src="appSetting.is_use_stock == '1' ? appImg.plugins_out : appSetting.sell_out_pic"></image>
  27. </view>
  28. <view class="t-omit-two goods-name">{{item.name}}</view>
  29. <view class='goods-price'>¥{{item.price}}</view>
  30. <view class='goods-num goods-num-zero' v-if="item.goods_stock == 0">售罄</view>
  31. <view class='goods-num' v-else>库存:{{item.goods_stock}}</view>
  32. <image class='more-handle' @click.stop='showMenu(item.id)' src='./../image/more-handle.png'></image>
  33. <view v-if="item.id == id" class='main-between more'>
  34. <view @click.stop="toEdit(item.id)">
  35. <view class='more-item'>
  36. <image src='./../image/goods-edit.png'></image>
  37. <view>编辑</view>
  38. </view>
  39. </view>
  40. <view @click.stop="toSwitch('0',item.id)">
  41. <view v-if="activeTab == '1'" class='more-item'>
  42. <image src='./../image/down.png'></image>
  43. <view>下架</view>
  44. </view>
  45. </view>
  46. <view @click.stop="toSwitch('1',item.id)">
  47. <view v-if="activeTab == '0'" class='more-item'>
  48. <image src='./../image/toUp.png'></image>
  49. <view>上架</view>
  50. </view>
  51. </view>
  52. <view @click.stop="toDelete(item.id)">
  53. <view class='more-item'>
  54. <image src='./../image/del.png'></image>
  55. <view>删除</view>
  56. </view>
  57. </view>
  58. </view>
  59. <view v-if="item.id == id" class='and-more'></view>
  60. </view>
  61. </view>
  62. <view class='no-tip' v-if="list.length === 0 && !loading">
  63. <image class="icon-image" :src='adminImg.no_goods'></image>
  64. <view>没有任何商品哦~</view>
  65. </view>
  66. <view class="safe-area-inset-bottom">
  67. <view class="u-bottom-height"></view>
  68. </view>
  69. <view class="safe-area-inset-bottom u-bottom-fixed">
  70. <view :class="['main-between', 'bottom-tab']">
  71. <view class="box-grow-1 tab-item" @click="toRedirect('/pages/app_admin/index/index')">
  72. <image class="tab-icon" src="./../image/index.png"></image>
  73. <view>首页</view>
  74. </view>
  75. <view class="box-grow-1 tab-item" @click="toRedirect('/pages/app_admin/order/order')">
  76. <image class="tab-icon" src="./../image/order.png"></image>
  77. <view>订单</view>
  78. </view>
  79. <view class="box-grow-1 tab-item active" @click="reload">
  80. <image class="tab-icon" src="./../image/goods-active.png"></image>
  81. <view>商品</view>
  82. </view>
  83. <view class="box-grow-1 tab-item" @click="toRedirect('/pages/app_admin/setting/setting')">
  84. <image class="tab-icon" src="./../image/setting.png"></image>
  85. <view>设置</view>
  86. </view>
  87. </view>
  88. </view>
  89. <view class="dialog" v-if="is_switch || is_delete">
  90. <view class="dialog-item" v-if="is_switch || is_delete">
  91. <view class="dialog-title">提示</view>
  92. <view class="dialog-txt" v-if="is_switch && activeTab== '1'">是否下架该商品</view>
  93. <view class="dialog-txt" v-if="is_switch && activeTab== '0'">是否上架该商品</view>
  94. <view class="dialog-txt" v-if="is_delete">是否删除该商品</view>
  95. <view class="main-center btn-area">
  96. <view class="submit-btn" @click='cancel'>取消</view>
  97. <view class="line"></view>
  98. <view v-if="is_switch" class="submit-btn be-submit" @click='goods_switch'>确认</view>
  99. <view v-if="is_delete" class="submit-btn be-submit" @click='goods_destroy'>确认</view>
  100. </view>
  101. </view>
  102. </view>
  103. </app-layout>
  104. </template>
  105. <script>
  106. import appTabNav from "../../../components/basic-component/app-tab-nav/app-tab-nav.vue";
  107. import { mapState } from "vuex";
  108. export default {
  109. data() {
  110. return {
  111. tabList: [
  112. {id:1, name: '出售中'},
  113. {id:0, name: '下架中'}
  114. ],
  115. theme: {
  116. color: '#446dfd'
  117. },
  118. activeTab: '1',
  119. getFocus: false,
  120. keyword: '',
  121. page: 1,
  122. id: null,
  123. more_list: false,
  124. iphone_x: false,
  125. status: null,
  126. page_loading: true,
  127. list: [],
  128. is_switch: false,
  129. is_delete: false,
  130. toSearch: false,
  131. device: null,
  132. first: false,
  133. loading: false
  134. }
  135. },
  136. components: {
  137. "app-tab-nav": appTabNav
  138. },
  139. computed: {
  140. ...mapState({
  141. userInfo: state => state.user.info,
  142. appImg: state => state.mallConfig.__wxapp_img.mall,
  143. appSetting: state => state.mallConfig.mall.setting,
  144. adminImg: state => state.mallConfig.__wxapp_img.app_admin,
  145. })
  146. },
  147. methods: {
  148. toEdit(id) {
  149. uni.navigateTo({
  150. url: '/pages/app_admin/add-goods/add-goods?id=' + id
  151. })
  152. },
  153. clearSearch() {
  154. this.keyword = '';
  155. this.reload();
  156. },
  157. toAdd() {
  158. uni.navigateTo({
  159. url: '/pages/app_admin/add-goods/add-goods'
  160. })
  161. },
  162. toRedirect(url) {
  163. uni.redirectTo({
  164. url: url
  165. })
  166. },
  167. beSearch() {
  168. this.getFocus=false;
  169. if (this.keyword.length == 0) {
  170. this.toSearch = !this.toSearch
  171. }else {
  172. this.toSearch = this.toSearch;
  173. }
  174. },
  175. reload() {
  176. uni.showLoading({
  177. mask: true,
  178. title: '加载中...'
  179. });
  180. this.list = [];
  181. this.page = 1;
  182. this.id = null;
  183. this.getList();
  184. },
  185. cancel() {
  186. this.id = null;
  187. this.is_delete = false;
  188. this.is_switch = false;
  189. },
  190. toDelete(e) {
  191. this.is_delete = true;
  192. },
  193. showMenu(id) {
  194. if(this.id == id) {
  195. this.id = null
  196. }else {
  197. this.id = id;
  198. }
  199. },
  200. toSwitch(status,id) {
  201. let that = this;
  202. that.id = id;
  203. that.status = status;
  204. that.is_switch = true;
  205. },
  206. tabStatus(e) {
  207. if(this.loading) {
  208. return false
  209. }
  210. this.list = [];
  211. this.page = 1;
  212. this.activeTab = e.currentTarget.dataset.id;
  213. uni.showLoading({
  214. mask: true,
  215. title: '加载中...'
  216. });
  217. this.getList();
  218. },
  219. getList() {
  220. let that = this;
  221. if(that.loading) {
  222. return false
  223. }
  224. that.loading = true;
  225. let para = {
  226. keyword: that.keyword
  227. };
  228. para.status = that.activeTab;
  229. that.$request({
  230. url: that.$api.app_admin.goods,
  231. data: {
  232. page: that.page,
  233. search: JSON.stringify(para)
  234. }
  235. }).then(response=>{
  236. that.loading = false;
  237. uni.hideLoading();
  238. that.$hideLoading();
  239. if(response.code === 0) {
  240. that.list = that.list.concat(response.data.list);
  241. that.page++;
  242. that.more_list = false;
  243. that.first = true;
  244. if (response.data.list.length == response.data.pagination.pageSize) {
  245. that.more_list = true;
  246. }
  247. }else {
  248. uni.showToast({
  249. title: response.msg,
  250. icon: 'none',
  251. duration: 1000
  252. });
  253. }
  254. }).catch(response => {
  255. that.loading = false;
  256. uni.hideLoading();
  257. that.$hideLoading();
  258. });
  259. },
  260. goods_destroy() {
  261. let that = this;
  262. uni.showLoading({
  263. mask: true,
  264. title: '加载中...'
  265. });
  266. that.$request({
  267. url: that.$api.app_admin.goods_destroy,
  268. data: {
  269. id: that.id
  270. },
  271. method: 'post'
  272. }).then(response=>{
  273. uni.hideLoading();
  274. if(response.code == 0) {
  275. that.page = 1;
  276. that.list = [];
  277. that.id = null;
  278. that.is_delete = false;
  279. that.getList();
  280. }else {
  281. uni.showToast({
  282. title: response.msg,
  283. icon: 'none',
  284. duration: 1000
  285. });
  286. }
  287. }).catch(response => {
  288. uni.hideLoading();
  289. });
  290. },
  291. goods_switch() {
  292. let that = this;
  293. that.$request({
  294. url: that.$api.app_admin.goods_switch,
  295. data: {
  296. status: that.status,
  297. id: that.id
  298. },
  299. method: 'post'
  300. }).then(response=>{
  301. if(response.code == 0) {
  302. that.page = 1;
  303. that.id = null;
  304. that.list = [];
  305. that.is_switch = false;
  306. that.getList();
  307. }else {
  308. uni.showToast({
  309. title: response.msg,
  310. icon: 'none',
  311. duration: 1000
  312. });
  313. }
  314. }).catch(response => {
  315. });
  316. },
  317. },
  318. onLoad() { this.$commonLoad.onload();
  319. let that = this;
  320. uni.getSystemInfo({
  321. success: function (res) {
  322. if(res.model.indexOf('iPhone X') > -1 || res.model.indexOf('iPhone 11') > -1 || res.model.indexOf('iPhone11') > -1 || res.model.indexOf('iPhone12') > -1 || res.model.indexOf('Unknown Device') > -1) {
  323. that.iphone_x = true;
  324. }
  325. }
  326. })
  327. this.activeTab = '1';
  328. this.$showLoading({
  329. type: 'global',
  330. text: '加载中...'
  331. });
  332. this.getList();
  333. },
  334. onReachBottom: function() {
  335. if (this.more_list) {
  336. this.getList();
  337. }
  338. },
  339. onShow() {
  340. let that = this;
  341. that.id = null;
  342. if(that.first) {
  343. this.$showLoading({
  344. type: 'global',
  345. text: '加载中...'
  346. });
  347. that.list = [];
  348. that.page = 1;
  349. that.getList();
  350. }
  351. }
  352. }
  353. </script>
  354. <style scoped lang="scss">
  355. .search {
  356. z-index: 30;
  357. height: #{88rpx};
  358. padding: #{16rpx} #{35rpx};
  359. background-color: #EFEFF4;
  360. position: fixed;
  361. top: 0;
  362. left: 0;
  363. right: 0;
  364. width: 100%;
  365. }
  366. .search input {
  367. padding: 0 #{70rpx} 0 #{30rpx};
  368. }
  369. .search-clear {
  370. position: absolute;
  371. right: #{15rpx};
  372. top: #{14rpx};
  373. width: #{30rpx};
  374. height: #{30rpx};
  375. z-index: 100;
  376. }
  377. .search-content {
  378. background-color: #fff;
  379. height: #{56rpx};
  380. border-radius: #{28rpx};
  381. width: #{502rpx};
  382. }
  383. input.search-content {
  384. width: #{482rpx};
  385. font-size: #{26rpx};
  386. }
  387. .msg-item {
  388. margin: #{24rpx};
  389. margin-bottom: 0;
  390. background-color: #fff;
  391. border-radius: #{16rpx};
  392. position: relative;
  393. padding: #{24rpx};
  394. .out-dialog {
  395. width: #{148rpx};
  396. height: #{148rpx};
  397. position: absolute;
  398. top: #{24rpx};
  399. left: #{24rpx};
  400. z-index: 5;
  401. background-color: rgba(0,0,0,.5);
  402. image {
  403. width: #{148rpx};
  404. height: #{148rpx};
  405. }
  406. }
  407. }
  408. .msg-img {
  409. height: #{148rpx};
  410. width: #{148rpx};
  411. display: block;
  412. }
  413. .goods-name {
  414. font-size: #{26rpx};
  415. color: #353535;
  416. position: absolute;
  417. top: #{22rpx};
  418. left: #{192rpx};
  419. width: #{486rpx};
  420. }
  421. .goods-price {
  422. font-size: #{32rpx};
  423. color: #ff4544;
  424. position: absolute;
  425. bottom: #{55rpx};
  426. left: #{192rpx};
  427. }
  428. .goods-num {
  429. font-size: #{24rpx};
  430. color: #999999;
  431. position: absolute;
  432. bottom: #{20rpx};
  433. left: #{192rpx};
  434. }
  435. .goods-num-zero {
  436. color: #ff4544;
  437. }
  438. .add-goods {
  439. width: #{180rpx};
  440. height: #{56rpx};
  441. line-height: #{54rpx};
  442. border-radius: #{28rpx};
  443. border: #{1rpx} solid #446dfd;
  444. padding-left: #{18rpx};
  445. font-size: #{26rpx};
  446. color: #446dfd;
  447. margin-left: #{20rpx};
  448. background-color: #fff;
  449. }
  450. .add-goods image{
  451. height: #{28rpx};
  452. width: #{28rpx};
  453. margin-right: #{8rpx};
  454. margin-top: #{14rpx};
  455. display: block;
  456. }
  457. .more-handle {
  458. height: #{56rpx};
  459. width: #{56rpx};
  460. position: absolute;
  461. bottom: #{16rpx};
  462. right: #{24rpx};
  463. }
  464. .more {
  465. height: #{100rpx};
  466. border-radius: #{8rpx};
  467. background-color: rgba(0, 0, 0, .75);
  468. padding: #{18rpx} 0 #{8rpx};
  469. font-size: #{20rpx};
  470. color: #fff;
  471. z-index: 6;
  472. position: absolute;
  473. bottom: #{62rpx};
  474. right: #{24rpx};
  475. }
  476. .more-item {
  477. width: #{90rpx};
  478. text-align: center;
  479. }
  480. .more .more-item image {
  481. height: #{40rpx};
  482. width: #{40rpx};
  483. }
  484. .and-more {
  485. width: 0;
  486. height: 0;
  487. border-left: #{10rpx} solid transparent;
  488. border-right: #{10rpx} solid transparent;
  489. border-top: #{10rpx} solid rgba(0, 0, 0, .75);
  490. position: absolute;
  491. bottom: #{54rpx};
  492. right: #{44rpx};
  493. z-index: 6;
  494. }
  495. .bottom-tab {
  496. width: 100%;
  497. height: #{96rpx};
  498. background-color: #fff;
  499. font-size: #{20rpx};
  500. color: #9096ad;
  501. padding-top: #{14rpx};
  502. }
  503. .u-bottom-fixed {
  504. z-index: 999;
  505. position: fixed;
  506. bottom: 0;
  507. left: 0;
  508. right: 0;
  509. width: 100%;
  510. background-color: #ffffff;
  511. }
  512. .tab-item {
  513. text-align: center;
  514. }
  515. .tab-icon {
  516. height: #{48rpx};
  517. width: #{48rpx};
  518. display: inline-block;
  519. }
  520. .tab-item.active {
  521. color: #446dfd;
  522. }
  523. .tab-item view {
  524. margin-top: #{-5rpx};
  525. }
  526. .screen {
  527. position: fixed;
  528. top: 0;
  529. left: 0;
  530. height: 100%;
  531. width: 100%;
  532. background-color: rgba(0, 0, 0, 0)
  533. }
  534. .btn-area {
  535. height: #{88rpx};
  536. position: relative;
  537. border-top: #{1rpx} solid #e2e2e2;
  538. }
  539. .btn-area .line {
  540. height: #{32rpx};
  541. width: #{1rpx};
  542. background-color: #e2e2e2;
  543. position: absolute;
  544. top: #{28rpx};
  545. left: 0;
  546. right: 0;
  547. margin: 0 auto;
  548. }
  549. .submit-btn {
  550. height: #{88rpx};
  551. line-height: #{88rpx};
  552. font-size: #{32rpx};
  553. color: #666;
  554. width: #{310rpx};
  555. text-align: center;
  556. }
  557. .submit-btn.be-submit {
  558. color: #446dfd;
  559. }
  560. .dialog {
  561. position: fixed;
  562. height: 100%;
  563. width: 100%;
  564. bottom: 0;
  565. left: 0;
  566. z-index: 10;
  567. background-color: rgba(0, 0, 0, .3);
  568. }
  569. .dialog-item {
  570. padding-top: #{35rpx};
  571. position: fixed;
  572. top: 30%;
  573. left: 0;
  574. right: 0;
  575. margin: 0 auto;
  576. width: #{620rpx};
  577. border-radius: #{16rpx};
  578. background-color: #fff;
  579. }
  580. .dialog-title {
  581. font-size: #{32rpx};
  582. color: #353535;
  583. margin-bottom: #{6rpx};
  584. text-align: center;
  585. }
  586. .dialog-txt {
  587. margin: #{40rpx} auto;
  588. text-align: center;
  589. font-size: #{32rpx};
  590. color: #353535;
  591. }
  592. .no-tip {
  593. position: fixed;
  594. top: 35%;
  595. left: 0;
  596. right: 0;
  597. color: #666666;
  598. font-size: #{24rpx};
  599. text-align: center;
  600. }
  601. .no-tip .icon-image {
  602. height: #{240rpx};
  603. width: #{240rpx};
  604. margin-bottom: #{20rpx};
  605. }
  606. .u-bottom-height {
  607. height: 116upx;
  608. }
  609. .search-icon {
  610. height: #{24rpx};
  611. width: #{24rpx};
  612. }
  613. .search-text {
  614. color: #b2b2b2;
  615. font-size: #{24rpx};
  616. margin: 0 #{5rpx};
  617. }
  618. .top-place {
  619. height: #{88rpx};
  620. }
  621. </style>