<template>
  <div class="app-container">
    <div v-if="MainTable == false">
      <MainForm
        ref="MainForm"
        :searchdata="formOption"
        :display="display"
        :form="queryParms"
        :show="show"
        :hidedata="hidedata"
        @handleClick="handleClick"
      />
      <div style="width:40%;margin-left:60%;margin-bottom: -10%">
        <el-button
          type="cyan"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置</el-button
        >
        <el-button
          @click="handleClick"
          :icon="arrow"
          size="mini"
        >展开</el-button
        >
      </div>
      <listComponent
        style="clear:both"
        v-if="waitFor"
        :tableData="tableData"
        @selectionbox="selectionbox"
        @see="viewMethod"
        @modify="modification"
        @deletion="deletion"
        @buttonList="buttonList"
        @showSearch="showSearch"
        @getList="getList"
        @feedback="feedback"
        :customButton="customButton"
        :arrow="arrow"
        :seachButton="seachButton"
        :setRowList="listStyle"
        :listStyle="listStyle"
        :queryList="queryList"/>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParms.pageNum"
        :limit.sync="queryParms.pageSize"
        @pagination="getList"
      />
    </div>
    <div v-if="MainTable == true">
      <MainForm
        ref="detailForm"
        :searchdata="detailOption"
        :display="display"
        :form="detailForm"
        :show="show = true"
        @backRules="backRules"
        @handleClick="handleClick"
        @verificationRules="verificationRules"
        @changeWarehouse="changeWarehouse"
      />
      <list-component
        v-if="waitFor"
        :tableData="detailData"
        @selectionbox="selectionbox"
        @see="viewMethod"
        @modify="modification"
        @deletion="deletion"
        @buttonList="buttonList"
        @showSearch="showSearch"
        @getList="getList"
        @deletRows="deletRows"
        @feedback="feedback"
        @totalAmount="totalAmount"
        :seachButton="confirmButton"
        :customButton="detailButton"
        :listStyle="detailStyle"
        :setRowList="detailStyle"
        :tatolLabel="tatolLabel"
        :listData="listData"
        :queryList="detailList"/>
    </div>
  </div>
</template>

<script>
import { select } from '@/api/system/set'
import MainForm from '@/combination/MainForm'
import { listInStock, addSave, getSave, getArea,
  getustomer,getEntry, getwarehouse, getGoodName,
  canBedelet, delRows, getWarehousekeeper, addWarehous,
  deletMain, delFee, copyNew, listQuery} from '@/api/warehouse/inStock'
