<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <style>
        [v-cloak] {
            display: none;
        }

        .layui-card-header {
            border-bottom-color: #b2b2b2;
        }

        .wq-radio-item {
            width: auto;
            background-color: #fff;
            padding: 2px 4px;
            border-radius: 15px;
            cursor: pointer;
            min-width: 50px;
            font-size: 12px;

        }

        .wq-upload {
            display: flex;
            gap: 6px;
            padding: 0 12px;
            height: 85px;
            line-height: 85px;
        }

        .wq-upload-item {
            position: relative;
            width: 30%;
            border: 1px dashed #a2a2a2;
            border-radius: 5px;
            text-align: center;
            overflow: hidden;
            cursor: pointer;
        }

        .wq-upload-icon {
            font-size: 26px;
            color: #a2a2a2;
            line-height: inherit;
        }

        .wq-radio-item:first-child {
            background-color: #FF2D70;
            color: #fff;
        }

        .form-cover {
            position: relative;
            width: 209px;
            height: 130px;
            border: 1px dashed #d9d9d9;
            text-align: center;
            border-radius: 13px;
            overflow: hidden;


            cursor: pointer;
        }

        .form-cover:hover {
            border-color: #09f;
        }

        .ws-radio-list {
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
            width: 90%;
            margin: 0 auto;
            max-height: 170px;
            overflow: hidden;
            overflow-y: auto;
            scrollbar-width: none;
        }

        .ws-radio-list::-webkit-scrollbar {
            display: none;
        }
    </style>
