article-category.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <template>
  2. <div class="banner-box" v-loading="loading > 0">
  3. <Header :title="title"></Header>
  4. <div class="container">
  5. <div class="content">
  6. <!-- 表格 -->
  7. <div class="btn" @click="handleBannerModal('add')">+ 创建文章分类</div>
  8. <el-table
  9. :data="list"
  10. class="order-table table no-border-table"
  11. ref="orderTable"
  12. :header-cell-style="{
  13. border: 'none',
  14. color: '#333',
  15. background: '#f6f6f6',
  16. borderBottom: '1px solid #E8E8E8',
  17. height: '54px',
  18. }"
  19. :row-style="{
  20. height: '54px',
  21. }"
  22. >
  23. <el-table-column
  24. prop="name"
  25. align="center"
  26. label="类目名称"
  27. ></el-table-column>
  28. <el-table-column prop="orderBy" align="center" label="排序">
  29. <div slot-scope="scope" @click="changeSortModal(scope.row.id)">
  30. {{ scope.row.orderBy }}
  31. </div>
  32. </el-table-column>
  33. <el-table-column label="操作" align="center" width="180">
  34. <div slot-scope="scope" style="display: flex">
  35. <div>
  36. <button
  37. size="mini"
  38. class="table-btn"
  39. @click="handleBannerModal('edit', scope.row)"
  40. >
  41. 编辑
  42. </button>
  43. </div>
  44. <div>
  45. <button
  46. size="mini"
  47. class="table-btn"
  48. @click="deleteBanner(scope.row.id)"
  49. >
  50. 删除
  51. </button>
  52. </div>
  53. </div>
  54. </el-table-column>
  55. </el-table>
  56. </div>
  57. </div>
  58. <el-dialog
  59. :visible.sync="addBannerShow"
  60. class="dialog"
  61. width="560px"
  62. top="25vh"
  63. >
  64. <div slot="title" class="dialog-title">
  65. {{ (type === "add" ? "发布" : "编辑") + "文章分类" }}
  66. </div>
  67. <el-form
  68. ref="form"
  69. :rules="rules"
  70. :model="addBannerForm"
  71. class="banner-form"
  72. label-width="auto"
  73. >
  74. <el-form-item
  75. label="分类名称:"
  76. prop="link"
  77. class="form-item"
  78. >
  79. <el-input
  80. size="small"
  81. placeholder="请输入分类名称"
  82. class="add-renovation-input"
  83. v-model="addBannerForm.name"
  84. style="width: 254px"
  85. ></el-input>
  86. </el-form-item>
  87. <el-form-item label="排序:" prop="sort" class="form-item">
  88. <el-input
  89. size="small"
  90. placeholder="请输入序号"
  91. class="add-renovation-input"
  92. style="width: 160px"
  93. v-model.number="addBannerForm.orderBy"
  94. type="number"
  95. onkeypress="return( /[\d]/.test(String.fromCharCode(event.keyCode)))"
  96. ></el-input>
  97. <div class="sort-tip">数值越大,排序越靠前</div>
  98. </el-form-item>
  99. </el-form>
  100. <div slot="footer" class="dialog-footer">
  101. <el-button class="cancel-btn btn" @click="addBannerShow = false"
  102. >取 消</el-button
  103. >
  104. <el-button class="confirm-btn btn" @click="handleBanner"
  105. >确 定</el-button
  106. >
  107. </div>
  108. </el-dialog>
  109. <!-- 修改排序弹窗 -->
  110. <el-dialog title="更改排序" width="400px" :visible.sync="sortShow">
  111. <el-form label-width="60px" size="mini" ref="editSort" inline-message>
  112. <el-form-item label="排序:" prop="tableData" style="margin-top: 15px">
  113. <el-input v-model="currentSort" type="number" />
  114. </el-form-item>
  115. </el-form>
  116. <div slot="footer" class="dialog-footer">
  117. <el-button class="btn cancel-btn" @click="sortShow = false"
  118. >取 消</el-button
  119. >
  120. <el-button class="btn confirm-btn" @click="saveSort">确 定</el-button>
  121. </div>
  122. </el-dialog>
  123. </div>
  124. </template>
  125. <script type="text/ecmascript-6">
  126. import Header from '../../components/common/header';
  127. export default {
  128. components: {
  129. Header
  130. },
  131. name: 'banner',
  132. data() {
  133. return {
  134. loading: 0, // 加载中
  135. title: {
  136. // 页面标题
  137. firstTitile: '商城设置',
  138. secondTitle: '文章分类'
  139. },
  140. list: [], // 轮播列表
  141. rules: {},
  142. wayMap: {
  143. 1: '商品',
  144. 2: '文章',
  145. 3: '其他'
  146. },
  147. sortShow: false,
  148. currentSort: 0,
  149. addBannerForm: {
  150. name: '',
  151. orderBy: null
  152. },
  153. addBannerShow: false,
  154. bannerId: null,
  155. type: ''
  156. };
  157. },
  158. mounted() {
  159. // 获取列表
  160. this.getList();
  161. },
  162. computed: {},
  163. methods: {
  164. // 表格序号
  165. tableIndex(index) {
  166. return ++index;
  167. },
  168. // 获取轮播列表
  169. getList() {
  170. this.loading++;
  171. this.httpGet(this.$root.getArticleCategoryList, {}).then(
  172. (res) => {
  173. this.loading--;
  174. this.list = res;
  175. this.total = res.total;
  176. },
  177. (res) => {
  178. this.loading--;
  179. this.$message.error(res);
  180. }
  181. );
  182. },
  183. // 编辑轮播弹窗
  184. handleBannerModal(type, rowData) {
  185. this.type = type;
  186. if (type === 'edit') {
  187. this.bannerId = rowData.id;
  188. this.addBannerForm = {
  189. name: rowData.name,
  190. orderBy: rowData.orderBy,
  191. };
  192. } else {
  193. this.addBannerForm = {
  194. name: '',
  195. orderBy: null
  196. };
  197. this.$refs.form && this.$refs.form.clearValidate();
  198. }
  199. this.addBannerShow = true;
  200. },
  201. changeWay() {
  202. this.addBannerForm.link = '';
  203. },
  204. // 删除轮播图
  205. deleteBanner(id) {
  206. this.$confirm(
  207. `<p class='title'><i class='icon el-icon-question'></i>提醒</p><p class='text'>确定要删除该分类吗?</p>`,
  208. {
  209. confirmButtonText: '确定',
  210. cancelButtonText: '取消',
  211. cancelButtonClass: 'cancel-btn',
  212. confirmButtonClass: 'confirm-btn',
  213. customClass: 'confirm-box',
  214. dangerouslyUseHTMLString: true,
  215. showClose: false,
  216. type: 'none'
  217. }
  218. ).then(() => {
  219. this.loading++;
  220. this.httpDelete(this.$root.deleteArticleCategory, {
  221. id
  222. }).then(
  223. (res) => {
  224. this.$message({
  225. message: '操作成功',
  226. type: 'success'
  227. });
  228. this.loading--;
  229. this.getList();
  230. },
  231. (res) => {
  232. this.loading--;
  233. this.$message.error(res);
  234. }
  235. );
  236. });
  237. },
  238. // 轮播
  239. handleBanner() {
  240. this.$refs.form.validate((valid) => {
  241. if (valid) {
  242. let url =
  243. this.type === 'add'
  244. ? this.$root.addArticleCategory
  245. : this.$root.updateArticleCategory;
  246. let method =
  247. this.type === 'add'
  248. ? 'httpPost'
  249. : 'httpPut';
  250. let inputData =
  251. this.type === 'add'
  252. ? {
  253. ...this.addBannerForm
  254. }
  255. : {
  256. ...this.addBannerForm,
  257. id: this.bannerId
  258. };
  259. this.loading++;
  260. this[method](url, inputData).then(
  261. (res) => {
  262. this.$message({
  263. message: '操作成功',
  264. type: 'success'
  265. });
  266. this.loading--;
  267. this.addBannerShow = false;
  268. this.getList();
  269. },
  270. (res) => {
  271. this.loading--;
  272. this.$message.error(res);
  273. }
  274. );
  275. }
  276. });
  277. },
  278. changeSortModal() {
  279. // this.sortShow = true;
  280. },
  281. // 图片改变
  282. addChangeImg(e) {
  283. this.upPic(e, (res) => {
  284. this.$set(this.addBannerForm, 'pic', res);
  285. // 清空input value,解决重复图片不触发change
  286. this.$refs.inputImg.value = '';
  287. this.$refs.form.clearValidate(['pic']);
  288. });
  289. },
  290. // 上传图片
  291. upPic(e, fun) {
  292. // 上传图片
  293. let file = e.target.files[0];
  294. if (!file) {
  295. return;
  296. }
  297. this.request.upPic({ prefix: 'other', file: file }).then(
  298. (res) => {
  299. fun(res);
  300. },
  301. (res) => {}
  302. );
  303. },
  304. saveSort() {}
  305. }
  306. };
  307. </script>
  308. <style lang="stylus" rel="stylesheet/stylus">
  309. @import '~assets/public.styl';
  310. </style>
  311. <style lang="stylus" rel="stylesheet/stylus" scoped>
  312. @import '~assets/main.styl';
  313. .banner-box {
  314. height: 100%;
  315. width: 100%;
  316. flex-y(flex-start, flex-start);
  317. overflow-y: hidden;
  318. background: bg-color;
  319. .container {
  320. box-sizing: border-box;
  321. height: 100%;
  322. width: 100%;
  323. overflow-y: auto;
  324. flex-y(flex-start, flex-start);
  325. padding: 24px;
  326. // content 表格
  327. .content {
  328. flex: 1;
  329. width: 100%;
  330. font-size: 14px;
  331. background: white;
  332. box-sizing: border-box;
  333. padding: 24px 32px;
  334. border-radius: 2px;
  335. // 按钮
  336. .btn {
  337. // width: 100px;
  338. display: inline-block;
  339. padding: 0 10px;
  340. height: 32px;
  341. line-height: 32px;
  342. confirm-btn();
  343. font-size: 14px;
  344. margin-bottom: 16px;
  345. // margin: 16px 0;
  346. }
  347. .tip {
  348. margin-left: 32px;
  349. color: #999;
  350. }
  351. // 表格按钮
  352. .table-btn {
  353. width: 65px;
  354. height: 24px;
  355. line-height: 24px;
  356. color: gray3;
  357. font-size: 12px;
  358. margin-right: 8px;
  359. cancel-btn();
  360. }
  361. .table-img {
  362. height: 70px;
  363. width: auto;
  364. }
  365. }
  366. }
  367. .dialog-content {
  368. flex-y();
  369. }
  370. .addImg {
  371. .icon {
  372. width: 270px;
  373. height: 108px;
  374. }
  375. }
  376. .banner-form {
  377. margin-top: 16px;
  378. // margin-bottom: 80px;
  379. padding-left: 80px;
  380. .sort-tip {
  381. word(14px, #c8c8c8);
  382. line-height: 20px;
  383. }
  384. }
  385. }
  386. </style>