index.vue 11 KB

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