goods.vue 20 KB

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