从一个api里调值传参数到另一个api,怎么不行呢?

问题描述

从一个api里调值传参数到另一个api,但是在另一个api里是两张表

问题出现的环境背景及自己尝试过哪些方法

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)
<template>
<div>

<div class="fill" v-loading="twoloading">
  <table width="100%" border="0" cellspacing="1" cellpadding="4" bgcolor="#cccccc" class="tabtop13" align="center">
    <tr align="center">
      <td :rowspan="twoData.length+1" width="120px">项目资金投入明细</td>
      <td width="100px">项目</td>
      <td>规格</td>
      <td>单价</td>
      <td>规模单位</td>
      <td>金额</td>
      <td>操作</td>
    </tr>
    <tr align="center" v-for="(p, index) of twoData">
      <td>{{enumFfacYtype[p.roject_name]}}
        <!--<el-select placeholder="选择" v-model="p.project_key" :clearable="true" @change="ResetscaleTwo(p.project_key, index)">-->
          <!--<el-option key="1" label="水" value="water"></el-option>-->
          <!--<el-option key="2" label="电" value="electric"></el-option>-->
          <!--<el-option key="3" label="农业保险" value="agri_insurance"></el-option>-->
        <!--</el-select>-->
      </td>
      <td><el-input placeholder="规格" v-model="p.scale"></el-input></td>
      <td><el-input-number  :min="0" :controls="false" style="width: 110px" v-model="p.unit_price"></el-input-number></td>
      <td><el-input-number  :min="0" :controls="false" style="width: 110px" v-model="p.uscale "></el-input-number></td>
      <td><el-input-number  :min="0" :controls="false" style="width: 110px" v-model="p.funds"></el-input-number></td>
      <td>
        <el-button type="text" icon="el-icon-delete" @click="twoDelete(index)" style="font-size: 20px;color:red;"></el-button>
      </td>
    </tr>
  </table>
</div>
<div class="fill">
  <el-row type="flex" class="row-bg" justify="left">
    <el-col :span="3"><el-button @click="twoNew">新增数据</el-button></el-col>
    <el-col :span="3"><el-button @click="getTwoData">取消</el-button></el-col>
    <el-col :span="3"><el-button @click="submitTwo">保存</el-button></el-col>
  </el-row>
</div>

<div class="fill" v-loading="threeloading">
  <table width="100%" border="0" cellspacing="1" cellpadding="4" bgcolor="#cccccc" class="tabtop13" align="center">
    <tr align="center">
      <td :rowspan="threeData.length+2" width="120px">成本开支明细<div class="d-flex">
        <div style="width: 160px"><el-date-picker v-model="create_time" type="date" style="width: 100%;" placeholder="请选择开始日期"  value-format="yyyy-MM"></el-date-picker></div>
        <span class="pl-1 pr-1">至</span>
        <div style="width: 160px"><el-date-picker v-model="update_time" type="date" style="width: 100%;" placeholder="请选择截止日期"  value-format="yyyy-MM"></el-date-picker></div>
      </div></td>
      <td rowspan="2" width="100px">项目</td>
      <td rowspan="2">单价(元)</td>
      <td rowspan="2">数量</td>
      <td rowspan="2">金额</td>
      <td rowspan="2">附件</td>
      <td>生产管理情况</td>
      <!--<td rowspan="2">操作</td>-->
    </tr>
    <tr align="center">
      <td :rowspan="threeData.length+2"></td>
    </tr>
    <tr align="center" v-for="(p, index) of threeData">
      <td>{{enumFfacYtype[p.roject_name]}}</td>
      <td><el-input placeholder="请填写" v-model="p.unit_price"></el-input></td>
      <td><el-input placeholder="请填写" v-model="p.scale"></el-input></td>
      <td><el-input placeholder="请填写" v-model="p.funds"></el-input></td>
      <td><el-button>上传</el-button></td>
      <!--<td><el-select placeholder="请填写" v-model="p.is_normal">-->
        <!--<el-option key="1" label="不正常" value="0"></el-option>-->
        <!--<el-option key="2" label="正常" value="1"></el-option>-->
      <!--</el-select></td>-->
    </tr>
  </table>
