<config>
{
    "navigationBarTitleText": "填写维修记录",
}
</config>
<template>
    <div class="container">
        <div class="box-bottom">
            <van-field :border="false" label="维修描述" readonly> </van-field>
            <van-field
                :value="form.content"
                @input="form.content = $event.detail"
                :border="false"
                rows="1"
                autosize
                type="textarea"
                placeholder="请对维修情况进行适当的描述"
            />
        </div>
        <van-cell-group :border="false" class="form">
            <van-field label="图片上传" :border="false" readonly> </van-field>
            <van-uploader :file-list="images" :after-read="afterRead" @delete="deleteImg" />
        </van-cell-group>

        <div class="btn-list">
            <van-button :disabled="!canSubmit" type="default" @click="submit">提交</van-button>
        </div>
    </div>
</template>
<script>
import { mapState } from 'vuex';
export default {
    name: 'repairReport',
    metaInfo: {
        title: '申请报修'
    },
    data() {
        return {
            form: {
                phone: '',
                name: ''
            },
            images: [],
            imgBox: true
        };
    },
    computed: {
        ...mapState(['roomInfo']),
        canSubmit() {
            if (this.form.content && this.images.length != 0) {
                return true;
            } else {
                return false;
            }
        }
    },
    methods: {
        afterRead(file) {
            this.showLoading();
            this.$http
                .uploadFile(file.path)
                .then(res => {
                    this.imgBox = false;
                    this.hideLoading();
                    this.images = [
                        {
                            url: res
                        }
                    ];
                })
                .catch(e => {
                    this.hideLoading();
                    wx.showToast({
                        icon: 'none',
                        title: e.error
                    });
                });
        },
        deleteImg(e) {
            let list = [...this.images];
            list.splice(e.detail.index, 1);
            this.images = list;
        },
        submit() {}
    }
};
</script>
<style lang="less" scoped>
.container {
    /deep/ .van-uploader {
        padding-left: 18px;
    }
    /deep/.form {
        position: relative;

        .van-cell {
            --cell-vertical-padding: 18px;
            --cell-horizontal-padding: 18px;
            --field-label-color: #000000;
            --cell-text-color: #000;
            .van-field__label,
            .van-cell__title {
                font-weight: bold;
                font-size: 18px;
            }
            .van-cell__value {
                // text-align: left;
            }
            &::after {
                left: 100px !important;
            }
        }
    }
    .box-bottom {
        /deep/ .van-field__label {
            margin: 10px 0 0 2px;
            font-size: 18px;
            font-weight: bold;
            color: #000;
            /deep/ .van-field__body {
                margin-left: 3px !important;
                min-height: 200px !important;
                .van-field__input {
                    min-height: 200px !important;
                }
            }
        }
    }
    .btn-list {
        position: fixed;
        width: 100%;
        bottom: 0;
        background: #ffffff;
        padding-left: 43px;
        z-index: 999;
        .bottom();
        /deep/.van-button {
            width: 290px;
            height: 48px;
            background: rgba(255, 127, 31, 0.4);
            border-radius: 24px;
            line-height: 48px;
            text-align: center;
            font-size: 16px;
            font-weight: normal;
            color: #ffffff;
        }
    }
}
</style>
