problem.vue 11 KB

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