footer.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <div id="footer">
  3. <div class="smallBox">
  4. <div style="text-align: right">
  5. <el-button :size="size" @click="add(1)">添加</el-button>
  6. </div>
  7. <el-table :data="listData" style="width: 700px; margin-top: 10px" border>
  8. <el-table-column
  9. v-for="(item, index) in tableSet"
  10. :width="item.width"
  11. :key="index"
  12. :prop="item.prop"
  13. :label="item.label"
  14. align="center"
  15. >
  16. <template slot-scope="scope">
  17. <div v-if="item.scope === 'input'">
  18. <el-input-number
  19. @blur="changeVal(scope.row)"
  20. v-model="scope.row[item.prop]"
  21. :controls="false"
  22. :min="0"
  23. :precision="0"
  24. style="width: 80%"
  25. ></el-input-number>
  26. </div>
  27. <div v-else-if="item.scope === 'set'">
  28. <el-button type="text" @click="add(0, scope.row, scope.$index)"
  29. >修改</el-button
  30. >
  31. <el-button type="text" @click="del(scope.$index)">删除</el-button>
  32. </div>
  33. <div v-else>{{ scope.row[item.prop] }}</div>
  34. </template></el-table-column
  35. >
  36. </el-table>
  37. <div style="text-align: center; margin-top: 20px">
  38. <el-button :size="size" type="primary" @click="submit">保 存</el-button>
  39. </div>
  40. </div>
  41. <el-dialog
  42. @closed="loadingClose"
  43. :visible.sync="dialogVisible"
  44. width="680px"
  45. :show-close="false"
  46. :close-on-click-modal="false"
  47. >
  48. <div slot="title" class="hearders">
  49. <div class="leftTitle">
  50. {{ statusPop === 1 ? "添加" : statusPop === 0 ? "修改" : "详情" }}
  51. </div>
  52. <div class="rightBoxs">
  53. <img src="@/assets/images/Close@2x.png" alt="" @click="close" />
  54. </div>
  55. </div>
  56. <div>
  57. <el-form
  58. label-position="right"
  59. label-width="170px"
  60. :model="boxData"
  61. :rules="rules"
  62. ref="boxData"
  63. >
  64. <el-form-item label="文本内容" prop="name">
  65. <el-input v-model="boxData.name"></el-input>
  66. </el-form-item>
  67. </el-form>
  68. </div>
  69. <span slot="footer" class="dialog-footer">
  70. <el-button @click="close">取 消</el-button>
  71. <el-button @click="submitForm('boxData')" :loading="disabledBtn"
  72. >确 定</el-button
  73. >
  74. </span>
  75. </el-dialog>
  76. </div>
  77. </template>
  78. <script>
  79. import { listConfig,updateConfig } from "@/api/system/config";
  80. export default {
  81. data() {
  82. return {
  83. disabledBtn: false,
  84. dialogVisible: false,
  85. size: "mini",
  86. tableSet: [
  87. {
  88. label: "排序",
  89. prop: "sort",
  90. scope: "input",
  91. width: "120px",
  92. },
  93. {
  94. label: "文本内容",
  95. prop: "name",
  96. },
  97. {
  98. label: "操作",
  99. scope: "set",
  100. width: "160px",
  101. },
  102. ],
  103. Nav: [],
  104. initData: {},
  105. listData: [],
  106. statusPop: "",
  107. boxData: {},
  108. rules: {
  109. name: [{ required: true, message: "请填写文本内容", trigger: "blur" }],
  110. },
  111. newIndex: "",
  112. };
  113. },
  114. mounted() {
  115. this.init();
  116. },
  117. methods: {
  118. changeVal(row) {
  119. if (!row.sort && row.sort !== 0) {
  120. this.$message.warning("检测到你没有赋值或赋值异常,已自动赋值为0");
  121. row.sort = 0;
  122. } else {
  123. for (let i = 0; i < this.listData.length; i++) {
  124. if (
  125. this.listData[i].name !== row.name &&
  126. this.listData[i].sort == row.sort
  127. ) {
  128. this.$message.warning("检测到重复值,已自动赋值为0");
  129. row.sort = 0;
  130. }
  131. }
  132. }
  133. this.listData.sort(this.sort);
  134. },
  135. sort(a, b) {
  136. return a.sort - b.sort;
  137. },
  138. loadingClose() {
  139. this.disabledBtn = false;
  140. },
  141. del(index) {
  142. this.listData.splice(index, 1);
  143. },
  144. add(int, row, index) {
  145. this.statusPop = int;
  146. this.newIndex = index;
  147. if (int === 0) {
  148. this.boxData = JSON.parse(JSON.stringify(row));
  149. }
  150. if (int === 1) {
  151. var indexNum = 0;
  152. this.listData.forEach((item) => {
  153. if (item.sort >= indexNum) {
  154. indexNum = item.sort + 1;
  155. }
  156. });
  157. this.boxData = {};
  158. this.boxData.sort = indexNum;
  159. }
  160. this.dialogVisible = true;
  161. this.$nextTick(() => {
  162. this.$refs.boxData.clearValidate();
  163. });
  164. },
  165. close() {
  166. this.dialogVisible = false;
  167. },
  168. submitForm(formName) {
  169. this.$refs[formName].validate((valid) => {
  170. if (valid) {
  171. if (this.statusPop === 1) {
  172. this.listData.push(this.boxData);
  173. } else {
  174. this.listData.splice(this.newIndex, 1, this.boxData);
  175. }
  176. this.dialogVisible = false;
  177. } else {
  178. console.log("error submit!!");
  179. return false;
  180. }
  181. });
  182. },
  183. init() {
  184. listConfig({ configKey: "home.footer" }).then((res) => {
  185. if (res.rows.length) {
  186. this.initData = res.rows[0];
  187. this.listData = JSON.parse(res.rows[0].configValue);
  188. }
  189. });
  190. },
  191. submit() {
  192. let data = JSON.parse(JSON.stringify(this.listData));
  193. let copySubmitData = JSON.parse(JSON.stringify(this.initData));
  194. copySubmitData.configValue = JSON.stringify(data);
  195. updateConfig(copySubmitData).then((res) => {
  196. this.$message.success("保存成功");
  197. });
  198. },
  199. },
  200. };
  201. </script>
  202. <style lang="less" scoped>
  203. .smallBox {
  204. width: 700px;
  205. }
  206. /deep/.el-button {
  207. border-radius: 8px;
  208. }
  209. /deep/.el-dialog {
  210. border-radius: 8px;
  211. .el-dialog__header {
  212. padding: 0;
  213. .hearders {
  214. height: 40px;
  215. display: flex;
  216. align-items: center;
  217. justify-content: space-between;
  218. padding: 0px 18px 0px 20px;
  219. border-bottom: 1px solid #e2e2e2;
  220. .leftTitle {
  221. font-size: 14px;
  222. font-weight: bold;
  223. color: #2f4378;
  224. }
  225. .rightBoxs {
  226. display: flex;
  227. align-items: center;
  228. img {
  229. width: 14px;
  230. height: 14px;
  231. margin-left: 13px;
  232. cursor: pointer;
  233. }
  234. }
  235. }
  236. }
  237. .el-dialog__footer {
  238. padding: 0;
  239. .dialog-footer {
  240. padding: 0px 40px;
  241. height: 70px;
  242. border-top: 1px solid #e2e2e2;
  243. display: flex;
  244. align-items: center;
  245. justify-content: flex-end;
  246. }
  247. }
  248. }
  249. .imgBox {
  250. width: 100%;
  251. // height: 210px;
  252. border: 1px solid #e2e2e2;
  253. border-radius: 8px;
  254. padding: 8px 8px 3px;
  255. display: flex;
  256. flex-direction: column;
  257. align-items: center;
  258. .imgLabel {
  259. flex: 1;
  260. width: 100%;
  261. border: 1px dotted #e2e2e2;
  262. color: #999;
  263. font-size: 14px;
  264. cursor: pointer;
  265. border-radius: 8px;
  266. .msPhoto {
  267. display: flex;
  268. justify-content: center;
  269. align-items: center;
  270. max-width: 100%;
  271. max-height: 270px;
  272. img {
  273. max-width: 100%;
  274. max-height: 270px;
  275. }
  276. }
  277. .imgbbx {
  278. display: flex;
  279. flex-direction: column;
  280. align-items: center;
  281. justify-content: center;
  282. width: 100%;
  283. height: 100%;
  284. i {
  285. font-weight: bold;
  286. margin: 14px 0;
  287. font-size: 24px;
  288. }
  289. }
  290. }
  291. p {
  292. margin: 5px 0px;
  293. }
  294. }
  295. .dis_fs {
  296. display: flex;
  297. align-items: center;
  298. justify-content: center;
  299. width: 337.5px;
  300. height: 144px;
  301. border: 1px solid #999;
  302. .imgBoxs {
  303. width: 100%;
  304. height: 100%;
  305. }
  306. }
  307. .styPsty {
  308. margin-top: 10px;
  309. display: flex;
  310. align-items: center;
  311. .btns {
  312. border: 1px solid #999;
  313. font-size: 12px;
  314. height: 28px;
  315. line-height: 28px;
  316. padding: 0px 10px;
  317. border-radius: 4px;
  318. cursor: pointer;
  319. margin-right: 10px;
  320. flex-shrink: 0;
  321. }
  322. }
  323. </style>