<template>
    <view class="mx3">
        <view class="main-color-bg" style="height: 100rpx; margin: 0 -30rpx"></view>
        <view class="p3 bg-color-white" style="margin-top: -50rpx; border-radius: 20rpx">
            <u-form :model="form" ref="uForm" :label-width="150">
                <view class="main-color-text f-size-32 f-weight-6 mt-2">派工信息</view>
                <u-form-item label="派工人" required prop="zjName">
                    <u-input v-model="form.zjName" disabled @click="zjState = true" type="select" />
                    <u-select v-model="zjState" :list="zjList" @confirm="zjSubmit"></u-select>
                </u-form-item>

                <u-form-item label="备注">
                    <u-input v-model="form.repairDispatchRemark" type="textarea" :height="50" />
                </u-form-item>
            </u-form>
            <button class="main-color-bg text-color-white" @tap="handleSubmit">提交</button>
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            form: {
                zjName: '',
                repairDispatchRemark: '',
                repairPersonId: ''
            },
            zjState: false,
            zjList: [],
            id: '',
            rules: {
                zjName: [{
                    required: true,
                    message: '请选择派工人',
                    trigger: ['change', 'blur']
                }]
            }
        };
    },
    onLoad(options) {
        this.id = options.id
        this.$Http
            .queryUserDept({
                deptCode: this.$DictCache.VALUE.SYS_DEPT_CODE.SYS_DEPT_CODE_XIAN_CHANG_WEI_XIU_ZU,
                userStatus: 1
            })
            .then((res) => {
                console.log(res.data);
                const temp = []
                res.data.forEach((item, index) => {
                    temp.push({
                        label: item.realName,
                        value: item.userId
                    })
                })
                this.zjList = temp
            });
    },
    onReady() {
        this.$refs.uForm.setRules(this.rules);
    },
    methods: {
        // 派工
        zjSubmit(data) {
            // console.log(data);
            this.form.zjName = data[0].label;
            this.form.repairUserId = data[0].value
            // console.log(this.form.repairPersonId);
        },
        // 提交
        handleSubmit() {
            this.$refs.uForm.validate(valid => {
                if (valid) {
                    this.$Http
                        .dispatchModelByDTO({
                            repairDispatchRemark: this.form.repairDispatchRemark,
                            repairUserId: this.form.repairUserId,
                            id: this.id
                        })
                        .then((res) => {
                            console.log(res);
                            uni.redirectTo({
                                url: '/pages/service/service'
                            })
                        })
                }
            });
        }
    }
};
</script>

<style></style>
