<template>
  <div class="app-container">
    <!-- 筛选条件 -->
    <div>
      <el-form
        ref="searchForm"
        :model="searchForm"
        label-width="100px"
        size="small"
        label-position="left"
      >
        <el-row :gutter="20">
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="经销商名称" prop="customerName">
              <el-input
                v-model="searchForm.customerName"
                placeholder="请输入提货人姓名"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="提货人姓名" prop="takerName">
              <el-input
                v-model="searchForm.takerName"
                placeholder="请输入提货人姓名"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="电话" prop="telephone">
              <el-input
                v-model="searchForm.telephone"
                placeholder="请输入电话"
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :xs="24" :sm="12" :lg="6" class="tr">
            <el-form-item label="">
              <el-button size="small" @click="clearFn">清空</el-button>
              <el-button size="small" type="primary" @click="searchFn"
                >搜索</el-button
              >
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 按钮 -->
    <div class="btn-group clearfix">
      <div class="fl">
        <el-button type="primary" size="small" @click="addFn">新增</el-button>
      </div>
      <div class="fr">
        <el-button type="primary" size="small">导入</el-button>
        <el-button type="primary" size="small" @click="exportFn"
          >导出</el-button
        >
        <el-button type="primary" size="small">打印</el-button>
      </div>
    </div>
    <!-- 列表 -->
    <div class="mymain-container">
      <div class="table">
        <el-table
          v-loading="listLoading"
          :data="dataList"
          element-loading-text="Loading"
          border
          fit
          highlight-current-row
          stripe
        >
          <el-table-column
            type="selection"
            align="center"
            min-width="100"
          ></el-table-column>
          <el-table-column
            align="center"
            label="经销商名称"
            prop="customerName"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="提货人姓名"
            prop="takerName"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="身份证"
            prop="identity"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="联系电话"
            prop="phone"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="备用电话"
            prop="sparePhone"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="附件"
            prop="attach"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="有效期"
            prop="expireTime"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="创建人"
            prop="createUser"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="创建时间"
            prop="createDate"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="状态"
            prop="flag"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="操作"
            prop="caozuo"
            min-width="160"
            show-overflow-tooltip
          >
            <template slot-scope="scope"
              ><el-button
                type="text"
                class="textColor"
                @click="editFn(scope.row.id)"
                >详情</el-button
              >
              <el-button
                type="text"
                class="textColor"
                @click="stopFn(scope.row.id)"
                >停用</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页 -->
      <div class="fr">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="listTotal"
        >
        </el-pagination>
      </div>
    </div>

    <!-- 弹窗 -->
    <el-dialog
      title="提货人档案"
      :visible.sync="dialogForm"
      width="40%"
      :show-close="false"
      :close-on-click-modal="false"
    >
      <el-form ref="addForm" :model="addForm" label-width="120px">
        <el-form-item label="经销商名称">
          <el-select
            @onchange="changeFn"
            v-model="addForm.customerId"
            placeholder="名称"
          >
            <el-option
              v-for="item in dealerList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="提货人姓名">
              <el-input v-model="addForm.takerName"></el-input> </el-form-item
          ></el-col>
          <el-col :span="12">
            <el-form-item label="身份证号码">
              <el-input v-model="addForm.identity"></el-input> </el-form-item
          ></el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系电话">
              <el-input v-model="addForm.phone"></el-input> </el-form-item
          ></el-col>
          <el-col :span="12">
            <el-form-item label="备用电话">
              <el-input v-model="addForm.sparePhone"></el-input> </el-form-item
          ></el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="有效期">
              <el-date-picker
                v-model="addForm.expireTime"
                type="date"
                placeholder="选择日期"
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker> </el-form-item
          ></el-col>
          <el-col :span="12">
            <el-form-item label="验证码">
              <el-row :gutter="6">
                <el-col :span="14">
                  <el-input v-model="addForm.code" />
                </el-col>
                <el-col :span="9">
                  <el-button type="info" @click="getCodeFn"
                    >获取验证码</el-button
                  >
                </el-col>
              </el-row>
            </el-form-item></el-col
          >
        </el-row>
        <el-form-item label="上传提货人附件">
          <el-upload class="upload-demo">
            <el-button size="small" type="info">点击上传</el-button>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogForm = false">取 消</el-button>
        <el-button type="primary" @click="addDataFn">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getList,
  addDataList,
  getCodeApi,
  stopTaker,
} from "@/api/basic_data/taker";
import { getDealerList } from "@/api/basic_data/dealer";
import { downloadFiles } from "@/utils/util";
export default {
  data() {
    return {
      listLoading: false, // 列表加载loading
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页数量
      listTotal: 0, // 列表总数
      addForm: {
        customerId: "",
        takerName: "",
        identity: "",
        phone: "",
        sparePhone: "",
        sparePhone: "",
        expireTime: "",
        code: "",
      },
      dialogForm: false,
      dataList: [],
      searchForm: {
        customerName: "",
        takerName: "",
        telephone: "",
      },
      dealerList: [],
    };
  },
  async created() {
    await this.getDataList({ pageNum: 1, pageSize: 10 });
    await this.getDealerDataList({ pageNum: 1, pageSize: 10 });
  },
  methods: {
    changFn(v) {
      console.log(v);
    },
    //导出
    exportFn() {
      let screenData = {
        customerName: this.searchForm.customerName,
        takerName: this.searchForm.takerName,
      };
      downloadFiles("/taker-record/export", screenData);
    },
    //停用提货人档案
    async stopFn(id) {
      await stopTaker({ id });
    },
    //获取验证码
    async getCodeFn() {
      const res = await getCodeApi({ mobile: this.addForm.phone });
      console.log(res);
    },
    //获取经销商数据
    async getDealerDataList(data) {
      const res = await getDealerList(data);
      this.dealerList = res.data.records;
    },
    //获取列表数据
    async getDataList(data) {
      let res = await getList(data);
      console.log(res);
      this.dataList = res.data.records;
      this.listTotal = res.data.total;
    },
    //搜索功能
    async searchFn() {
      console.log(this.searchForm);
      await this.getDataList({ ...this.searchForm, pageNum: 1, pageSize: 10 });
    },
    //重置
    clearFn() {
      console.log(this.$refs.searchForm);
      this.$refs.searchForm.resetFields();
    },

    // 更改每页数量
    handleSizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.getDataList({ pageNum: 1, pageSize: this.pageSize });
    },
    // 更改当前页
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getDataList({ pageNum: val, pageSize: 10 });
    },
    //新增
    async addDataFn() {
      console.log(this.addForm);
      await addDataList({ ...this.addForm, orgNumber: "1122" });
      this.$message.success("新增成功");
      this.getDataList({ pageNum: 1, pageSize: 10 });
      this.dialogForm = false;
    },
    addFn() {
      this.dialogForm = true;
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-date-editor {
  width: 100%;
}
::v-deep .el-select {
  width: 100%;
}
::v-deep .el-col-9 .el-button {
  padding: 5px;
}
::v-deep .el-dialog__header {
  background-color: #dddddd;
}
.base {
  padding: 20px 20px 0;
}
.table {
  margin-top: 12px;
}
.right {
  float: right;
}
</style>