<template>
  <div>
    <el-button size="mini" type="primary" @click="dialogFormVisible = true">新 增</el-button>
    <el-dialog title="新 增" :visible.sync="dialogFormVisible" width="900px">
      <div slot="title" style="font-size: 15px">
        新增报价单
      </div>
      <el-row :gutter="120">
        <el-form :model="form" :rules="rules" ref="form" label-width="120px" label-position="left" size="mini">
          <el-col :span="10">
            <el-form-item label="项目名称" >
              <el-input v-model="form.projectname" placeholder="请选择项目" style="width: 100%" @focus="projectList"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="项目编号" >
              <el-input v-model="form.projectnum" placeholder="请输入项目编号" style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="收件单位" >
              <el-input v-model="form.sys_enterpriseid" placeholder="请选择收件单位" style="width: 100%" @focus="enterpriseList"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="收件人" >
              <el-input v-model="form.contactsid" placeholder="请选择收件人" style="width: 100%" ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="收件手机号" >
              <el-input v-model="form.phonenumber" placeholder="请输入联系方式" style="width: 100%" ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="报价单有效期" >
              <el-date-picker
                  v-model="form.invaliddate"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
<!--          <el-col :span="10">
            <el-form-item label="备注" >
              <el-input v-model="form.remarks" placeholder="请输入备注信息" style="width: 100%"></el-input>
            </el-form-item>
          </el-col>-->
          <el-col :span="20">
            <p>商品明细报价</p>
          </el-col>
          <el-col :span="20">
            <hr style="margin-top: 2%;margin-bottom: 2%">
          </el-col>
          <el-col :span="10">
            <el-form-item label="整单折扣(系数)" >
              <el-input v-model="form.discountrate" placeholder="保留两位小数" style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="2" :offset="1">
            <el-button size="small" @click="dialogProjectVisible = false" type="primary" class="normal-btn-width el-icon-plus">添加商品明细</el-button>
          </el-col>
          <el-col :span="2">
            <el-button size="small" @click="dialogProjectVisible = false" type="info" class="normal-btn-width">删除</el-button>
          </el-col>
        </el-form>
      </el-row>
      <div class="dialog-footer">
        <el-button size="small" @click="dialogProjectVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning" @click="onSubmit" class="normal-btn-width btn-warning">确 定</el-button>
      </div>
    </el-dialog>
<!--    <el-dialog title="新 增" :visible.sync="dialogProjectVisible" width="900px">
      <div slot="title" style="font-size: 15px">
        选择项目
      </div>
&lt;!&ndash;      <layoutTable :layout="tablecols" :data="list" :opwidth="200" :custom="true" :height="tableHieght" :checkbox="true" >
        <template v-slot:customcol="scope">
          <p>{{scope.column.data[scope.column.columnname]}}</p>
        </template>
      </layoutTable>&ndash;&gt;
      <layoutTable  @checkboxCallBack="checkboxCallBack" :layout="tablecols" :data="list" :opwidth="200" :custom="false" :height="320" :checkbox="true">
      </layoutTable>
      <div style="margin-top:16px;text-align:right">
        <el-pagination
            background
            small
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-size="params.content.pageSize"
            layout="total, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
      </div>
      <div class="dialog-footer">
        <el-button size="small" @click="dialogProjectVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning" @click="onProject" @rowClick="onProject" class="normal-btn-width btn-warning">确 定</el-button>
      </div>
    </el-dialog>-->
    <project :visible="visible" v-if="visible" @onProject="onProject"></project>
  </div>
</template>

<script>
import layoutTable from '@/components/table/index3'
import project from '../../SDrpManagement/QuotedPrice/detail/components/project'
export default {
  name: "add",
  data(){
    return {
      visible:false,
      dialogFormVisible:false,
      dialogProjectVisible:false,
      tableHieght:320,
      tablecols:[],
      list:[],
      total:0,
      currentPage:0,
      form:{
        sa_quotedpriceid:0,     //sat_notice_classid<=0时 为新增
        sys_enterpriseid: "",
        sa_projectid: "",
        discountrate:"" ,
        remarks: "",
        invaliddate: "",
        projectname: "",
        address: "",
        projectnum:""
      },
      rules:{},
      projectData:[],
      params:{
        "id": 20221020143502,
        "content": {
          "pageNumber": 1,
          "pageSize": 10,
          "type":0, //  1：我负责的；2：我参与的；3：我下属负责的；4：我下属参与的
          "where": {
            "condition": ""
          }
        }
      }
    }
  },
  components:{
    layoutTable,project
  },
  methods:{
    async onSubmit(){
      console.log(this.form)
      const res = await this.$api.requested({
        "id": 20221020164803,
        "version":1,
        "content":this.form
      })
      this.tool.showMessage(res,()=> {
        console.log(res)
        this.$refs['form'].resetFields();
        this.$emit("onSuccess")
        this.dialogFormVisible = false
      })
    },
    /*projectShow(){

      this.projectList()
    },*/
    async projectList(){
      this.visible = true
    },
    /*收件单位*/
    async enterpriseList(){
      console.log(this.form.projectname)
      if (this.form.projectname === ''){
        const res = await this.$api.requested({
          "id":"20220920083901",
          "content":{
            "pageNumber":1,
            "pageSize":20,
            "where":{
              "condition":"",
              "type":2,
              "sa_projectid":""
            }
          }
        })
        console.log("输出")
        console.log(res)
      }else {
        const res = await this.$api.requested({
          "id":"20220920083901",
          "content":{
            "pageNumber":1,
            "pageSize":20,
            "where":{
              "condition":"",
              "type":4,
              "sa_projectid":this.form.sa_projectid
            }
          }
        })
        console.log("缔约方输出")
        console.log(res)
      }

    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.params.content.pageSize = val
      this.projectList()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.content.pageNumber = val
      this.projectList()
    },
    onProject(data){
      this.visible = false
      console.log("获取")
      console.log(data)
      this.form = data
      this.form.sa_projectid = data.sa_projectid
      this.form.projectname = data.projectname
      this.form.projectnum = data.projectnum
    },
    checkboxCallBack(data) {
      console.log("选择12354")
      console.log(data)
      this.projectData = data
    },
  },
  created() {
    this.tablecols = this.tool.tabelCol(this.$route.name).projectTable.tablecols
  }

}
</script>

<style scoped>

</style>