index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <template>
  2. <div id="dict">
  3. <search-box :formList="formList" @search="search" @init="init" />
  4. <table-list
  5. :tableSets="tableSet"
  6. :tableData="tableData"
  7. :navText="navText"
  8. @addClick="addClick"
  9. :loading="loading"
  10. >
  11. <template slot="btn" slot-scope="props">
  12. <el-button type="text" @click="addClick(props.scope.row, 2)"
  13. >详情</el-button
  14. >
  15. <el-button type="text" @click="addClick(props.scope.row, 0)"
  16. >修改</el-button
  17. >
  18. <el-button type="text" @click="del(props.scope.row)">删除</el-button>
  19. </template>
  20. </table-list>
  21. <pagination
  22. :total="total"
  23. :pageSize="pageSize"
  24. :currentPage="currentPage"
  25. @handleSizeChange="handleSizeChange"
  26. @handleCurrentChange="handleCurrentChange"
  27. />
  28. <el-dialog
  29. :visible.sync="dialogVisible"
  30. width="560px"
  31. :show-close="false"
  32. :close-on-click-modal="false"
  33. >
  34. <div slot="title" class="hearders">
  35. <div class="leftTitle">
  36. {{ statusPop === 1 ? "添加" : statusPop === 0 ? "修改" : "详情" }}
  37. </div>
  38. <div class="rightBoxs">
  39. <img src="@/assets/images/Close@2x.png" alt="" @click="close" />
  40. </div>
  41. </div>
  42. <div>
  43. <el-form
  44. label-position="right"
  45. label-width="80px"
  46. :model="listData"
  47. :rules="rules"
  48. ref="listData"
  49. >
  50. <el-form-item
  51. v-for="(items, indexs) in listitem"
  52. :key="indexs"
  53. :label="items.label"
  54. :prop="items.prop"
  55. >
  56. <el-radio-group
  57. v-if="items.scope === 'status'"
  58. v-model="listData[items.prop]"
  59. >
  60. <el-radio
  61. v-for="(item, index) in items.options"
  62. :key="index"
  63. :label="item.value"
  64. :disabled="statusPop === 2"
  65. >{{ item.label }}</el-radio
  66. >
  67. </el-radio-group>
  68. <el-input
  69. :disabled="statusPop === 2"
  70. v-else-if="items.scope === 'textarea'"
  71. type="textarea"
  72. v-model="listData[items.prop]"
  73. ></el-input>
  74. <el-input
  75. :disabled="statusPop === 2"
  76. v-else
  77. v-model="listData[items.prop]"
  78. ></el-input>
  79. </el-form-item>
  80. </el-form>
  81. </div>
  82. <span slot="footer" class="dialog-footer">
  83. <el-button @click="close">取 消</el-button>
  84. <el-button
  85. type="primary"
  86. v-if="statusPop !== 2"
  87. @click="submit('listData')"
  88. >确 定</el-button
  89. >
  90. </span>
  91. </el-dialog>
  92. </div>
  93. </template>
  94. <script>
  95. import searchBox from "@/components/searchBox";
  96. import tableList from "@/components/tableList";
  97. import pagination from "@/components/pagination";
  98. export default {
  99. components: { searchBox, tableList, pagination },
  100. data() {
  101. return {
  102. loading: false, //当前表单加载是否加载动画
  103. navText: {
  104. title: "字典类型",
  105. index: 0,
  106. ch: "条",
  107. num: false,
  108. choice: true,
  109. addHide: false,
  110. backFatherBtn: {
  111. status: false,
  112. title: "未定义",
  113. },
  114. },
  115. tableSet: [
  116. {
  117. label: "字典编号",
  118. prop: "dictId",
  119. hidden: true,
  120. },
  121. {
  122. label: "字典名称",
  123. prop: "dictName",
  124. hidden: true,
  125. },
  126. {
  127. label: "字典类型",
  128. prop: "dictType",
  129. hidden: true,
  130. scope: "jumpPage",
  131. },
  132. {
  133. label: "状态",
  134. prop: "status",
  135. hidden: true,
  136. scope: "status",
  137. },
  138. {
  139. label: "备注",
  140. prop: "remark",
  141. hidden: true,
  142. },
  143. ], //表头信息
  144. tableData: [], //表单数据
  145. total: 0, //一共多少条
  146. pageSize: 10, //每页多少条数据
  147. currentPage: 1, //当前页码
  148. formList: [
  149. {
  150. label: "字典名称",
  151. prop: "dictName",
  152. placeholder: "请输入字典名称",
  153. },
  154. {
  155. label: "字典类型",
  156. prop: "dictType",
  157. placeholder: "请输入字典类型",
  158. },
  159. {
  160. label: "状态",
  161. prop: "status",
  162. placeholder: "请选择状态",
  163. scope: "select",
  164. options: [
  165. {
  166. label: "启用",
  167. value: 1,
  168. },
  169. {
  170. label: "停用",
  171. value: 0,
  172. },
  173. ],
  174. },
  175. ], //搜索
  176. listitem: [
  177. {
  178. label: "字典名称",
  179. prop: "dictName",
  180. },
  181. {
  182. label: "字典类型",
  183. prop: "dictType",
  184. },
  185. {
  186. label: "状态",
  187. prop: "status",
  188. scope: "status",
  189. options: [
  190. {
  191. label: "启用",
  192. value: "1",
  193. },
  194. {
  195. label: "关闭",
  196. value: "0",
  197. },
  198. ],
  199. },
  200. {
  201. label: "备注",
  202. prop: "remark",
  203. scope: "textarea",
  204. },
  205. ],
  206. statusPop: -1,
  207. dialogVisible: false,
  208. listData: {},
  209. rules: {
  210. dictName: [
  211. { required: true, message: "请输入字典名称", trigger: "blur" },
  212. {
  213. min: 2,
  214. max: 10,
  215. message: "长度在 2 到 10 个字符",
  216. trigger: "blur",
  217. },
  218. ],
  219. dictType: [
  220. { required: true, message: "请输入字典类型", trigger: "blur" },
  221. ],
  222. status: [{ required: true, message: "请选择状态", trigger: "change" }],
  223. remark: [{ required: true, message: "请填写备注", trigger: "blur" }],
  224. },
  225. };
  226. },
  227. mounted() {
  228. this.search();
  229. },
  230. methods: {
  231. search(v) {
  232. console.log(v);
  233. if (v === undefined) {
  234. v = {
  235. statusArray: "0,1",
  236. pageSize: this.pageSize,
  237. pageNum: this.currentPage,
  238. };
  239. }
  240. var data = {
  241. dictName: v.dictName || "",
  242. dictType: v.dictType || "",
  243. statusArray: v.status === undefined ? "0,1" : v.status,
  244. pageSize: this.pageSize,
  245. pageNum: this.currentPage,
  246. };
  247. this.loading = true;
  248. this.$api
  249. .obtaindicttype(data)
  250. .then((res) => {
  251. this.tableData = res.rows;
  252. this.total = res.total;
  253. this.navText.index = res.total;
  254. this.loading = false;
  255. })
  256. .catch((err) => {
  257. this.loading = false;
  258. });
  259. },
  260. init() {
  261. this.search();
  262. },
  263. del(v) {
  264. this.$confirm("此操作将删除该字典类型, 是否继续?", "提示", {
  265. confirmButtonText: "确定",
  266. cancelButtonText: "取消",
  267. type: "warning",
  268. })
  269. .then(() => {
  270. var data = JSON.parse(JSON.stringify(v));
  271. data.status = "-1";
  272. this.$api.editdicttype(data).then((res) => {
  273. this.$message.success("删除成功");
  274. this.search();
  275. this.dialogVisible = false;
  276. });
  277. })
  278. .catch(() => {
  279. this.$message({
  280. type: "info",
  281. message: "已取消删除",
  282. });
  283. });
  284. },
  285. addClick(v, int) {
  286. if (v === undefined) {
  287. this.statusPop = 1;
  288. this.listData = {};
  289. } else {
  290. this.statusPop = int;
  291. var data = v.dictId;
  292. this.$api.getdicttype(data).then((res) => {
  293. this.listData = res.data;
  294. });
  295. }
  296. this.dialogVisible = true;
  297. },
  298. submit(formName) {
  299. this.$refs[formName].validate((valid) => {
  300. if (valid) {
  301. this.rulesTableSumbit();
  302. } else {
  303. return false;
  304. }
  305. });
  306. },
  307. rulesTableSumbit() {
  308. if (this.statusPop === 1) {
  309. this.$api.adddicttype(this.listData).then((res) => {
  310. this.$message.success("新增成功");
  311. this.dialogVisible = false;
  312. this.search();
  313. });
  314. }
  315. if (this.statusPop === 0) {
  316. this.$api.editdicttype(this.listData).then((res) => {
  317. this.$message.success("修改成功");
  318. this.dialogVisible = false;
  319. this.search();
  320. });
  321. }
  322. },
  323. close() {
  324. this.dialogVisible = false;
  325. },
  326. handleSizeChange(v) {
  327. this.pageSize = v;
  328. this.currentPage = 1;
  329. this.search();
  330. },
  331. handleCurrentChange(v) {
  332. this.currentPage = v;
  333. this.search();
  334. },
  335. },
  336. };
  337. </script>
  338. <style lang="less" scoped>
  339. /deep/.el-button {
  340. border-radius: 8px;
  341. }
  342. /deep/.el-dialog {
  343. border-radius: 8px;
  344. .el-dialog__header {
  345. padding: 0;
  346. .hearders {
  347. height: 40px;
  348. display: flex;
  349. align-items: center;
  350. justify-content: space-between;
  351. padding: 0px 18px 0px 20px;
  352. border-bottom: 1px solid #e2e2e2;
  353. .leftTitle {
  354. font-size: 14px;
  355. font-weight: bold;
  356. color: #2f4378;
  357. }
  358. .rightBoxs {
  359. display: flex;
  360. align-items: center;
  361. img {
  362. width: 14px;
  363. height: 14px;
  364. margin-left: 13px;
  365. cursor: pointer;
  366. }
  367. }
  368. }
  369. }
  370. .el-dialog__footer {
  371. padding: 0;
  372. .dialog-footer {
  373. padding: 0px 40px;
  374. height: 70px;
  375. border-top: 1px solid #e2e2e2;
  376. display: flex;
  377. align-items: center;
  378. justify-content: flex-end;
  379. }
  380. }
  381. }
  382. .imgBox {
  383. width: 100%;
  384. // height: 210px;
  385. border: 1px solid #e2e2e2;
  386. border-radius: 8px;
  387. padding: 8px 8px 3px;
  388. display: flex;
  389. flex-direction: column;
  390. align-items: center;
  391. .imgLabel {
  392. flex: 1;
  393. width: 100%;
  394. border: 1px dotted #e2e2e2;
  395. color: #999;
  396. font-size: 14px;
  397. cursor: pointer;
  398. border-radius: 8px;
  399. .msPhoto {
  400. display: flex;
  401. justify-content: center;
  402. align-items: center;
  403. max-width: 100%;
  404. max-height: 270px;
  405. img {
  406. max-width: 100%;
  407. max-height: 270px;
  408. }
  409. }
  410. .imgbbx {
  411. display: flex;
  412. flex-direction: column;
  413. align-items: center;
  414. justify-content: center;
  415. width: 100%;
  416. height: 100%;
  417. i {
  418. font-weight: bold;
  419. margin: 14px 0;
  420. font-size: 24px;
  421. }
  422. }
  423. }
  424. p {
  425. margin: 5px 0px;
  426. }
  427. }
  428. </style>