</head>
<body>
<div class="layui-fluid" id="app" v-cloak>

    @verbatim
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md6">
                <div class="layui-card">
                    <div class="layui-card-header">采集项：{{ nameForZh }}</div>
                    <div class="layui-card-body" style="max-height: 500px;overflow: auto;padding: 15px;">
                        <div class="layui-form " lay-filter="form">

                            <div class="layui-form-item" style="display: none;">
                                <label class="layui-form-label">采集项</label>
                                <div class="layui-input-block">
                                    <input class="layui-input layui-disabled" disabled v-model="data.name"/>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">标题</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" v-model="data.title" autocomplete="off" lay-verify="required"/>
                                </div>
                            </div>

                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">指引语</label>
                                <div class="layui-input-block">
                                    <textarea maxlength="200" style="padding-bottom: 15px; resize: none;overflow: auto;" placeholder="请输入内容" v-model="data.subTitle" autocomplete="off" lay-verify="required" class="layui-textarea"></textarea>
                                    <div id="wordCount" style="text-align:right; font-size: 12px; color: #999;position: absolute;  bottom: 0;  right: 25px;">{{data.subTitle.length}}
                                        /200
                                    </div>
                                </div>
                            </div>


                            <div class="layui-form-item layui-hide">
                                <label class="layui-form-label">是否开启</label>
                                <div class="layui-input-block">
                                    <input type="radio" lay-filter="show" name="show" value="1" title="开启" v-model="data.show"/>
                                    <input type="radio" lay-filter="show" name="show" value="0" title="关闭" v-model="data.show"/>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">是否必填</label>
                                <div class="layui-input-block">
                                    <input type="radio" lay-filter="skip" name="skip" value="0" title="必填" v-model="data.skip"/>
                                    <input type="radio" lay-filter="skip" name="skip" value="1" title="跳过" v-model="data.skip"/>
                                </div>
                            </div>


                            <div class="layui-form-item">
                                <label class="layui-form-label">封面</label>
                                <div class="layui-input-block">
                                    <a class="layui-btn layui-btn-sm layui-bg-blue" id="cover">上传</a>
                                    <div class="form-cover" style="display: none;">
                                        <i v-if="!data.cover" class="layui-icon layui-icon-addition" style="line-height: 130px;font-size: 26px;"></i>
                                        <img v-else lay-tips="点击更换封面" :src="data.cover" style="width: 209px;height: 130px;object-fit: cover;vertical-align:middle;"/>
                                    </div>
                                </div>
                            </div>


                            <div class="layui-form-item layui-hide">
                                <label class="layui-form-label">类型</label>
                                <div class="layui-input-inline">
                                    <select name="type" lay-filter="type" v-model="data.type">
                                        <option value="text">文本</option>
                                        <option value="longText">长文本</option>
                                        <option value="radio">选项</option>
                                        <option value="date">日期</option>
                                        <option value="image">视频/图片</option>
                                    </select>
                                </div>
                            </div>


                            <div class="layui-form-item" style="display:block;padding-left: 110px;">
                                <button class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
                                <a class="layui-btn layui-btn-primary" @click="back">返回</a>
                            </div>

                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-col-md6">
                <div class="layui-card">
                    <div class="layui-card-header">预览</div>
                    <div class="layui-card-body" style="margin: 0 auto;margin-top:10px;background-color: #E9EAEC;border-radius:37px; width: 231px;height: 500px;background-image: url('/static/img/iphone_x.png');background-repeat: round;">
                        <div style="padding-top: 55px; ">
                            <template v-if="data.show == 1">
                                <div style="text-align: center;">
                                    <img :src="data.cover" alt="请上传封面" :style="{border:data.cover?0:'1px solid #828282'}" style="width: 209px;height: 130px;border-radius: 13px;object-fit: cover;">
                                </div>
                                <div style="height: 56px;display: none;">
                                    <div style="font-size: 18px;padding-top:58px;text-align: center;">
                                        {{data.title}}
                                    </div>
                                    <div style="text-align: center;font-size: 12px;color: #a2a2a2;cursor: pointer;" v-if="data.skip == 1">
                                        跳过
                                    </div>
                                </div>
                                <div style="margin-top: 32px;text-align: center;">
                                    <div v-if="data.type == 'text'">
                                        <input style="font-size:14px;padding-left:12px;width: 80%;border: 1px solid #d2d2d2;height:38px;line-height:1.3;border-radius:19px;"/>
                                    </div>
                                    <div v-else-if="data.type == 'longText'">
                                        <textarea style="resize: none;font-size: 14px;width: 80%;height: 80px;"></textarea>
                                    </div>
                                    <div v-else-if="data.type == 'radio' || data.type == 'checkbox'">
                                        <div class="ws-radio-list">
                                            <div class="wq-radio-item" style="" v-for="(item, index) in data.data" :key="index">{{item}}</div>
                                        </div>
                                    </div>

                                    <div v-else-if="data.type == 'line'" style="text-align: left;padding-left: 15px;max-height: 170px;overflow: hidden;">
                                        <div v-for="(item, index) in data.data" :key="index">
                                            <input type="radio" :id="`line_${index}`" name="line" :title="item" checked v-if="index == 0"/>
                                            <input type="radio" :id="`line_${index}`" name="line" :title="item" v-else/>
                                            <label :for="'line_' + index" style="margin-left: 5px;">{{ item }}</label>
                                        </div>
                                    </div>
                                    <div v-if="data.type == 'line'">
                                        <input placeholder="输入社交账号" style="font-size:14px;padding-left:12px;width: 80%;border: 1px solid #d2d2d2;height:38px;line-height:1.3;border-radius:19px;"/>
                                    </div>
                                    <div v-else-if="data.type == 'date'">
                                        <input placeholder="选择日期" disabled style="cursor: pointer; font-size:14px;padding-left:12px;width: 80%;border: 1px solid #d2d2d2;height:38px;line-height:1.3;border-radius:19px;"/>
                                    </div>
                                    <div v-else-if="data.type == 'image'" class="wq-upload">
                                        <div class="wq-upload-item" style="width: 100%;height:116.4375px;line-height: 116.4375px;" title="点击上传视频">
                                            <i class="layui-icon layui-icon-video wq-upload-icon"></i>
                                        </div>
                                        <div class="wq-upload-item layui-hide">
                                            <i class="layui-icon layui-icon-picture-fine wq-upload-icon"></i>
                                        </div>
                                        <div class="wq-upload-item layui-hide">
                                            <i class="layui-icon layui-icon-picture-fine wq-upload-icon"></i>
                                        </div>
                                    </div>
                                    <div v-else-if="data.type == 'phone'" style="position: relative;">
                                        <input placeholder="请输入手机号" style="font-size:12px;margin-bottom: 5px; padding-left:12px;width: 80%;border: 1px solid #d2d2d2;height:38px;line-height:1.3;border-radius:19px;"/>
                                        <input placeholder="验证码" style="font-size:12px;padding-left:12px;width: 80%;border: 1px solid #d2d2d2;height:38px;line-height:1.3;border-radius:19px;"/>
                                        <div style="position:absolute;right: 25px;bottom: 8px;font-size: 12px;color: #FF2D70;">
                                            获取验证码
                                        </div>

                                    </div>
                                </div>

                                <div style="text-align: center;position: absolute;bottom: 40px;width:90%">
                                    <a class="layui-btn" style="width: 80%;border-radius: 8px;background-color: #FF2D70;">下一步</a>
                                </div>
                            </template>
                            <template v-else>
                                <div style="text-align: center;font-size: 18px;">暂无预览</div>
                            </template>
                        </div>
                    </div>
                </div>
            </div>
            @endverbatim
        </div>
