<template>
  <div>
    <a-row>
      <a-col :span="24">
        <div class="tb-title">
          <span>项目组成员 <strong>(注：主要成员（不含申请者）)</strong></span>
        </div>
      </a-col>
    </a-row>

    <a-row type="flex" class="item_inner">
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div>序号</div>
        </div>
      </a-col>
      <a-col :span="2" class="bg-gray">
        <div class="special-middle">
          <div class="required">姓名</div>
        </div>
      </a-col>
      <a-col :span="3" class="bg-gray">
        <div class="special-middle">
          <div class="required">身份证号</div>
        </div>
      </a-col>
      <a-col :span="2" class="bg-gray">
        <div class="special-middle">
          <div class="required">技术职务</div>
        </div>
      </a-col>
      <a-col :span="4" class="bg-gray">
        <div class="special-middle">
          <div class="required">专业</div>
        </div>
      </a-col>
      <a-col :span="2" class="bg-gray">
        <div class="special-middle">
          <div class="required">学位</div>
        </div>
      </a-col>
      <a-col :span="4" class="bg-gray">
        <div class="special-middle">
          <div class="required">工作单位</div>
        </div>
      </a-col>
      <a-col :span="3" class="bg-gray">
        <div class="special-middle">
          <div class="required">项目分工</div>
        </div>
      </a-col>
      <a-col :span="3" class="bg-gray">
        <div class="special-middle">
          <div>操作</div>
        </div>
      </a-col>
    </a-row>

    <a-row v-for="(member, index) in members" :key="index" type="flex" class="item_inner">
      <a-col :span="1">
        <div class="special-middle">
          <div>
            {{ index + 1 }}
          </div>
        </div>
      </a-col>
      <a-col :span="2">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.name'" :rules="{required: true,message: '*',trigger: 'blur',}">
              <a-input v-model="member.name" :maxLength="20" placeholder="姓名" style="width: 80%" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="3">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.certId'" :rules="{required: true,message: '*',trigger: 'blur',}">
              <a-input v-model="member.certId" :maxLength="20" placeholder="身份证号"  style="width: 80%" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="2">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.duty'" :rules="{required: true, message: '*',trigger: 'change',}">
              <para-select v-model="member.duty" :typeId="55" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="4">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.spec'" :rules="{required: true,message: '*',trigger: 'change',}">
              <para-multi-select v-model="member.spec" :width="105" :typeId="42" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="2">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.degree'" :rules="{required: true,message: '*',trigger: 'change',}">
              <para-select v-model="member.degree" :typeId="9" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="4">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.workUnit'" :rules="{required: true,message: '*',trigger: 'blur',}">
              <a-input v-model="member.workUnit" :maxLength="50" placeholder="工作单位" style="width: 80%" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="3">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.projWork'" :rules="{required: true,message: '*',trigger: 'blur',}">
              <a-input v-model="member.projWork" :maxLength="50" placeholder="项目分工" style="width: 80%" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="3">
        <div class="special-middle">
          <div>
            <a-button icon="arrow-up" type="primary" shape="circle" :disabled="index == 0" @click="memberUp(index)"></a-button>
            <a-button icon="arrow-down" type="primary" shape="circle" style="margin-left:5px;" :disabled="members.length == index + 1" @click="menberDown(index)"></a-button>
            <a-popconfirm title="确定要删除吗？" ok-text="确定" cancel-text="取消" @confirm="removeMembers(member)">
              <a-button type="link" size="small">删除</a-button>
            </a-popconfirm>
          </div>
        </div>
      </a-col>
    </a-row>
    <a-row v-if="members && members.length < 10" type="flex">
      <a-col :span="24" style="text-align: center;">
        <div class="special-middle">
          <div>
            <a-button type="dashed" style="width: 50%" @click="addMembers">
              <a-icon type="plus" /> 添加
            </a-button>
          </div>
        </div>
      </a-col>
    </a-row>
  </div>
</template>

<script>
//用法 <proj-group-member :members.sync="formData.members" />

import paraMultiSelect from '@/views/components/common/paraMultiSelect'
import paraSelect from '@/views/components/common/paraSelect'

const Member = {
  showIndex: 1,
  name: null,
  certId: null,
  sex: null,
  birthday: null,
  age: null,
  title: null,
  // duty: null,
  spec: null,
  degree: null,
  workUnit: null,
  projWork: null,
}

export default {
  name: 'ProjGroupMember',
  data () {
    return {

    }
  },
  props: {
    members: {
      type: Array,
      default: () => {
        return [{ ...Member }]
      }
    },
  },
  components: {
    paraMultiSelect,
    paraSelect
  },
  created () {

  },
  methods: {
    removeMembers (item) {//移除成员
      let index = this.members.indexOf(item)
      if (index !== -1) {
        this.members.splice(index, 1)
      }
    },
    memberToTop (item) {//成员置顶
      let index = this.members.indexOf(item)
      if (index !== -1) {
        this.members.splice(index, 1)
        this.members.unshift({ ...item })
      }
    },
    addMembers () {//添加成员
      Member.showIndex = this.members.length + 1
      this.members.push({ ...Member })
    },
    memberUp (index) {
      let arr = this.members
      arr.splice(index - 1, 1, ...arr.splice(index, 1, arr[index - 1]))
    },
    menberDown (index) {
      let arr = this.members
      arr.splice(index, 1, ...arr.splice(index + 1, 1, arr[index]))
    }
  }
}
</script>
