家政小程序
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.4KB

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