<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="originsave" size="mini" class="btn-add" @click="handleAddorigin()" 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.originName}}</template>
        </el-table-column>
        <!-- <el-table-column label="生产地面积（亩）" width="100px" align="center">
          <template slot-scope="scope">{{scope.row.originArea}}</template>
        </el-table-column> -->
        <el-table-column label="生产地图片" width="100" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.imgUrl">
              <el-image 
                style="width: 100%; max-height: 100px"
                :src="scope.row.imgUrl.split(',')[0]+'?imageMogr2/quality/60'" 
                :preview-src-list="scope.row.imgUrl.split(',').map(item => {return item+'?imageMogr2/quality/60'})">
              </el-image>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="生产地宣传视频" show-overflow-tooltip  width="100px" align="center">
          <template slot-scope="scope"><a :href="scope.row.videoUrl" v-if="scope.row.videoUrl" target="_blank">视频地址</a></template>
        </el-table-column>
        <el-table-column label="生产地vr" show-overflow-tooltip  width="100px" align="center">
          <template slot-scope="scope"><a :href="scope.row.vrUrl" v-if="scope.row.vrUrl" target="_blank">vr地址</a></template>
        </el-table-column>
        <el-table-column label="实时监控视频" show-overflow-tooltip  width="100px" align="center">
          <template slot-scope="scope"><a :href="scope.row.cameraUrl" v-if="scope.row.cameraUrl" target="_blank">监控地址</a></template>
        </el-table-column>
        <el-table-column label="人员数" align="center">
          <template slot-scope="scope">{{scope.row.peopleNum}}</template>
        </el-table-column>
        <el-table-column label="建立日期（年）" align="center">
          <template slot-scope="scope">{{scope.row.foundDate}}</template>
        </el-table-column>
        <el-table-column label="联系人" width="100px" align="center">
          <template slot-scope="scope">{{scope.row.linkUser}}</template>
        </el-table-column>
        <el-table-column label="联系方式" width="110px" align="center">
          <template slot-scope="scope">{{scope.row.linkPhone}}</template>
        </el-table-column>
        <el-table-column label="简介" show-overflow-tooltip  width="120px" align="center">
          <template slot-scope="scope">{{scope.row.summary}}</template>
        </el-table-column>
        <el-table-column label="产出物" align="center">
          <template slot-scope="scope">
            <span v-for="(item,index) in scope.row.productlist" :key="index">{{ index == scope.row.productlist.length-1 && item.productName || (item.productName + ',')  }}</span>
          </template>
        </el-table-column>
        <el-table-column label="产出物种植面积（亩）" align="center">
          <template slot-scope="scope">{{scope.row.originArea}}</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.provinceName}}</template>
        </el-table-column>
        <el-table-column label="所在市" align="center">
          <template slot-scope="scope">{{scope.row.cityName}}</template>
        </el-table-column>
        <el-table-column label="所在县" align="center">
          <template slot-scope="scope">{{scope.row.countyName}}</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="供应商名称" show-overflow-tooltip align="center">
          <template slot-scope="scope">{{scope.row.compName}}</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="originupdate"
                       type="text"
                       @click="handleUpdateorigin(scope.$index, scope.row)">
              编辑
            </el-button>
            <el-button size="mini" v-if="origindelete"
                       type="text"
                       @click="handleDelete(scope.$index, scope.row)">删除
            </el-button>
            </el-row>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <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,createorigin,deleteOrigin,getorigin,updateorigin} from '@/api/origin';
  import {formatDate} from '@/utils/date';
  import {originsave,originupdate,origindelete} from '@/api/permissions'

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

  export default {
    name: 'roleList',
    data() {
      return {
        originsave,
        originupdate,
        origindelete,
        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.pageNo = 1;
        this.getList();
      },
      handleSizeChange(val) {
        this.listQuery.pageNo = 1;
        this.listQuery.pageSize = val;
        this.getList();
      },
      handleCurrentChange(val) {
        this.listQuery.pageNo = val;
        this.getList();
      },
      handleAddorigin() {
        this.$router.push({path:'/pms/addorigin'});
      },
      handleDelete(index, row) {
        this.$confirm('是否要删除该供应商?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let id = [];
          id.push(row.id);
          let params=new URLSearchParams();
          params.append("id",id);
          console.log('del-params',params);
          deleteOrigin(params).then(response => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.getList();
          });
        });
      },
      handleUpdateorigin(index,row){
        this.$router.push({path:'/pms/updateorigin',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;
        }).catch(err => {
          this.listLoading = false;
        });
      }
    }
  }
</script>
<style></style>


