<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-row>
          <el-form-item label="地点" prop="fUpdateaddress">
            <el-select
              style="width: 240px"
              v-model="queryParams.fUpdateaddress"
              placeholder="请输入或选择地点"
              clearable size="small"
              filterable
              :remote-method="addressMethod"
            >
              <el-option
                v-for="item in this.addressOptions"
                :key="item.fId"
                :label="item.fName"
                :value="item.fName">
                <span style="float: left;color: #8492a6; font-size: 13px">{{ item.typesName }}</span>
                <span style="float: right;">{{ item.fName }}</span>
              </el-option>
            </el-select>
          </el-form-item>

<!--          <el-form-item label="箱型" prop="fNo">-->
<!--            <el-input-->
<!--              v-model="queryParams.fNo"-->
<!--              style="width: 240px"-->
<!--              placeholder="请输入箱号"-->
<!--              clearable-->
<!--              size="small"-->
<!--              @keyup.enter.native="handleQuery"-->
<!--            />-->
<!--          </el-form-item>-->

      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table @cell-click="modiEy" :cell-style="cellStyle" v-loading="loading" :data="corpsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" width="55" label="行号" align="center" />
      <el-table-column
        class-name="small-padding fixed-width"
        v-for="(item,index) in boxDistributionName"
        :key="item.index"
        :label="item"
        :value="item.index"
        :prop="item"
      >
      </el-table-column>
    </el-table>

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

  </div>
</template>

<script>
  import { listCorps, listName, getaddress, delCorps, changeCorpsStatus,exportCorps } from "@/api/kaihe/containerNews/boxDistribution";
  export default {
    name: "boxDistribution",
    components: {
    },
    data() {
      return {
        tableStyle:{
          cellColor: 'dodgerblue',		//行内字体颜色
          cellCursor:'pointer'
        },
        //标签名
        boxDistributionName:[],
        //模糊下拉查询地点
        addressOptions:[],

        contactList:[],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 客户详情表格数据
        corpsList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          fUpdateaddress:null,
        },
      };
    },
    created() {
      this.getList();
      this.addressMethod()
    },
    activated() {
      this.getList()
    },
    methods: {
      cellStyle(row, rowIndex){
        if(row.columnIndex !== 0 && row.columnIndex !== 1 && row.columnIndex !== 2 ){
          return 'color: ' + this.tableStyle.cellColor +
            ';cursor' + this.tableStyle.cellCursor;
        }
      },
      //模糊查询地点
      addressMethod(){
        let queryParams = { pageNum: 1,};
        getaddress(queryParams).then(response=>{
          this.addressOptions = response.rows
        })
      },
      //点击列表传值跳转
      modiEy(row, column, cell, event){
        let res = {}
        if(column.label =='空' || column.label =='重'){
           res = {
            updateEFName:column.label,
             addressName:row["地点"]
          }
        }else if(column.label =='好' || column.label =='坏'){
           res = {
            cntrstatusName:column.label,
             addressName:row["地点"]
          }
        }else{
           res = {
            typeidName:column.label,
             addressName:row["地点"]
          }
        }
        if(row[column.label] == 0 || column.label == '地点'){
        }else{
          this.$router.push({
            path: "/containerNews/modifyPage",
            query: { data: JSON.stringify(res) },
          });
        }
      },

      /** 查询客户详情列表 */
      getList() {
        this.loading = true;
        listName().then(response =>{
          this.boxDistributionName = response.rows
        })
        listCorps(this.queryParams).then(response => {
          this.corpsList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },

      // 从表重置
      contList() {
        this.contactList = []
      },
      // 状态修改
      handleStatusChange(row) {
        let text = row.fStatus === "0" ? "启用" : "停用";
        this.$confirm('确认要"' + text + '""' + row.fName + '"吗?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return changeCorpsStatus(row.fId, row.fStatus);
        }).then(() => {
          this.msgSuccess(text + "成功");
        }).catch(function() {
          row.fStatus = row.fStatus === "0" ? "1" : "0";
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.fId)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
    }
  };
</script>
<style lang="scss">

</style>
