index.vue 12 KB

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