<template>
  <div v-if="pageDisplay" class="app-container">
    <formComponent
    v-if="searchWhether"
    :formOption="formOption"
    :dataList="dataList"
    :inDex="inDex"
    ref="avatar"
    @submitForm="submitForm"
    @returnToForm="returnToForm"
    />
    <listComponent
      :tableData="tableData"
      @selectionbox="selectionbox"
      @see="viewMethod"
      @modify="modification"
      @deletion="deletion"
      @buttonList="buttonList"
      @showSearch="showSearch"
      @feedback="feedback"
      @getList="getList"
      :isItHidden="isItHidden"
      :customButton="customButton"
      :listStyle="listStyle"
      :queryList="queryList"
      :setRowList="setRowList"
    />
  </div>
  <div v-else class="app-container">
    <formComponent
    v-if="searchWhether"
    :formOption="contentOption"
    :dataList="dataList"
    :inDex="inDex"
    ref="avatar"
    @submitForm="submitForm"
    @returnToForm="returnToForm"
    />
    <listComponent
      :tableData="contentList"
      @selectionbox="selectionbox"
      @see="viewMethod"
      @modify="modification"
      @deletion="deletion"
      @buttonList="buttonList"
      @showSearch="showSearch"
      @feedback="feedback"
      @getList="getList"
      :isItHidden="isItHidden"
      :customButton="contentButton"
      :listStyle="listStyle"
      :queryList="purchaseList"
      :setRowList="setRowList"
    />
  </div>
</template>

