index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <!-- 运营管理 场景时间 -->
  2. <template>
  3. <div class="app-container">
  4. <el-button
  5. type="primary"
  6. size="mini"
  7. icon="el-icon-plus"
  8. @click="getDialog('新增')"
  9. v-hasPermi="['operation:sceneTime:add']"
  10. >新增</el-button
  11. >
  12. <!-- 列表 -->
  13. <el-table :data="tableData" v-loading="loading">
  14. <el-table-column type="index" label="序号" align="center" />
  15. <el-table-column label="时间段" align="center">
  16. <template slot-scope="scope">
  17. <span>{{ scope.row.startTime }} - {{ scope.row.endTime }}</span>
  18. </template>
  19. </el-table-column>
  20. <el-table-column label="时间段文案" prop="name" align="center" />
  21. <el-table-column label="时间Icon" width="100px" align="center">
  22. <template slot-scope="scope">
  23. <el-image :src="scope.row.pic" style="background: #000" />
  24. </template>
  25. </el-table-column>
  26. <el-table-column label="创建时间" prop="createtTime" align="center" />
  27. <el-table-column label="操作" align="center">
  28. <template slot-scope="scope">
  29. <el-button type="text" @click="getDialog('查看', scope.row)"
  30. >查看</el-button
  31. >
  32. <el-button
  33. type="text"
  34. @click="getDialog('编辑', scope.row)"
  35. v-hasPermi="['operation:sceneTime:edit']"
  36. >编辑</el-button
  37. >
  38. <el-button
  39. type="delete"
  40. @click="getDelete(scope.row, 2)"
  41. v-hasPermi="['operation:sceneTime:delete']"
  42. >删除</el-button
  43. >
  44. </template>
  45. </el-table-column>
  46. </el-table>
  47. <!-- 弹窗 -->
  48. <el-dialog
  49. :visible.sync="dialogVisible"
  50. :title="title"
  51. width="500px"
  52. :before-close="cancel"
  53. >
  54. <el-form
  55. :model="dialogForm"
  56. ref="dialogForm"
  57. :rules="rules"
  58. label-width="110px"
  59. :disabled="disabled"
  60. >
  61. <el-form-item label="时间段:" prop="date">
  62. <el-time-picker
  63. is-range
  64. v-model="dialogForm.date"
  65. start-placeholder="开始时间"
  66. end-placeholder="结束时间"
  67. value-format="HH:mm:ss"
  68. format="HH:mm:ss"
  69. placeholder="选择时间范围"
  70. />
  71. </el-form-item>
  72. <el-form-item label="时间段文案:" prop="name">
  73. <el-input v-model="dialogForm.name" placeholder="请输入时间段文案" />
  74. </el-form-item>
  75. <el-form-item label="时间段Icon:" prop="pic">
  76. <Upload
  77. listType="picture-card"
  78. :url="dialogForm.pic"
  79. @upload="upload"
  80. style="background: #000"
  81. :disabled="disabled"
  82. />
  83. </el-form-item>
  84. </el-form>
  85. <div slot="footer">
  86. <el-button @click="cancel">取消</el-button>
  87. <el-button v-if="!disabled" type="primary" @click="getSubmit"
  88. >确定</el-button
  89. >
  90. </div>
  91. </el-dialog>
  92. </div>
  93. </template>
  94. <script>
  95. import { change, detail, list, submit } from "@/api/operation/sceneTime";
  96. import { dialogCallBack } from "@/utils/DialogUtil";
  97. export default {
  98. name:"OperationSceneTime",
  99. data() {
  100. return {
  101. // 遮罩层
  102. loading: false,
  103. // 列表
  104. tableData: [],
  105. // 弹窗
  106. dialogVisible: false,
  107. // 弹窗title
  108. title: "",
  109. // 弹窗表单
  110. dialogForm: {},
  111. // 校验
  112. rules: {
  113. date: [
  114. {
  115. required: true,
  116. message: "请选择时间段",
  117. trigger: "change",
  118. },
  119. ],
  120. name: [
  121. {
  122. required: true,
  123. message: "请输入时间段文案",
  124. trigger: "blur",
  125. },
  126. ],
  127. pic: [
  128. {
  129. required: true,
  130. message: "请上传图片",
  131. trigger: "change",
  132. },
  133. ],
  134. },
  135. // 只读
  136. disabled: false,
  137. };
  138. },
  139. mounted() {
  140. this.getList();
  141. },
  142. methods: {
  143. // 列表
  144. getList() {
  145. this.loading = true;
  146. list().then((res) => {
  147. if (res.code === 0) {
  148. this.tableData = res.data;
  149. this.loading = false;
  150. }
  151. });
  152. },
  153. // 弹窗
  154. getDialog(title, row) {
  155. this.dialogVisible = true;
  156. this.title = title;
  157. this.disabled = title === "查看" ? true : false;
  158. if (row) {
  159. this.getDetail(row.id);
  160. }
  161. },
  162. // 详情
  163. getDetail(id) {
  164. detail(id).then((res) => {
  165. if (res.code === 0) {
  166. this.dialogForm = res.data;
  167. this.$set(this.dialogForm, "date", [
  168. res.data.startTime,
  169. res.data.endTime,
  170. ]);
  171. }
  172. });
  173. },
  174. // 上传icon
  175. upload(e) {
  176. this.dialogForm.pic = e.file;
  177. },
  178. // 取消
  179. cancel() {
  180. this.dialogVisible = false;
  181. this.dialogForm = {
  182. date: ["", ""],
  183. name: "",
  184. pic: "",
  185. };
  186. this.$refs.dialogForm.resetFields();
  187. },
  188. // 确定
  189. getSubmit() {
  190. this.$refs.dialogForm.validate((valid) => {
  191. if (valid) {
  192. this.dialogForm.startTime = this.dialogForm.date[0];
  193. this.dialogForm.endTime = this.dialogForm.date[1];
  194. delete this.dialogForm.date;
  195. submit(this.dialogForm).then((res) => {
  196. if (res.code === 0) {
  197. this.$message.success("提交成功!");
  198. this.getList();
  199. this.cancel();
  200. }
  201. });
  202. } else {
  203. return false;
  204. }
  205. });
  206. },
  207. getDelete(row, status) {
  208. var that = this;
  209. dialogCallBack(that, function () {
  210. that
  211. .$confirm(`是否删除${row.name}?`, "提示:", {
  212. type: "warning",
  213. })
  214. .then(() => {
  215. change(row.id, status).then((res) => {
  216. if (res.code === 0) {
  217. that.$message.success("删除成功!");
  218. that.getList();
  219. }
  220. });
  221. });
  222. });
  223. },
  224. },
  225. };
  226. </script>