<template>
  <div>
    <el-form ref="form" >
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="tableList"
        :needPage="false"
        :minHeight="100"
        tool-class="ele-toolbar-form"
        cache-key="eomContactPageTable"
        :summary-method="getSummaries"
        show-summary
      >
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>
          <div class="listToolbar">
            <el-button
              v-if="dialogType !== 'view'"
              size="small"
              type="primary"
              icon="el-icon-plus"
              class="ele-btn-icon"
              @click="handleAddInfo"
            >
              新增
            </el-button>
      
          </div>
        </template>

        <template v-slot:action="{ row, $index }" v-if="dialogType !== 'view'">
          <el-popconfirm
            class="ele-action"
            title="确定要删除此信息吗？"
            @confirm="handleDelInfo($index)"
          >
            <template v-slot:reference>
              <el-link type="danger" :underline="false" icon="el-icon-delete">
                删除
              </el-link>
            </template>
          </el-popconfirm>
        </template>

        <template v-slot:dataTime="{ row, $index }"  v-if="dialogType !== 'view'">
          <el-form-item :prop="'tableList.' + $index + '.dataTime'">
            <el-date-picker
              v-model="row.dataTime"
              type="date"
              placeholder="选择日期"
              value-format="yyyy-MM-dd"

            >
            </el-date-picker>
          </el-form-item>
        </template>
        <template v-slot:cost="{ row, $index }" v-if="dialogType !== 'view'">
          <el-form-item :prop="'datasource.' + $index + '.cost'">
            <el-input type="number" v-model="row.cost"></el-input>
          </el-form-item>
        </template>
        <template
          v-slot:personal="{ row, $index }"
          v-if="dialogType !== 'view'"
        >
          <el-form-item :prop="'datasource.' + $index + '.personal'">
            <el-input type="number" v-model="row.personal"></el-input>
          </el-form-item>
        </template>
        <template v-slot:place="{ row, $index }" v-if="dialogType !== 'view'">
          <el-form-item :prop="'datasource.' + $index + '.place'">
            <el-input v-model="row.place"></el-input>
          </el-form-item>
        </template>
        <template v-slot:text="{ row, $index }" v-if="dialogType !== 'view'">
          <el-form-item :prop="'datasource.' + $index + '.text'">
            <el-input v-model="row.text"></el-input>
          </el-form-item>
        </template>
   
   
    
        <template v-slot:remark="{ row, $index }" v-if="dialogType !== 'view'">
          <el-form-item :prop="'datasource.' + $index + '.remark'">
            <el-input type="textarea" v-model="row.remark"></el-input>
          </el-form-item>
        </template>
   
      </ele-pro-table>
    </el-form>
    <productList
      :currentIndex="-1"
      @changeParent="changeParent"
      ref="productListRef"
    ></productList>
  </div>
</template>
  

  <script>
import { getSummaries } from '@/utils/util.js';
import productList from '@/BIZComponents/product-list.vue';
export default {
  name: 'relatedInfoTable',

  props: {
    dialogType: '',
    organizationList: {
      type: Array,
      default: () => {
        return [];
      }
    }
  },
  components: { productList },

  data() {
    return {
      tableList: [],
      currentIndex: '',
      defaultProps: {
        multiple: false,
        checkStrictly: true,
        emitPath: false,
        children: 'children',
        value: 'id',
        label: 'name'
      }
    };
  },
  computed: {
    columns() {
      return [
        {
          columnKey: 'index',
          label: '序号',
          type: 'index',
          width: 55,
          align: 'center',
          showOverflowTooltip: true,
          fixed: 'left'
        },
        {
          prop: 'dataTime',
          label: '日期',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 150,
          slot: 'dataTime'
        },
        {
          prop: 'personal',
          label: '人数',
          align: 'center',
          showOverflowTooltip: true,
          width: 80,
          slot: 'personal'
        },
        {
          prop: 'place',
          label: '地点',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 220,
          slot: 'place'
        },
        {
          prop: 'text',
          label: '参观行程',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 200,
          slot: 'text'
        },
       

        {
          prop: 'cost',
          label: '预计费用',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 120,
          slot: 'cost'
        },
        {
          prop: 'remark',
          label: '备注',
          minWidth: 200,
          align: 'center',
          showOverflowTooltip: true,
          slot: 'remark'
        },

        {
          columnKey: 'action',
          slot: 'action',
          label: '操作',
          resizable: false,
          width: 80,
          align: 'center',
          showOverflowTooltip: true,
          fixed: 'right'
        }
      ];
    }
  },
  mounted() {},
  methods: {
    getSummaries(param) {
      return getSummaries(param, 'cost');
    },
    //删除任务信息数据
    handleDelInfo(index) {
      this.tableList.splice(index, 1);
    },
    //修改回显
    putTableValue(data) {
      this.tableList = data || [];
    },
    getTableValue() {
      return this.tableList;
    },
    materialOpen(row, index) {
      this.currentIndex = index;
      this.$refs.productListRef.open(row, index);
    },
    changeParent(list) {
      if (list.length > 0) {
        this.$set(
          this.tableList[this.currentIndex],
          'materialName',
          list[0].name
        );
        this.$set(this.tableList[this.currentIndex], 'materialId', list[0].id);
      }
    },
    ownershipChange(index) {
      this.$nextTick(()=>{
        const data =this.$refs.deptRef.getCheckedNodes()
        this.$set(this.tableList[index], 'ownershipName', data[0].label);

      })
    },
    handleAddInfo() {
      this.tableList.push({
        dataTime: '',
        personal: '',
        place: '',
        materialName: '',
        materialId: '',
        materialNum: '',
        ownershipId: '',
        ownershipName: '',
        remark: '',
        cost: ''
      });
    }
  }
};
</script>
  
  
  <style scoped lang="scss">
:deep(.el-form-item) {
  margin-bottom: 0;
}
.listToolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
  