<template>
  <div>
    <el-dropdown size="small" :hide-on-click="false" @command="addBtn">
      <span class="el-dropdown-link">
        <el-button class="inline-16" ref="btn" size="mini" type="primary">确 认</el-button>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="人工">人工</el-dropdown-item>
        <el-dropdown-item command="非贷款">非贷款</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>

    <el-dialog :visible.sync="drawer" width="60%" append-to-body>
      <el-table
        ref="multipleTable"
        :data="tableData"
        style="width: 100%"
        size="mini"
        border>
        <el-table-column
          prop="enterprisename"
          label="经销商名称"
          width="180">
        </el-table-column>
        <el-table-column
          prop="agentnum"
          label="经销商编号"
          width="180">
        </el-table-column>
         <el-table-column
          prop="contact"
          label="联系人">
        </el-table-column>
        <el-table-column
          label="地址">
          <template slot-scope="scope">
            {{scope.row.province}}{{scope.row.city}}{{scope.row.county}}{{scope.row.address}}
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          width="90">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="selectRow(scope.row)">选 择</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div style="margin-top:16px;text-align:right">
        <el-pagination
          background
          small
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="param.content.pageNumber"
          :page-size="param.content.pageSize"
          layout="total, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: '',
  components:{},
  data() {
    return {
      drawer:false,
      visibleAgent:false,
      tableData:[],
      total:0,
      param:{
        "classname": "webmanage.sale.agents.agents",
        "method": "query_agentList",
        "content": {
            "pageNumber": 1,
            "pageSize": 20,
            "where": {
                "condition": ""
            }
        }
      },
    };
  },
  computed:{
  },
  watch:{
  },
  created () {
    this.listData()
  },
  methods: {
    async addBtn (type) {
      if (type == '人工') {
        this.drawer = true
      } else {
        this.$confirm('确定该数据变更为非贷款吗?','提示',{
          confirmButtonText:'确定',
          cancelButtonText:'取消',
          type:'warning'
        }).then( async () => {
          let res = await this.$api.requested({
            "id": 20230106154204,
            "content": {
                "sa_bankstatementid": this.$route.query.id,
                "status":"已确认(非货款)", //已确认(人工),已确认(非货款)
                "sys_enterpriseid":''//状态为已确认(非货款)时不传
            }
          })
          console.log(res);
          this.tool.showMessage(res,() => {
            this.$emit('onSuccess')
          })
        })
      }
    },
    async listData () {
      const res = await this.$api.requested(this.param)
      this.tableData = res.data
      this.total = res.total
      console.log(this.tableData);
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.param.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.param.content.pageNumber = val
      this.listData()
    },
    selectRow (row) {
      this.$confirm('确定该经销商为这条数据的变更人吗?','提示',{
          confirmButtonText:'确定',
          cancelButtonText:'取消',
          type:'warning'
        }).then( async () => {
          let res = await this.$api.requested({
            "id": 20230106154204,
            "content": {
                "sa_bankstatementid": this.$route.query.id,
                "status":"已确认(人工)", //已确认(人工),已确认(非货款)
                "sys_enterpriseid":row.sys_enterpriseid//状态为已确认(非货款)时不传
            }
          })
          console.log(res);
          this.tool.showMessage(res,() => {
            this.$emit('onSuccess')
            this.drawer = false
          })
        })
    }
  },
};
</script>

<style scoped>

</style>
