<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="row_center">
      <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="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 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 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="4" class="bg-gray">
        <div class="special-middle">
          <div>操作</div>
        </div>
      </a-col>
    </a-row>
    <a-row v-for="(item, index) in fundCompositions" :key="'projFundComposition' + index" type="flex" class="row_center">
      <a-col :span="3">
        <div class="special-middle">
          <a-form-model-item :prop="'fundCompositions.' + index + '.year'" :rules="{ required: true, message: '*' }">
            <a-input-number v-model="item.year" :min="0" :step="1" style="width: 80%" />
          </a-form-model-item>
        </div>
      </a-col>
      <a-col :span="2">
        <div class="special-middle">
          <a-form-model-item :prop="'fundCompositions.' + index + '.totalFund'" :rules="{ required: true, message: '*' }">
            <a-input-number v-model="item.totalFund" :min="0" :step="0.01" style="width: 80%" />
          </a-form-model-item>
        </div>
      </a-col>
      <a-col :span="3">
        <div class="special-middle">
          <a-form-model-item :prop="'fundCompositions.' + index + '.specialFund'" :rules="{ required: true, message: '*' }">
            <a-input-number v-model="item.specialFund" :min="0" :step="0.01" style="width: 80%" />
          </a-form-model-item>
        </div>
      </a-col>
      <a-col :span="3">
        <div class="special-middle">
          <a-form-model-item :prop="'fundCompositions.' + index + '.selfFund'" :rules="{ required: true, message: '*' }">
            <a-input-number v-model="item.selfFund" :min="0" :step="0.01" style="width: 80%" />
          </a-form-model-item>
        </div>
      </a-col>
      <a-col :span="3">
        <div class="special-middle">
          <a-form-model-item :prop="'fundCompositions.' + index + '.cityFund'" :rules="{ required: true, message: '*' }">
            <a-input-number v-model="item.cityFund" :min="0" :step="0.01" style="width: 80%" />
          </a-form-model-item>
        </div>
      </a-col>
      <a-col :span="3">
        <div class="special-middle">
          <a-form-model-item :prop="'fundCompositions.' + index + '.otherFund'" :rules="{ required: true, message: '*' }">
            <a-input-number v-model="item.otherFund" :min="0" :step="0.01" style="width: 80%" />
          </a-form-model-item>
        </div>
      </a-col>
      <a-col :span="3">
        <div class="special-middle">
          <a-form-model-item :prop="'fundCompositions.' + index + '.remark'" :rules="{ required: true, message: '*' }">
            <a-input v-model="item.remark" :maxLength="100" style="width: 80%;" />
          </a-form-model-item>
        </div>
      </a-col>
      <a-col :span="4">
        <div class="special-middle">
          <a-button icon="arrow-up" type="primary" shape="circle" size="small" :disabled="index == 0" @click="moveUp(index)"></a-button>
          <a-button icon="arrow-down" type="primary" shape="circle" size="small" style="margin-left:3px" :disabled="fundCompositions.length == index + 1" @click="moveDown(index)"></a-button>
          <a-popconfirm title="确定要删除吗？" ok-text="确定" cancel-text="取消" @confirm="removeArray(item)">
            <a-button type="link" size="small">[删除]</a-button>
          </a-popconfirm>
        </div>
      </a-col>
    </a-row>
    <a-row type="flex">
      <a-col :span="24" style="text-align: center;">
        <div class="special-middle">
          <a-button type="dashed" style="width: 50%" @click="addArray">
            <a-icon type="plus" /> 添加
          </a-button>
        </div>
      </a-col>
    </a-row>
  </div>
</template>

<script>
//用法  <proj-fund-composition :fundCompositions.sync="formData.fundCompositions" />

const Model = { year: null, totalFund: null, specialFund: null, selfFund: null, cityFund: null, otherFund: null, remark: null }

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

    }
  },
  props: {
    fundCompositions: {
      type: Array,
      default: () => {
        return []
      }
    },
  },
  components: {
  },
  created () {
  },
  methods: {
    moveToTop (item) {//成员置顶
      let index = this.fundCompositions.indexOf(item)
      if (index !== -1) {
        this.fundCompositions.splice(index, 1)
        this.fundCompositions.unshift({ ...item })
      }
    },
    moveUp (index) {
      let arr = this.fundCompositions
      arr.splice(index - 1, 1, ...arr.splice(index, 1, arr[index - 1]))
    },
    moveDown (index) {
      let arr = this.fundCompositions
      arr.splice(index, 1, ...arr.splice(index + 1, 1, arr[index]))
    },
    addArray () {//添加成员
      this.fundCompositions.push({ ...Model })
    },
    removeArray (item) {//移除成员
      let index = this.fundCompositions.indexOf(item)
      if (index !== -1) {
        this.fundCompositions.splice(index, 1)
      }
    },
  }
}
</script>
