<template>
  <div class="add">
    <el-button @click="dialogVisible=true" type="text" size="small" :disabled="!editData.itemclassname">编辑</el-button>
    <el-dialog
      title="编辑产品数据"
      :visible.sync="dialogVisible"
      width="60%"
      :before-close="handleClose"
      append-to-body>
      <readHeaderTable v-if="editData" :layout="tablecols" :custom="true" :data="[editData]">
        <template v-slot:customcol="scope">
            <div v-if="scope.column.columnname != 'itemclassfullname'" class="base-target">
              <input type="text" v-model="editData[scope.column.columnname]" @input="baseTargetChange($event,scope.column.data,scope.column.columnname)">
            </div>
            <div v-else>
              {{scope.column.data.itemclassname}}
            </div>
        </template>
      </readHeaderTable>
      <span slot="footer" class="dialog-footer" style="display:flex;justify-content: space-evenly">
        <div>
          <el-button @click="dialogVisible = false" size="small">取 消</el-button>
          <el-button type="primary" @click="editProject" size="small">确定添加</el-button>
        </div>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import readHeaderTable from './readHeaderTable'
export default {
  name: '',
  data() {
    return {
      dialogVisible:false
    };
  },
  components:{readHeaderTable},
  props:['editData','tablecols'],
  computed:{
  },
  watch:{
  },
  methods: {
    async editProject() {
      let itemInfo = {
        sa_salesforecastid:this.editData.sa_salesforecastid,
        itemclassnum:this.editData.itemclassnum,
        orderqty:this.editData.orderqty ? this.editData.orderqty : '0',
        orderamount:this.editData.orderamount,
        invoiceqty:this.editData.invoiceqty ? this.editData.invoiceqty : '0',
        invoiceamount:this.editData.invoiceamount,
        outqty:this.editData.outqty ? this.editData.outqty : '0',
        outamount:this.editData.outamount,
      }
      try {
        if(this.editData.invoiceamount === '' || this.editData.orderamount === '' || this.editData.outamount === '') throw '111'
        let res = await this.$api.requested({
            "id": 20220906155003,
            "version":1,
            "content": {
                "sa_salesforecastmodelid":this.$route.query.id2,
                "sa_salesforecastbillid":this.editData.sa_salesforecastbillid,
                "sa_projectid": this.editData.sa_projectid,
                "itemclassinfos": [itemInfo]
            }
        })
        console.log(res);
        
        this.tool.showMessage(res,() => {
          this.$emit('editSuccess')
          this.dialogVisible = false
        })
      } catch (err) {
        this.$notify({
          title:'提示',
          message:'请完整填写数据',
          type:'warning'
        })
      }
         
    },
    handleClose() {
      this.dialogVisible = false
    },
    /* 基本目标更改 */
    baseTargetChange(val,data,name) {
      data[name] = val.target.value
    }
  }
}
</script>

<style scoped>
.base-target {
  width: 100%;
  padding: 0 15px;
  border: 1px solid #c0c4cc;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-all;
  border-radius: 5px;
  background: #ffffff;
}
.base-target input {
  border: 0 none;
  outline: none;
  height: 32px;
  width: 100%;
}
</style>
