<template>
  <div>
    <basic-container >
      <el-form :model="form" ref="form" label-width="130px">
        <el-row>
          <el-col v-for="(item, index) in basicData.column" :span="item.span?item.span:8" :key="index">
            <el-form-item :label="item.label" :prop="item.prop" :rules="item.rules">
              <el-date-picker v-if="item.type === 'datetime'" style="width: 100%;" v-model="form[item.prop]" size="small" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss"/>
              <el-select v-else-if="item.type === 'select'" style="width: 100%" size="small" placeholder="请选择" clearable filterable></el-select>
              <el-input type="age" v-else v-model="form[item.prop]" size="small" autocomplete="off" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </basic-container>
    <basic-container>
      <avue-crud :option="option"
                 :data="dataList"
                 ref="crud"
                 v-model="form"
                 :page.sync="page"
                 @row-del="rowDel"
                 @row-update="rowUpdate"
                 @row-save="rowSave"
                 @search-change="searchChange"
                 @search-reset="searchReset"
                 @selection-change="selectionChange"
                 @current-change="currentChange"
                 @size-change="sizeChange"
                 @refresh-change="refreshChange"
                 @on-load="onLoad">
        <template slot="menuLeft">
          <el-button type="primary"
                     size="small"
                     icon="el-icon-upload2"
                     plain
                     @click="handleDelete">导 出
          </el-button>
          <el-button type="primary"
                     size="small"
                     icon="el-icon-upload2"
                     plain
                     @click="handleDelete">打 印
          </el-button>
          <el-button type="primary"
                     size="small"
                     icon="el-icon-upload2"
                     plain
                     @click="handleDelete">请 核
          </el-button>
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button
            type="text"
            icon="el-icon-edit"
            size="small"
            @click.stop="rowDel(scope.row,scope.index)"
          >移除
          </el-button>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
  import option from "./configuration/settleAccounts.json";
  import {customerList, typeSave,detail,deleteDetails} from "@/api/basicData/customerCategory"

  export default {
    name: "customerInformation",
    data() {
      return {
        form: {},
        option: option,
        parentId:0,
        dataList: [],
        page: {
          pageSize: 10,
          pagerCount: 5,
          total: 0,
        },
        query:{},
        //顶部from数据
        basicData: {
          column: [
            {
              label: '代码',
              prop: 'orderNo',
              rules: [
                {
                  required: false,
                  message: ' ',
                  trigger: 'blur'
                }
              ]
            }, {
              label: '项目名称',
              prop: 'orderNo',
              rules: [
                {
                  required: true,
                  message: ' ',
                  trigger: 'blur'
                }
              ]
            }, {
              label: '客户名称',
              prop: 'orderNo',
              data: [],
              rules: [
                {
                  required: true,
                  message: ' ',
                  trigger: 'blur'
                }
              ]
            }, {
              label: '责任人',
              prop: 'orderNo',
              data: [],
              rules: [
                {
                  required: true,
                  message: ' ',
                  trigger: 'blur'
                }
              ]
            }, {
              label: '电话',
              prop: 'orderNo',
              rules: [
                {
                  required: true,
                  message: ' ',
                  trigger: 'blur'
                }
              ]
            }, {
              label: '预收金额',
              prop: 'orderNo',
              rules: [
                {
                  required: true,
                  message: ' ',
                  trigger: 'blur'
                }
              ]
            }, {
              label: '开始日期',
              prop: 'orderNo',
              type:'datetime',
              data: [],
              rules: [
                {
                  required: true,
                  message: ' ',
                  trigger: 'blur'
                }
              ]
            }, {
              label: '结束日期',
              prop: 'orderNo',
              type:'datetime',
              data: [],
              rules: [
                {
                  required: true,
                  message: ' ',
                  trigger: 'blur'
                }
              ]
            }, {
              label: '收款方式',
              prop: 'orderNo',
              type:'select',
              data: [],
              rules: [
                {
                  required: true,
                  message: ' ',
                  trigger: 'blur'
                }
              ]
            }, {
              label: '备注',
              prop: 'orderNo',
              rules: [
                {
                  required: true,
                  message: ' ',
                  trigger: 'blur'
                }
              ]
            }
          ],
        },
      }
    },
    created() {

    },
    methods: {
      //删除列表后面的删除按钮触发触发(row, index, done)
      rowDel(row, index, done) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          // 数据回调进行刷新
          done(row);
        });
      },
      //修改时的修改按钮点击触发
      rowUpdate(row, index, done, loading) {
        this.$message({
          type: "success",
          message: "操作成功!"
        });
        done(row);
      },
      //新增修改时保存触发
      rowSave(row, done, loading) {
        setTimeout(() => {
          this.$message.success("保存成功");
          loading();
          done();
        }, 1000);
      },
      //新增子项触发
      handleAdd(row) {
        this.parentId = row.id;
        const column = this.findObject(this.option.column, "parentId");
        column.value = row.id;
        column.addDisabled = true;
        this.$refs.crud.rowAdd();
      },
      //点击搜索按钮触发
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        params.parentId = 0
        this.onLoad(this.page, params);
        done()
      },
      searchReset() {
        console.log('1')
      },
      selectionChange() {
        console.log('1')
      },
      currentChange() {
        console.log('1')
      },
      sizeChange() {
        console.log('1')
      },
      refreshChange() {
        console.log('1')
      },
      onLoad(page, params = {}) {
        const {createTimeA} = this.query;
        let values = {
          ...params,
          size:this.page.pageSize,
          current:this.page.currentPage
        };
        if (createTimeA) {
          values = {
            ...params,
            createTime: createTimeA[0] + ' 00:00:00',
            endTime: createTimeA[1] + ' 23:59:59',
            ...this.query,
            size:this.page.pageSize,
            current:this.page.currentPage
          };
          values.createTimeA = null;
        }
        values.parentId = 0
        customerList(values).then(res => {
          this.dataList = [
            {
              fwxm: "食品许可",
              sfjy: "5000",
              jjdw: "次",
              sl:"12",
              bj: "3000",
              hjje: "6000",
              qesf: "8000",
              hejijin:"1500",
              querenshou:"300",
              pinlv:"年",
              tixingri:"2022-11-30",
              beizhu:"132",
              renwubu:"商务部",
              cnegzuoren:"小明",
            },
            {
              fwxm: "食品许可",
              sfjy: "5000",
              jjdw: "次",
              sl:"12",
              bj: "3000",
              hjje: "6000",
              qesf: "8000",
              hejijin:"1500",
              querenshou:"300",
              pinlv:"年",
              tixingri:"2022-11-30",
              beizhu:"132",
              renwubu:"商务部",
              cnegzuoren:"小明",
            }
          ];
          this.page.total = 1;
        })
      },
    }
  }
</script>

<style scoped>

</style>
