helpContent.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <div class="m-container">
  3. <h2>
  4. <div class="squrt"></div>帮助中心
  5. </h2>
  6. <div class="m-core">
  7. <div class="newBand"
  8. v-permission="'helpCenterContent/modify'"
  9. @click="openTypes('create')">添加</div>
  10. <div class="newBand"
  11. v-permission="'/helpCategory'"
  12. @click="onToUrl()">分类管理</div>
  13. <!-- 搜索标题 -->
  14. <save-form :inline="true"
  15. class="searchForm"
  16. @submit="search"
  17. :model="searchForm">
  18. <el-form-item prop="hasPracticeCourse">
  19. <el-cascader ref="cascader"
  20. :show-all-levels="false"
  21. :options="treeList"
  22. v-model="searchForm.catalogId"
  23. :props="{ checkStrictly: true }"
  24. clearable></el-cascader>
  25. </el-form-item>
  26. <el-form-item>
  27. <el-button native-type="submit" type="danger">搜索</el-button>
  28. </el-form-item>
  29. </save-form>
  30. <div class="tableWrap">
  31. <el-table :data="tableList"
  32. :header-cell-style="{background:'#EDEEF0',color:'#444'}">>
  33. <el-table-column width="120px"
  34. align="center"
  35. prop="id"
  36. label="编号"></el-table-column>
  37. <el-table-column align="center"
  38. prop="title"
  39. label="标题"></el-table-column>
  40. <el-table-column align="center"
  41. prop="content"
  42. label="内容">
  43. <template slot-scope="scope">
  44. <!-- <overflow-text :text="scope.row.content"></overflow-text> -->
  45. <Tooltip :content="scope.row.content"></Tooltip>
  46. </template>
  47. </el-table-column>
  48. <el-table-column align="center"
  49. prop="catalog.text"
  50. label="分类名"></el-table-column>
  51. <el-table-column align="center"
  52. label="操作">
  53. <template slot-scope="scope">
  54. <el-button v-permission="'helpCenterContent/modify'"
  55. @click="openTypes('update', scope.row)"
  56. type="text">修改</el-button>
  57. <el-button @click="onTypeDelOpeation(scope.row)"
  58. v-permission="'helpCenterContent/delete'"
  59. type="text">删除</el-button>
  60. </template>
  61. </el-table-column>
  62. </el-table>
  63. <pagination sync :total.sync="pageInfo.total"
  64. :page.sync="pageInfo.page"
  65. :limit.sync="pageInfo.limit"
  66. :page-sizes="pageInfo.page_size"
  67. @pagination="getList" />
  68. </div>
  69. </div>
  70. <el-dialog :title="formTitle[formActionTitle]"
  71. :visible.sync="typeStatus"
  72. @close="onFormClose('ruleForm')"
  73. width="500px">
  74. <el-form :model="form"
  75. :rules="rules"
  76. ref="ruleForm">
  77. <el-form-item label="标题"
  78. prop="title"
  79. :label-width="formLabelWidth">
  80. <el-input v-model.trim="form.title"
  81. autocomplete="off"
  82. placeholder="请输入标题"></el-input>
  83. </el-form-item>
  84. <el-form-item label="分类"
  85. prop="catalogId"
  86. :label-width="formLabelWidth">
  87. <el-cascader v-if="typeStatus"
  88. style="width: 100%;"
  89. :show-all-levels="false"
  90. ref="formCascader"
  91. :options="treeList"
  92. v-model="form.catalogId"
  93. :props="{ checkStrictly: true }"
  94. clearable></el-cascader>
  95. </el-form-item>
  96. <el-form-item label="内容"
  97. prop="content"
  98. :label-width="formLabelWidth">
  99. <el-input type="textarea"
  100. :rows="3"
  101. placeholder="请输入内容"
  102. v-model="form.content">
  103. </el-input>
  104. </el-form-item>
  105. </el-form>
  106. <span slot="footer"
  107. class="dialog-footer">
  108. <el-button @click="typeStatus = false">取 消</el-button>
  109. <el-button type="primary"
  110. @click="onTypeSubmit('ruleForm')">确 定</el-button>
  111. </span>
  112. </el-dialog>
  113. </div>
  114. </template>
  115. <script>
  116. import pagination from "@/components/Pagination/index";
  117. import Tooltip from '@/components/Tooltip'
  118. // import store from '@/store'
  119. import {
  120. helpCenterCatalogList,
  121. helpCenterContentList,
  122. helpCenterContentModify,
  123. helpCenterContentDelete
  124. } from "@/api/appTenant";
  125. export default {
  126. components: { pagination, Tooltip },
  127. name: "helpCategory",
  128. data () {
  129. return {
  130. searchForm: {
  131. catalogId: null
  132. },
  133. treeList: [],
  134. tableList: [],
  135. formActionTitle: "create",
  136. formTitle: {
  137. create: "添加帮助中心",
  138. update: "修改帮助中心"
  139. },
  140. typeStatus: false, // 添加教学点
  141. formLabelWidth: "100px",
  142. form: {
  143. title: null, // 标题
  144. content: null, // 内容
  145. catalogId: null, // 分类编号
  146. },
  147. rules: {
  148. title: [{ required: true, message: "请输入标题", trigger: "blur" }],
  149. content: [{ required: true, message: "请输入内容", trigger: "blur" }],
  150. catalogId: [{ required: true, message: "请输入选择分类", trigger: "blur" }]
  151. // subjectIds: [{ required: true, message: "请选择声部组合", trigger: "change" }]
  152. },
  153. pageInfo: {
  154. // 分页规则
  155. limit: 10, // 限制显示条数
  156. page: 1, // 当前页
  157. total: 0, // 总条数
  158. page_size: [10, 20, 40, 50] // 选择限制显示条数
  159. },
  160. tempTreeList: []
  161. };
  162. },
  163. mounted () {
  164. this.getList();
  165. this.getTreeList()
  166. },
  167. methods: {
  168. search() {
  169. this.pageInfo.page = 1
  170. this.getList()
  171. },
  172. onTypeDelOpeation (row) {
  173. this.$confirm('您是否删除该内容?', '提示', {
  174. confirmButtonText: '确定',
  175. cancelButtonText: '取消',
  176. type: 'warning'
  177. }).then(() => {
  178. helpCenterContentDelete({ id: row.id }).then(res => {
  179. this.messageTips('删除', res)
  180. })
  181. }).catch(() => {
  182. })
  183. },
  184. onTypeSubmit (formName) {
  185. // 添加数据
  186. this.$refs[formName].validate(valid => {
  187. if (valid) {
  188. if (this.formActionTitle == "create") {
  189. let params = {
  190. title: this.form.title, // 标题
  191. content: this.form.content, // 内容
  192. catalogId: this.form.catalogId[this.form.catalogId.length - 1], // 分类编号
  193. }
  194. helpCenterContentModify(params).then(res => {
  195. this.messageTips("添加", res);
  196. });
  197. } else if (this.formActionTitle == "update") {
  198. let params = {
  199. id: this.form.id,
  200. title: this.form.title, // 标题
  201. content: this.form.content, // 内容
  202. catalogId: this.form.catalogId[this.form.catalogId.length - 1], // 分类编号
  203. }
  204. helpCenterContentModify(params).then(res => {
  205. this.messageTips("修改", res);
  206. });
  207. }
  208. } else {
  209. return false;
  210. }
  211. });
  212. },
  213. messageTips (title, res) {
  214. if (res.code == 200) {
  215. this.$message.success(title + "成功");
  216. this.typeStatus = false;
  217. this.getList();
  218. } else {
  219. this.$message.error(res.msg);
  220. }
  221. },
  222. getList () {
  223. let catalogId = this.searchForm.catalogId ? this.searchForm.catalogId : null
  224. if (catalogId) {
  225. catalogId = catalogId[catalogId.length - 1]
  226. }
  227. let params = {
  228. catalogIds: catalogId,
  229. page: this.pageInfo.page,
  230. rows: this.pageInfo.limit
  231. }
  232. helpCenterContentList(params).then(res => {
  233. let result = res.data;
  234. if (res.code == 200) {
  235. this.tableList = result.rows;
  236. this.pageInfo.total = result.total
  237. }
  238. });
  239. },
  240. getTreeList () {
  241. helpCenterCatalogList({
  242. parentId: 0
  243. }).then(res => {
  244. let result = res.data;
  245. if (res.code == 200) {
  246. this.treeList = this.setTableData(result);
  247. }
  248. });
  249. },
  250. setTableData (result) {
  251. let list = []
  252. list = result.map(res => {
  253. let tempList = {}
  254. tempList = {
  255. value: res.id,
  256. label: res.text,
  257. parentId: res.parentId
  258. }
  259. if (res.children && res.children.length > 0) {
  260. tempList.children = this.setTableData(res.children)
  261. }
  262. return tempList
  263. })
  264. return list
  265. },
  266. openTypes (type, row) {
  267. this.typeStatus = true
  268. this.formActionTitle = type
  269. if (type == "update") {
  270. // 修改的时候赋值
  271. this.form = {
  272. id: row.id,
  273. title: row.title, // 标题
  274. content: row.content, // 内容
  275. catalogId: this.getAllIds(row), // 分类编号
  276. };
  277. }
  278. },
  279. onToUrl () {
  280. this.$router.push('/insideSetting/helpCategory')
  281. },
  282. getAllIds (row) {
  283. let idAndParent = [];// idAndParent保存 Tree所有节点的id和parentId
  284. this.getIdAndParent(this.treeList, idAndParent);
  285. let parentIds = []; // 用于保存选中节点的父节点及父节点的父节点
  286. this.getId(row.catalogId, parentIds, idAndParent);
  287. return parentIds.reverse(); //反转数组
  288. },
  289. getIdAndParent (tree, idAndParentIds) {// idAndParentIds用来保存所有节点的id,parentId
  290. // 对原有的数据结构进行遍历,拿出所有节点的id,parentId到一个一维数组中。
  291. tree.forEach(item => {
  292. let mid = {
  293. id: item.value,
  294. parentId: item.parentId,
  295. };
  296. idAndParentIds.push(mid);
  297. if (item.children) {
  298. this.getIdAndParent(item.children, idAndParentIds);
  299. }
  300. });
  301. },
  302. getId (id, parentIds, idAndParent) {
  303. idAndParent.forEach(item => {
  304. if (item.id == id) {
  305. parentIds.push(id);
  306. if (item.parentId != -1) {
  307. this.getId(item.parentId, parentIds, idAndParent);
  308. }
  309. }
  310. });
  311. },
  312. onFormClose (formName) {
  313. // 关闭弹窗重置验证
  314. this.form = {
  315. title: null, // 标题
  316. content: null, // 内容
  317. catalogId: [], // 分类编号
  318. }
  319. this.$refs.formCascader.handleClear()
  320. this.$refs[formName].resetFields();
  321. }
  322. }
  323. };
  324. </script>
  325. <style lang="scss" scoped>
  326. .el-button--primary {
  327. background: #14928a;
  328. border-color: #14928a;
  329. color: #fff;
  330. &:hover,
  331. &:active,
  332. &:focus {
  333. background: #14928a;
  334. border-color: #14928a;
  335. color: #fff;
  336. }
  337. }
  338. /deep/.el-date-editor.el-input {
  339. width: 100% !important;
  340. }
  341. /deep/.el-select {
  342. width: 100% !important;
  343. }
  344. /deep/.el-table .cell {
  345. display: -webkit-box;
  346. overflow: hidden;
  347. text-overflow: ellipsis;
  348. -webkit-line-clamp: 3;
  349. -webkit-box-orient: vertical;
  350. }
  351. /deep/.el-dialog__body {
  352. padding: 10px 20px;
  353. }
  354. .newBand {
  355. display: inline-block;
  356. }
  357. </style>