goods-list.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <div class="app-list-content">
  3. <cl-crud class="liu-crud-wrap" @load="onLoad">
  4. <template #slot-tabs="{ scope }">
  5. <el-tabs class="liu-tabs" type="border-card">
  6. <el-tab-pane label="全部"></el-tab-pane>
  7. <el-tab-pane label="上架"></el-tab-pane>
  8. <el-tab-pane label="下架"></el-tab-pane>
  9. </el-tabs>
  10. </template>
  11. <template #table-column-avatarUrl="{scope}">
  12. <div>
  13. <img :src="scope.row.imgList" alt />
  14. </div>
  15. </template>
  16. <template #table-column-goodsName="{scope}">
  17. <span>{{ scope.row.goodsName }}</span>
  18. <!-- <span>二维码</span> -->
  19. <span @click="openLinkFn(scope.row.shortUrl)">链接</span>
  20. </template>
  21. <!-- 添加商品 -->
  22. <template #slot-add-goods-btn="{scope}">
  23. <el-button type="primary" size="mini" @click="addFn">添加</el-button>
  24. </template>
  25. <!-- 状态 -->
  26. <template #table-column-status="{scope}">
  27. <span>{{ scope.row.status == 1 ? '上架' : '下架' }}</span>
  28. </template>
  29. <!-- 修改 -->
  30. <template #slot-modify="{scope}">
  31. <el-button type="text">修改</el-button>
  32. </template>
  33. <!-- 下架 -->
  34. <template #slot-takeOff="{scope}">
  35. <el-button type="text" @click="downFn(scope.row)">下架</el-button>
  36. </template>
  37. </cl-crud>
  38. <!-- 添加商品 -->
  39. <el-dialog title="商品短链接:" :visible.sync="dialogFormVisible" width="40%">
  40. <div>
  41. <el-input v-model="sortLink" :disabled="true"></el-input>
  42. </div>
  43. <div slot="footer" class="dialog-footer">
  44. <el-button @click="dialogFormVisible = false">取 消</el-button>
  45. <el-button type="primary" @click="dialogFormVisible = false">发到手机</el-button>
  46. </div>
  47. </el-dialog>
  48. </div>
  49. </template>
  50. <script>
  51. export default {
  52. data() {
  53. return {
  54. dialogFormVisible: false,
  55. sortLink: ''
  56. };
  57. },
  58. methods: {
  59. // 打开链接
  60. openLinkFn(link) {
  61. this.sortLink = link || '';
  62. this.dialogFormVisible = true;
  63. },
  64. // 添加商品
  65. addFn() {
  66. this.$router.push('/goods/add');
  67. },
  68. downFn(item) {
  69. this.$confirm('是否下架该商品?', '提示', {
  70. confirmButtonText: '确定',
  71. cancelButtonText: '取消',
  72. type: 'warning'
  73. })
  74. .then(() => {
  75. this.$service.goods
  76. .changeStatus({
  77. id: item.id,
  78. status: item.status == 0 ? 1 : 0
  79. })
  80. .then(res => {
  81. item.status = item.status == 0 ? 1 : 0;
  82. this.$message.success('操作成功!');
  83. });
  84. })
  85. .catch(() => {
  86. this.$message({
  87. type: 'info',
  88. message: '已取消删除'
  89. });
  90. });
  91. },
  92. // cl-crud 组件
  93. onLoad({ ctx, app }) {
  94. ctx.service(this.$service.goods)
  95. .set('table', {
  96. columns: [
  97. {
  98. prop: 'id',
  99. label: 'ID',
  100. align: 'center'
  101. },
  102. {
  103. prop: 'avatarUrl',
  104. label: '封面',
  105. align: 'center'
  106. },
  107. {
  108. prop: 'goodsName',
  109. label: '标题',
  110. align: 'center'
  111. },
  112. {
  113. prop: 'mobile',
  114. label: '顺序',
  115. align: 'center'
  116. },
  117. {
  118. prop: 'price',
  119. label: '价格',
  120. align: 'center',
  121. emptyText: '无',
  122. 'min-width': 150
  123. },
  124. {
  125. prop: 'actualSold',
  126. label: '销量',
  127. align: 'center'
  128. },
  129. {
  130. prop: 'viewNum',
  131. label: '浏览量',
  132. align: 'center'
  133. },
  134. {
  135. prop: 'status',
  136. label: '状态',
  137. align: 'center'
  138. },
  139. {
  140. prop: 'createDate',
  141. label: '创建时间',
  142. align: 'center'
  143. }
  144. ],
  145. // 操作列
  146. op: {
  147. visible: true, // 是否显示
  148. // 同 element-ui Table-column Attributes
  149. props: {
  150. width: 150,
  151. align: 'center',
  152. fixed: 'right',
  153. label: '操作'
  154. },
  155. // 布局,请移步 `layout`
  156. layout: ['slot-modify', 'slot-takeOff']
  157. }
  158. })
  159. .set('layout', [
  160. ['slot-tabs'],
  161. ['search-key', 'flex1', 'refresh-btn', 'slot-add-goods-btn'],
  162. ['data-table'],
  163. ['flex1', 'pagination']
  164. ])
  165. .done();
  166. app.refresh({ status: 0 });
  167. }
  168. }
  169. };
  170. </script>