<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-form-model ref="form" :model="model" :rules="validatorRules">
      <a-row>
        <a-col :span="24">
          <a-form-model-item label="责任人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="username">
            <a-select
            v-model="model.username"
            placeholder="请选择责任人"
            show-search
            allowClear
            option-label-prop="label">
                <a-select-option
                v-for="item in zrrOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                <!-- {{item.value+'('+item.label+')'}} -->
                <span style="float: left">{{ item.label }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">{{ item.value }}</span>
                </a-select-option>
            </a-select>
            <!-- <j-dict-select-tag v-model="model.username" placeholder="请选择用户名称" 
                   dictCode="sys_user,realname,username"/> -->
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>
  </a-modal>
</template>

<script>

import { getNextZrr, runFlowPathPass1 } from '@/api/api'

export default{
    props: {
      fatherMethod: {
        type: Function,
        default: null
      }
    },
    data() {
        return {
            model:{},
            title:'是否通过',
            width:800,
            visible: false,
            disableSubmit: false,
            labelCol: {
            xs: { span: 24 },
            sm: { span: 5 },
            },
            wrapperCol: {
            xs: { span: 24 },
            sm: { span: 16 },
            },
            validatorRules: {
                username: [
                    { required: true, message: '请选择责任人!'},
                ],
            },
            // 责任人
            zrrOptions: [],
            // 当前点击业务详情
            record: {}
        }
    },
    methods: {
      next (record) {
        this.visible=true
        var data = { 'runFlowPath': record.id }
        getNextZrr(data).then((res) =>{
            this.zrrOptions = res.map(res => {
                return {
                    value: res.userName,  //传的值
                    label: res.realName,  //展示
                }
            })
        })
        this.record = record
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        that.$refs.form.validate(valid => {
          if (valid) {
            console.log(that.record.id)
            // 下一步
            const data = {
                runFlowPath: that.record.id,
                nextStepUser: that.model.username
            }
            // var data = { 'runFlowPath': that.record.id, 'nextStepUser': that.model.username}
            runFlowPathPass1(data).then(response => {
                if (response.code == '200') {
                    that.visible=false
                    that.record = {};
                    that.model= {}
                    // 调用父页面方法
                    if (that.fatherMethod) {
                        that.fatherMethod(1);
                    }
                }
                if (response.code == '500') {
                    that.$message.error(response.message)
                }
            })
          }
        })

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleCancel () {
        this.close()
        this.$refs.form.resetFields()
        // this.$emit('close');
        // this.visible = false;
        this.record = {};
        this.model= {}
      }

    }
}
</script>
