index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <!-- 运营管理 爱听弹窗 -->
  2. <template>
  3. <div class="app-container">
  4. <!-- 搜索 -->
  5. <el-form inline size="mini">
  6. <el-form-item label="弹窗名称:">
  7. <el-input v-model="form.name" placeholder="请输入弹窗名称" />
  8. </el-form-item>
  9. <el-form-item label="当前状态:">
  10. <el-select v-model="form.status" placeholder="请选择当前状态">
  11. <el-option
  12. v-for="item in disabledOptions"
  13. :key="item.value"
  14. :value="item.value"
  15. :label="item.label"
  16. />
  17. </el-select>
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button type="primary" icon="el-icon-search" @click="getSearch"
  21. >搜索</el-button
  22. >
  23. <el-button icon="el-icon-refresh" @click="getRefresh">重置</el-button>
  24. <el-button
  25. type="primary"
  26. icon="el-icon-plus"
  27. plain
  28. @click="getDialog('新增')"
  29. v-hasPermi="['operation:dialog:add']"
  30. >新增</el-button
  31. >
  32. </el-form-item>
  33. </el-form>
  34. <!-- 列表 -->
  35. <el-table :data="tableData" v-loading="loading">
  36. <el-table-column label="序号" type="index" align="center" />
  37. <el-table-column
  38. label="弹窗名称"
  39. prop="name"
  40. align="center"
  41. show-overflow-tooltip
  42. />
  43. <el-table-column label="弹窗图片" align="center" width="100px">
  44. <template slot-scope="scope">
  45. <el-image :src="scope.row.pic" />
  46. </template>
  47. </el-table-column>
  48. <el-table-column
  49. label="关联设备"
  50. align="center"
  51. :formatter="devFormatter"
  52. show-overflow-tooltip
  53. />
  54. <el-table-column label="创建时间" prop="createTime" align="center" />
  55. <el-table-column
  56. label="当前状态"
  57. prop="status"
  58. align="center"
  59. :formatter="statusFormatter"
  60. />
  61. <el-table-column label="操作" align="center">
  62. <template slot-scope="scope">
  63. <el-button type="text" @click="getDialog('查看', scope.row.id)"
  64. >查看</el-button
  65. >
  66. <el-button
  67. v-if="scope.row.status === 0"
  68. type="text"
  69. @click="getChange(scope.row, 1, '下架')"
  70. v-hasPermi="['operation:dialog:down']"
  71. >下架</el-button
  72. >
  73. <span v-else style="margin-left: 10px">
  74. <el-button
  75. type="text"
  76. @click="getDialog('编辑', scope.row.id)"
  77. v-hasPermi="['operation:dialog:edit']"
  78. >编辑</el-button
  79. >
  80. <el-button
  81. type="text"
  82. @click="getChange(scope.row, 0, '上架')"
  83. v-hasPermi="['operation:dialog:up']"
  84. >上架</el-button
  85. >
  86. <el-button
  87. type="delete"
  88. @click="getDelete(scope.row, 2, '删除')"
  89. v-hasPermi="['operation:dialog:delete']"
  90. >删除</el-button
  91. >
  92. </span>
  93. </template>
  94. </el-table-column>
  95. </el-table>
  96. <pagination
  97. v-show="total > 0"
  98. :total="total"
  99. :page.sync="form.pageNum"
  100. :limit.sync="form.pageSize"
  101. @pagination="getList"
  102. />
  103. <!-- 弹窗 -->
  104. <el-dialog
  105. :visible.sync="dialogVisible"
  106. :title="title"
  107. width="500px"
  108. :before-close="getClose"
  109. >
  110. <el-form label-width="auto" :disabled="title === '查看' ? true : false">
  111. <el-form-item label="弹窗名称:">
  112. <el-input v-model="dialogForm.name" placeholder="请输入弹窗名称" />
  113. </el-form-item>
  114. <el-form-item label="关联设备:">
  115. <el-select
  116. v-model="dialogForm.deviceIds"
  117. multiple
  118. filterable
  119. placeholder="请选择关联设备"
  120. >
  121. <el-option
  122. v-for="item in devOptions"
  123. :key="item.value"
  124. :value="item.value"
  125. :label="item.label"
  126. />
  127. </el-select>
  128. </el-form-item>
  129. <el-form-item label="弹窗图片:">
  130. <Upload
  131. listType="picture-card"
  132. :url="dialogForm.pic"
  133. @upload="upload"
  134. :disabled="title === '查看' ? true : false"
  135. />
  136. </el-form-item>
  137. </el-form>
  138. <div slot="footer">
  139. <el-button @click="getClose">取消</el-button>
  140. <el-button v-if="title !== '查看'" type="primary" @click="getSubmit"
  141. >确定</el-button
  142. >
  143. </div>
  144. </el-dialog>
  145. </div>
  146. </template>
  147. <script>
  148. import { change, detail, devList, list, submit } from "@/api/operation/dialog";
  149. import { disabledMixin } from "@/mixin/index";
  150. import { dialogCallBack } from "@/utils/DialogUtil";
  151. export default {
  152. name:"OperationDialog",
  153. mixins: [disabledMixin],
  154. data() {
  155. return {
  156. // 遮罩层
  157. loading: false,
  158. // 表单
  159. form: {
  160. pageNum: 1,
  161. pageSize: 10,
  162. },
  163. // 总数据
  164. total: 0,
  165. // 列表
  166. tableData: [],
  167. // 弹窗
  168. dialogVisible: false,
  169. // 弹窗名称
  170. title: "新增",
  171. // 弹窗表单
  172. dialogForm: {},
  173. // 设备列表
  174. devOptions: [],
  175. allDevs: [],
  176. };
  177. },
  178. mounted() {
  179. this.getList();
  180. this.getDev(1);
  181. },
  182. methods: {
  183. // 列表
  184. getList() {
  185. this.loading = true;
  186. list(this.form).then((res) => {
  187. if (res.code === 0) {
  188. this.tableData = res.data.records;
  189. this.total = res.data.total;
  190. this.loading = false;
  191. }
  192. });
  193. },
  194. // 搜索
  195. getSearch() {
  196. this.form.pageNum = 1;
  197. this.getList();
  198. },
  199. // 重置
  200. getRefresh() {
  201. this.form = {
  202. pageNum: 1,
  203. pageSize: 10,
  204. };
  205. this.getList();
  206. },
  207. // 上下架
  208. getChange(row, status, title) {
  209. this.$confirm(`是否${title}${row.name}?`, "提示", {
  210. type: "warning",
  211. })
  212. .then((res) => {
  213. change(row.id, status).then((res) => {
  214. if (res.code === 0) {
  215. this.$message.success(`${title}成功!`);
  216. this.getList();
  217. }
  218. });
  219. })
  220. .catch(() => {});
  221. },
  222. // 删除
  223. getDelete(row, status, title) {
  224. var that = this;
  225. dialogCallBack(that, function () {
  226. that
  227. .$confirm(`是否${title}${row.name}?`, "提示", {
  228. type: "warning",
  229. })
  230. .then((res) => {
  231. change(row.id, status).then((res) => {
  232. if (res.code === 0) {
  233. that.$message.success(`${title}成功!`);
  234. that.getList();
  235. }
  236. });
  237. })
  238. .catch(() => {});
  239. });
  240. },
  241. // 弹窗
  242. getDialog(title, id) {
  243. this.dialogVisible = true;
  244. this.title = title;
  245. this.getDev(2);
  246. if (id) {
  247. detail(id).then((res) => {
  248. if (res.code === 0) {
  249. this.dialogForm = res.data;
  250. this.dialogForm.deviceIds = res.data.deviceIds.split(",");
  251. res.data.existDeviceList.map((i) => {
  252. this.devOptions.unshift({
  253. value: i.clientTypeId,
  254. label: i.name,
  255. });
  256. });
  257. }
  258. });
  259. }
  260. },
  261. // 设备列表
  262. getDev(type) {
  263. this.devOptions = [];
  264. devList(type).then((res) => {
  265. if (res.code === 0) {
  266. res.data.map((i) => {
  267. let obj = {
  268. value: i.clientTypeId,
  269. label: i.name,
  270. };
  271. type === 1 ? this.allDevs.push(obj) : this.devOptions.push(obj);
  272. });
  273. }
  274. });
  275. },
  276. // 上传
  277. upload(e) {
  278. this.dialogForm.pic = e.file;
  279. },
  280. // 关闭
  281. getClose() {
  282. this.dialogVisible = false;
  283. this.dialogForm = {};
  284. },
  285. // 确定
  286. getSubmit() {
  287. this.dialogForm.deviceIds = this.dialogForm.deviceIds.join(",");
  288. submit(this.dialogForm).then((res) => {
  289. if (res.code === 0) {
  290. this.$message.success("提交成功!");
  291. this.getClose();
  292. this.getList();
  293. }
  294. });
  295. },
  296. // 字典翻译
  297. devFormatter(row) {
  298. return row.deviceIds
  299. ? row.deviceIds
  300. .split(",")
  301. .map((i) => this.selectDictLabel(this.allDevs, i))
  302. .join(",")
  303. : "";
  304. },
  305. statusFormatter(row) {
  306. return this.selectDictLabel(this.disabledOptions, row.status);
  307. },
  308. },
  309. };
  310. </script>
  311. <style lang="scss" scoped>
  312. </style>