<template>
  <el-dialog
    title="附加收费"
    width="600px"
    :visible.sync="visible"
    :before-close="_close"
  >
    <el-table :data="chargeTable" border style="width: 100%;" height="350" :row-style="{ color: '#303133' }"
              :header-cell-style="{backgroundColor: 'rgb(245, 247, 250)',color: '#606266'}" highlight-current-row
              @select-all="handleSelectionChange"
              @select='selectDrugs'>
      <el-table-column align="center" type="selection" width="60"></el-table-column>
      <el-table-column align="center" prop="name" label="名称" width="160">
        <template slot-scope="scope">{{ scope.row.item_name }}</template>
      </el-table-column>
      <el-table-column align="center" prop="name" label="金额(元)">
        <template slot-scope="scope">
          <el-input type="number" v-model="scope.row.price" placeholder="请输入金额"></el-input>
        </template>
      </el-table-column>
    </el-table>
    <div slot="footer" class="dialog-footer">
      <el-button @click="hide">取 消</el-button>
      <el-button type="primary" @click="submitAction()">保 存</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { saveCharges } from '@/api/project/project'

  export default {
    props: {
      hisPatientInfo: Object,
      patientInfo: Object,
      additions: Array

    },
    data() {
      return {
        visible: false,
        chargeTable: [],
        charges: []
      }
    },
    methods: {
      selectDrugs(selection, row) {
        this.charges = selection
      },
      _close: function(done) {
        // this.clear()
        done()
      },
      clear: function() {
        this.form.id = 0
        this.form.name = ''
        this.form.intro = ''
      },
      show() {
        this.chargeTable = []
       
        this.visible = true
        for (let i = 0; i < this.additions.length; i++) {
          let obj = {
            id: '0',
            item_id: this.additions[i].id,
            item_name: this.additions[i].name,
            price: this.additions[i].price,
            count: this.additions[i].count,
          }
          this.chargeTable.push(obj)
        }

      },
      hide() {
        this.visible = false
      },
      handleSelectionChange(val) {
        this.charges = val
      },
      submitAction() {
        this.$emit('setData', this.charges)
      }
    },
    watch: {
      hisPatientInfo: function(val) {
        console.log('患者ID', this)
      }
    }
  }
</script>

