index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <template>
  2. <div class="app-container">
  3. <!-- 列表 -->
  4. <el-table :data="tableData" ref="tableData" row-key="id" :default-sort="{ prop: 'sort', order: 'ascending' }"
  5. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
  6. <el-table-column width="80px">
  7. <template slot-scope="scope">
  8. <el-link v-if="scope.row.hidden" :underline="false" class="el-icon-arrow-right" @click="getList(scope.row)" />
  9. </template>
  10. </el-table-column>
  11. <el-table-column label="导航名称" align="center" prop="name" show-overflow-tooltip>
  12. <template slot-scope="scope">
  13. <span v-if="scope.row.lv === 1">{{ scope.row.name }}</span>
  14. </template>
  15. </el-table-column>
  16. <el-table-column label="排序" align="center">
  17. <template slot-scope="scope">
  18. <span v-if="scope.row.lv === 2">{{ scope.row.sort }}</span>
  19. </template>
  20. </el-table-column>
  21. <el-table-column label="模块类型" align="center" prop="moduleTypeId" show-overflow-tooltip :formatter="typeFormatter" />
  22. <el-table-column label="模块名称" align="center" prop="moduleName" show-overflow-tooltip />
  23. <el-table-column label="模块数量" align="center" prop="moduleNum" />
  24. <el-table-column label="创建时间" align="center" prop="createTime" show-overflow-tooltip />
  25. <el-table-column label="有效时间" align="center" width="380px">
  26. <template slot-scope="scope">
  27. <span v-if="scope.row.lv === 3">
  28. {{ scope.row.rsDates[0] }} - {{ scope.row.rsDates[1] }}
  29. </span>
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="当前状态" align="center" prop="isProgressStatus" :formatter="statusFormatter" />
  33. <el-table-column label="操作" align="center">
  34. <template slot-scope="scope">
  35. <span v-if="scope.row.lv === 1">
  36. <el-button type="text" @click="getDialog('新增', scope.row)"
  37. v-hasPermi="['operation:recommend:add']">新增</el-button>
  38. <el-button type="text" @click="getHistoryDialog(scope.row.id)">历史记录</el-button>
  39. </span>
  40. <span v-else-if="scope.row.lv === 2">
  41. <el-button type="text" @click="getDetail(scope.row)" v-hasPermi="['operation:recommend:add']">新增</el-button>
  42. <el-button type="text" @click="getDialog('查看', scope.row)">查看</el-button>
  43. <el-button type="text" @click="getDialog('编辑', scope.row)"
  44. v-hasPermi="['operation:recommend:edit']">编辑</el-button>
  45. <el-button type="delete" @click="getDelete(scope.row)"
  46. v-hasPermi="['operation:recommend:delete']">删除</el-button>
  47. </span>
  48. <span v-else>
  49. <el-button type="text" @click="getDetail(scope.row, true)">查看</el-button>
  50. <el-button type="text" @click="getDetail(scope.row)" v-hasPermi="['operation:recommend:edit']">编辑</el-button>
  51. <el-button type="delete" @click="getDelete(scope.row)"
  52. v-hasPermi="['operation:recommend:delete']">删除</el-button>
  53. </span>
  54. </template>
  55. </el-table-column>
  56. </el-table>
  57. <!-- 弹窗 -->
  58. <el-dialog :visible.sync="dialogVisible" :title="title" width="500px" :before-close="cancel">
  59. <el-form :model="dialogForm" :rules="rules" ref="dialogForm" label-width="100px" :disabled="title === '查看'">
  60. <el-form-item label="模块类型:" prop="moduleTypeId">
  61. <el-select v-model="dialogForm.moduleTypeId" placeholder="请选择模块类型" :disabled="title === '编辑'">
  62. <el-option v-for="item in typeOptions" :key="item.typeId" :value="item.typeId" :label="item.typeName" />
  63. </el-select>
  64. </el-form-item>
  65. <el-form-item label="排序:" prop="sort">
  66. <el-input-number v-model="dialogForm.sort" :min="1" />
  67. </el-form-item>
  68. </el-form>
  69. <div slot="footer">
  70. <el-button @click="cancel">取消</el-button>
  71. <el-button v-if="title !== '查看'" type="primary" @click="getSubmit">确定</el-button>
  72. </div>
  73. </el-dialog>
  74. <!-- 历史记录 -->
  75. <el-dialog :visible.sync="dialogVisible_list" title="历史记录" width="1200px">
  76. <el-form inline size="mini">
  77. <el-form-item label="创建时间:">
  78. <el-date-picker v-model="dialogForm_list.rsDates" type="datetimerange" start-placeholder="开始日期"
  79. end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss" />
  80. </el-form-item>
  81. <el-form-item label="模块名称:">
  82. <el-input v-model="dialogForm_list.moduleName" placeholder="请输入模块名称" clearable />
  83. </el-form-item>
  84. <el-form-item>
  85. <el-button type="primary" icon="el-icon-search" @click="getSearch">搜索</el-button>
  86. <el-button icon="el-icon-refresh" @click="getRefresh">重置</el-button>
  87. </el-form-item>
  88. </el-form>
  89. <el-table :data="dialogTableData" v-loading="loading">
  90. <el-table-column label="模块名称" prop="moduleName" align="center" show-overflow-tooltip />
  91. <el-table-column label="模块类型" prop="moduleTypeId" align="center" :formatter="typeFormatter" />
  92. <el-table-column label="模块数量" prop="moduleNum" align="center" />
  93. <el-table-column label="有效时间" align="center" width="380px">
  94. <template slot-scope="scope">
  95. <span>{{ scope.row.rsDates[0] }} - {{ scope.row.rsDates[1] }}</span>
  96. </template>
  97. </el-table-column>
  98. <el-table-column label="当前状态" prop="isProgressStatus" align="center" :formatter="statusFormatter" />
  99. <el-table-column label="创建时间" prop="createTime" align="center" show-overflow-tooltip />
  100. <el-table-column label="操作" align="center">
  101. <template slot-scope="scope">
  102. <el-button type="text" @click="getDetail(scope.row, true)">查看</el-button>
  103. </template>
  104. </el-table-column>
  105. </el-table>
  106. <pagination v-show="total > 0" :total="total" :page.sync="dialogForm_list.pageNum"
  107. :limit.sync="dialogForm_list.pageSize" @pagination="getHistoryList" />
  108. </el-dialog>
  109. </div>
  110. </template>
  111. <script>
  112. import { tabList, typeList, list, submit, listDetail, remove, history, timeChange } from '@/api/operation/recommend'
  113. export default {
  114. data() {
  115. return {
  116. // 遮罩层
  117. loading: false,
  118. // 列表
  119. tableData: [],
  120. // 弹窗
  121. dialogVisible: false,
  122. dialogVisible_list: false,
  123. // 弹窗表单
  124. dialogForm: {},
  125. dialogForm_list: {
  126. pageNum: 1,
  127. pageSize: 10
  128. },
  129. // 弹窗title
  130. title: '新增',
  131. // 弹窗列表
  132. dialogTableData: [],
  133. // 总数据
  134. total: 0,
  135. // 导航栏
  136. tabOptions: [],
  137. // 模块类型
  138. typeOptions: [],
  139. // 校验
  140. rules: {
  141. categoryId: [{
  142. required: true, message: '请选择导航', tigger: 'change'
  143. }],
  144. moduleTypeId: [{
  145. required: true, message: '请选择模块类型', tigger: 'change'
  146. }],
  147. sort: [{
  148. required: true, type: 'number', message: '请选择排序', tirgger: 'blur, change'
  149. }]
  150. },
  151. // 当前状态
  152. statusOptions: [{
  153. value: 0,
  154. label: '生效中'
  155. }, {
  156. value: 1,
  157. label: '未生效'
  158. }, {
  159. value: 2,
  160. label: '未配置时间'
  161. }, {
  162. value: 3,
  163. label: '已失效'
  164. }]
  165. }
  166. },
  167. mounted() {
  168. this.getTabList()
  169. this.getTypeList()
  170. },
  171. methods: {
  172. // 导航列表
  173. getTabList() {
  174. tabList().then(res => {
  175. if (res.code === 0) {
  176. res.data.map(i => {
  177. i.hidden = true
  178. i.children = []
  179. })
  180. this.tabOptions = res.data
  181. this.tableData = res.data
  182. }
  183. })
  184. },
  185. // 模块列表
  186. getTypeList() {
  187. typeList().then(res => {
  188. if (res.code === 0) {
  189. this.typeOptions = res.data
  190. }
  191. })
  192. },
  193. // 首次获取二级列表
  194. getList(row) {
  195. let e = this.tableData[row.tabIndex - 1]
  196. list(row.id).then(res => {
  197. if (res.code === 0) {
  198. if (res.data.length > 0) {
  199. e.children = res.data
  200. e.hidden = false
  201. this.$nextTick(() => {
  202. this.$refs.tableData.toggleRowExpansion(row, true)
  203. })
  204. } else {
  205. this.$message.warning('暂无模块!')
  206. }
  207. }
  208. })
  209. },
  210. // 提交二级
  211. getSubmit() {
  212. this.$refs.dialogForm.validate((valid) => {
  213. if (valid) {
  214. submit(this.dialogForm).then(res => {
  215. if (res.code === 0) {
  216. this.$message.success('提交成功')
  217. this.cancel()
  218. this.getTabList()
  219. }
  220. })
  221. } else {
  222. return false
  223. }
  224. })
  225. },
  226. // 取消
  227. cancel() {
  228. this.dialogVisible = false
  229. this.$refs.dialogForm.resetFields()
  230. this.dialogForm = {}
  231. },
  232. // 弹窗
  233. getDialog(title, row) {
  234. this.title = title
  235. this.dialogVisible = true
  236. this.dialogForm.categoryId = row.id
  237. if (row.lv === 2) {
  238. listDetail(row.id).then(res => {
  239. if (res.code === 0) {
  240. this.dialogForm = res.data
  241. }
  242. })
  243. }
  244. },
  245. // 详情页
  246. getDetail(row, boolean) {
  247. this.$router.push({
  248. path: `/operation/recommend/detail`,
  249. query: row.lv === 2 ? {
  250. secondId: row.id,
  251. moduleTypeId: row.moduleTypeId
  252. } : {
  253. threeId: row.id,
  254. moduleTypeId: row.moduleTypeId,
  255. boolean: boolean
  256. }
  257. })
  258. },
  259. // 删除
  260. getDelete(row) {
  261. this.$confirm(`是否删除?`, '提醒', {
  262. type: 'warning'
  263. }).then(() => {
  264. remove(row.lv, row.id).then(res => {
  265. if (res.code === 0) {
  266. this.$message.success('删除成功!')
  267. this.getTabList()
  268. }
  269. })
  270. }).catch(() => { })
  271. },
  272. // 历史记录
  273. getHistoryDialog(id) {
  274. this.dialogVisible_list = true
  275. this.loading = true
  276. this.dialogForm_list.categoryId = id
  277. this.getHistoryList()
  278. },
  279. // 历史记录列表
  280. getHistoryList() {
  281. history(this.dialogForm_list).then(res => {
  282. if (res.code === 0) {
  283. this.dialogTableData = res.data.records
  284. this.total = res.data.total
  285. this.loading = false
  286. }
  287. })
  288. },
  289. // 搜索
  290. getSearch() {
  291. this.dialogForm_list.pageNum = 1
  292. this.getHistoryList()
  293. },
  294. // 重置
  295. getRefresh() {
  296. this.dialogForm_list = {
  297. pageNum: 1,
  298. pageSize: 10,
  299. categoryId: this.dialogForm_list.categoryId
  300. }
  301. this.getHistoryList()
  302. },
  303. // 有效时间
  304. getChange(row) {
  305. timeChange({
  306. moduleId: row.id,
  307. timeList: row.rsDates
  308. }).then(res => {
  309. if (res.code === 0) {
  310. this.$message.success('修改成功!')
  311. this.getTabList()
  312. }
  313. })
  314. },
  315. // 字典翻译
  316. statusFormatter(row) {
  317. return this.selectDictLabel(this.statusOptions, row.isProgressStatus)
  318. },
  319. typeFormatter(row) {
  320. return row.lv !== 1 ? this.typeOptions.find(i => i.typeId === row.moduleTypeId).typeName : ''
  321. }
  322. }
  323. }
  324. </script>
  325. <style lang="scss">
  326. .popper-class {
  327. .el-picker-panel__footer {
  328. button:first-child {
  329. display: none;
  330. }
  331. }
  332. }
  333. </style>