<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="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">姓名</div>
        </div>
      </a-col>
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">性别</div>
        </div>
      </a-col>
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">出生年月</div>
        </div>
      </a-col>
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">证件类型</div>
        </div>
      </a-col>
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">证件号码</div>
        </div>
      </a-col>
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">民族</div>
        </div>
      </a-col>
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">国别或地区</div>
        </div>
      </a-col>
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">工作单位</div>
        </div>
      </a-col>
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">职称</div>
        </div>
      </a-col>
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">最高学位</div>
        </div>
      </a-col>
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">电子邮箱</div>
        </div>
      </a-col>
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">手机</div>
        </div>
      </a-col>
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">电话</div>
        </div>
      </a-col>
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">传真</div>
        </div>
      </a-col>
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">项目分工</div>
        </div>
      </a-col>
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">每年工作（月）</div>
        </div>
      </a-col>
      <a-col :span="1" class="bg-gray">
        <div class="special-middle">
          <div class="required">从事专业</div>
        </div>
      </a-col>
      <a-col :span="6" 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="1">
        <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="1">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.sex'" :rules="{required: true,message: '*',trigger: 'change',}">
              <base-select v-model="member.sex" :type="16" :isAll="true" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="1">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.birthday'" :rules="{required: true,message: '*',trigger: 'change',}">
              <a-date-picker format="YYYY-MM-DD" valueFormat="YYYY-MM-DD HH:mm:ss" v-model="member.birthday" style="width: 150px" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="1">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.certificateType'" :rules="{required: true,message: '*',trigger: 'blur',}">
              <para-select v-model="member.certificateType" :typeId="49" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="1">
        <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="1">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.nation'" :rules="{required: true,message: '*',trigger: 'change',}">
              <para-select v-model="member.nation" :typeId="11" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="1">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.country'" :rules="{required: true,message: '*',trigger: 'blur',}">
              <a-input v-model="member.country" :maxLength="50" placeholder="国别或地区" style="width: 80%" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="1">
        <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="1">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.title'" :rules="{required: true,message: '*',trigger: 'change',}">
              <para-multi-select v-model="member.title" :width="105" :typeId="42" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="1">
        <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="1">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.email'" :rules="{required: true,message: '*',trigger: 'blur',}">
              <a-input v-model="member.email" :maxLength="50" placeholder="电子邮箱" style="width: 80%" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="1">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.mobile'" :rules="{required: true,message: '*',trigger: 'blur',}">
              <a-input v-model="member.mobile" :maxLength="20" placeholder="手机" style="width: 80%" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="1">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.telephone'" :rules="{required: true,message: '*',trigger: 'blur',}">
              <a-input v-model="member.telephone" :maxLength="20" placeholder="电话号码" style="width: 80%" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="1">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.fax'" :rules="{required: true,message: '*',trigger: 'blur',}">
              <a-input v-model="member.fax" :maxLength="20" placeholder="传真" style="width: 80%" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="1">
        <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="20" placeholder="项目分工" style="width: 80%" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="1">
        <div class="special-middle">
          <div>
            <a-form-model-item :prop="'members.' + index + '.forMonths'" :rules="{required: true,message: '*',trigger: 'blur',}">
              <a-input-number v-model="member.forMonths" :min="0" :step="0.1" style="width: 80%" />
            </a-form-model-item>
          </div>
        </div>
      </a-col>
      <a-col :span="1">
        <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="6">
        <div class="special-middle">
          <div>
            <a-button icon="arrow-up" type="primary" shape="circle" size="small" :disabled="index == 0" @click="memberUp(index)"></a-button>
            <a-button icon="arrow-down" type="primary" shape="circle" size="small" 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'
import baseSelect from '@/views/components/common/baseSelect'

const Member = {name: null,sex: null,birthday: null,certificateType: null,certId: null,nation: null,country: null,workUnit: null,title: null,degree: null,email: null,mobile: null,telephone: null,fax: null,projWork: null,forMonths: null,spec: null}

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

    }
  },
  props: {
    members: {
      type: Array,
      default: () => {
        return [{ ...Member }]
      }
    },
  },
  components: {
    paraMultiSelect,paraSelect,baseSelect
  },
  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>
<style scoped lang="less">
input[type="text"],
input[type="password"],
input[type="number"],
textarea {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 24px;
  padding: 2px 6px;
  color: rgba(0, 0, 0, 0.65);
  font-size: 12px;
  border-radius: 2px;
}
::v-deep .ant-select {
  font-size: 12px;
}
::v-deep .ant-select .ant-select-selection--single {
  height: 24px !important;
}
::v-deep .ant-select .ant-select-selection__rendered {
  line-height: 22px !important;
  margin-right: 6px !important;
  margin-left: 6px !important;
}
::v-deep .ant-select .ant-select-selection__rendered .ant-form-item-control {
  line-height: 26px !important;
}
::v-deep .ant-col .ant-form-item .ant-col {
  padding: 0px;
}
::v-deep .from-table .item_inner .ant-col {
  text-align: left !important;
}
::v-deep .special-pum-select .ant-form-item-control-wrapper {
  display: flex;
  justify-content: center;
  align-content: center;
}
::v-deep .special-pum-select .ant-form-item-children {
  display: block;
}
::v-deep .special-pum-select .ant-form-item-control {
  line-height: 26px;
}
</style> 
