category.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <div class="app-content">
  3. <!-- list -->
  4. <div class="list-wrap">
  5. <block v-if="!$util.isEmpty(list.data)">
  6. <div class="list" v-for="(item, index) in list.data" :key="index">
  7. <div class="list-index">{{ item.inTurn }}</div>
  8. <div class="list-img">
  9. <img :src="item.img" alt="分类图" mode="center" />
  10. </div>
  11. <div class="list-det">
  12. <div class="app-size-28 app-color-0">{{ item.categoryName || '暂无' }}</div>
  13. <div>{{ item.description || '暂无' }}</div>
  14. <div class="list-operate">
  15. <div class="operate-det">
  16. <span>商品数: {{ item.goodsNum }}</span>
  17. <span>销量: {{ item.sold }}</span>
  18. <span :style="{color: item.status == 1 ? '#049E2C' : '#ff6900'}">{{ item.status == 1? '启用' : '禁用' }}</span>
  19. </div>
  20. <div class="operate-icon-wrap" @click="operateFn(item, index)">
  21. <div class="operate-icon">
  22. <i class="iconfont" :class="[ index == operateIndex ? 'iconcaozuojihuo' : 'iconcaozuo']"></i>
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. <!-- operate -->
  29. <operate-module v-show="operateShow" :top="operateTop" :right="30" :btnData="btnData" />
  30. </block>
  31. <block v-else>
  32. <app-wrapper-empty title="暂无数据" :is-empty="$util.isEmpty(list.data)" />
  33. </block>
  34. </div>
  35. <!-- button -->
  36. <div class="app-footer">
  37. <button class="admin-button-com middle blue" @click="addCategoryFn">添加分类</button>
  38. </div>
  39. <!-- modify -->
  40. <modal-module :show="modifyModal" :maskClosable="false" @cancel="modalCancel" @click="modifyModalClick" width="92%" :title="modifyTitle" padding="30rpx 30rpx">
  41. <template v-slot:content>
  42. <div class="app-modal-input-wrap modify-modal">
  43. <div class="inp-list-line">
  44. <div class="line-label">分类名称</div>
  45. <div class="line-input">
  46. <input type="text" v-model="modifyForm.categoryName" :adjust-position="false" class="inp-input" placeholder="填价格,图片可当商品卖(选填)" />
  47. </div>
  48. </div>
  49. <div class="inp-list-line">
  50. <div class="line-label">图片</div>
  51. <div class="line-input flex-strat">
  52. <app-uploader :multiple="false" ref="appUploader" :imgList.sync="modifyForm.img" />
  53. </div>
  54. </div>
  55. <div class="inp-list-line">
  56. <div class="line-label">排序</div>
  57. <div class="line-input">
  58. <input type="text" v-model="modifyForm.inTurn" :adjust-position="false" class="inp-input" placeholder="默认排序最新在前面" />
  59. </div>
  60. </div>
  61. <div class="inp-list-line switch-wrap">
  62. <div class="line-label">启用状态</div>
  63. <div class="line-input flex-strat">
  64. <switch :checked="modifyForm.status == '0' ? false : true" @change="switchChangeFn" />
  65. </div>
  66. </div>
  67. </div>
  68. </template>
  69. </modal-module>
  70. <!-- 删除提示 -->
  71. <modal-module :show="delModal" :maskClosable="false" @cancel="modalCancel" @click="delModalClick" content="确定删除该分类吗?" color="#333" :size="32" padding="30rpx 30rpx"></modal-module>
  72. </div>
  73. </template>
  74. <script>
  75. import ModalModule from '@/components/plugin/modal'
  76. import AppUploader from '@/components/app-uploader'
  77. import OperateModule from '@/admin/home/components/module/operate'
  78. import AppWrapperEmpty from '@/components/app-wrapper-empty'
  79. import { list } from '@/mixins'
  80. // api
  81. import { categoryListB, categoryStatusB, categoryAddB, categoryUpdateB, categoryDelB } from '@/api/goods'
  82. export default {
  83. name: 'category-manage',
  84. components: {
  85. ModalModule,
  86. AppUploader,
  87. OperateModule,
  88. AppWrapperEmpty
  89. },
  90. mixins: [list],
  91. data() {
  92. return {
  93. modifyModal: false,
  94. modifyTitle: '添加',
  95. modifyForm: {
  96. categoryName: '',
  97. img: [],
  98. inTurn: 0,
  99. status: 1
  100. },
  101. // 删除弹窗
  102. delModal: false,
  103. // operate
  104. operateShow: false,
  105. operateData: {},
  106. operateIndex: null,
  107. operateTop: 0
  108. }
  109. },
  110. computed: {
  111. btnData() {
  112. return [
  113. {
  114. text: '编辑',
  115. icon: 'iconbianji',
  116. click: () => {
  117. // this.operateShow = false
  118. this.modifyModal = true
  119. this.modifyTitle = '编辑'
  120. this.modifyForm = {
  121. categoryName: this.operateData.categoryName,
  122. img: [this.operateData.img],
  123. inTurn: this.operateData.inTurn,
  124. status: this.operateData.status
  125. }
  126. }
  127. },
  128. {
  129. text: this.operateData.status == 1 ? '禁用' : '启用',
  130. icon: this.operateData.status == 1 ? 'iconjinyong' : 'iconqiyong',
  131. click: () => {
  132. this.changeStatusFn()
  133. }
  134. },
  135. {
  136. text: '删除',
  137. icon: 'iconshanchu1',
  138. click: () => {
  139. this.operateCancle()
  140. this.delModal = true
  141. }
  142. }
  143. // {
  144. // text: '分享',
  145. // icon: 'iconfenxiang1',
  146. // click: () => {
  147. // this.$msg('功能开发中...')
  148. // }
  149. // }
  150. ]
  151. }
  152. },
  153. onPullDownRefresh() {
  154. this.resetList()
  155. this._list().then(res => {
  156. uni.stopPullDownRefresh()
  157. })
  158. },
  159. onReachBottom() {
  160. if (this.list.data.length < this.list.total) {
  161. this._list().then(res => {
  162. uni.stopPullDownRefresh()
  163. })
  164. } else {
  165. uni.stopPullDownRefresh()
  166. }
  167. },
  168. onLoad() {
  169. // this.init()
  170. },
  171. methods: {
  172. async init() {
  173. this._list()
  174. },
  175. _list() {
  176. return categoryListB().then(res => {
  177. let data = {
  178. code: res.code,
  179. msg: res.msg,
  180. data: {
  181. list: res.data
  182. }
  183. }
  184. this.completes(data)
  185. })
  186. },
  187. _categoryAddOrEditB() {
  188. let host = this.modifyTitle == '编辑' ? categoryUpdateB : categoryAddB
  189. let form = JSON.parse(JSON.stringify(this.modifyForm))
  190. form.img = this.$util.imgSubstr(form.img)
  191. form.img = form.img.join()
  192. if (this.modifyTitle == '编辑') {
  193. form.categoryId = this.operateData.id
  194. }
  195. categoryAddB({
  196. ...form
  197. }).then(res => {
  198. this.$msg('操作成功!')
  199. this.modalCancel()
  200. this.operateCancle()
  201. setTimeout(() => {
  202. this.resetList()
  203. this._list()
  204. }, 1000)
  205. })
  206. },
  207. // 操作
  208. addCategoryFn() {
  209. this.resetForm()
  210. this.modifyModal = true
  211. this.modifyTitle = '新增'
  212. },
  213. resetForm() {
  214. this.modifyForm = {
  215. categoryName: '',
  216. img: [],
  217. inTurn: 0,
  218. status: 1
  219. }
  220. },
  221. modifyModalClick(e) {
  222. if (e.index === 0) {
  223. this.modalCancel()
  224. } else {
  225. this._categoryAddOrEditB()
  226. }
  227. },
  228. modalCancel() {
  229. this.delModal = false
  230. this.modifyModal = false
  231. },
  232. switchChangeFn(e) {
  233. this.modifyForm.status = e.detail.value ? 1 : 0
  234. },
  235. delModalClick(e) {
  236. if (e.index === 0) {
  237. this.modalCancel()
  238. } else {
  239. categoryDelB({ categoryId: this.operateData.id }).then(res => {
  240. this.modalCancel()
  241. this.operateCancle()
  242. this.$msg('删除成功!')
  243. this.resetList()
  244. this._list()
  245. })
  246. }
  247. },
  248. // operate
  249. operateFn(item, index) {
  250. if (this.operateIndex == index) {
  251. this.operateCancle()
  252. } else {
  253. this.operateData = item
  254. this.operateIndex = index
  255. this.operateShow = true
  256. this.operateTop = (index + 1) * 191
  257. }
  258. },
  259. operateCancle() {
  260. this.operateData = {}
  261. this.operateIndex = null
  262. this.operateShow = false
  263. },
  264. changeStatusFn() {
  265. let status = this.operateData.status == 1 ? 0 : 1
  266. categoryStatusB({
  267. categoryId: this.operateData.id,
  268. status: status
  269. }).then(res => {
  270. this.list.data[this.operateIndex].status = status
  271. this.operateCancle()
  272. this.$msg('操作成功!')
  273. })
  274. }
  275. }
  276. }
  277. </script>
  278. <style lang="scss" scoped>
  279. .app-content {
  280. min-height: calc(100vh - 100px);
  281. padding-bottom: 100px;
  282. }
  283. // list
  284. .list-wrap {
  285. position: relative;
  286. background-color: #fff;
  287. .list {
  288. height: 130px;
  289. @include disFlex(center, flex-start);
  290. padding: 30px 0;
  291. margin: 0 30px;
  292. color: $fontColor3;
  293. border-bottom: 1px solid $borderColor;
  294. .list-index {
  295. width: 50px;
  296. }
  297. .list-img {
  298. width: 130px;
  299. height: 130px;
  300. img {
  301. height: 100%;
  302. }
  303. }
  304. .list-det {
  305. width: calc(100% - 200px);
  306. margin-left: 20px;
  307. & > div {
  308. margin-top: 14px;
  309. &:first-child {
  310. margin-top: 0;
  311. }
  312. }
  313. .list-operate {
  314. @include disFlex(center, space-between);
  315. .operate-det {
  316. & > span {
  317. margin-left: 60px;
  318. &:first-child {
  319. margin-left: 0;
  320. }
  321. }
  322. }
  323. }
  324. }
  325. }
  326. }
  327. // button
  328. .app-footer {
  329. justify-content: flex-end;
  330. .admin-button-com {
  331. width: 200px;
  332. margin-right: 30px;
  333. }
  334. }
  335. // 编辑弹窗
  336. .modify-modal {
  337. .line-label {
  338. width: 140px;
  339. flex-shrink: 0;
  340. }
  341. .switch-wrap {
  342. margin-top: 30px;
  343. }
  344. }
  345. </style>