<template>
  <mt-radio
    title="转单给"
    align="right"
    v-model="userid"
    :options="userlist"
    @change="transferJob"
  >
  </mt-radio>
</template>

<script>
  import {MessageBox, Indicator, Toast} from 'mint-ui'
  import {transferJob} from '@/api/job'
  import {getUserList} from '@/api/user'

  export default {
    name: "ChoosePeople",
    data() {
      return {
        value: '',//jobId
        userid: '',//转单给的对象的id
        userlist: []//用户列表
      }
    },
    methods: {
      initDialog(showWindow, jobId){
        this.value = jobId
        this.fetchData()
      },
      //获取其他成员列表
      fetchData() {
        const params = {
          deptid: this.$store.getters.deptid,
          hasMine: '0',
          roleTips:'leader,member'
        }
        getUserList(params).then(response => {
          this.userlist = []
          if(response.code==200){
            if(response.data.length>0){
              for(const user of response.data){
                this.userlist.push({value:user.id, label:user.name})
              }
            }
          }
        })
      },
      //转单
      transferJob() {
        const question = `确定要转单吗？`
        MessageBox.confirm(question).then(action => {
          if (action == 'confirm') {
            transferJob(this.value, this.userid).then(response => {
              if (response.code == 200) {
                Toast({
                  message: '转单成功',
                  position: 'bottom',
                })
                this.$router.push({name: 'job'})
              }
            })
          }
        })
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
  .mint-radiolist-title {
    font-size: 1rem
  }
</style>
