<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
          <el-form-item label="申请人名称" prop="name">
            <el-input v-model="queryParams.name" placeholder="请输入申请人名称" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="手机号码" prop="phone">
            <el-input v-model="queryParams.phone" placeholder="请输入手机号码" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select v-model="queryParams.status" placeholder="请选择" clearable size="small" @change="handleQuery()" style="width: 200px;margin-right: 1px;">
              <el-option label="全部" value="" />
              <el-option label="已联系" :value="1" />
              <el-option label="未联系" :value="0" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <!-- <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['business:craetor:add']"
            >添加</el-button>
          </el-col> -->
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="channelList">
          <el-table-column label="编号" prop="id" width="100px" />
          <el-table-column label="申请人姓名" prop="name" show-overflow-tooltip />
          <el-table-column label="手机号" prop="phone" />
          <el-table-column label="所在地区">
            <template slot-scope="{ row }">
              {{ row.province ? row.province + '/' + row.city + '/' + row.area : '-' }}
            </template>
          </el-table-column>
          <el-table-column label="行业资源" prop="resource">
            <template slot-scope="{ row }">
              <span v-if="row.resource">
                <span v-if="row.resource.length > 19">
                  <el-popover placement="top-start" width="400" trigger="hover" :content="row.resource">
                    <span slot="reference">{{row.resource.slice(0, 19).concat("...")}}</span>
                  </el-popover>
                </span>
                <span v-else>
                  {{ row.resource }}
                </span>
              </span>
              <span v-else>-</span>
            </template>
          </el-table-column>
          <el-table-column label="申请时间" prop="createdTime">
            <template slot-scope="{ row }">
              {{ parseTime(row.createdTime) }}
            </template>
          </el-table-column>

          <el-table-column label="状态" key="status">
            <template slot-scope="{ row }">
              <el-tag v-if="row.status == 0" type="success">未联系</el-tag>
              <el-tag v-else type="info">已联系</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <span v-if="scope.row.status == 0">
                <el-button size="mini" type="text" @click="handleStatusChange(scope.row)" v-hasPermi="['business:apply:update']">
                  <span>标记为已联系</span>
                </el-button>
              </span>
              <span v-else>-</span>

            </template>
          </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="pageParams.pageNum" :limit.sync="pageParams.pageSize" @pagination="getList" />
      </el-col>
    </el-row>

  </div>
</template>

<script>
import { listCreator, updateCreatorStatus } from "@/api/admin/creator";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import Spec from '../goods/components/spec.vue';
export default {
  name: "Channel",
  components: {
    Spec
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      channelList: [],
      // 查询参数
      queryParams: {
        name: "",
        phone: "",
        status: "",
      },
      pageParams: {
        pageNum: 1,
        pageSize: 10,
        // orderByColumn: 'id',
        // isAsc: 'desc',

      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listCreator('pageNum=' + this.pageParams.pageNum + '&pageSize=' + this.pageParams.pageSize + '&', this.queryParams).then(response => {
        this.channelList = response.rows;
        this.channelList.forEach(item => {
          item.statusV = JSON.parse(item.status).value + ""
        })
        this.total = response.total;
        this.loading = false;
      }
      );
    },
    // //切换排序
    // sortChannelId(row){
    //   if (row){
    //     let prop =  row.prop == 'commRate' ? ('t1.'+ row.prop) : row.prop;
    //     this.pageParams.orderByColumn = prop
    //     this.pageParams.isAsc = row.order=='ascending'?"asc":"desc";
    //     this.getList()
    //   }
    // },

    // 状态修改
    handleStatusChange(row) {
      this.$confirm('确认标记"' + row.name + '"为已联系吗?', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return updateCreatorStatus(row.id);
      }).then(() => {
        this.msgSuccess("标记成功");
        this.getList();
      }).catch(function () {
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.pageParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        name: "",
        phone: "",
        status: "",
      },
        this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
<style lang="sass" scoped>
</style>
