<template>
  <div class="goodsList">
    <div class="head-title">
        商品列表
        <el-button style="float:right;margin-top: -5px;margin-left:20px;" size="small" type="primary">商品导出</el-button>
        <el-button @click="CommonJump('goodsServicesEdit')" style="float:right;margin-top: -5px;margin-left:20px;" size="small" type="primary">添加商品</el-button>
        <el-button style="float:right;margin-top: -5px;margin-left:20px;" size="small" type="primary">更新所有商品销量</el-button>

    </div>
    <div class="content">
        <div>
            <el-tabs v-model="activeName" @tab-click="handleClick">
                <el-tab-pane :dataId="0" label="全部" name="first"></el-tab-pane>
                <el-tab-pane label="上架中" name="second"></el-tab-pane>
                <el-tab-pane label="下架中" name="third"></el-tab-pane>
                <el-tab-pane label="售罄" name="fourth"></el-tab-pane>
            </el-tabs>
        </div>
        <div>
            <el-button style="margin-right:20px;" size="small">分类筛选</el-button>
            <span>添加时间：</span>
            <el-date-picker
            v-model="msg.val"
            @change="getList"
            size="small"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
            </el-date-picker>
            <div class="searchInput" style="width:250px">
                <el-input style="display:inline-block;width:225px;height:30px"
                placeholder="请输入名称搜索"
                v-model="msg.Name"
                @clear="getList"
                size="small"
                clearable>
                </el-input>
                <span @click="getList" class="el-icon-search" style="color:#979dad;font-size:14px;position:relative;top:1px"></span>
            </div>
            <span class='blue point'>清空筛选条件</span>
        </div>
        <div style="margin-top:15px">
            <el-button style="margin-left:10px;" size="mini">上架</el-button>
            <el-button style="margin-left:10px;" size="mini">下架</el-button>
            <el-button style="margin-left:10px;" size="mini">删除</el-button>
            <el-button style="margin-left:10px;" size="mini">批量设置</el-button>

        </div>
        <el-table
            :data="tableData"
            v-loading="loading"
            border
            style="width: 100%;margin:20px 0">
            <el-table-column
            type="selection"
            width="55">
            </el-table-column>
            <el-table-column
            prop="Id"
            width="80"
            sortable
            label="ID">
            </el-table-column>
            <el-table-column
            prop="address"
            sortable
            label="排序">
                <template slot-scope="scope">
                    <template v-if="!scope.row.editsort">
                        <span>{{scope.row.Sort}}</span>
                        <img @click="scope.row.editsort=true,scope.row.SortNew=scope.row.Sort" style="width:15px;height:15px;margin-left:7px" src="../../assets/img/userman/edit1.png" alt="">
                    </template>
                    <template v-else>
                        <el-input v-model="scope.row.SortNew" type="number" min="1" size="small" style="display:inline-block;width:150px"></el-input>
                        <span @click="scope.row.editsort=false" class="el-icon-error" style="color: rgb(245, 108, 108);"></span>
                        <span @click="Edit(scope.row,2)" class="el-icon-success" style="color:#67c23a"></span>
                    </template>
                </template>  
            </el-table-column>
            <el-table-column
            prop="Remark"
            label="分类">
                <template slot-scope="scope">
                    <el-tag size="mini" v-for="(item,index) in scope.row.CategoryList" :key="index">{{item.CategoryName}}</el-tag>
                </template>
            </el-table-column>
            <el-table-column
            prop="address"
            width="300"
            label="商品名称">
                <template slot-scope="scope">
                    <div flex="box:first">
                        <img style="width:50px;height:50px;margin-right:1px" :src="domainManager().ImageUrl+scope.row.CoverImage" alt="">
                        <template v-if="!scope.row.editname">
                            <div flex="cross:top" style="display:inline-flex">
                                <div flex="dir:left" >
                                    <el-tooltip class="item" effect="dark" :content="scope.row.Name" placement="top">
                                        <div class="vue-line-clamp" style="word-break: break-all; -webkit-line-clamp: 2;">
                                            <span>{{scope.row.Name}}</span>
                                        </div>
                                    </el-tooltip>
                                    <img @click="scope.row.editname=true,scope.row.NameNew=scope.row.Name" style="width:15px;height:15px;margin-left:7px" src="../../assets/img/userman/edit1.png" alt="">
                                </div>
                            </div>
                        </template>
                        <template v-else>
                            <el-input v-model="scope.row.NameNew" type="number" min="1" size="small" style="display:inline-block;width:150px"></el-input>
                            <span @click="scope.row.editname=false" class="el-icon-error" style="color: rgb(245, 108, 108);"></span>
                            <span @click="Edit(scope.row,2)" class="el-icon-success" style="color:#67c23a"></span>
                        </template>
                    </div>
                    
                </template>  
            </el-table-column>
            <el-table-column
            prop="SellingPrice"
            width="100"
            sortable
            label="售价">
            </el-table-column>
            <el-table-column
            prop="InventoryNum"
            width="100"
            sortable
            label="库存">
            </el-table-column>
            <el-table-column
            prop="SalesNum"
            width="105"
            sortable
            label="已出售量">
            </el-table-column>
            <el-table-column
            prop="UpdateDate"
            width="110"
            label="是否加入快速购买">
                <template slot-scope="scope">
                    <el-switch
                        @change="Edit(scope.row,1)"
                        v-model="scope.row.IsQuickBuy"
                        active-color="#409EFF"
                        :active-value="1"
                        :inactive-value="0">
                    </el-switch>
                </template>  
            </el-table-column>
            <el-table-column
            prop="CreateDate"
            width="150"
            label="添加时间">
            </el-table-column>
            <el-table-column
            prop="UpdateDate"
            width="100"
            label="状态">
                <template slot-scope="scope">
                    <el-tag v-if="scope.row.GoodsStatus==1" type="success">销售中</el-tag>
                    <el-tag v-if="scope.row.GoodsStatus==2" type="warning">下架中</el-tag>
                </template>  
            </el-table-column>
            <el-table-column
            prop="address"
            width="200"
            label="操作">
            <template slot-scope="scope">
                <img @click="Delete(scope.row)" style="width:32px;height:32px;margin:0 10px" src="../../assets/img/userman/edit.png" alt="">
                <img @click="Delete(scope.row)" style="width:32px;height:32px;margin:0 10px" src="../../assets/img/userman/del.png" alt="">
            </template>    
            </el-table-column>
        </el-table>
        <el-pagination style="text-align:right"
        background
        @current-change="handleCurrentChange"
        :page-size="msg.pageSize"
        layout="prev, pager, next"
        :total="total">
        </el-pagination>
    </div>
        
  </div>
