家政小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.vue 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <style lang="less">
  2. @import '../../styles/common.less';
  3. .ivu-card-head {
  4. p {
  5. height: 32px;
  6. line-height: 32px;
  7. }
  8. button {
  9. float: right;
  10. }
  11. }
  12. .ivu-table-cell img {
  13. width: 100%;
  14. }
  15. </style>
  16. <template>
  17. <div>
  18. <Row class="margin-top-10" v-show="proShow">
  19. <Col>
  20. <Card>
  21. <p slot="title">
  22. <Icon type="android-remove"></Icon>
  23. 分类信息
  24. <Button type="primary" @click="add">新增</Button>
  25. </p>
  26. <div class="edittable-table-height-con">
  27. <Table :columns="columns" :data="prosHandle"></Table>
  28. <Page :total="total" :page-size="pageSize" @on-change="getData"></Page>
  29. </div>
  30. </Card>
  31. </Col>
  32. </Row>
  33. <edit v-show="editShow" @pub-success="pubSuccess" :form-content="formContent"></edit>
  34. </div>
  35. </template>
  36. <script>
  37. import edit from "./edit";
  38. export default {
  39. name: 'product',
  40. components: {
  41. edit
  42. },
  43. computed: {
  44. editShow() {
  45. return !this.proShow;
  46. },
  47. prosHandle() {
  48. let products = [].concat(JSON.parse(JSON.stringify(this.products)));
  49. console.log(products);
  50. return products;
  51. }
  52. },
  53. data () {
  54. return {
  55. total: 0,
  56. pageSize: 20,
  57. proShow: true,
  58. formContent: {},
  59. columns: [
  60. {title: "分类名称", key: 'name', align: 'center'},
  61. {title: "描述信息", key: 'info', align: 'center'},
  62. {title: "服务标题", key: 'server', align: 'center'},
  63. {title: "图片位置", key: 'photo', align: 'center',
  64. render: (h, params) => {
  65. console.log(params);
  66. return h('img', {
  67. attrs: {
  68. src: params.row.photo
  69. }
  70. })
  71. }
  72. },
  73. {title: "显示位置", key: 'location', align: 'center'},
  74. {
  75. title: "操作",
  76. key: "action",
  77. align: 'center',
  78. render: (h, params) => {
  79. return h('div', [
  80. h('Button', {
  81. props: {
  82. type: 'primary',
  83. size: 'default'
  84. },
  85. style: {
  86. marginRight: '5px'
  87. },
  88. on: {
  89. click: () => {
  90. let id = params.row.id;
  91. this.proShow = false;
  92. this.products.forEach((product) => {
  93. if (product.id == id) {
  94. this.formContent = product;
  95. }
  96. })
  97. }
  98. }
  99. }, '修改'),
  100. h('Button', {
  101. props: {
  102. type: 'error',
  103. size: 'default'
  104. },
  105. style: {
  106. marginRight: '5px'
  107. },
  108. on: {
  109. click: () => {
  110. let id = params.row.id;
  111. this.axios.delete(`/classify/${id}`)
  112. .then((res) => {
  113. this.products = this.products.filter((product) => {
  114. if (product.id != id) {
  115. return true;
  116. }
  117. });
  118. });
  119. }
  120. }
  121. }, '删除')
  122. ]);
  123. }
  124. }
  125. ],
  126. products: []
  127. };
  128. },
  129. methods: {
  130. add () {
  131. this.proShow = false;
  132. this.formContent = {};
  133. },
  134. pubSuccess() {
  135. this.proShow = true;
  136. this.getData();
  137. },
  138. getData (num) {
  139. this.axios.get("/classifies", {
  140. params: {
  141. page: num || 1
  142. }
  143. }).then((res) => {
  144. this.products = res.data.data;
  145. this.pageSize = res.data.per_page;
  146. this.total = res.data.total;
  147. });
  148. }
  149. },
  150. created () {
  151. this.getData();
  152. }
  153. };
  154. </script>