9040769de5b70456c102d5c1d0235f2663820f8a.svn-base 14 KB

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