Usermanage.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <div class="table">
  3. <div class="crumbs">
  4. <el-breadcrumb separator="/">
  5. <el-breadcrumb-item><i class="el-icon-lx-cascades"></i> 用户管理</el-breadcrumb-item>
  6. </el-breadcrumb>
  7. </div>
  8. <div class="container">
  9. <div class="handle-box">
  10. <el-button type="primary" icon="add" @click="addUser">新增用户</el-button>
  11. </div>
  12. <div class="handle-box">
  13. <!-- <el-select v-model="status" placeholder="状态" class="handle-select mr10">
  14. <el-option key="" label="全部" value=""></el-option>
  15. <el-option key="1" label="上架" value="1"></el-option>
  16. <el-option key="2" label="下架" value="0"></el-option>
  17. </el-select> -->
  18. <el-input v-model="goodsName" placeholder="商品名称" class="handle-input mr10"></el-input>
  19. <el-button type="primary" icon="search" @click="getDataList">查询</el-button>
  20. </div>
  21. <dptable :columns="columns" :dataSource="tableData" :options="options" :fetch="getDataList" :pagination="pagination" @row-click="handleRowClick" @selection-change="handleSelectionChange"/>
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. import dptable from '../../common/Dptable'
  27. export default {
  28. components: {
  29. dptable
  30. },
  31. data(){
  32. return {
  33. //=>>需要自己根据业务进行修改
  34. // 访问数据的地址
  35. url: '/api/goodsManage/showGoodsList',
  36. delurl: '/api/goodsManage/deleteGoods',
  37. // 检索条件
  38. goodsName: '',
  39. // status: '',
  40. // 数据列的定义
  41. columns: [
  42. {
  43. prop: 'goodsId', label: '商品ID', width: 60
  44. // render: (row) => {
  45. // if (row.status == 0) {
  46. // return (
  47. // <span style="color: blue" >{row.goodsId}</span>
  48. // );
  49. // } else {
  50. // return (
  51. // <span>{row.goodsId}</span>
  52. // );
  53. // }
  54. // }
  55. },
  56. {
  57. text: true, prop: 'goodsName', label: '商品名称', align: 'left', width: 300
  58. // render: (row, index) => {
  59. // return (
  60. // <span style="color: blue" onClick={e => this.handleClick(e, row)}>{row.title}</span>
  61. // )
  62. // }
  63. },
  64. {
  65. prop: 'goodsTypeId', label: '类型ID', align: 'right', width: 160, formatter: (row, column) => {
  66. return Number(row[column.prop]).toFixed(2);
  67. }
  68. },
  69. {
  70. prop: 'createDate', label: '发布时间', width: 200, formatter: (row, column) => {
  71. // 自行添加数据格式化操作
  72. var date = row[column.prop];//row.createDate;
  73. if (date == undefined) {
  74. return "";
  75. }
  76. return this.$moment(date).format("YYYY-MM-DD HH:mm:ss");
  77. }
  78. },
  79. {
  80. prop: 'status', label: '状态', width: 60, formatter: (row, column) => {
  81. // 自行添加数据格式化操作
  82. return row[column.prop] == 1 ? '上架' : '下架';// row.status == 1 ? '上架' : '下架';
  83. // if(row.status == 1){
  84. // return row.status == '上架';
  85. // }else if(row.status == 0){
  86. // return row.status == '下架';
  87. // }
  88. }
  89. },
  90. {
  91. button: true, label: '操作',
  92. group: [{
  93. // you can props => type size icon disabled plain
  94. name: '编辑',
  95. type: 'warning',
  96. icon: 'el-icon-edit',
  97. plain: true,
  98. onClick: (row, index) => { // 箭头函数写法的 this 代表 Vue 实例
  99. console.log(row, index);
  100. this.enditRow(row.goodsId);
  101. }
  102. },
  103. {
  104. name: '删除',
  105. type: 'danger',
  106. icon: 'el-icon-delete',
  107. disabled: false,
  108. onClick: row => {
  109. console.log(row);
  110. this.deleteRow(row.goodsId);
  111. }
  112. // onClick(row) { // 这种写法的 this 代表 group 里的对象
  113. // this.disabled = true;
  114. // console.log(this);
  115. // }
  116. }]
  117. }
  118. //=>>需要自己根据业务进行修改
  119. ],
  120. tableData: [
  121. ],
  122. pagination: {
  123. resultCount: 0,
  124. currentPage: 1,
  125. pageSize: 20
  126. },
  127. options: {
  128. mutiSelect: true,// 是否有前部的多选框
  129. index: false, // 显示序号, 多选则 mutiSelect
  130. initTable: true, // 是否一挂载就加载数据
  131. }
  132. }
  133. },
  134. methods: {
  135. handleClick(e, row){
  136. //transform-vue-jsx 的nativeOnClick 失效 , 所以采用 event.cancelBubble 控制点击事件的冒泡... 如果点击事件不影响你的点击行事件,可以不传
  137. e.cancelBubble = true // 停止冒泡,否则会触发 row-click
  138. console.log(row)
  139. },
  140. getDataList() {
  141. this.options.loading = true;
  142. const querystring = require('querystring');
  143. this.$axios.post(this.url, querystring.stringify({
  144. //goodsId: "1",
  145. // status: this.status,
  146. goodsName: this.goodsName,
  147. pageSize: this.pagination.pageSize,
  148. currentPage: this.pagination.currentPage
  149. })).then(res => {
  150. console.log(res);
  151. const { list, page } = res.data;
  152. this.tableData = res.data.list;
  153. this.pagination.resultCount = page.resultCount;
  154. this.pagination.currentPage = page.currentPage;
  155. this.options.loading = false;
  156. }).catch((error) => {
  157. console.log(error)
  158. this.options.loading = false
  159. })
  160. },
  161. handleRowClick(row, event, column){ // 点击行的事件,同理可以绑定其他事件
  162. console.log('click row:',row, event, column)
  163. },
  164. handleSelectionChange(selection){
  165. console.log(selection)
  166. },
  167. addUser() {
  168. this.$router.push({
  169. path: '/admin/updateuser',
  170. params: {
  171. id: 1
  172. }
  173. })
  174. },
  175. // 编辑行
  176. enditRow(key) {
  177. this.$router.push({
  178. path: '/admin/updateuser',
  179. query: {
  180. goodsId: key
  181. }
  182. });
  183. //this.getDataList();
  184. },
  185. // 删除行
  186. deleteRow(key) {
  187. const querystring = require('querystring');
  188. this.$axios.post(this.delurl, querystring.stringify({
  189. goodsId: key
  190. })).then(res => {
  191. console.log(res);
  192. if (res.data.rtnCode == 0) {
  193. this.$message.success("删除成功!");
  194. } else {
  195. this.$message.error(res.data.rtnMsg);
  196. }
  197. this.getDataList();
  198. }).catch((error) => {
  199. console.log(error)
  200. this.$message.error("数据处理异常,请与管理员联系!");
  201. })
  202. }
  203. }
  204. }
  205. </script>
  206. <style scoped>
  207. .handle-box {
  208. margin-bottom: 20px;
  209. }
  210. .handle-select {
  211. width: 120px;
  212. }
  213. .handle-input {
  214. width: 300px;
  215. display: inline-block;
  216. }
  217. .del-dialog-cnt{
  218. font-size: 16px;
  219. text-align: center
  220. }
  221. .table{
  222. width: 100%;
  223. font-size: 14px;
  224. }
  225. .red{
  226. color: #ff0000;
  227. }
  228. .mr10{
  229. margin-right: 10px;
  230. }
  231. </style>