应用层PC端前端服务

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /**
  2. * 基础菜单 商品管理
  3. */
  4. <template>
  5. <div>
  6. <!-- 面包屑导航 -->
  7. <el-breadcrumb separator-class="el-icon-arrow-right">
  8. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  9. <el-breadcrumb-item>商品管理</el-breadcrumb-item>
  10. </el-breadcrumb>
  11. <!-- 搜索筛选 -->
  12. <el-form :inline="true" :model="formInline" class="user-search">
  13. <el-form-item label="搜索:">
  14. <el-input size="small" v-model="formInline.deptName" placeholder="输入部门名称"></el-input>
  15. </el-form-item>
  16. <el-form-item label="">
  17. <el-input size="small" v-model="formInline.deptNo" placeholder="输入部门代码"></el-input>
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
  21. <el-button size="small" type="primary" icon="el-icon-plus" @click="handleEdit()">添加</el-button>
  22. </el-form-item>
  23. </el-form>
  24. <!--列表-->
  25. <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
  26. <el-table-column align="center" type="selection" width="60">
  27. </el-table-column>
  28. <el-table-column sortable prop="deptName" label="部门名称" width="300">
  29. </el-table-column>
  30. <el-table-column sortable prop="deptNo" label="部门代码" width="300">
  31. </el-table-column>
  32. <el-table-column sortable prop="editTime" label="修改时间" width="300">
  33. <template slot-scope="scope">
  34. <div>{{scope.row.editTime|timestampToTime}}</div>
  35. </template>
  36. </el-table-column>
  37. <el-table-column sortable prop="editUser" label="修改人" width="300">
  38. </el-table-column>
  39. <el-table-column align="center" label="操作" min-width="300">
  40. <template slot-scope="scope">
  41. <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
  42. <el-button size="mini" type="danger" @click="deleteUser(scope.$index, scope.row)">删除</el-button>
  43. </template>
  44. </el-table-column>
  45. </el-table>
  46. <!-- 分页组件 -->
  47. <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
  48. <!-- 编辑界面 -->
  49. <el-dialog :title="title" :visible.sync="editFormVisible" width="30%" @click="closeDialog">
  50. <el-form label-width="120px" :model="editForm" :rules="rules" ref="editForm">
  51. <el-form-item label="部门名称" prop="deptName">
  52. <el-input size="small" v-model="editForm.deptName" auto-complete="off" placeholder="请输入部门名称"></el-input>
  53. </el-form-item>
  54. <el-form-item label="部门代码" prop="deptNo">
  55. <el-input size="small" v-model="editForm.deptNo" auto-complete="off" placeholder="请输入部门代码"></el-input>
  56. </el-form-item>
  57. </el-form>
  58. <div slot="footer" class="dialog-footer">
  59. <el-button size="small" @click="closeDialog">取消</el-button>
  60. <el-button size="small" type="primary" :loading="loading" class="title" @click="submitForm('editForm')">保存</el-button>
  61. </div>
  62. </el-dialog>
  63. </div>
  64. </template>
  65. <script>
  66. import { deptList, deptSave, deptDelete } from '../../api/userMG'
  67. import Pagination from '../../components/Pagination'
  68. export default {
  69. data() {
  70. return {
  71. nshow: true, //switch开启
  72. fshow: false, //switch关闭
  73. loading: false, //是显示加载
  74. editFormVisible: false, //控制编辑页面显示与隐藏
  75. title: '添加',
  76. editForm: {
  77. deptId: '',
  78. deptName: '',
  79. deptNo: '',
  80. token: localStorage.getItem('logintoken')
  81. },
  82. // rules表单验证
  83. rules: {
  84. deptName: [
  85. { required: true, message: '请输入部门名称', trigger: 'blur' }
  86. ],
  87. deptNo: [{ required: true, message: '请输入部门代码', trigger: 'blur' }]
  88. },
  89. formInline: {
  90. page: 1,
  91. limit: 10,
  92. varLable: '',
  93. varName: '',
  94. token: localStorage.getItem('logintoken')
  95. },
  96. // 删除部门
  97. seletedata: {
  98. ids: '',
  99. token: localStorage.getItem('logintoken')
  100. },
  101. userparm: [], //搜索权限
  102. listData: [], //用户数据
  103. // 分页参数
  104. pageparm: {
  105. currentPage: 1,
  106. pageSize: 10,
  107. total: 10
  108. }
  109. }
  110. },
  111. // 注册组件
  112. components: {
  113. Pagination
  114. },
  115. /**
  116. * 数据发生改变
  117. */
  118. /**
  119. * 创建完毕
  120. */
  121. created() {
  122. this.getdata(this.formInline)
  123. },
  124. /**
  125. * 里面的方法只有被调用才会执行
  126. */
  127. methods: {
  128. // 获取公司列表
  129. getdata(parameter) {
  130. this.loading = true
  131. // 模拟数据开始
  132. let res = {
  133. code: 0,
  134. msg: null,
  135. count: 5,
  136. data: [
  137. {
  138. addUser: null,
  139. editUser: null,
  140. addTime: 1521062371000,
  141. editTime: 1526700200000,
  142. deptId: 2,
  143. deptName: 'XX分公司',
  144. deptNo: '1',
  145. parentId: 1
  146. },
  147. {
  148. addUser: null,
  149. editUser: null,
  150. addTime: 1521063247000,
  151. editTime: 1526652291000,
  152. deptId: 3,
  153. deptName: '上海测试',
  154. deptNo: '02',
  155. parentId: 1
  156. },
  157. {
  158. addUser: null,
  159. editUser: null,
  160. addTime: 1526349555000,
  161. editTime: 1526349565000,
  162. deptId: 12,
  163. deptName: '1',
  164. deptNo: '11',
  165. parentId: 1
  166. },
  167. {
  168. addUser: null,
  169. editUser: null,
  170. addTime: 1526373178000,
  171. editTime: 1526373178000,
  172. deptId: 13,
  173. deptName: '5',
  174. deptNo: '5',
  175. parentId: 1
  176. },
  177. {
  178. addUser: null,
  179. editUser: null,
  180. addTime: 1526453107000,
  181. editTime: 1526453107000,
  182. deptId: 17,
  183. deptName: 'v',
  184. deptNo: 'v',
  185. parentId: 1
  186. }
  187. ]
  188. }
  189. this.loading = false
  190. this.listData = res.data
  191. this.pageparm.currentPage = this.formInline.page
  192. this.pageparm.pageSize = this.formInline.limit
  193. this.pageparm.total = res.count
  194. // 模拟数据结束
  195. /***
  196. * 调用接口,注释上面模拟数据 取消下面注释
  197. */
  198. // deptList(parameter)
  199. // .then(res => {
  200. // this.loading = false
  201. // if (res.success == false) {
  202. // this.$message({
  203. // type: 'info',
  204. // message: res.msg
  205. // })
  206. // } else {
  207. // this.listData = res.data
  208. // // 分页赋值
  209. // this.pageparm.currentPage = this.formInline.page
  210. // this.pageparm.pageSize = this.formInline.limit
  211. // this.pageparm.total = res.count
  212. // }
  213. // })
  214. // .catch(err => {
  215. // this.loading = false
  216. // this.$message.error('菜单加载失败,请稍后再试!')
  217. // })
  218. },
  219. // 分页插件事件
  220. callFather(parm) {
  221. this.formInline.page = parm.currentPage
  222. this.formInline.limit = parm.pageSize
  223. this.getdata(this.formInline)
  224. },
  225. // 搜索事件
  226. search() {
  227. this.getdata(this.formInline)
  228. },
  229. //显示编辑界面
  230. handleEdit: function(index, row) {
  231. this.editFormVisible = true
  232. if (row != undefined && row != 'undefined') {
  233. this.title = '修改'
  234. this.editForm.deptId = row.deptId
  235. this.editForm.deptName = row.deptName
  236. this.editForm.deptNo = row.deptNo
  237. } else {
  238. this.title = '添加'
  239. this.editForm.deptId = ''
  240. this.editForm.deptName = ''
  241. this.editForm.deptNo = ''
  242. }
  243. },
  244. // 编辑、增加页面保存方法
  245. submitForm(editData) {
  246. this.$refs[editData].validate(valid => {
  247. if (valid) {
  248. deptSave(this.editForm)
  249. .then(res => {
  250. this.editFormVisible = false
  251. this.loading = false
  252. if (res.success) {
  253. this.getdata(this.formInline)
  254. this.$message({
  255. type: 'success',
  256. message: '公司保存成功!'
  257. })
  258. } else {
  259. this.$message({
  260. type: 'info',
  261. message: res.msg
  262. })
  263. }
  264. })
  265. .catch(err => {
  266. this.editFormVisible = false
  267. this.loading = false
  268. this.$message.error('公司保存失败,请稍后再试!')
  269. })
  270. } else {
  271. return false
  272. }
  273. })
  274. },
  275. // 删除公司
  276. deleteUser(index, row) {
  277. this.$confirm('确定要删除吗?', '信息', {
  278. confirmButtonText: '确定',
  279. cancelButtonText: '取消',
  280. type: 'warning'
  281. })
  282. .then(() => {
  283. deptDelete(row.deptId)
  284. .then(res => {
  285. if (res.success) {
  286. this.$message({
  287. type: 'success',
  288. message: '公司已删除!'
  289. })
  290. this.getdata(this.formInline)
  291. } else {
  292. this.$message({
  293. type: 'info',
  294. message: res.msg
  295. })
  296. }
  297. })
  298. .catch(err => {
  299. this.loading = false
  300. this.$message.error('公司删除失败,请稍后再试!')
  301. })
  302. })
  303. .catch(() => {
  304. this.$message({
  305. type: 'info',
  306. message: '已取消删除'
  307. })
  308. })
  309. },
  310. // 关闭编辑、增加弹出框
  311. closeDialog() {
  312. this.editFormVisible = false
  313. }
  314. }
  315. }
  316. </script>
  317. <style scoped>
  318. .user-search {
  319. margin-top: 20px;
  320. }
  321. .userRole {
  322. width: 100%;
  323. }
  324. </style>