f5da83a2791c56dd3e60a504fec076f9fef13868.svn-base 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <template>
  2. <el-row :gutter="5" style="margin-top:5px;margin-left:5px;">
  3. <el-col :span="5">
  4. <el-card class="box-card">
  5. <div slot="header" class="clearfix" style="text-align: right; ">
  6. <el-row :gutter="2" style="margin-top:5px; margin-left:5px;">
  7. <el-col :span="12" style="text-align: left; vertical-align:middle; font-size: 20px"> <span>字典分类 </span></el-col>
  8. <el-col :span="6"> <el-col :span="6"> <el-button type="warning" icon="el-icon-edit" size="mini" @click="jump" /></el-col>
  9. </el-col>
  10. <el-col :span="6"> <el-button type="primary" icon="el-icon-refresh" size="mini" /></el-col>
  11. </el-row>
  12. </div>
  13. <div class="component-item">
  14. <el-tree
  15. ref="tree"
  16. class="filter-tree"
  17. :data="parent"
  18. :props="defaultProps"
  19. default-expand-all
  20. @node-click="handleNodeClick"
  21. />
  22. </div>
  23. </el-card>
  24. </el-col>
  25. <el-col :span="19">
  26. <div class="app-container">
  27. <div class="filter-container">
  28. <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">
  29. 新增
  30. </el-button>
  31. </div>
  32. <el-table
  33. v-loading="listLoading"
  34. element-loading-text="给我一点时间"
  35. :data="list"
  36. border
  37. fit
  38. highlight-current-row
  39. style="width: 100%;"
  40. :row-style="rowStyle"
  41. :cell-style="cellStyle"
  42. class="elTable"
  43. row-key="id"
  44. default-expand-all
  45. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  46. >
  47. <el-table-column label="名称" header-align="center" width="150px" align="center">
  48. <template slot-scope="scope">
  49. <span>{{ scope.row.label }}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="值" min-width="150px" header-align="center" align="center">
  53. <template slot-scope="scope">
  54. <span>{{ scope.row.value }}</span>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="顺序" min-width="150px" header-align="center" align="center">
  58. <template slot-scope="scope">
  59. <span>{{ scope.row.orderby }}</span>
  60. </template>
  61. </el-table-column>
  62. <!-- <el-table-column label="是否牧场" min-width="150px" header-align="center" align="center">
  63. <template slot-scope="scope">
  64. <el-switch
  65. v-model="scope.row.isPasture"
  66. :active-value="1"
  67. :inactive-value="0"
  68. @change="handleEnableChange(scope.$index, scope.row)"
  69. />
  70. </template>
  71. </el-table-column> -->
  72. <el-table-column label="启用" min-width="150px" header-align="center" align="center">
  73. <template slot-scope="scope">
  74. <el-switch
  75. v-model="scope.row.enable"
  76. active-color="#13ce66"
  77. inactive-color="#ff4949"
  78. :active-value="1"
  79. :inactive-value="0"
  80. @change="handleEnableChange(scope.$index, scope.row)"
  81. />
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="操作" header-align="center" align="center" width="260" class-name="small-padding fixed-width" fixed="right">
  85. <template slot-scope="{row}">
  86. <el-button type="primary" size="mini" @click="handleUpdate(row)">
  87. 编辑
  88. </el-button>
  89. <el-button v-if="row.status!='已删'" size="mini" type="danger" @click="handleDelete(row)">
  90. 删除
  91. </el-button>
  92. </template>
  93. </el-table-column>
  94. </el-table>
  95. <pagination v-show="total>=0" :total="total" :page.sync="getdataListParm.offset" :limit.sync="getdataListParm.pagecount" @pagination="getList" />
  96. <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
  97. <el-form
  98. ref="dataForm"
  99. v-enterToNext="true"
  100. :rules="rules"
  101. :model="deptform"
  102. label-position="left"
  103. label-width="100px"
  104. style="width: 600px; margin-left:50px;"
  105. >
  106. <el-form-item label="名称" prop="label">
  107. <el-input
  108. ref="label"
  109. v-model="deptform.label"
  110. />
  111. </el-form-item>
  112. <el-form-item label="值" prop="value">
  113. <el-input
  114. ref="value"
  115. v-model="deptform.value"
  116. />
  117. </el-form-item>
  118. <el-form-item label="顺序" prop="orderby">
  119. <el-input
  120. ref="orderby"
  121. v-model="deptform.orderby"
  122. />
  123. </el-form-item>
  124. <!-- <el-form-item label="是否牧场" prop="isPasture">
  125. <el-input
  126. ref="isPasture"
  127. v-model="deptform.isPasture"
  128. />
  129. </el-form-item> -->
  130. <el-form-item label="启用" prop="enable">
  131. <el-switch
  132. ref="enable"
  133. v-model="deptform.enable"
  134. active-color="#13ce66"
  135. inactive-color="#ff4949"
  136. :active-value="1"
  137. :inactive-value="0"
  138. />
  139. </el-form-item>
  140. </el-form>
  141. <div slot="footer" class="dialog-footer">
  142. <el-button
  143. v-if="dialogStatus==='create'"
  144. ref="createb"
  145. type="success"
  146. @click="createData_again()"
  147. >
  148. 确认新增
  149. </el-button>
  150. <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
  151. 确认
  152. </el-button>
  153. <el-button @click="dialogFormVisible = false">
  154. 关闭
  155. </el-button>
  156. </div>
  157. </el-dialog>
  158. </div>
  159. </el-col>
  160. </el-row>
  161. </template>
  162. <script>
  163. import waves from '@/directive/waves' // waves directive
  164. import enterToNext from '@/directive/enterToNext' // enterToNext directive
  165. import { PostDataByName, GetDataByName, getRecuData } from '@/api/common'
  166. import { isIntegerZero } from '@/utils/validate'
  167. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  168. import { MessageBox } from 'element-ui'
  169. export default {
  170. name: 'Dict',
  171. components: { Pagination },
  172. directives: { waves, enterToNext },
  173. data() {
  174. return {
  175. defaultProps: {
  176. children: 'children',
  177. label: 'name'
  178. },
  179. dictid: 0,
  180. list: [],
  181. total: 0,
  182. listLoading: true,
  183. requestParam: {
  184. name: '',
  185. params: []
  186. },
  187. deptform: {
  188. label: '',
  189. value: '',
  190. orderby: '',
  191. enable: '',
  192. pid: ''
  193. },
  194. getdataListParm: { name: 'getDictList',
  195. offset: 1,
  196. pagecount: 8,
  197. params: [] },
  198. getRecuListParm: { name: 'getDictclass',
  199. idname: 'id',
  200. params: [-1] },
  201. rules: {
  202. label: [{ type: 'string', required: true, message: '名称必填', trigger: 'change' }],
  203. value: [{ type: 'string', required: true, message: '只必填', trigger: 'change' }],
  204. orderby: [{ validator: isIntegerZero, trigger: 'blur' }]
  205. },
  206. dialogFormVisible: false,
  207. parentDeptVisible: true,
  208. dialogStatus: '',
  209. textMap: {
  210. update: '编辑',
  211. create: '新增'
  212. },
  213. parent: [],
  214. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  215. cellStyle: { padding: 0 + 'px' }
  216. }
  217. },
  218. created() {
  219. this.getList()
  220. },
  221. methods: {
  222. jump() {
  223. this.$router.push('/console/menu')
  224. // 传递的参数用{{ $route.query.goodsId }}获取
  225. // this.$router.push({ path: '/cart?goodsId=12' })
  226. // this.$router.go(-2)
  227. // 后退两步
  228. },
  229. handleNodeClick(data) {
  230. if (data.children.length === 0) {
  231. this.listLoading = true
  232. this.dictid = data.id
  233. this.getdataListParm.params = [data.id, data.id]
  234. GetDataByName(this.getdataListParm).then(response => {
  235. this.list = response.data.list
  236. this.total = response.data.total
  237. // Just to simulate the time of the request
  238. setTimeout(() => {
  239. this.listLoading = false
  240. }, 100)
  241. })
  242. }
  243. },
  244. getDownList() {
  245. getRecuData(this.getRecuListParm).then(response => {
  246. this.parent = response.data
  247. })
  248. },
  249. getList() {
  250. this.listLoading = true
  251. this.getDownList()
  252. GetDataByName(this.getdataListParm).then(response => {
  253. this.list = response.data.list
  254. this.total = response.data.total
  255. setTimeout(() => {
  256. this.listLoading = false
  257. }, 100)
  258. })
  259. },
  260. resetRequestParam() {
  261. this.deptform.id = ''
  262. this.deptform.pid = ''
  263. this.deptform.label = ''
  264. this.deptform.value = ''
  265. this.deptform.orderby = '0'
  266. this.deptform.enable = '1'
  267. },
  268. handleCreate() {
  269. this.resetRequestParam()
  270. this.dialogStatus = 'create'
  271. this.deptform.orderby = '0'
  272. this.deptform.enable = 1
  273. this.dialogFormVisible = true
  274. this.$nextTick(() => {
  275. this.$refs['dataForm'].clearValidate()
  276. this.$refs['label'].focus()
  277. })
  278. },
  279. createData() {
  280. this.$refs['dataForm'].validate((valid) => {
  281. if (valid) {
  282. this.requestParam.name = 'insertDictList'
  283. this.requestParam.params = []
  284. this.requestParam.params[0] = this.deptform.label
  285. this.requestParam.params[1] = this.deptform.value
  286. this.requestParam.params[2] = this.deptform.orderby
  287. this.requestParam.params[3] = this.deptform.enable
  288. this.requestParam.params[4] = this.dictid
  289. PostDataByName(this.requestParam).then(() => {
  290. this.getList()
  291. this.dialogFormVisible = false
  292. this.$notify({
  293. title: '成功',
  294. message: '新增成功',
  295. type: 'success',
  296. duration: 2000
  297. })
  298. })
  299. }
  300. })
  301. },
  302. createData_again() {
  303. this.$refs['dataForm'].validate((valid) => {
  304. if (valid) {
  305. this.requestParam.name = 'insertDictList'
  306. this.requestParam.params = []
  307. this.requestParam.params[0] = this.deptform.label
  308. this.requestParam.params[1] = this.deptform.value
  309. this.requestParam.params[2] = this.deptform.orderby
  310. this.requestParam.params[3] = this.deptform.enable
  311. this.requestParam.params[4] = this.dictid
  312. PostDataByName(this.requestParam).then(() => {
  313. this.$nextTick(() => {
  314. this.$refs['label'].focus()
  315. })
  316. this.getList()
  317. this.resetRequestParam()
  318. this.deptform.orderby = '0'
  319. this.deptform.enable = 1
  320. this.$notify({
  321. title: '成功',
  322. message: '新增成功',
  323. type: 'success',
  324. duration: 2000
  325. })
  326. })
  327. }
  328. })
  329. },
  330. handleUpdate(row) {
  331. this.deptform.id = row.id
  332. this.deptform.label = row.label
  333. this.deptform.value = row.value
  334. this.deptform.orderby = row.orderby
  335. this.deptform.enable = row.enable
  336. this.deptform.pid = row.pid
  337. this.dialogStatus = 'update'
  338. this.dialogFormVisible = true
  339. this.$nextTick(() => {
  340. this.$refs['dataForm'].clearValidate()
  341. this.$refs['label'].focus()
  342. })
  343. },
  344. updateData() {
  345. this.$refs['dataForm'].validate((valid) => {
  346. if (valid) {
  347. this.requestParam.name = 'updateDictList'
  348. this.requestParam.params = []
  349. this.requestParam.params[0] = this.deptform.label
  350. this.requestParam.params[1] = this.deptform.value
  351. this.requestParam.params[2] = this.deptform.orderby
  352. this.requestParam.params[3] = this.deptform.enable
  353. this.requestParam.params[4] = this.dictid
  354. this.requestParam.params[5] = this.deptform.id
  355. PostDataByName(this.requestParam).then(() => {
  356. this.getList()
  357. this.resetRequestParam()
  358. this.dialogFormVisible = false
  359. this.$notify({
  360. title: '成功',
  361. message: '修改成功',
  362. type: 'success',
  363. duration: 2000
  364. })
  365. })
  366. }
  367. })
  368. },
  369. handleEnableChange(index, row) {
  370. this.requestParam.name = 'updateDictList'
  371. this.requestParam.params = []
  372. this.requestParam.params[0] = row.label
  373. this.requestParam.params[1] = row.value
  374. this.requestParam.params[2] = row.orderby
  375. this.requestParam.params[3] = row.enable
  376. this.requestParam.params[4] = this.dictid
  377. this.requestParam.params[5] = row.id
  378. PostDataByName(this.requestParam).then(() => {
  379. this.$notify({
  380. title: '成功',
  381. message: '修改成功',
  382. type: 'success',
  383. duration: 2000
  384. })
  385. })
  386. },
  387. handleDelete(row) {
  388. MessageBox.confirm('名称:' + row.label, '确认删除?', {
  389. confirmButtonText: '确认',
  390. cancelButtonText: '取消',
  391. type: 'warning'
  392. }).then(() => {
  393. this.requestParam.name = 'deleteDictList'
  394. this.requestParam.params = []
  395. this.requestParam.params[0] = row.id
  396. PostDataByName(this.requestParam).then(() => {
  397. this.getList()
  398. this.resetRequestParam()
  399. this.dialogFormVisible = false
  400. this.$notify({
  401. title: '成功',
  402. message: '删除成功',
  403. type: 'success',
  404. duration: 2000
  405. })
  406. })
  407. }).catch(() => {
  408. this.$message({
  409. type: 'info',
  410. message: '已取消删除'
  411. })
  412. })
  413. }
  414. }
  415. }
  416. </script>