Explorar el Código

59 照片商品管理

loki hace 3 años
padre
commit
a67bbb6ce4

+ 9 - 0
src/components/BaseTable.vue

@@ -47,6 +47,15 @@
                   }}
                 </el-tag>
               </span>
+              <span v-else-if="column.type === 'switch'">
+                <el-switch
+                  :value="scope.row[column.key]"
+                  :active-text="column.switchName[0]"
+                  :inactive-text="column.switchName[1]"
+                  @change="column.api(scope.row)"
+                >
+                </el-switch>
+              </span>
               <span v-else>{{ scope.row[column.key] || '-' }}</span>
             </template>
           </el-table-column>

+ 32 - 9
src/views/photoManagement/imageGoodsManagement/index.vue

@@ -15,7 +15,7 @@
 <script>
 import toolbar from './toolbar';
 import mxFilterList from '@/mixins/filterList';
-import { getPage, delItem } from '@/api/photoWarehouse';
+import { getPage, delItem, updateItem } from '@/api/photoWarehouse';
 
 export default {
   name: 'ImageGoodsManagement',
@@ -116,10 +116,21 @@ export default {
         {
           key: 'isBeautiful',
           name: '精选',
-          width: this.$col.s,
-          type: 'tag',
-          fetchTagType: val => (val ? 'success' : 'info'),
-          tagName: row => (row.isBeautiful ? '是' : '否')
+          width: this.$col.m,
+          type: 'switch',
+          switchName: ['是', '否'],
+          api: async row => {
+            console.log(row);
+            row.isBeautiful = !row.isBeautiful;
+            const { success } = await updateItem(row);
+            if (success) {
+              this.$success('修改成功!');
+            }
+            this.$g_emit('photo_reload');
+          }
+          // type: 'tag',
+          // fetchTagType: val => (val ? 'success' : 'info'),
+          // tagName: row => (row.isBeautiful ? '是' : '否')
         },
         {
           key: 'isTake',
@@ -132,10 +143,22 @@ export default {
         {
           key: 'isShow',
           name: '状态',
-          width: this.$col.s,
-          type: 'tag',
-          fetchTagType: val => (val ? 'success' : 'info'),
-          tagName: row => (row.isShow ? '上架' : '下架')
+          width: this.$col.b,
+          type: 'switch',
+          switchName: ['上架', '下架'],
+          api: async row => {
+            console.log(row);
+            row.isShow = !row.isShow;
+            const { success } = await updateItem(row);
+            if (success) {
+              this.$success('修改成功!');
+            }
+            this.$g_emit('photo_reload');
+          }
+          // width: this.$col.s,
+          // type: 'tag',
+          // fetchTagType: val => (val ? 'success' : 'info'),
+          // tagName: row => (row.isShow ? '上架' : '下架')
         },
         {
           key: 'action',