<template>
  <el-dialog title="选择渠道商" width="700px" class="dialog-width" :visible="dialogFormVisibleT" :modal-append-to-body="true"
    append-to-body :close-on-click-modal="false" @close="cancelForm">
    <section>
      <el-row class="searchbox">
        <el-form label-width="100px">
          <el-col :span="12">
            <el-form-item label="商户名称：" prop="channelName">
              <el-input v-model.trim="tableFrom.channelName" size="small" placeholder="请输入" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4" style="margin-left:10px"><el-button type="primary" size="small" style="margin-top: 2px;"
              @click="search">搜索</el-button></el-col>
        </el-form>
      </el-row>
      <div class="boxtable">
        <el-table v-loading="listLoading" :data="tableData.data" style="width: 100%" size="mini"
          :highlight-current-row="true" :header-cell-style="{ fontWeight: 'bold' }" @row-click="rowclick">
          <el-table-column label="商户名称" prop="name" min-width="150" />
        </el-table>
        <div class="block mb20">
          <el-pagination :page-sizes="[10, 20, 30, 40]" :page-size="tableFrom.limit" :current-page="tableFrom.page"
            layout="total, sizes, prev, pager, next, jumper" :total="tableData.total" @size-change="handleSizeChange"
            @current-change="pageChange" />
        </div>
      </div>
    </section>
    <!-- <div slot="footer" class="dialog-footer">
      <el-button @click="cancelForm()">取 消</el-button>
      <el-button type="primary" @click="submitForm()">确 定</el-button>
    </div> -->
  </el-dialog>
</template>
<script>
import { channellistApi } from '@/api/distribution';
export default {
  props: ['visible'],

  data() {
    return {
      dialogFormVisibleT: this.visible,
      listLoading: false,
      tableFrom: {
        page: 1,
        limit: 10,
        channelName: '',
      },
      tableData: {
        data: [],
        total: 0,
      },
    }
  },

  watch: {
    visible() {
      this.dialogFormVisibleT = this.visible
    }
  },

  mounted() {
    this.getList()
  },

  methods: {
    search() {
      this.tableFrom.page = 1
      this.getList()
    },

    getList(num) {
      this.tableFrom.page = num ? num : this.tableFrom.page;
      this.listLoading = true;
      channellistApi(this.tableFrom).then(res => {
        console.log('res', res)
        this.tableData.data = res.list
        this.tableData.total = res.total
        this.listLoading = false;
      }).catch((res) => {
        this.listLoading = false;
      });
    },

    handleClick(tab, event) {
      console.log(tab, event);
    },

    pageChange(page) {
      this.tableFrom.page = page;
      this.getList();
    },

    handleSizeChange(val) {
      this.tableFrom.limit = val;
      this.getList();
    },

    rowclick(row, column, event) {
      row.index = new Date().getTime()
      console.log(row)
      this.$emit("channelpop", row);
      this.cancelForm()
    },

    cancelForm() {
      //取消关闭
      this.$emit("update:visible", false);
      this.$nextTick(() => {
        // this.$refs.ruleForm.resetFields(); //重置输入框提示
      });
    },
  }
}
</script>
<style scoped lang="scss"></style>