<template>
  <basic-container v-if="show">
    <avue-crud :option="option"
               :data="dataList"
               ref="crud"
               v-model="form"
               :page.sync="page"
               :search.sync="search"
               :table-loading="loading"
               :cell-style="cellStyle"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @saveColumn="saveColumn"
               @resetColumn="resetColumn"
               @on-load="onLoad">
      <template slot="menuLeft">
      <!--  <el-button type="primary"
                   size="small"
                   icon="el-icon-plus"
                   @click="addReceipt">新 单
        </el-button>-->
      </template>
      <template slot="corpIdSearch">
        <select-component
          v-model="search.corpId"
          :configuration="configuration"
        ></select-component>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button
          type="text"
          size="small"
          icon="el-icon-delete"
          :disabled="scope.row.checkStatus !== '录入'"
          @click.stop="rowDel(scope.row, scope.index)"
        >删除
        </el-button>
      </template>
      <template slot-scope="scope" slot="srcOrderno">
        <span style="color: #409EFF;cursor: pointer" @click.stop="editOpen(scope.row)">{{ scope.row.srcOrderno }}</span>
      </template>
      <template slot-scope="scope" slot="corpId">
        <span style="color: #409EFF;cursor: pointer" @click.stop="editOpen(scope.row)">{{ scope.row.corpName }}</span>
      </template>
    </avue-crud>
  </basic-container>
  <detail-page
    ref="detail"
    @goBack="goBack"
    :detailData="detailData"
    v-else
  ></detail-page>
</template>

<script>
  import option from "./configuration/mainList.json";
  import { getList,remove} from "@/api/financialManagement/paymentRequest";
  import detailPage from "./paymentRequestDetails";

  export default {
    data() {
      return {
        loading : false,
        form: {},
        search:{},
        show:true,
        detailData:{},
        option: {},
        parentId:0,
        dataList: [],
        page: {
          pageSize: 10,
          pagerCount: 5,
          total: 0,
        },
        query:{},
        configuration:{
          multipleChoices:false,
          multiple:false,
          disabled:false,
          searchShow:true,
          collapseTags:false,
          clearable:true,
          placeholder:'请点击右边按钮选择',
          dicData:[]
        },
      }
    },
    async created() {
      this.option = await this.getColumnData(this.getColumnName(61), option);
    },
    activated() {
      if(!this.show && !this.$store.getters.pqStatus){
        this.show = true;
      }
      setTimeout(() => {
        if(this.$route.query.check && this.show){
          this.detailData={
            check:this.$route.query.check
          }
          this.show = false;
          this.$store.commit("PQ_IN_DETAIL");
        }
        if(this.$route.query.params  && this.show){
          let lockData = {
            moduleName: 'ffsq',
            tableName: 'finance_settlement',
            billId: this.$route.query.params,
            no: localStorage.getItem('browserID'),
            billNo:""
          }

          this.detailData={
            id:this.$route.query.params,
            view:true,
            lockData:lockData
          }
          this.show = false;
          this.$store.commit("PQ_IN_DETAIL");
        }
      }, 100);
    },
    components:{
      detailPage
    },
    mounted() {
      // this.option.height = window.innerHeight - 200;
    },
    methods: {
      //新单打开
      addReceipt(row){
        this.detailData = {
          id: row.id,
          status: 1
        };
        this.show = false;
        this.$store.commit("PQ_IN_DETAIL");
      },
      //编辑打开
      editOpen(row) {
        let lockData = {
          moduleName: 'sq',
          tableName: 'business_order',
          billId: row.id,
          no: localStorage.getItem('browserID'),
          billNo:row.orderNo
        }

        this.detailData = {
          id: row.id,
          view:true,
          lockData:lockData
        };

        this.show = false;
        this.$store.commit("PQ_IN_DETAIL");
      },
      rowDel(row, index, done) {
        if(row.id){
          this.$confirm("确定将选择数据删除?", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(() => {
            remove(row.id).then(res =>{
              if(res.data.success){
                this.$message.success("操作成功!");
                this.onLoad(this.page);
              }
            })
          });
        }
      },
      //点击搜索按钮触发
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done()
      },
      searchReset() {
        console.log('1')
      },
      selectionChange() {
        console.log('1')
      },
      sizeChange() {
        console.log('1')
      },
      currentChange(val) {
        this.page.currentPage = val
      },
      refreshChange(params) {
        this.onLoad(this.page,params);
      },
      paramsAdjustment(params) {
        params = Object.assign({}, this.search);
        if (params.createTime &&  params.createTime.length !==0 ) {  //合同
          params.createStartDate = params.createTime[0]+ " " + "00:00:00";
          params.createEndDate = params.createTime[1] + " " + "23:59:59";
          this.$delete(params,'createTime')
        }
        return params
      },
      onLoad(page, params) {
        this.loading = true
        params = this.paramsAdjustment(params)
        params.billType = "申请"
        getList(page.currentPage, page.pageSize,params).then(res =>{
          this.dataList = res.data.data.records
          this.page.total = res.data.data.total
        }).finally(()=>{
          this.loading = false
        })
      },
      goBack() {
        this.detailData=this.$options.data().detailData
        this.show = true;
        this.onLoad(this.page,this.search)
      },
      cellStyle() {
        return "padding:0;height:40px;";
      },
      //列保存触发
      async saveColumn() {
        const inSave = await this.saveColumnData(
          this.getColumnName(61),
          this.option
        );
        if (inSave) {
          this.$message.success("保存成功");
          //关闭窗口
          this.$refs.crud.$refs.dialogColumn.columnBox = false;
        }
      },
      async resetColumn() {
        const inSave = await this.delColumnData(
          this.getColumnName(61),
          option
        );
        if (inSave) {
          this.$message.success("重置成功");
          this.option = option;
          //关闭窗口
          this.$refs.crud.$refs.dialogColumn.columnBox = false;
        }
      },
    }
  }
</script>

<style scoped>

</style>
