goods-manage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <template>
  2. <view class="business-detail-box">
  3. <Navbar navType='customLeft' title=' ' :leftWidth='500' color="#666">
  4. <view class="nav-left">
  5. <view class="tabs">
  6. <view class="tab" v-for="(item, index) in tab" :key="index" :class="{active: type === item.type}"
  7. @click="changeTab(item.type)">{{item.name}}</view>
  8. </view>
  9. </view>
  10. </Navbar>
  11. <view class="content">
  12. <view class="top"></view>
  13. <view class="good-box">
  14. <view class="left">
  15. <view class="category-box">
  16. <view class="category-item" v-for="item in categoryList" :key="item.id"
  17. :class="{active: categoryId === item.id}" @click="changeCategory(item)">
  18. {{item.name}}
  19. <view class="bar"></view>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="right">
  24. <view class="list">
  25. <view class="list-item" v-for="item in secCategoryList" :key="item.id" v-if="goodsObj[item.name]">
  26. <view class="name">{{item.name}}</view>
  27. <view class="goods">
  28. <view class="good" :class="{active: good.id === id}" v-for="good in goodsObj[item.name]" @click="handleEditModal(good)">
  29. <image class="pic" :src="good.masterPic" mode=""></image>
  30. <view class="good-right">
  31. <view class="name">{{good.name}}</view>
  32. <view class="bottom">
  33. <view>¥:<text>{{good.minPrice | moneyFormat}}</text></view>
  34. <view>库存:<text>{{good.totalStock}}</text></view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. <uni-popup ref="editPopup" type="bottom" :safe-area="false" @change="changePopup">
  45. <view class="options">
  46. <view class="option" @click="toDetail">
  47. <IconText :code="`\ue88e`" color="#1D9BF0" class="icon" size="30"></IconText>
  48. 编辑商品
  49. </view>
  50. <view class="option" @click="updateStatusModal">
  51. <IconText :code="`\ue87e`" color="#FF8D1A" class="icon" size="30"></IconText>
  52. {{ type === 3 ? '商品下架' : '商品开售' }}
  53. </view>
  54. <view class="option" @click="updateTwigModal">
  55. <IconText :code="`\ue880`" color="#00BAAD" class="icon" size="30"></IconText>
  56. 商品排序
  57. </view>
  58. <view class="option" @click="deleteGoodModal">
  59. <IconText :code="`\ue881`" color="#FF4A74" class="icon" size="30"></IconText>
  60. 删除
  61. </view>
  62. </view>
  63. </uni-popup>
  64. <uni-popup ref="updateTwig" type="center" :safe-area="false">
  65. <view class="twig-box">
  66. <view class="title">商品排序</view>
  67. <view class="input-box">
  68. <view class="label">排序:</view>
  69. <input class="input" type="text" v-model="twig" placeholder=" " />
  70. </view>
  71. <view class="tip">数值越大,商品越靠前</view>
  72. <view class="btn" @click="updateTwig">确认</view>
  73. </view>
  74. </uni-popup>
  75. <ShowModal ref="updateStatus" title="提示" @submit="updateStatus" leftBtnText="取消" :content="`是否确认将该商品移动至“${type === 3 ? '仓库中' : '出售中'}”?`"
  76. btnText="确认" />
  77. <ShowModal ref="deleteGood" title="提示" @submit="deleteGood" leftBtnText="取消" content="是否确定删除该商品"
  78. btnText="确认" />
  79. </view>
  80. </template>
  81. <script lang='ts'>
  82. import {
  83. Component,
  84. Prop,
  85. Vue
  86. } from 'vue-property-decorator';
  87. @Component({
  88. filters: {
  89. juliFormat(val: any) {
  90. if (!val) return '0m';
  91. if (val < 1000) {
  92. return val + 'm'
  93. } else {
  94. return (val / 1000).toFixed(2) + 'km'
  95. };
  96. },
  97. moneyFormat(val: any) {
  98. if (!+val) return '0.00';
  99. return (+val).toFixed(2);
  100. }
  101. }
  102. })
  103. export default class BusinessDetail extends Vue {
  104. id: any = null;
  105. gid: any = null;
  106. cur: number = 0 // 当前滑块的index
  107. type: any = 3;
  108. tab: any = [{
  109. name: '出售中',
  110. type: 3,
  111. },
  112. {
  113. name: '仓库',
  114. type: 1,
  115. }
  116. ];
  117. categoryList: any = [];
  118. categoryId: any = null;
  119. secCategoryList: any = [];
  120. goodsObj: any = {};
  121. twig: any = null;
  122. onLoad() {
  123. uni.setNavigationBarColor({
  124. frontColor: '#ffffff', //文字颜色
  125. backgroundColor: '#ffffff' //底部背景色
  126. });
  127. this.getCategoryList();
  128. }
  129. changeTab(type: any) {
  130. this.type = type;
  131. this.getGoodsList();
  132. }
  133. changeCategory(item: any) {
  134. this.categoryId = item.id;
  135. this.secCategoryList = item.second;
  136. this.getGoodsList();
  137. }
  138. handleEditModal(good: any){
  139. this.id = good.id;
  140. this.gid = good.gid;
  141. this.twig = good.twig;
  142. (this.$refs.editPopup as any).open();
  143. }
  144. changePopup(e: any){
  145. if(e.show === false) this.id = null;
  146. }
  147. getCategoryList() {
  148. uni.showLoading({
  149. title: '加载中',
  150. });
  151. this.$http
  152. .get({
  153. url: this.$api.getCategoryListB,
  154. data: {}
  155. })
  156. .then((res: any) => {
  157. this.categoryList = res.list;
  158. if (res.list.length) {
  159. this.categoryId = res.list[0].id;
  160. this.secCategoryList = res.list[0].second;
  161. }
  162. uni.hideLoading();
  163. this.getGoodsList();
  164. }, (err: any) => {
  165. uni.hideLoading();
  166. });
  167. }
  168. getGoodsList() {
  169. uni.showLoading({
  170. title: '加载中',
  171. });
  172. this.$http
  173. .get({
  174. url: this.$api.getGoodsListB,
  175. data: {
  176. status: this.type,
  177. firstSortId: this.categoryId,
  178. page: 1,
  179. size: 999
  180. }
  181. })
  182. .then((res: any) => {
  183. uni.hideLoading();
  184. let obj: any = {};
  185. res.list.forEach((item: any) => {
  186. if (obj[item.secondSortName]) {
  187. obj[item.secondSortName].push(item);
  188. } else {
  189. obj[item.secondSortName] = [item]
  190. }
  191. });
  192. this.goodsObj = obj;
  193. }, (err: any) => {
  194. uni.hideLoading();
  195. });
  196. }
  197. toDetail(){
  198. this.$Router.push({
  199. path: '/packages/goods/add-good',
  200. query: {
  201. gid: this.gid,
  202. id: this.id
  203. }
  204. })
  205. }
  206. updateStatusModal(){
  207. (this.$refs.updateStatus as any).open();
  208. }
  209. updateStatus(){
  210. uni.showLoading({
  211. title: '加载中',
  212. });
  213. this.$http
  214. .put({
  215. url: this.$api.updateGoodStatus,
  216. data: {
  217. id: this.id,
  218. status: this.type === 3 ? 1 : 3
  219. }
  220. })
  221. .then((res: any) => {
  222. uni.hideLoading();
  223. this.getGoodsList();
  224. }, (err: any) => {
  225. uni.hideLoading();
  226. });
  227. }
  228. updateTwigModal(){
  229. (this.$refs.updateTwig as any).open();
  230. }
  231. updateTwig(){
  232. uni.showLoading({
  233. title: '加载中',
  234. });
  235. this.$http
  236. .put({
  237. url: this.$api.updateGoodTwig,
  238. data: {
  239. id: this.id,
  240. twig: +this.twig
  241. }
  242. })
  243. .then((res: any) => {
  244. uni.hideLoading();
  245. this.getGoodsList();
  246. (this.$refs.updateTwig as any).close();
  247. }, (err: any) => {
  248. uni.hideLoading();
  249. });
  250. }
  251. deleteGoodModal(){
  252. (this.$refs.deleteGood as any).open();
  253. }
  254. deleteGood(){
  255. uni.showLoading({
  256. title: '加载中',
  257. });
  258. this.$http
  259. .delete({
  260. url: this.$api.deleteGoodB,
  261. data: {
  262. gid: this.gid
  263. }
  264. })
  265. .then((res: any) => {
  266. uni.hideLoading();
  267. this.getGoodsList();
  268. }, (err: any) => {
  269. uni.hideLoading();
  270. });
  271. }
  272. }
  273. </script>
  274. <style lang="scss" scoped>
  275. .business-detail-box {
  276. height: 100vh;
  277. @include flex-y(flex-start);
  278. .top {
  279. width: 100%;
  280. box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.3);
  281. }
  282. .nav-left {
  283. .tabs {
  284. @include flex-x(flex-start);
  285. .tab {
  286. @include word-vw(20, #999);
  287. font-weight: bold;
  288. @include flex-x(flex-start);
  289. padding: 0 vw(10);
  290. &.active {
  291. color: #333;
  292. }
  293. }
  294. }
  295. }
  296. .content {
  297. width: 100%;
  298. flex: 1;
  299. .good-box {
  300. width: 100%;
  301. height: 100%;
  302. @include flex-x();
  303. .left {
  304. width: vw(80);
  305. height: 100%;
  306. background: #fff;
  307. flex-shrink: 0;
  308. .category-box {
  309. .category-item {
  310. height: vw(40);
  311. @include flex-x(center);
  312. @include word-vw(15, #999);
  313. position: relative;
  314. &.active {
  315. background: #F8F8F8;
  316. @include word-vw(15, #333);
  317. .bar {
  318. width: vw(4);
  319. height: 100%;
  320. background: #F75E24;
  321. position: absolute;
  322. left: 0;
  323. top: 0;
  324. }
  325. }
  326. }
  327. }
  328. }
  329. .right {
  330. flex: 1;
  331. height: 100%;
  332. background: #F7F7F7;
  333. @include flex-y(flex-start);
  334. .list {
  335. width: 100%;
  336. padding: vw(3) vw(15) 0;
  337. @include flex-y(flex-start);
  338. box-sizing: border-box;
  339. .list-item {
  340. width: 100%;
  341. margin-top: vw(12);
  342. .name {
  343. line-height: vw(25);
  344. height: vw(25);
  345. @include word-vw(12, #333);
  346. @include flex-x(flex-start);
  347. }
  348. .goods {
  349. width: 100%;
  350. margin-top: vw(3);
  351. .good {
  352. width: 100%;
  353. background: #fff;
  354. border-radius: vw(5);
  355. @include flex-x();
  356. padding: vw(8);
  357. box-sizing: border-box;
  358. border: vw(1) solid #fff;
  359. margin-bottom: vw(10);
  360. &.active{
  361. border-color: $btn-color;
  362. }
  363. .pic {
  364. width: vw(60);
  365. height: vw(60);
  366. margin-right: vw(5);
  367. flex-shrink: 0;
  368. }
  369. .good-right {
  370. flex: 1;
  371. padding: vw(1) 0;
  372. height: vw(60);
  373. box-sizing: border-box;
  374. @include flex-y(space-between, flex-start);
  375. .name {
  376. @include word-vw(12, #333);
  377. font-weight: 550;
  378. }
  379. .bottom {
  380. @include word-vw(10, #333);
  381. @include flex-x(flex-start);
  382. view {
  383. margin-right: vw(15);
  384. text {
  385. color: #FF4F50;
  386. }
  387. }
  388. }
  389. }
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }
  396. }
  397. .twig-box{
  398. width: vw(300);
  399. background: #fff;
  400. border-radius: vw(10);
  401. padding: 0 vw(20);
  402. box-sizing: border-box;
  403. padding-bottom: vw(20);
  404. .title{
  405. height: vw(75);
  406. @include flex-x(center);
  407. @include word-vw(18, #333);
  408. }
  409. .input-box{
  410. @include flex-x();
  411. height: vw(45);
  412. margin-top: vw(25);
  413. .label{
  414. width: vw(60);
  415. }
  416. .input{
  417. flex: 1;
  418. height: vw(45);
  419. border-radius: vw(5);
  420. background: #EFEFEF;
  421. padding: 0 vw(16);
  422. }
  423. }
  424. .tip{
  425. padding-left: vw(60);
  426. margin-top: vw(8);
  427. @include word-vw(15, #999);
  428. }
  429. .btn{
  430. width: vw(200);
  431. height: vw(50);
  432. border-radius: vw(25);
  433. background: $btn-color;
  434. @include word-vw(16, #fff);
  435. margin: vw(30) auto 0;
  436. @include flex-x(center);
  437. }
  438. }
  439. .options{
  440. @include flex-x();
  441. background: #fff;
  442. flex-wrap: wrap;
  443. padding: vw(20) vw(20);
  444. border-top-left-radius: vw(10);
  445. border-top-right-radius: vw(10);
  446. .option{
  447. width: vw(105);
  448. height: vw(105);
  449. border-radius: vw(10);
  450. box-shadow: 0px 1px 7px 2px rgba(0, 0, 0, 0.05);
  451. margin-bottom: vw(10);
  452. @include flex-y(center);
  453. @include word-vw(12, #333);
  454. .icon{
  455. margin-bottom: vw(12);
  456. }
  457. }
  458. }
  459. }
  460. </style>