<template> 
  <div class="app-container">
    <el-card class="filter-container" shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
        <el-button
          style="float:right"
          type="primary"
          @click="handleSearchList()"
          size="small">
          查询搜索
        </el-button>
        <el-button
          style="float:right;margin-right: 15px"
          @click="handleResetSearch()"
          size="small">
          重置
        </el-button>
      </div>
      <div style="margin-top: 15px">
        <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
          <el-form-item label="输入搜索：">
            <el-input v-model="listQuery.keyword" class="input-width" placeholder="供应商名称" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
      <el-button v-if="companycreate" size="mini" class="btn-add" @click="handleAddCompany()" style="margin-left: 20px">添加</el-button>
    </el-card>
    <div class="table-container">
      <el-table ref="roleTable"
                :data="list"
                style="width: 100%;"
                v-loading="listLoading" border>
        <!-- <el-table-column label="编号" width="80" align="center">
          <template slot-scope="scope">{{scope.row.id}}</template>
        </el-table-column> -->
        <el-table-column label="供应商名称" width="100px" show-overflow-tooltip align="center">
          <template slot-scope="scope">{{scope.row.compName}}</template>
        </el-table-column>
        <el-table-column label="供应商类型" width="100px" align="center">
          <template slot-scope="scope">{{scope.row.companyType}}</template>
        </el-table-column>
        <el-table-column label="供应商评级"  width="100" align="center">
          <template slot-scope="scope">{{scope.row.compLevel}}</template>
        </el-table-column>
        <el-table-column label="供应商资质" width="100px" show-overflow-tooltip align="center">
          <template slot-scope="scope">{{scope.row.compQual}}</template>
        </el-table-column>
        <el-table-column label="供应商图片" width="100px" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.files.length>0">
              <el-image 
                style="width: 100%; max-height: 100px"
                :src="scope.row.files[0].fileUrl+'?imageMogr2/quality/60'" 
                :preview-src-list="scope.row.files.map(item => {return item.fileUrl+'?imageMogr2/quality/60'})">
              </el-image>
            </div>
          </template>
        </el-table-column>
        <!-- <el-table-column label="供应商资质图片" width="100px" align="center">
          <template slot-scope="scope">{{scope.row.companyType}}</template>
        </el-table-column>
        <el-table-column label="企业logo图片" align="center">
          <template slot-scope="scope">{{scope.row.companyType}}</template>
        </el-table-column>
        <el-table-column label="公众号二维码图片" align="center">
          <template slot-scope="scope">{{scope.row.companyType}}</template>
        </el-table-column> -->
        <el-table-column label="淘宝店地址" width="100px" align="center">
          <template slot-scope="scope">{{scope.row.companyType}}</template>
        </el-table-column>
        <el-table-column label="京东店地址" width="100px" align="center">
          <template slot-scope="scope">{{scope.row.companyType}}</template>
        </el-table-column>
        <el-table-column label="自主商城地址" width="120px" align="center">
          <template slot-scope="scope">{{scope.row.companyType}}</template>
        </el-table-column>
        <el-table-column label="是否认证" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.isCert == 1">是</div>
            <div v-else>否</div>
          </template>          
        </el-table-column>
        <el-table-column label="生产许可证号" align="center">
          <template slot-scope="scope">{{scope.row.compProdLicenseNum}}</template>
        </el-table-column>
        <el-table-column label="经营许可证号" align="center">
          <template slot-scope="scope">{{scope.row.compManageLicenseNum}}</template>
        </el-table-column>
        <el-table-column label="社会信用代码" align="center">
          <template slot-scope="scope">{{scope.row.compSocialCode}}</template>
        </el-table-column>
        <el-table-column label="联系人" align="center">
          <template slot-scope="scope">{{scope.row.compConPerson}}</template>
        </el-table-column>
        <el-table-column label="联系方式" align="center">
          <template slot-scope="scope">{{scope.row.compConNum}}</template>
        </el-table-column>
        <el-table-column label="对外企业qq" align="center">
          <template slot-scope="scope">{{scope.row.compQq}}</template>
        </el-table-column>
        <el-table-column label="经营产品" show-overflow-tooltip align="center">
          <template slot-scope="scope">{{scope.row.compManageProduct}}</template>
        </el-table-column>
        <el-table-column label="简介" align="center">
          <template slot-scope="scope">{{scope.row.compSum}}</template>
        </el-table-column>
        <el-table-column label="所在省" align="center">
          <template slot-scope="scope">{{scope.row.provinceId}}</template>
        </el-table-column>
        <el-table-column label="所在市" align="center">
          <template slot-scope="scope">{{scope.row.cityId}}</template>
        </el-table-column>
        <el-table-column label="所在县" align="center">
          <template slot-scope="scope">{{scope.row.countyId}}</template>
        </el-table-column>
        <el-table-column label="详细地址" show-overflow-tooltip align="center">
          <template slot-scope="scope">{{scope.row.detailAddress}}</template>
        </el-table-column>
        <el-table-column label="经度（°）" align="center">
          <template slot-scope="scope">{{scope.row.longitude}}</template>
        </el-table-column>
        <el-table-column label="维度（°）" align="center">
          <template slot-scope="scope">{{scope.row.latitude}}</template>
        </el-table-column>
        <!-- <el-table-column label="带动农户人数" align="center">
          <template slot-scope="scope">{{scope.row.countyId}}</template>
        </el-table-column>
        <el-table-column label="其中建档立卡人数" align="center">
          <template slot-scope="scope">{{scope.row.countyId}}</template>
        </el-table-column> -->
        <el-table-column label="操作" width="160" fixed="right" align="center">
          <template slot-scope="scope">
            <el-row>
            <el-button size="mini" v-if="companyupdate"
                       type="text"
                       @click="handleUpdateCompany(scope.$index, scope.row)">
              编辑
            </el-button>
            <el-button size="mini" v-if="companydelete"
                       type="text"
                       @click="handleDelete(scope.$index, scope.row)">删除
            </el-button>
            <el-button size="mini"
                       type="text"
                       @click="handleInvite(scope.$index, scope.row)">邀请码
            </el-button>
            </el-row>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container" style="maring-bottom:30px">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNo"
        :page-size="listQuery.pageSize"
        :page-sizes="[5,10,15]"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  import {fetchList,createCompany,deleteCompany,getCompany,updateCompany} from '@/api/company';
  import {formatDate} from '@/utils/date';
  import {companycreate,companydelete,companyupdate} from '@/api/permissions'

  const defaultListQuery = {
    pageNo: 1,
    pageSize: 5,
    keyword: null
  };

  export default {
    name: 'roleList',
    data() {
      return {
        companycreate,
        companydelete,
        companyupdate,
        listQuery: Object.assign({}, defaultListQuery),
        list: null,
        total: null,
        listLoading: false,
        dialogVisible: false,
        isEdit: false
      }
    },
    created() {
      this.getList();
    },
    filters: {
      formatDateTime(time) {
        if (time == null || time === '') {
          return 'N/A';
        }
        let date = new Date(time);
        return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
      }
    },
    methods: {
      handleResetSearch() {
        this.listQuery = Object.assign({}, defaultListQuery);
      },
      handleSearchList() {
        this.listQuery.pageNum = 1;
        this.getList();
      },
      handleSizeChange(val) {
        this.listQuery.pageNum = 1;
        this.listQuery.pageSize = val;
        this.getList();
      },
      handleCurrentChange(val) {
        this.listQuery.pageNum = val;
        this.getList();
      },
      handleAddCompany() {
        this.$router.push({path:'/ums/addCompany'});
      },
      handleInvite(index, row){
        console.log('row',row);
        this.$router.push({path:'/ums/inviteCode',query:{id:row.id,compName:row.compName}});
      },
      handleDelete(index, row) {
        this.$confirm('是否要删除该供应商?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let compId = [];
          compId.push(row.id);
          let params=new URLSearchParams();
          params.append("compId",compId);
          console.log('del-params',params);
          // return false;
          deleteCompany(params).then(response => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.getList();
          });
        });
      },
      handleUpdateCompany(index,row){
        this.$router.push({path:'/ums/updateCompany',query:{id:row.id}});
      },
      getList() {
        this.listLoading = true;
        fetchList(this.listQuery).then(response => {
          console.log('response',JSON.parse(JSON.stringify(response)));
          this.listLoading = false;
          this.list = response.data.list;
          this.total = response.data.total;
        });
      }
    }
  }
</script>
<style></style>


