<template>
  <div class="quickBuy">
    <div class="head-title">
        服务列表
        <el-button @click="CommonJump('goodsServicesEdit')" style="float:right;margin-top: -5px;margin-left:20px;" size="small" type="primary">添加服务</el-button>
    </div>
    <div class="content">
        <div>
            <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>
            <el-select size="small" @change="getList" v-model="msg.IsDefault" placeholder="请选择">
                <el-option label="不限" :value="0"></el-option>
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="2"></el-option>
            </el-select>
            
        </div>
        <el-table
            :data="tableData"
            v-loading="loading"
            border
            style="width: 100%;margin:20px 0">
            <el-table-column
            prop="Id"
            width="80"
            label="ID">
            </el-table-column>
            <el-table-column
            prop="Name"
            label="服务名称">
            </el-table-column>
            <el-table-column
            prop="Remark"
            label="备注">
            </el-table-column>
            <el-table-column
            prop="address"
            label="是否默认">
                <template slot-scope="scope">
                    <el-switch
                    @change="Edit(scope.row,1)"
                    v-model="scope.row.IsDefault"
                    active-color="#409EFF"
                    :active-value="1"
                    :inactive-value="0">
                </el-switch>
                </template>  
            </el-table-column>
            <el-table-column
            prop="address"
            label="排序">
                <template slot-scope="scope">
                    <template v-if="!scope.row.editState">
                        <span>{{scope.row.Sort}}</span>
                        <img @click="scope.row.editState=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.editState=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="UpdateDate"
            width="150"
            label="添加日期">
            </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{
            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:{
        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/GetProductServicePageList", 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.editState=false;
                    })
                    this.tableData=pageData;
                }
                
            })
        },
    },
};
</script>

<style>

.quickBuy .content .searchInput{
    border: 1px solid #DCDFE6;
    border-radius: 4px;
}
.quickBuy .content .searchInput .el-input__inner{
    border:none;outline:none;
    height: 30px;
    line-height: 30px;
}
.quickBuy .content .searchInput{
    line-height: normal;
    display: inline-table;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    width:250px;
    margin-right: 20px;
}
.quickBuy .content{
    background: #fff;
    margin-top:10px;
    padding: 20px;
    box-sizing: border-box;
}
</style>