import Cookies from 'js-cookie'
export default {
  name: 'inStock',
  data(){
    return{
      ids:[],
      listData:{
        fFeeid:[],
        fFeeunitid:[],
        fStltypeid:[],
        fWarehouseid:[]
      },
      selection:[],
      // 非单个禁用
      single: true,
      // 总条数
      total: 0,
      inDex:4,
      tatolLabel:['单价','数量','金额'],
      MainTable:false,
      show: false,
      arrow:'el-icon-arrow-up',
      queryList:{
        tableName:'入库主表',
        columnList:[]
      },
      detailList:{
        tableName:'仓库入库详情',
        columnList:[]
      },
      //判断自定义列是否有值再渲染组件
      waitFor:false,
      display:3,
      queryParms:{
        pageNum: 1,
        pageSize: 10,
        fBilltype:'RK'
      },
      detailForm:{

      },
      //主页面默认显示4个表单数据
      formOption:[
        {
          span:6,
          label: 'fBillno',
          name:"系统编号",
          form:2,
          width:200,
          labelSize:'80',
          rules: { required:false }
        },
        {
          span:6,
          label: 'fGoodsid',
          name:"项目名称",
          form:1,
          width:200,
          labelSize:'80',
          rules: { required:false },
          data:[]
        },
        {
          span:6,
          label: 'fCorpid',
          name:"客户名称",
          form:1,
          width:200,
          labelSize:'80',
          rules: { required:false },
          data:[]
        },
        {
          span:6,
          label: 'moneys',
          name:"金额",
          form:5,
          width:200,
          labelSize:'80',
          rules: { required:false }
        },
        // {
        //   span:6,
        //   label: 'cLoadDate',
        //   name:"申请日期",
        //   form:3,
        //   width:200,
        //   labelSize:'80',
        //   rules:''
        // },
        // {
        //   span:6,
        //   label: 'createBy',
        //   name:"申请人",
        //   form:2,
        //   width:200,
        //   labelSize:'80',
        //   rules:''
        // },
        // {
        //   span:6,
        //   label: 'remark',
        //   name:"备注",
        //   form:2,
        //   width:200,
        //   labelSize:'80',
        //   rules:''
        // },

      ],
      //隐藏表单数据
      hidedata:[
        {
          span:6,
          label: 'cLoadDate',
          name:"申请日期",
          form:3,
          width:200,
          labelSize:'80',
          rules: { required:false }
        },
        {
          span:6,
          label: 'createBy',
          name:"申请人",
          form:2,
          width:200,
          labelSize:'80',
          rules: { required:false }
        },
        {
          span:6,
          label: 'remark',
          name:"备注",
          form:2,
          width:200,
          labelSize:'80',
          rules: { required:false }
        },
      ],
      //表名称
      tableData:[],
      //从表表名
      detailData:[],
      //传输表
      mainStyle:[],
      //表数据
      listStyle: [
        {
          surface: "1",
          label: "serialNumber",
          name: "序号",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "2",
          label: "fBillno",
          name: "申请编号",
          checked: 0,
          width: 100,
        },{
          surface: "3",
          label: "projectName",
          name: "项目名称",
          checked: 0,
          width: 200,
          operation:1
        },{
          surface: "4",
          label: "corpName",
          name: "客户名称",
          checked: 0,
          width: 200,
          operation:1
        },{
          surface: "5",
          label: "fMoney",
          name: "金额",
          checked: 0,
          width: 200,
          operation:1
        },{
          surface: "6",
          label: "createTime",
          name: "申请日期",
          checked: 0,
          width: 200,
          operation:1
        },{
          surface: "7",
          label: "createBy",
          name: "申请人",
          checked: 0,
          width: 200,
          operation:1
        },{
          surface: "8",
          label: "fBillstatusName",
          name: "状态",
          checked: 0,
          width: 200,
          operation:1
        },{
          surface: "9",
          label: "fReviewDate",
          name: "审核日期",
          checked: 0,
          width: 200,
          operation:1,
        },{
          surface: "10",
          label: "remark",
          name: "备注",
          checked: 0,
          width: 200,
          operation:1
        },{
          surface: "11",
          label: "fMaterial2",
          name: "操作",
          checked: 0,
          width: 200,
          operation:1
        }

      ],
      //从表数据

      detailStyle: [
        {
          surface: "1",
          label: "serialNumber",
          name: "序号",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "2",
          label: "fFeeid",
          name: "品名",
          checked: 0,
          width: 200,
          changeable:1,
          data:[],
        },{
          surface: "3",
          label: "fUnitprice",
          name: "单价",
          checked: 0,
          width: 200,
          operation:2,
          changeable:2,
          disabled:false,
          onabort:'this.value=this.value.replace(/[^\\d^\\.]+/g,\'\')'
        },{
          surface: "4",
          label: "fQty",
          name: "数量",
          checked: 0,
          width: 200,
          operation:2,
          changeable:2,
          disabled:false,
          onabort:'this.value=this.value.replace(/[^\\d^\\.]+/g,\'\')'
        },{
          surface: "5",
          label: "fFeeunitid",
          name: "计量单位",
          checked: 0,
          width: 200,
          changeable:1,
          operation:2,
          data:[],
          disabled:false
        },{
          surface: "6",
          label: "fWarehouseid",
          name: "库区",
          checked: 0,
          width: 200,
          operation:2,
          changeable:1,
          data:[],
          disabled:false
        },{
          surface: "7",
          label: "fAmount",
          name: "金额",
          checked: 0,
          width: 200,
          operation:2,
          changeable: 2,
          disabled: true,
          doNot:'1'
        },{
          surface: "8",
          label: "fStltypeid",
          name: "付费方式",
          checked: 0,
          width: 200,
          operation:2,
          changeable: 1,
          data:[],
          disabled:false
        },{
          surface: "9",
          label: "remark",
          name: "备注",
          checked: 0,
          width: 200,
          operation:2,
          changeable: 2,
          disabled:false
        },{
          surface: "10",
          label: "fReviewDate",
          name: "审核日期",
          checked: 0,
          width: 200,
          operation:2,
          changeable: 3,
          disabled:true,
          doNot:'1'
        },
        {
          surface: "11",
          label: "createBy",
          name: "申请人",
          checked: 0,
          width: 200,
          operation:2,
          changeable: 2,
          disabled:true,
          doNot:'1'
        },{
          surface: "12",
          label: "fMaterial10",
          name: "操作",
          checked: 0,
          width: 200,
          operation:2,
          disabled:false
        }

      ],
      //详情主表
      detailOption:[
        {
          span:6,
          label: 'fBillno',
          name:"系统编号",
          form:2,
          width:200,
          labelSize:'80',
          rules:'',
          disabled:true,
          doNot:'1'
        },
        {
          span:6,
          label: 'fCorpid',
          name:"供应商",
          form:1,
          width:200,
          labelSize:'80',
          rules:{required: false},
          data:[],
          disabled:false
        },
        {
          span:6,
          label: 'fStorekeeper',
          name:"库管员",
          form:1,
          width:200,
          labelSize:'80',
          rules: {required: false},
          data:[],
          disabled:false
        },
        {
          span:6,
          label: 'fWarehouseid',
          name:"仓库",
          form:1,
          width:200,
          labelSize:'80',
          rules:{ required: true, message: ' ', trigger: 'blur' },
          data:[],
          disabled:false
        },
        {
          span:6,
          label: 'fBsdate',
          name:"入库日期",
          form:3,
          width:200,
          labelSize:'80',
          rules:{ required: true, message: ' ', trigger: 'blur' },
          disabled:false
        },
        {
          span:6,
          label: 'fSbu',
          name:"付款单位",
          form:1,
          width:200,
          labelSize:'80',
          rules:{required: false},
          data:[],
          disabled:false
        },
        {
          span:6,
          label: 'remark',
          name:"备注",
          form:4,
          width:200,
          labelSize:'80',
          rules:'',
          disabled:false
        },
      ],
      //详情主表隐藏
      hideDetail:[
      //   {
      //     span:6,
      //     label: 'fBsdate',
      //     name:"入库日期",
      //     form:3,
      //     width:200,
      //     labelSize:'80',
      //     rules:''
      //   },
      //   {
      //     span:6,
      //     label: 'fSbu',
      //     name:"付款单位",
      //     form:1,
      //     width:200,
      //     labelSize:'80',
      //     rules:'',
      //     data:[]
      //   },
      //   {
      //     span:6,
      //     label: 'remark',
      //     name:"备注",
      //     form:4,
      //     width:200,
      //     labelSize:'80',
      //     rules:''
      //   },
      //
      ],
      //按钮
      customButton:[
        {
          type:'primary',
          size:'mini',
          icon:'el-icon-plus',
          name:'新增',
          disabled:false,
        },{
          type:'success',
          size:'mini',
          icon:'el-icon-edit',
          name:'修改',
          disabled:true
        },{
          type:'info',
          size:'mini',
          icon:'el-icon-plus',
          name:'复制新增',
          disabled:true
        },
      ],
      seachButton:[
        {
          type:'',
          size:'mini',
          icon:'el-icon-search',
          name:'搜索',
          disabled:false,
        },{
          type:'',
          size:'mini',
          icon:'el-icon-refresh',
          name:'重置',
          disabled:false,
        },{
          type:'',
          size:'mini',
          icon:'el-icon-arrow-up',
          name:'展开',
          disabled:false
        }
      ],
      detailButton:[
        {
          type:'danger',
          size:'mini',
          icon:'el-icon-refresh-left',
          name:'返回列表',
          disabled:false,
        },{
          type:'primary',
          size:'mini',
          icon:'el-icon-edit',
          name:'录入',
          disabled:false,
        },{
          type:'success',
          size:'mini',
          icon:'el-icon-check',
          name:'保存',
          disabled:false
        },{
          type:'info',
          size:'mini',
          icon:'el-icon-edit',
          name:'修改',
          disabled:false,
          res:1
        },{
          type:'info',
          size:'mini',
          icon:'el-icon-edit',
          name:'打印',
          disabled:false,
          res:1
        },{
          type:'info',
          size:'mini',
          icon:'el-icon-edit',
          name:'入库确认',
          disabled:false,
          res:1
        },
        {
          type:'warning',
          size:'mini',
          icon:'el-icon-refresh',
          name:'刷新',
          disabled:false,
          res:1
        }
      ],
      confirmButton:[
        {
          type:'cyan',
          size:'mini',
          icon:'',
          name:'打印',
          disabled:false,
        },{
          type:'info',
          size:'mini',
          icon:'',
          name:'入库确认',
          disabled:false
        }
      ]
    }
  },
  created() {
    console.log(Cookies.get("userName"))
    console.log(this.queryList.tableName)
    let data = {
      tableName: this.queryList.tableName,
      userId: Cookies.get("userName"),
    };
    this.getRow(data)
    let list = {
      fBilltype:'RK'
    }
    this.query(list)
    this.getRow()
    this.getList()
    this.selectMethods()
  },
  methods:{
    //查询主页列数据
    query(data){
      listQuery(data).then(res =>{
        this.tableData = res.rows
      })
    },
    //更换仓库
    changeWarehouse(){
      if(this.detailData.length != 0){
        for(let li in this.detailData){
          this.detailData[li].fWarehouseid = ''
        }
      }
      getArea(this.detailForm.fWarehouseid).then(res=>{
        this.listData.fWarehouseid = []
        for(let item in res.data){
          this.listData.fWarehouseid.push({
            label:res.data[item].fWarehouseInformation,
            value:res.data[item].id
          })
        }
      })
    },
    //自动合计金额
    totalAmount(){
      for(let li in this.detailData){
        if(this.detailData[li].fUnitprice && this.detailData[li].fQty){
          this.detailData[li].fAmount = (this.detailData[li].fUnitprice * this.detailData[li].fQty).toFixed(2)
        }
      }
    },
    //搜索、重置、展开
    feedback(res){
      if (res == '展开'){
        if (this.inDex == 4){
          this.inDex = this.formOption.length
        }else {
          this.inDex = 4
        }
      }else if (res == '搜索'){
        this.$refs.avatar.submitForm()
      }else if (res == '重置'){
        this.$refs.avatar.form = {}
      }
    },
    selectMethods(){
      this.mainMethods()
      this.detailMethods()
    },
    //主页面下拉获取名称
    mainMethods(){
      for(let li in this.formOption){
        // if(this.formOption[li].name == '项目名称'){
        //   let queryParams = { pageNum: 1,}
        //   getEntry(queryParams).then(res=>{
        //     for(let item in res.data){
        //       this.formOption[li].data.push({
        //         label:res.data[item].projectName,
        //         value:res.data[item].fId
        //       })
        //     }
        //   })
        // }
        // else
          if(this.formOption[li].name == '客户名称'){
          let queryParams = { pageNum: 1, fTypeid: 1}
          getustomer(queryParams).then(res => {
            for(let item in res.data){
              this.formOption[li].data.push({
                label:res.data[item].fName,
                value:res.data[item].fId
              })
            }
          })
        }
      }
    },
    //弹窗页获取下拉名称
    detailMethods(){
      for(let li in this.detailOption){
        if(this.detailOption[li].name == '仓库'){
          //获取仓库
          let queryParams = { pageNum: 1 }
          getwarehouse(queryParams).then(res=>{
            for(let item in res.rows){
              this.detailOption[li].data.push({
                label:res.rows[item].fName,
                value:res.rows[item].fId
              })

            }
          })
        }else if(this.detailOption[li].name == '供应商'){
          //获取供应商
          let queryParams = { pageNum: 1, fTypeid: 1}
          getustomer(queryParams).then(res => {
            for(let item in res.data){
              this.detailOption[li].data.push({
                label:res.data[item].fName,
                value:res.data[item].fId
              })
            }
          })
        }else if(this.detailOption[li].name == '付款单位'){
          //获取付款单位
          let queryParams = { pageNum: 1, fTypeid: 1}
          getustomer(queryParams).then(res => {
            for(let item in res.data){
              this.detailOption[li].data.push({
                label:res.data[item].fName,
                value:res.data[item].fId
              })
            }
          })
        }else if(this.detailOption[li].name == '库管员'){
          let queryParams = { pageNum: 1,roleName:'库管'}
          getWarehousekeeper(queryParams).then(res=>{
            for(let item in res.rows){
              this.detailOption[li].data.push({
                label:res.rows[item].userName,
                value:res.rows[item].userId
              })
            }
          })
        }
      }
      //获取计量单位字典表
      this.getDicts('data_unitfees').then((response) => {
        if (response.data) {
          for (let item in response.data) {
            this.listData.fFeeunitid.push({
              label: response.data[item].dictLabel,
              value: response.data[item].dictValue
            })
          }
        }
      })
      //获取品名
      let queryParams = { pageNum: 1 }
      getGoodName(queryParams).then(res=>{
        for(let item in res.rows){
          this.listData.fFeeid.push({
            label:res.rows[item].fName,
            value:res.rows[item].fId
          })
        }
      })
      //付费方式
      this.getDicts('f_paymode').then((response) => {
        if (response.data) {
          for (let item in response.data) {
            this.listData.fStltypeid.push({
              label: response.data[item].dictLabel,
              value: response.data[item].dictValue
            })
          }
        }
      })
    },
    handleClick(){
      this.show = !this.show
      if(this.show){
        this.arrow = 'el-icon-arrow-down'
      }else{
        this.arrow = 'el-icon-arrow-up'
      }
    },
    handleQuery(){
      this.$refs.MainForm.hide()
      this.getList();
    },
    resetQuery(){
      this.queryParms = {

      }
      this.handleQuery()
    },
    //查询列数据
    getRow() {
      let data = {
        tableName: this.queryList.tableName,
        userId: Cookies.get("userName"),
      };
      console.log(data)
      select(data).then((res) => {
        if (data.tableName === '仓库入库详情') {
          if (res.data.length != 0) {
            this.detailList.columnList = res.data.filter((e) => e.checked == 0);
            this.detailList.columnList = res.data;
            this.setRowList = res.data
            this.detailList.columnList = this.detailList.columnList.filter((e) => e.checked == 0);
            // this.waitFor = true
          }else {
            // this.waitFor = true
            this.detailList.columnList = this.detailStyle
            this.setRowList = this.detailStyle
          }
          // this.pageDisplay = false
          // this.isItHidden = false
          // this.inDex = this.contentOption.length
        }else {
          if (res.data.length != 0) {
            this.queryList.columnList = res.data.filter((e) => e.checked == 0);
            this.queryList.columnList = res.data;
            this.setRowList = res.data
            this.queryList.columnList = this.queryList.columnList.filter((e) => e.checked == 0);
            this.waitFor = true
          }else {
            this.waitFor = true
            this.queryList.columnList = this.listStyle
            console.log(this.queryList.columnList.fFeeid)
            this.setRowList = this.listStyle
          }
          // this.pageDisplay = true
          // this.isItHidden = true
          // this.inDex = 4
        }
      });
    },
    //选择框
    selectionbox(selection){
      this.selection = selection
      this.ids = selection.map((item) => item.fId)
      this.single = selection.length !== 1
      for(let li in this.customButton){
        if(this.customButton[li].name == '修改' || this.customButton[li].name == '复制新增'){
          this.customButton[li].disabled = this.single
        }
      }
    },
    //查看
    viewMethod(scope){
      console.log(scope)
      this.detailList.columnList = this.detailStyle
      getSave(scope.row.fId).then(res=>{
        if(res.data.warehouseBills){
          this.detailForm = res.data.warehouseBills
            this.$set(this.detailForm,'fStorekeeper',JSON.parse(this.detailForm.fStorekeeper))
        }
        if(res.data.tWarehousebillsfees){
          this.detailData = res.data.tWarehousebillsfees
          for(let li in this.detailData){
            this.$set(this.detailData[li],'fFeeunitid',JSON.stringify(this.detailData[li].fFeeunitid))
            this.$set(this.detailData[li],'fStltypeid',JSON.stringify(this.detailData[li].fStltypeid))
          }
        }
        for(let li in this.detailStyle){
          this.detailStyle[li].disabled = true
        }
        for(let item in this.detailOption){
          this.detailOption[item].disabled = true
        }
        for(let li in this.detailButton){
          if(this.detailForm.fBillstatus == '6'){
            if(this.detailButton[li].name == '返回列表'){
              this.detailButton[li].disabled = false
            }else if(this.detailButton[li].name == '录入' || this.detailButton[li].name == '保存'
              || this.detailButton[li].name == '打印' || this.detailButton[li].name == '入库确认'
              || this.detailButton[li].name == '刷新'){
              this.detailButton[li].disabled = true
            }
          }else if(this.detailButton[li].name == '录入' || this.detailButton[li].name == '保存'
          || this.detailButton[li].name == '打印' || this.detailButton[li].name == '入库确认'
          || this.detailButton[li].name == '刷新'){
            this.detailButton[li].disabled = true
          }
        }
        getArea(this.detailForm.fWarehouseid).then(res=>{
          this.listData.fWarehouseid = []
          for(let item in res.data){
            this.listData.fWarehouseid.push({
              label:res.data[item].fWarehouseInformation,
              value:res.data[item].id
            })
          }
        })
          for(let li in this.detailStyle){
            if(this.detailStyle[li].name == '库区'){

            }
          }
        this.MainTable = true
      })
    },
    //修改
    modification(scope){
      console.log(scope)
    },
    //删除
    deletion(scope){
      console.log(scope)
      const fIds = scope.row.fId || this.ids;
      let tips = "";
      deletMain(fIds).then(res=>{
        switch (res.msg) {
          case "0": {
            this.$message.error("当前数据已被其他操作员操作，请刷新页面");
            break;
          }
          case "1": {
            tips = "当前主表有数据，确认是否删除？";
            this.delete_s(fIds, tips);
            break;
          }
          case "2": {
            tips = "当前主表有数据，从表有数据，确认是否删除？";
            this.delete_s(fIds, tips);
            break;
          }
          default: {
            return this.$message.error("未知错误，无状态");
          }
        }
      })

    },
    delete_s(fIds, tips) {
      this.$confirm(tips, "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
            return delFee(fIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    //删除从表行
    deletRows(index,rows){
        if(rows[index].fId){
          let formData = {
              fId:this.detailForm.fId,
              fDateChanged:this.detailForm.fDateChanged
            }
          canBedelet(formData).then(res=>{
            return delRows(rows[index].fId)
          })
            .then(()=>{
              getSave(this.detailForm.fId).then(res=>{
                if(res.data.warehouseBills){
                  this.detailForm = res.data.warehouseBills
                  this.$set(this.detailForm,'fStorekeeper',JSON.parse(this.detailForm.fStorekeeper))
                }
                if(res.data.tWarehousebillsfees){
                  this.detailData = res.data.tWarehousebillsfees
                  for(let li in this.detailData){
                    this.$set(this.detailData[li],'fFeeunitid',JSON.stringify(this.detailData[li].fFeeunitid))
                    this.$set(this.detailData[li],'fStltypeid',JSON.stringify(this.detailData[li].fStltypeid))
                  }
                }
              })
              this.msgSuccess("删除成功");
            })
          .catch(res=>{
            this.$message.error(res)
          })
        }else {
          rows.splice(index, 1)
        }
    },
    //必填项
    verificationRules(valid){
      console.log(valid)
      if(valid){
        this.detailData.push({
          serialNumber:null,
          fFeeid:null,
          fUnitprice:null,
          fQty:null,
          fFeeunitid:'1',
          fWarehouseid:null,
          fAmount:null,
          fStltypeid:'1',
          remark:null,
          fReviewDate:null,
          createBy:null,
        })
      }
    },
    //返回列表是否保存
    backRules(){
        for(let li in this.detailOption) {
          if(this.detailOption[li].name == '供应商'){
            if(this.detailOption[li].disabled == true){
              this.show = false
              // row.icon = 'el-icon-arrow-up'
              this.MainTable = false
            } else {
              this.$confirm("返回列表，是否保存?", "提示", {
                confirmButtonText: "保存",
                cancelButtonText: "取消",
                type: "warning",
              }).then(() => {
                this.$refs.detailForm.saveRules()
                }).catch(() => {
                  this.show = false
                  // row.icon = 'el-icon-arrow-up'
                  this.MainTable = false
                  this.getList();
                });
            }
          }
        }
    },
    backSave(valid){
      if(valid){
        this.detailForm.fMoney = 0
        for(let li in this.detailData){
          if(this.detailData[li]){
            this.detailForm.fMoney += Number(this.detailData[li].fAmount)
          }
        }
        let formData = new window.FormData();
        formData.append('tWarehousebills', JSON.stringify(this.detailForm))
        formData.append('tWarehousebillsfees', JSON.stringify(this.detailData))
        formData.append('fBilltype', 'RK')
        addSave(formData).then(res=>{
          this.$message.success("操作成功")
          this.MainTable = false
          this.getList();
          this.show = false
          row.icon = 'el-icon-arrow-up'
        })
      }
    },
    //所以按钮
    buttonList(row){
      console.log(row)
      console.log(this.detailStyle)
      if(row.name == '新增'){
        this.detailList.columnList = this.detailStyle
        this.detailForm = {}
        this.detailData = []
          //从表修改按钮
          for(let li in this.detailStyle){
            if(!this.detailStyle[li].doNot){
              this.detailStyle[li].disabled = false
            }
          }
          for(let item in this.detailOption){
            if(!this.detailOption[item].doNot){
              this.detailOption[item].disabled = false
            }
          }
          for(let li in this.detailButton){
            this.detailButton[li].disabled = false
          }
        this.MainTable = true
      }else if(row.name == '录入'){
        this.$refs.detailForm.rules()
      }else if(row.name == '返回列表'){
        this.backRules()
      }else if(row.name == '展开'){
        this.show = !this.show
        if(this.show){
          row.icon = 'el-icon-arrow-down'
        }else{
          row.icon = 'el-icon-arrow-up'
        }
        this.getList()
      }else if(row.name == '保存'){
        this.detailForm.fMoney = 0
        for(let li in this.detailData){
          if(this.detailData[li]){
            this.detailForm.fMoney += Number(this.detailData[li].fAmount)
          }
        }
        let formData = new window.FormData();
        formData.append('tWarehousebills', JSON.stringify(this.detailForm))
        formData.append('tWarehousebillsfees', JSON.stringify(this.detailData))
        formData.append('fBilltype', 'RK')
        addSave(formData).then(res=>{
          console.log(res)
          this.detailForm = res.data.warehouseBills
          this.$set(this.detailForm,'fStorekeeper',JSON.parse(this.detailForm.fStorekeeper))
          this.detailData = res.data.tWarehousebillsCntrs
          for(let li in this.detailData){
            this.$set(this.detailData[li],'fFeeunitid',JSON.stringify(this.detailData[li].fFeeunitid))
            this.$set(this.detailData[li],'fStltypeid',JSON.stringify(this.detailData[li].fStltypeid))
          }
          this.$message.success("操作成功")
        })
      }else if(row.name == '入库确认'){
        this.detailForm.fMoney = 0
        for(let li in this.detailData){
          if(this.detailData[li]){
            this.detailForm.fMoney += Number(this.detailData[li].fAmount)
          }
        }
        let formData = new window.FormData();
        formData.append('tWarehousebills', JSON.stringify(this.detailForm))
        formData.append('tWarehousebillsfees', JSON.stringify(this.detailData))
        formData.append('fBilltype', 'RK')
        addWarehous(formData).then(res=>{
          if(res.data.warehouseBills){
            this.detailForm = res.data.warehouseBills
            this.$set(this.detailForm,'fStorekeeper',JSON.parse(this.detailForm.fStorekeeper))
          }
          if(res.data.tWarehousebillsCntrs){
            this.detailData = res.data.tWarehousebillsCntrs
            for(let li in this.detailData){
            this.$set(this.detailData[li],'fFeeunitid',JSON.stringify(this.detailData[li].fFeeunitid))
            this.$set(this.detailData[li],'fStltypeid',JSON.stringify(this.detailData[li].fStltypeid))
          }
          }
          this.$message.success("操作成功")
          for(let li in this.detailStyle){
            this.detailStyle[li].disabled = true
          }
          for(let item in this.detailOption){
            this.detailOption[item].disabled = true
          }
          for(let li in this.detailButton) {
            if (this.detailButton[li].name == '返回列表') {
              this.detailButton[li].disabled = false
            }
          }
        })
      }else if(row.name == '刷新'){
        getSave(this.detailForm.fId).then(res=>{
          if(res.data.warehouseBills){
            this.detailForm = res.data.warehouseBills
            this.$set(this.detailForm,'fStorekeeper',JSON.parse(this.detailForm.fStorekeeper))
          }
          if(res.data.tWarehousebillsfees){
            this.detailData = res.data.tWarehousebillsfees
            for(let li in this.detailData){
              this.$set(this.detailData[li],'fFeeunitid',JSON.stringify(this.detailData[li].fFeeunitid))
              this.$set(this.detailData[li],'fStltypeid',JSON.stringify(this.detailData[li].fStltypeid))
            }
          }
        })
      }else if(row.name == '复制新增'){
        console.log(this.selection[0].fId)
        let formData = {
          fBilltype:'RK',
          fId:this.selection[0].fId
        }
        copyNew(formData).then(res=>{
          this.$message.success("操作成功")
          this.getList()
        })
      }
      if(row.res === 1){
        //从表修改按钮
        for(let li in this.detailStyle){
          if(!this.detailStyle[li].doNot){
            this.detailStyle[li].disabled = false
          }
        }
        for(let item in this.detailOption){
          if(!this.detailOption[item].doNot){
            this.detailOption[item].disabled = false
          }
        }
        for(let li in this.detailButton){
          this.detailButton[li].disabled = false
        }
      }

    },
    // 显示搜索条件、点击后会调用此方法
    showSearch(){
      console.log('到我了')
    },
    //点击刷新会调用此方法
    getList(){
      this.queryParms.fBilltype = 'RK'
      listInStock(this.queryParms).then(res=>{
        this.tableData = res.rows
        this.total = res.total
      })
    },
  }
}
</script>

<style scoped>

</style>