</div>

<script src="/static/js/vue.js"></script>
<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index', 'table', 'dropdown'], function () {
        const $ = layui.$, form = layui.form, table = layui.table, upload = layui.upload,
            laydate = layui.laydate,
            layer = layui.layer;
        const {createApp} = Vue;


        layui.vue = createApp({
            data() {
                return {
                    city: [],
                    lang: "{{$lang}}",
                    data: {
                        id: "{{$id}}",
                        name: "{{$name}}",
                        title: "{{$title}}",
                        subTitle: `{{$subTitle}}`.replace(/&#039;/g, "'"),
                        cover: "{{$cover}}",
                        data: JSON.parse(atob(`{{$data}}`)),
                        skip: "{{$skip}}",
                        show: "{{$show}}",
                        type: `{{$type}}`,
                    }
                }
            },
            computed: {
                nameForZh() {
                    let zh = {
                        name: '姓名',
                        sex: '性别',
                        birthday: '生日',
                        city: '家庭地址',
                        occupation: '职业',
                        income: '年收入',
                        declaration: '恋爱宣言',
                        phone: '手机号',
                        tags: '标签',
                        line: '社交账号',
                        video: '视频'
                    };
                    return zh[this.data.name];
                },
            },
            mounted() {
                form.val('form', {
                    skip: this.data.skip,
                    show: this.data.show,
                    type: this.data.type,
                });
                form.on('select(type)', (data) => {
                    this.data.type = data.value;
                    setTimeout(() => {
                        form.render();
                    }, 10);
                });
                form.on('radio(skip)', (data) => {
                    this.data.skip = data.value;
                });
                form.on('radio(show)', (data) => {
                    this.data.show = data.value;
                });
                form.render();
                upload.render({
                    elem: '#cover',
                    url: '/upload-image',
                    field: "image",
                    data: {
                        _token: "{{ csrf_token() }}",
                    },
                    done: (res) => {
                        if (res.code === 0) {
                            this.data.cover = res.data.path;
                        } else {
                            layer.msg(res.msg, {icon: 5});
                        }
                    }

                });
                form.on('submit(submit)', (obj) => {
                    $.ajax({
                        url: "/user/setItem",
                        method: "post",
                        headers: {
                            'X-CSRF-TOKEN': "{{ csrf_token() }}",
                        },
                        data: {
                            lang: this.lang,
                            data: this.data
                        },
                        success: (res) => {
                            if (res.code === 0) {
                                layer.msg('保存成功');
                            } else {
                                layer.alert(res.msg);
                            }
                        }
                    })


                });

            },
            created() {
                const that = this;
            },
            methods: {


                addData() {
                    layer.prompt({title: '请输入文本'}, (value, index, elem) => {
                        if (value === '') return elem.focus();
                        this.data.data.push(value);
                        setTimeout(() => form.render(), 10);
                        layer.close(index);
                    });
                },
                back() {
                    window.history.back()
                }
            }
        }).mount('#app');
    })
</script>
</body>
</html>