</template>

<script>
export default {
    name: "quickBuy",
    data(){
        return{
            activeName:'first',
            editState:false,
            msg:{
                pageIndex:1,
                pageSize:15,
                Name:'',
                IsDefault:0,
            },
            total:0,
            tableData:[],
            loading:false,
            addMsg:{
                Id:0,
                Sort:'',
                Name:'',
                IsDefault:1,
                Remark:'',
                UpdateType:1,
            },
            rules:{
                CategoryIdNew: [
                    { required: true, message: '分类不能为空', trigger: 'change' }
                ],
                Sort: [
                    { required: true, message: '请输入排序', trigger: 'blur' }
                ],
            },
            msg1:{
                Id:0,
                Name:'',
                Tier:0,
                ParentId:0,
                Enabled:1,
                IsShow:1,
            },

        }
    },
    created(){
        this.getList();

    },
    methods:{
        handleClick(val){
            this.msg.AuditStatus=val.$attrs.dataId;
        },
        Delete(item){
            let that=this;
            that.$confirm('是否删除?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.apipost('/api/product/DelProductServiceInfo',{ServiceId:item.Id},
                    res => {
                    if (res.data.resultCode === 1) {
                        this.getList();
                        this.Success(res.data.message)

                    } else {
                        this.Error(res.data.message);
                    }
                    },
                    null
                );
            }).catch(() => {
                
            });
        },
        Edit(row,num){
            let addMsg=row;
            addMsg.Sort=addMsg.SortNew;
            addMsg.UpdateType=num;
            this.apipost('/api/product/SetProductServiceInfo',addMsg,
                res => {
                if (res.data.resultCode === 1) {
                    this.getList();
                    this.Success(res.data.message)

                } else {
                    this.Error(res.data.message);
                }
                },
                null
            );

        },
        
        handleCurrentChange(val) {
            this.msg.pageIndex = val;
            this.getList();
        },
        getList(){
            this.loading=true;
            this.apipost("/api/product/GetProductGoodsPageList", this.msg, res => {
                this.loading=false;
                if(res.data.resultCode==1){
                    this.total=res.data.data.count;
                    let pageData=res.data.data.pageData;
                    pageData.forEach(item=>{
                        item.SortNew=item.Sort;
                        item.NameNew=item.Name;
                        item.editsort=false;
                        item.editname=false;
                    })
                    this.tableData=pageData;
                }
                
            })
        },
    },
};
</script>

<style>
.goodsList .vue-line-clamp {
    display: block;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}
.goodsList .content{
    background: #fff;
    margin-top:10px;
    padding: 20px;
    box-sizing: border-box;
}
</style>
