index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. <!-- 运营管理 首页推荐 推荐管理 -->
  2. <template>
  3. <div class="app-container">
  4. <!-- 列表 -->
  5. <el-table
  6. :data="tableData"
  7. ref="tableData"
  8. row-key="id"
  9. :default-sort="{ prop: 'sort', order: 'ascending' }"
  10. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  11. >
  12. <el-table-column width="80px">
  13. <template slot-scope="scope">
  14. <el-link
  15. v-if="scope.row.hidden"
  16. :underline="false"
  17. class="el-icon-arrow-right"
  18. @click="getList(scope.row, scope.row.index)"
  19. />
  20. </template>
  21. </el-table-column>
  22. <el-table-column
  23. label="导航名称"
  24. align="center"
  25. prop="name"
  26. show-overflow-tooltip
  27. >
  28. <template slot-scope="scope">
  29. <span v-if="scope.row.lv === 1">{{ scope.row.name }}</span>
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="排序" align="center">
  33. <template slot-scope="scope">
  34. <span v-if="scope.row.lv === 2">{{ scope.row.sort }}</span>
  35. </template>
  36. </el-table-column>
  37. <el-table-column
  38. label="模块类型"
  39. align="center"
  40. prop="moduleTypeId"
  41. show-overflow-tooltip
  42. :formatter="typeFormatter"
  43. />
  44. <el-table-column
  45. label="模块名称"
  46. align="center"
  47. prop="moduleName"
  48. show-overflow-tooltip
  49. />
  50. <el-table-column label="模块数量" align="center" prop="moduleNum" />
  51. <el-table-column
  52. label="创建时间"
  53. align="center"
  54. prop="createTime"
  55. show-overflow-tooltip
  56. />
  57. <el-table-column label="有效时间" align="center" width="380px">
  58. <template slot-scope="scope">
  59. <span v-if="scope.row.lv === 3">
  60. {{ scope.row.rsDates[0] }} - {{ scope.row.rsDates[1] }}
  61. </span>
  62. </template>
  63. </el-table-column>
  64. <el-table-column
  65. label="当前状态"
  66. align="center"
  67. prop="isProgressStatus"
  68. :formatter="statusFormatter"
  69. />
  70. <el-table-column label="操作" align="center">
  71. <template slot-scope="scope">
  72. <span v-if="scope.row.lv === 1">
  73. <el-button
  74. type="text"
  75. @click="getDialog('新增', scope.row)"
  76. v-hasPermi="['operation:recommend:add']"
  77. >新增</el-button
  78. >
  79. <el-button type="text" @click="getHistoryDialog(scope.row.id)"
  80. >历史记录</el-button
  81. >
  82. </span>
  83. <span v-else-if="scope.row.lv === 2">
  84. <el-button
  85. type="text"
  86. @click="getDetail(scope.row)"
  87. v-hasPermi="['operation:recommend:add']"
  88. >新增</el-button
  89. >
  90. <el-button type="text" @click="getDialog('查看', scope.row)"
  91. >查看</el-button
  92. >
  93. <el-button
  94. type="text"
  95. @click="getDialog('编辑', scope.row)"
  96. v-hasPermi="['operation:recommend:edit']"
  97. >编辑</el-button
  98. >
  99. <el-button
  100. type="delete"
  101. @click="getDelete(scope.row)"
  102. v-hasPermi="['operation:recommend:delete']"
  103. >删除</el-button
  104. >
  105. </span>
  106. <span v-else>
  107. <el-button type="text" @click="getDetail(scope.row, true)"
  108. >查看</el-button
  109. >
  110. <el-button
  111. type="text"
  112. @click="getDetail(scope.row)"
  113. v-hasPermi="['operation:recommend:edit']"
  114. >编辑</el-button
  115. >
  116. <el-button
  117. type="delete"
  118. @click="getDelete(scope.row)"
  119. v-hasPermi="['operation:recommend:delete']"
  120. >删除</el-button
  121. >
  122. <el-button
  123. type="text"
  124. @click="getCopy(scope.row)"
  125. v-hasPermi="['operation:recommend:copy']"
  126. >复制</el-button
  127. >
  128. </span>
  129. </template>
  130. </el-table-column>
  131. </el-table>
  132. <!-- 弹窗 -->
  133. <el-dialog
  134. :visible.sync="dialogVisible"
  135. :title="title"
  136. width="500px"
  137. :before-close="cancel"
  138. >
  139. <el-form
  140. :model="dialogForm"
  141. :rules="rules"
  142. ref="dialogForm"
  143. label-width="100px"
  144. :disabled="title === '查看'"
  145. >
  146. <el-form-item label="模块类型:" prop="moduleTypeId">
  147. <el-select
  148. v-model="dialogForm.moduleTypeId"
  149. placeholder="请选择模块类型"
  150. :disabled="title === '编辑'"
  151. >
  152. <el-option
  153. v-for="item in typeOptions"
  154. :key="item.typeId"
  155. :value="item.typeId"
  156. :label="item.typeName"
  157. />
  158. </el-select>
  159. </el-form-item>
  160. <el-form-item label="排序:" prop="sort">
  161. <el-input-number v-model="dialogForm.sort" :min="1" />
  162. </el-form-item>
  163. </el-form>
  164. <div slot="footer">
  165. <el-button @click="cancel">取消</el-button>
  166. <el-button v-if="title !== '查看'" type="primary" @click="getSubmit"
  167. >确定</el-button
  168. >
  169. </div>
  170. </el-dialog>
  171. <!-- 历史记录 -->
  172. <el-dialog
  173. :visible.sync="dialogVisible_list"
  174. title="历史记录"
  175. width="1200px"
  176. >
  177. <el-form inline size="mini">
  178. <el-form-item label="创建时间:">
  179. <el-date-picker
  180. v-model="dialogForm_list.rsDates"
  181. type="datetimerange"
  182. start-placeholder="开始日期"
  183. end-placeholder="结束日期"
  184. value-format="yyyy-MM-dd HH:mm:ss"
  185. format="yyyy-MM-dd HH:mm:ss"
  186. />
  187. </el-form-item>
  188. <el-form-item label="模块名称:">
  189. <el-input
  190. v-model="dialogForm_list.moduleName"
  191. placeholder="请输入模块名称"
  192. clearable
  193. />
  194. </el-form-item>
  195. <el-form-item>
  196. <el-button type="primary" icon="el-icon-search" @click="getSearch"
  197. >搜索</el-button
  198. >
  199. <el-button icon="el-icon-refresh" @click="getRefresh">重置</el-button>
  200. </el-form-item>
  201. </el-form>
  202. <el-table :data="dialogTableData" v-loading="loading">
  203. <el-table-column
  204. label="模块名称"
  205. prop="moduleName"
  206. align="center"
  207. show-overflow-tooltip
  208. />
  209. <el-table-column
  210. label="模块类型"
  211. prop="moduleTypeId"
  212. align="center"
  213. :formatter="typeFormatter"
  214. />
  215. <el-table-column label="模块数量" prop="moduleNum" align="center" />
  216. <el-table-column label="有效时间" align="center" width="380px">
  217. <template slot-scope="scope">
  218. <span>{{ scope.row.rsDates[0] }} - {{ scope.row.rsDates[1] }}</span>
  219. </template>
  220. </el-table-column>
  221. <el-table-column
  222. label="当前状态"
  223. prop="isProgressStatus"
  224. align="center"
  225. :formatter="statusFormatter"
  226. />
  227. <el-table-column
  228. label="创建时间"
  229. prop="createTime"
  230. align="center"
  231. show-overflow-tooltip
  232. />
  233. <el-table-column label="操作" align="center">
  234. <template slot-scope="scope">
  235. <el-button type="text" @click="getDetail(scope.row, true)"
  236. >查看</el-button
  237. >
  238. </template>
  239. </el-table-column>
  240. </el-table>
  241. <pagination
  242. v-show="total > 0"
  243. :total="total"
  244. :page.sync="dialogForm_list.pageNum"
  245. :limit.sync="dialogForm_list.pageSize"
  246. @pagination="getHistoryList"
  247. />
  248. </el-dialog>
  249. </div>
  250. </template>
  251. <script>
  252. import {
  253. history,
  254. list,
  255. listDetail,
  256. remove,
  257. submit,
  258. tabList,
  259. timeChange,
  260. typeList,
  261. } from "@/api/operation/recommend";
  262. import { dialogCallBack } from "@/utils/DialogUtil";
  263. export default {
  264. name: "OperationRecommend",
  265. data() {
  266. return {
  267. // 遮罩层
  268. loading: false,
  269. // 列表
  270. tableData: [],
  271. // 弹窗
  272. dialogVisible: false,
  273. dialogVisible_list: false,
  274. // 弹窗表单
  275. dialogForm: {},
  276. dialogForm_list: {
  277. pageNum: 1,
  278. pageSize: 10,
  279. },
  280. // 弹窗title
  281. title: "新增",
  282. // 弹窗列表
  283. dialogTableData: [],
  284. // 总数据
  285. total: 0,
  286. // 导航栏
  287. tabOptions: [],
  288. // 模块类型
  289. typeOptions: [],
  290. // 校验
  291. rules: {
  292. categoryId: [
  293. {
  294. required: true,
  295. message: "请选择导航",
  296. tigger: "change",
  297. },
  298. ],
  299. moduleTypeId: [
  300. {
  301. required: true,
  302. message: "请选择模块类型",
  303. tigger: "change",
  304. },
  305. ],
  306. sort: [
  307. {
  308. required: true,
  309. type: "number",
  310. message: "请选择排序",
  311. tirgger: "blur, change",
  312. },
  313. ],
  314. },
  315. // 当前状态
  316. statusOptions: [
  317. {
  318. value: 0,
  319. label: "生效中",
  320. },
  321. {
  322. value: 1,
  323. label: "未生效",
  324. },
  325. {
  326. value: 2,
  327. label: "未配置时间",
  328. },
  329. {
  330. value: 3,
  331. label: "已失效",
  332. },
  333. ],
  334. // 当前数据缓存
  335. index: null,
  336. };
  337. },
  338. mounted() {
  339. this.getTabList();
  340. this.getTypeList();
  341. },
  342. methods: {
  343. // 导航列表
  344. getTabList() {
  345. tabList().then((res) => {
  346. if (res.code === 0) {
  347. res.data.map((i, index) => {
  348. i.index = index;
  349. i.hidden = true;
  350. i.children = [];
  351. });
  352. this.tabOptions = res.data;
  353. this.tableData = res.data;
  354. }
  355. });
  356. },
  357. // 模块列表
  358. getTypeList() {
  359. typeList().then((res) => {
  360. if (res.code === 0) {
  361. this.typeOptions = res.data;
  362. }
  363. });
  364. },
  365. // 首次获取二级列表
  366. getList(row, index) {
  367. let e = this.tableData[index];
  368. list(row.id).then((res) => {
  369. if (res.code === 0) {
  370. if (res.data.length > 0) {
  371. e.children = res.data;
  372. e.hidden = false;
  373. this.$nextTick(() => {
  374. this.$refs.tableData.toggleRowExpansion(row, true);
  375. });
  376. } else {
  377. this.$message.warning("暂无模块!");
  378. }
  379. }
  380. });
  381. },
  382. // 提交二级
  383. getSubmit() {
  384. this.$refs.dialogForm.validate((valid) => {
  385. if (valid) {
  386. submit(this.dialogForm).then((res) => {
  387. if (res.code === 0) {
  388. this.$message.success("提交成功");
  389. this.cancel();
  390. this.getList(this.tableData[this.index], this.index);
  391. }
  392. });
  393. } else {
  394. return false;
  395. }
  396. });
  397. },
  398. // 取消
  399. cancel() {
  400. this.dialogVisible = false;
  401. this.$refs.dialogForm.resetFields();
  402. this.dialogForm = {};
  403. },
  404. // 弹窗
  405. getDialog(title, row) {
  406. this.index = this.tableData.findIndex((i) => i.id == row.id);
  407. this.title = title;
  408. this.dialogVisible = true;
  409. this.dialogForm.categoryId = row.id;
  410. if (row.lv === 2) {
  411. listDetail(row.id).then((res) => {
  412. if (res.code === 0) {
  413. this.dialogForm = res.data;
  414. }
  415. });
  416. }
  417. },
  418. // 详情页
  419. getDetail(row, boolean) {
  420. console.log("gadfqwerqweqr====000==");
  421. // this.dialogVisible_list = true;
  422. // this.loading = false;
  423. this.$router.push({
  424. path: `/operation/homePage/recommend/detail`,
  425. query:
  426. row.lv === 2
  427. ? {
  428. secondId: row.id,
  429. moduleTypeId: row.moduleTypeId,
  430. }
  431. : {
  432. threeId: row.id,
  433. moduleTypeId: row.moduleTypeId,
  434. boolean: boolean,
  435. },
  436. });
  437. },
  438. // 删除
  439. getDelete(row) {
  440. var that = this;
  441. dialogCallBack(that, function () {
  442. that
  443. .$confirm(`是否删除?`, "提示:", {
  444. type: "warning",
  445. })
  446. .then(() => {
  447. let index = that.tableData.findIndex((i) => i.id == row.categoryId);
  448. remove(row.lv, row.id).then((res) => {
  449. if (res.code === 0) {
  450. that.$message.success("删除成功!");
  451. that.getList(that.tableData[index], index);
  452. }
  453. });
  454. })
  455. .catch(() => {});
  456. });
  457. },
  458. // 历史记录
  459. getHistoryDialog(id) {
  460. this.dialogVisible_list = true;
  461. this.loading = true;
  462. this.dialogForm_list.categoryId = id;
  463. this.getHistoryList();
  464. },
  465. // 历史记录列表
  466. getHistoryList() {
  467. history(this.dialogForm_list).then((res) => {
  468. if (res.code === 0) {
  469. this.dialogTableData = res.data.records;
  470. this.total = res.data.total;
  471. this.loading = false;
  472. }
  473. });
  474. },
  475. // 搜索
  476. getSearch() {
  477. this.dialogForm_list.pageNum = 1;
  478. this.getHistoryList();
  479. },
  480. // 重置
  481. getRefresh() {
  482. this.dialogForm_list = {
  483. pageNum: 1,
  484. pageSize: 10,
  485. categoryId: this.dialogForm_list.categoryId,
  486. };
  487. this.getHistoryList();
  488. },
  489. // 有效时间
  490. getChange(row) {
  491. timeChange({
  492. moduleId: row.id,
  493. timeList: row.rsDates,
  494. }).then((res) => {
  495. if (res.code === 0) {
  496. this.$message.success("修改成功!");
  497. this.getTabList();
  498. }
  499. });
  500. },
  501. // 复制
  502. getCopy(row) {
  503. this.$router.push({
  504. path: `/operation/homePage/recommend/detail`,
  505. query: {
  506. copyId: row.id,
  507. moduleTypeId: row.moduleTypeId,
  508. },
  509. });
  510. },
  511. // 字典翻译
  512. statusFormatter(row) {
  513. return this.selectDictLabel(this.statusOptions, row.isProgressStatus);
  514. },
  515. typeFormatter(row) {
  516. return row.lv !== 1
  517. ? this.typeOptions.find((i) => i.typeId === row.moduleTypeId).typeName
  518. : "";
  519. },
  520. },
  521. };
  522. </script>
  523. <style lang="scss">
  524. .popper-class {
  525. .el-picker-panel__footer {
  526. button:first-child {
  527. display: none;
  528. }
  529. }
  530. }
  531. </style>