<template>
  <basic-container>
    <avue-crud :option="option"
               :data="dataList"
               ref="crud"
               v-model="form"
               :page.sync="page"
               :search.sync="search"
               :table-loading="loading"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
      <template slot="cornIdSearch">
        <select-component
          v-model="search.cornId"
          :configuration="configuration"
        ></select-component>
      </template>
      <template slot-scope="scope" slot="cornId">
        {{ scope.row.cornName }}
      </template>
      <template slot="menuLeft">
        <el-button
          icon="el-icon-printer"
          size="small"
          type="primary"
          @click.stop="downFile"
        >报 表
        </el-button>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button
          type="text"
          icon="el-icon-view"
          size="small"
          @click.stop=""
        >发送
        </el-button>
        <el-button
          type="text"
          icon="el-icon-edit"
          :disabled="scope.row.status != 1"
          size="small"
          @click.stop="completion(scope.row)"
        >完工
        </el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
  import option from "./configuration/mainList.json";
  import { getFlowList } from "@/api/workManagement/mainProject";
  import { updateItemStatus } from "@/api/workManagement/mainProject";
  export default {
    name: "customerInformation",
    data() {
      return {
        loading : false,
        form: {},
        search:{},
        configuration:{
          multipleChoices:false,
          multiple:false,
          disabled:false,
          searchShow:true,
          collapseTags:false,
          clearable:true,
          placeholder:'请点击右边按钮选择',
          dicData:[]
        },
        option: option,
        parentId:0,
        dataList: [],
        page: {
          currentPage: 1,
          total: 0,
          pageSize: 10
        },
        query:{}
      }
    },
    created() {

    },
    mounted() {
      // option.height = window.innerHeight - 350 ;
    },
    methods: {
      downFile(){
        let searchParams = Object.assign({},this.search);
        let param = this.paramsAdjustment(searchParams)
        getFlowList(1, 10000,param).then(res =>{
          const fileData = this.deepClone(res.data.data.records)
          fileData.map(item =>{
            item.cornId = item.cornName
          })
          const fileColumn = this.deepClone(option.column)
          fileColumn.shift();
          this.$Export.excel({
            title: "任务",
            columns: fileColumn,
            data: fileData,
          });
        })
      },
      //完工
      completion(row){
        this.$confirm("确认将此任务完工?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          updateItemStatus(row.id,4).then(res =>{
            if(res.data.success){
              this.$message({
                type: "success",
                message: "操作成功!"
              });
              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')
      },
      currentChange(val) {
        this.page.currentPage = val
        this.onLoad(this.page)
      },
      sizeChange() {
        console.log('1')
      },
      refreshChange() {
        this.onLoad(this.page)
      },
      paramsAdjustment(params){
        params = Object.assign({},this.search);
        if (params.beginTime &&  params.beginTime.length !=0) {  //发货
          params.beginStartTime = params.beginTime[0]+ " " + "00:00:00";
          params.beginEndTime = params.beginTime[1] + " " + "23:59:59";
          this.$delete(params,'beginTime')
        }
        if(!params.status){
          params.status = "1,4,5";
        }
        return params
      },
      onLoad(page, params = {}) {
        params =  this.paramsAdjustment(params)
        this.loading = true
        getFlowList(page.currentPage, page.pageSize,params).then(res =>{
          this.dataList = res.data.data.records
          this.page.total = res.data.data.total
        }).finally(()=>{
          this.loading = false
        })
      },
    }
  }
</script>

<style scoped>

</style>
