<template>
  <div class="address">
    <!--        <area-select type='text' :level='2' v-model="selected" :data="pcaa"></area-select>-->

    <el-dialog title="选择外协单位" width="900px" :visible.sync="outerVisible">
      <div class="address-search">
        <el-input placeholder="关键字" v-model="searchVal" class="input-with-select">
          <el-button @click="handleSearch" slot="append" type="success" icon="el-icon-search">搜索</el-button>
        </el-input>
      </div>
      <div style="clear: both;margin-bottom: 20px"></div>
      <el-table
        border
        max-height="480"
        size="mini"
        @selection-change="handleSelectionChange"
        ref="multipleTable"
        :data="tableData">
        <el-table-column width="80" center label="操作">
          <template slot-scope="scope">
            <template>
              <el-button @click="chooseThis(scope.row.id,scope.row.outAssistName)" type="primary" size="mini">
                选择
              </el-button>
            </template>
          </template>
        </el-table-column>
        <el-table-column
          label="外协厂名称"
          prop="outAssistName"
        >
        </el-table-column>
        <el-table-column
          label="加工类型"
          prop="workType"
        >
        </el-table-column>
        <el-table-column
          prop="workQuality"
          label="加工厂等级">
        </el-table-column>

        <el-table-column
          label="联系人"
          prop="contactMan"
        >
        </el-table-column>
        <el-table-column
          prop="contactPhone"
          label="联系电话">
        </el-table-column>
        <el-table-column
          align="left"
          class-name="status-col"
          width="280"
          label="联系地址">
          <template slot-scope="{row}">
            <span>{{ row.province + row.city + row.area + row.address }}</span>
          </template>
        </el-table-column>
      </el-table>
      <div class="page">
        <pagination v-show="listData.total>0" :total="listData.total" :page.sync="listData.page"
                    :limit.sync="listData.pageSize" @pagination="getInfo"/>
      </div>
      <div style="clear: both"></div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="outerVisible = false">关闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { getOutsideProcessingInfoList} from '@/api/baseInfo/outsideProcessingInfo.js'

export default {
  name: 'factory',
  data() {
    return {
      total: 0,
      searchVal:"",
      outerVisible:false,
      multipleSelection: [],
      tableData: [],
      listLoading: false,
      listData: {
        total: 0,
        page: 1,
        pageSize: 20
      },
    }
  },
  mounted() {
    // this.getInfo()
  },
  methods: {
    chooseThis(id,outAssistName){
      this.$emit('getFactory',id,outAssistName);
      this.outerVisible = false;
    },
    handleSearch(){
      this.listData.page = 1;
      this.getInfo()
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    getInfo(page=1) {
      const _that = this
      _that.listLoading = true
      if(!_that.searchVal){
        var params = {
          enable:1
        }
      }else {
        var params = {
          enable:1,
          keyWord:_that.searchVal
        }
      }
      var page = {
        pageIndex: _that.listData.page,
        pageSize: _that.listData.pageSize
      }
      var data = {
        'params': JSON.stringify(params),
        'page': JSON.stringify(page)
      }
      // console.log(data)
      getOutsideProcessingInfoList(data).then(response => {
        // console.log(response)
        const data = response.data
        // //  组合表单数据
        _that.tableData = data
        _that.listData.total = response.total;
        // //console.log(_that.tableData)
        _that.listLoading = false
      }).catch(err => {
        _that.$message.error(err)
        _that.listLoading = false
      })
    },
    handleCurrentChange(val) {
      // console.log(val);
      this.getInfo(val)
    }
  }
}
</script>

<style scoped>
.page {
  float: right;
  margin-top: 20px;
}

.address-search {
  display: inline-block;
  width: 270px;
  float: left;
}

.address-tit {
  display: inline-block;
  float: left;
  margin-left: 15px;
}

.area-select .area-selected-trigger {
  padding: 0px 20px 0px 12px !important;
}

</style>
