<template>
    <el-dialog :title="typeTitle" :visible.sync="dialogCarVisible" width="500px" class="dialog-info">
        <div class="info-wrp">
            <div class="title"></div>
            <div class="info-item">
                <span>充值金额：</span>
                <!-- <span v-show="actionType=='check'">{{ info.money }}</span> -->
                <span>
                    <el-input placeholder="充值金额" v-model="info.money" size="small" style="width: 200px;" />
                </span>
            </div>
            <div class="info-item">
                <span>赠送金额：</span>
                <!-- <span v-show="actionType=='check'">{{ info.gift_money }}</span> -->
                <span>
                    <el-input placeholder="赠送金额" v-model="info.gift_money" size="small" style="width: 200px;" />
                </span>
            </div>
            <div class="info-item">
                <span>ID：</span>
                <!-- <span v-show="actionType=='check'">{{ info.id }}</span> -->
                <span>
                    <el-input placeholder="ID" v-model="info.id" size="small" style="width: 200px;" />
                </span>
            </div>
            <div class="info-item"> 
                <span>是否启用：</span>
                <!-- <span v-show="actionType=='check'">{{ info.status==1 ? '已启用' : '未启用' }}</span> -->
                <span>
                    <el-radio-group v-model="info.status">
                        <el-radio label='1'>已启用</el-radio>
                        <el-radio label='0'>未启用</el-radio>
                    </el-radio-group>
                </span>
            </div>
            <!-- <div class="info-item" v-show="bike.putStatus==1">
                <span>投放区域：</span>
                <span v-show="actionType=='check'">{{ bike.manageAreaName }}</span>
                <span v-show="actionType!='check'">
                    <el-select v-model="bike.manageAreaId" size="small" placeholder="请选择" style="width: 200px;">
                        <el-option v-for="item in $root.regionOptions" :key="item.id" :label="item.name" :value="item.id"/>
                    </el-select>
                </span>
            </div> -->
            <div class="info-item">
                <span>开始时间：</span>
                <!-- <span v-show="actionType=='check'" v-dateformat="info.startDate"></span> -->
                <span>
                    <el-date-picker v-model="info.start_time" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss">
                    </el-date-picker>
                </span>
            </div>
            <div class="info-item">
                <span>结束时间：</span>
                <!-- <span v-show="actionType=='check'" v-dateformat="info.create_time"></span> -->
                <span>
                    <el-date-picker v-model="info.create_time" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss">
                    </el-date-picker>
                </span>
            </div>
            <div class="btn-group">
                <el-row>
                    <el-button size=small @click="dialogCarVisible = false">取消</el-button>
                    <el-button size=small type="primary" @click="update">保存</el-button>
                    <!-- <el-button size=small type="primary" @click="addBike">确定</el-button> -->
                </el-row>
            </div>
        </div>
    </el-dialog>
</template>

<script>
    import SelectPlace from '@/components/SelectPlace'
    import api from '@/api/recharge'
    export default {
        name: "user-details",
        components: {
            SelectPlace
        },
        filters: {
            // troubleFilter(status) {
            //     let troubleMap = ['无故障', '有故障']
            //     return troubleMap[status]
            // }
        },
        data() {
            return {
                dialogCarVisible: false,
                info: {
                    money: "",
                    giftMoney: "",
                    manageAreaId: "",
                    startDate: "",
                    endDate: "",
                    id: "",
                    status:""
                },
                typeTitle: '修改配置'
            }
        },
        methods: {
            open(data) {
                console.log('open')
                console.log(data)
                this.dialogCarVisible = true
                if(data) {
                    console.log(data)
                    this.info = data
                    console.log(this.info)
                } else {
                    this.info = {
                    money: "",
                    giftMoney: "",
                    manageAreaId: "",
                    startDate: "",
                    endDate: "",
                    id: "",
                    status:""
                }
                }
            },
            // setCode(code) {
            //     console.log(code)
            //     this.bike.putArea = code
            //     // const arr = code.split(',')
            //     // this.bike.provinceCode = arr[0]
            //     // this.bike.cityCode = arr[1]
            //     // this.bike.areaCode = arr[2]
            //     // console.log(code)
            // },
            addBike() {
                api.addBike(this.info).then(res => {
                    console.log(res)
                    this.$message({
                        type: 'success',
                        message: '添加成功!'
                    });
                    this.dialogCarVisible = false
                    this.info = {
                    money: "",
                    giftMoney: "",
                    manageAreaId: "",
                    startDate: "",
                    endDate: "",
                    id: "",
                    status:""
                }
                    this.$emit('updateList')
                }).catch(err => {
                    console.log(err)
                })
            },
            update() {
                api.chargeUpdate(this.info).then(res => {
                    console.log(res)
                    this.$message({
                        type: 'success',
                        message: '修改成功!'
                    });
                    this.dialogCarVisible = false
                    this.$emit('updateList')
                }).catch(err => {
                    console.log(err)
                })
            }
        },
        created() {
            // console.log(this.type)
        }
    }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
    .dialog-info {
        top: -5vh;
    }
    .info-wrp {
        margin-top: -50px;
        .info-item {
            margin-left: 20px;
            margin-bottom: 10px;
            span:first-child {
                display: inline-block;
                width: 85px;
                text-align: right;
            }
        }
        .title {
            font-size: 16px;
            margin: 20px 0 10px;
            padding-top: 20px;
            border-top: 1px solid #ccc;
        }
        .btn-group {
            text-align: center;
            margin-top: 20px;
        }
    }
</style>