<script>
import {select} from '@/api/system/set'
import {listQuery} from '@/api/purchaseRequest/index'
import Cookies from 'js-cookie'
export default {
  name: 'index',
  data(){
    return{
      searchWhether:true,
      pageDisplay:true,
      dataList:{},
      contentList:[],
      inDex:4,
      tableData:[],
      tableList:[],
      isItHidden:true,
      listStyle:[
        {
          surface: "1",
          label: "serialNumber",
          name: "序号",
          checked: 0,
          width: 100,
          onabort:'',
        },{
          surface: "2",
          label: "fBillno",
          name: "申请编号",
          checked: 0,
          width: 100,
          onabort:'this.value=this.value.replace(/[^_a-zA-Z]/g,\'\')'
        },{
          surface: "3",
          label: "fGoodsid",
          name: "项目名称",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "4",
          label: "fCorpid",
          name: "客户名称",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "5",
          label: "fMoney",
          name: "金额",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "6",
          label: "createTime",
          name: "申请日期",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "7",
          label: "createBy",
          name: "申请人",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "8",
          label: "fReviewDate",
          name: "审核日期",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "9",
          label: "remark",
          name: "备注",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "10",
          label: "operation",
          name: "操作",
          checked: 0,
          width: 160,
          operation:'1',
          onabort:''
        }
      ],
      contentStyle:[
        {
          surface: "1",
          label: "fLineNumber",
          name: "序号",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "2",
          label: "fLineNumber",
          name: "品名",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "3",
          label: "asdaasd",
          name: "单价",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "4",
          label: "aadswada",
          name: "采购重量",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "5",
          label: "fLineNuber",
          name: "实际重量",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "6",
          label: "fLine2Nuber",
          name: "计量单位",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "7",
          label: "fLineN32uber",
          name: "金额",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "8",
          label: "fLinger",
          name: "付费方式",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "9",
          label: "fLineNubr",
          name: "备注",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "10",
          label: "fLieNuber",
          name: "申请日期",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "11",
          label: "feNuber",
          name: "申请人",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "12",
          label: "fLineuber",
          name: "审核日期",
          checked: 0,
          width: 100,
          onabort:''
        },{
          surface: "13",
          label: "fMaterialw1",
          name: "操作",
          checked: 0,
          width: 160,
          operation:'1',
          onabort:''
        }
      ],
      queryList:{
        tableName:'采购申请',
        columnList:[]
      },
      purchaseList:{
        tableName:'采购申请详情',
        columnList:[]
      },
      setRowList:[],
      customButton:[
        {
          type:'primary',
          size:'mini',
          icon:'el-icon-edit',
          name:'新增',
          disabled:false,
        },{
          type:'warning',
          size:'mini',
          icon:'el-icon-edit',
          name:'修改',
          disabled:false,
        },{
          type:'primary',
          size:'mini',
          icon:'el-icon-edit',
          name:'导出',
          disabled:false,
        },{
          type:'primary',
          size:'mini',
          icon:'el-icon-edit',
          name:'复制新增',
          disabled:false,
        }
      ],
      contentButton:[
        {
          type:'danger',
          size:'mini',
          icon:'el-icon-arrow-left',
          name:'返回列表',
          disabled:false,
        },{
          type:'primary',
          size:'mini',
          icon:'el-icon-plus',
          name:'录入',
          disabled:false,
        },{
          type:'success',
          size:'mini',
          icon:'el-icon-edit',
          name:'修改',
          disabled:false,
        },{
          type:'warning',
          size:'mini',
          icon:'el-icon-download',
          name:'导出',
          disabled:false,
        },{
          type:'info',
          size:'mini',
          icon:'el-icon-edit-outline',
          name:'打印',
          disabled:false,
        }
      ],
      formOption:[
        {
          span:6,
          label: 'fNum3ber',
          name:"申请编号",
          inputType:2,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },{
          span:6,
          label: 'fNu3mber',
          name:"项目名称",
          inputType:1,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },{
          span:6,
          label: 'fNumb2er',
          name:"客户名称",
          inputType:2,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },{
          span:6,
          label: 'fNumber',
          name:"申请人",
          inputType:2,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },{
          span:6,
          label: 'fNumberasda',
          name:"金额",
          inputType:5,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },{
          span:6,
          label: 'fNumber',
          name:"申请日期",
          inputType:3,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        }
      ],
      contentOption:[
        {
          span:6,
          label: 'fNum3ber',
          name:"系统编号",
          inputType:2,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },{
          span:6,
          label: 'fNum3ber',
          name:"项目名称",
          inputType:2,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },{
          span:6,
          label: 'fNum3ber',
          name:"项目主管",
          inputType:2,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },{
          span:6,
          label: 'fNum3ber',
          name:"客户",
          inputType:2,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },{
          span:6,
          label: 'fNum3ber',
          name:"供应商",
          inputType:2,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },{
          span:6,
          label: 'fNum3ber',
          name:"仓库",
          inputType:2,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },{
          span:6,
          label: 'fNum3ber',
          name:"提货日期",
          inputType:2,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },{
          span:6,
          label: 'fNum3ber',
          name:"申请人",
          inputType:2,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },
        {
          span:6,
          label: 'fNum3ber',
          name:"学生",
          inputType:2,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },{
          span:6,
          label: 'fNum3ber',
          name:"教室",
          inputType:2,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },{
          span:6,
          label: 'fNum3ber',
          name:"备注",
          inputType:2,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },
        {
          span:6,
          label: 'fNum3ber',
          name:"开票公司",
          inputType:2,
          width:200,
          labelSize:'80',
          rules:[{ required: false, message: ' '}]
        },
      ]
    }
  },
  created() {
    let data = {
      tableName: this.queryList.tableName,
      userId: Cookies.get("userName"),
    };
    this.getRow(data)
    this.query()
  },
  methods:{
    //查询主页列数据
    query(){
      listQuery('SQ').then(res =>{
        this.tableData = res.rows
      })
    },
    //查询列数据
    getRow(data) {
      console.log(data.tableName)
      select(data).then((res) => {
        console.log(res)
        if (data.tableName === '采购申请详情'){
          if (res.data.length != 0) {
            this.purchaseList.columnList = res.data.filter((e) => e.checked == 0);
            this.purchaseList.columnList = res.data;
            this.setRowList = res.data
            this.purchaseList.columnList = this.purchaseList.columnList.filter((e) => e.checked == 0);
            // this.waitFor = true
          }else {
            // this.waitFor = true
            this.purchaseList.columnList = this.contentStyle
            this.setRowList = this.contentStyle
          }
          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
            this.setRowList = this.listStyle
            console.log(this.queryList.columnList)
          }
          this.pageDisplay = true
          this.isItHidden = true
          this.inDex = 4
        }
      });
    },
    returnToForm(row){
      console.log(row,111)
    },
    //查看
    viewMethod(scope){
      console.log(scope)
    },
    //修改
    modification(scope){
      console.log(scope)
    },
    //删除
    deletion(scope){
      console.log(scope)
    },
    //选择框
    selectionbox(selection){
      console.log(selection)
    },
    //所以按钮
    buttonList(row){
      console.log(row)
      let data
      switch(row.name) {
        case '新增':
          data = {
            tableName: this.purchaseList.tableName,
            userId: Cookies.get("userName"),
          };
          this.getRow(data)
          break;
        case '返回列表':
          data = {
            tableName: this.queryList.tableName,
            userId: Cookies.get("userName"),
          };
          this.getRow(data)
          break;
        default:
          this.$message.error('按钮未知错误');
      }
    },
    // 显示搜索条件、点击后会调用此方法
    showSearch(){
      console.log('到我了')
      this.searchWhether = !this.searchWhether
    },
    //搜索、重置、展开
    feedback(res){
      console.log(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 = {}
      }
    },
    //表单验证通过执行搜索
    submitForm(){
      console.log('执行搜索')
    },
    //点击刷新会调用此方法
    getList(){
      console.log('到我了2')
    }
  }
}
</script>

<style scoped>

</style>