</div>
<div class="fill">
  <el-row type="flex" class="row-bg" justify="left">
    <el-col :span="6"><el-button @click="threeNew">新增一行</el-button></el-col>
    <el-col :span="3"><el-button @click="getTwoData">取消</el-button></el-col>
    <el-col :span="3"><el-button @click="submitThree">保存</el-button></el-col>
  </el-row>
</div>

</div>
</template>

<script>
import {getBusinessFacilities, getFacProduce, getSource, postSource, putSource, deleteSource,

deleteProject, getProject, getProjectt, putProject, putProjectt, postProject, postProjectt} from '@/api/credit'

import SelectProject from '@/components/SelectProject'
import {enumCapitalSourceKey, enumFfacYtype} from '@/utils/enum'
export default {

components: {
  SelectProject
},

props: {},

data() {
  return {
    enumCapitalSourceKey,
    enumFfacYtype,

    twoloading: false,
    threeloading: false,

    isput: false,
    Twoisput: false,
    threeisput: false,
    twoData: [],
    threeData: [],
    update_time: '',
    create_time: '',
    tableData: [],
    tempData: []
  }
},

computed: {},
watch: {},

created() {
  this.form = JSON.parse(localStorage.getItem('detail'))
  this.getData()
},

mounted() {
},

methods: {
  getData() {
  
    this.getBussinData()
    this.getFacPData()
  },
  getFacPData() {
    this.tempData = []
    this.twoData = []
    getFacProduce({
      service_id: this.form.service_id,
      customer_id: this.form.customer_id
    }, {service_id: 'eq', customer_id: 'eq'}).then(res => {
      if (res.data) {
        this.tempData = res.data
        // for (let i = 0; i < this.tempData.length; i++) {
        //   this.getTwoData(this.tempData[i].id, i)
        // }
      }
    }).catch(err => {
      console.log(err)
    })
  },
  getBussinData() {
    this.tableData = []
    this.twoData = []
    this.threeData = []
    getBusinessFacilities({
      service_id: this.form.service_id,
      customer_id: this.form.customer_id
    }, {service_id: 'eq', customer_id: 'eq'}).then(res => {
      if (res.data) {
        this.tableData = res.data
        for (let i = 0; i < this.tableData.length; i++) {
          this.getTwoData(this.tableData[i].id, i)
        }
        for (let t = 0; t < this.tableData.length; t++) {
          this.getThreeData(this.tableData[t].id, t)
        }
      }
    }).catch(err => {
      console.log(err)
    })
  },
 
  getTwoData(id, i) {
    this.twoloading = true
    getProject({
      customer_id: this.form.customer_id,
      customer_related_id: this.form.customer_related_id,
      id: id
    }, {id: 'eq', customer_id: 'eq', customer_related_id: 'eq'}).then(res => {
      if (res.data) {
        let tem = []
        tem = res.data
        for (let p = 0; p < tem.length; p++) {
          tem[p].roject_name = this.tableData[i].fac_type
          tem[p].id = this.tableData[i].id
          // tem[p].fac_name = this.tempData[i].fac_name
          // tem[p].id = this.tempData[i].id
          this.twoData.push(tem[p])
        }
        this.Twoisput = true
      } else {
        this.twoData.push({
          roject_name: this.tableData[i].fac_type,
          id: this.tableData[i].id
          // fac_name: this.tempData[i].fac_name
          // // id: this.tempData[i].id
        })
      }
    }).catch(err => {
      console.log(err)
    }).then(() => {
      this.twoloading = false
    })
  },
  getThreeData(id, t) {
    this.threeloading = true
    getProjectt({
      customer_id: this.form.customer_id,
      customer_related_id: this.form.customer_related_id,
      id: id
    }, {id: 'eq', customer_id: 'eq', customer_related_id: 'eq'}).then(res => {
      if (res.data) {
        let tem = []
        tem = res.data
        for (let p = 0; p < tem.length; p++) {
          tem[p].roject_name = this.tableData[t].fac_type
          tem[p].id = this.tableData[t].id
          this.threeData.push(tem[p])
        }
        this.threeisput = true
        // this.create_time = this.threeData[0].create_time
        // this.update_time = this.threeData[0].update_time
      } else {
        this.threeData.push({
          roject_name: this.tableData[t].fac_type,
          id: this.tableData[t].id
        })
      }
    }).catch(err => {
      console.log(err)
    }).then(() => {
      this.threeloading = false
    })
  },

  twoNew() {
    if (this.Twoisput) {
      this.twoData = [{}]
    }
    this.twoData.push({})
    this.Twoisput = false
  },
  threeNew() {
    // if (this.threeisput) {
    //   this.threeData = [{}]
    // }
    this.threeData.push({})
    this.threeisput = false
  },
  submitThree() {
    this.threeloading = true
    let i = 1
    for (let t = 0; t < this.threeData.length; t++) {
      if (this.threeData[t].unit_price) {
        this.$delete(this.threeData[t], 'roject_name')
        this.threeData[t].customer_id = this.form.customer_id
        this.threeData[t].customer_related_id = this.form.id
        this.threeData[t].customer_name = this.form.farm_name
        this.threeData[t].id = this.id
        // this.threeData[t].create_time = this.create_time
        // this.threeData[t].update_time = this.update_time
      } else {
        i = 0
        this.threeloading = false
        return this.$message.warning('请完善保存信息!')
      }
    }
    if (i === 1) {
      if (!this.threeisput) {
        postProjectt(this.threeData).then(res => {
          if (res.data) {
            this.$message.success('添加信息成功!')
          } else {
            this.$message.error('添加信息失败,请重试!')
          }
        }).catch(err => {
          console.log(err)
          this.$message.error('添加信息失败,请重试!')
        }).then(() => {
          this.getThreeData()
        })
      } else {
        for (let p of this.threeData) {
          putProjectt(p.id, p).then(res => {
            if (res.data) {
              this.$message.success('修改信息成功!')
            }
          }).catch(err => {
            console.log(err)
            this.$message.error('修改信息失败,请重试!')
          }).then(() => {
            this.getThreeData()
          })
        }
      }
    }
  },
  submitTwo() {
    this.twoloading = true
    let i = 1
    for (let t = 0; t < this.twoData.length; t++) {
      if (this.twoData[t].scale && this.twoData[t].unit_price && this.twoData[t].funds) {
        this.$delete(this.twoData[t], 'roject_name')
        this.twoData[t].customer_id = this.form.customer_id
        this.twoData[t].customer_related_id = this.form.id
        this.twoData[t].id = this.id
        this.twoData[t].customer_name = this.form.farm_name
      } else {
        i = 0
        this.twoloading = false
        return this.$message.warning('请完善保存信息!')
      }
    }
    if (i === 1) {
      if (!this.Twoisput) {
        postProject(this.twoData).then(res => {
          if (res.data) {
            this.$message.success('添加信息成功!')
          } else {
            this.$message.error('添加信息失败,请重试!')
          }
        }).catch(err => {
          console.log(err)
          this.$message.error('添加信息失败,请重试!')
        }).then(() => {
          this.getTwoData()
        })
      } else {
        for (let p of this.twoData) {
          putProject(p.id, p).then(res => {
            if (res.data) {
              this.$message.success('修改信息成功!')
            }
          }).catch(err => {
            console.log(err)
            this.$message.error('修改信息失败,请重试!')
          }).then(() => {
            this.getTwoData()
          })
        }
      }
    }
  }
 
 
}

}
</script>

<style scoped>

</style>

你期待的结果是什么?实际看到的错误信息又是什么?

能给我的答案较全,其为什么会出现这个问题 Cannot read property 'fac_type' of undefined,这个我不是已经弄有值了吗

阅读 1.6k
1 个回答

应该是你tableData[i]中没有fac_type这个属性,你最好log一下tableData[i]

推荐问题