<template>
  <div class="mod-companyMsg app-container">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.companyName" placeholder="公司名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.linkMan" placeholder="联系人" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.linkPhone" placeholder="联系电话" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="getDataList">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="addOrUpdateHandle()"
            v-hasPermi="['fleet:companyMsg:add']"
          >新增
          </el-button>
        </el-col>
        <!--        <el-col :span="1.5">-->
        <!--          <el-button-->
        <!--            type="success"-->
        <!--            icon="el-icon-edit"-->
        <!--            size="mini"-->
        <!--            :disabled="single"-->
        <!--            @click="handleUpdate"-->
        <!--            v-hasPermi="['basicdata:corps:edit']"-->
        <!--          >修改</el-button>-->
        <!--        </el-col>-->
        <!--        <el-col :span="1.5">-->
        <!--          <el-button-->
        <!--            type="danger"-->
        <!--            icon="el-icon-delete"-->
        <!--            size="mini"-->
        <!--            :disabled="multiple"-->
        <!--            @click="handleDelete"-->
        <!--            v-hasPermi="['basicdata:corps:remove']"-->
        <!--          >删除</el-button>-->
        <!--        </el-col>-->
        <!--        <el-col :span="1.5">-->
        <!--          <el-button-->
        <!--            type="warning"-->
        <!--            icon="el-icon-download"-->
        <!--            size="mini"-->
        <!--            @click="handleExport"-->
        <!--            v-hasPermi="['basicdata:corps:export']"-->
        <!--          >导出</el-button>-->
        <!--        </el-col>-->
        <!--        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
      </el-row>
    </el-form>
    <el-table
      :data="dataList"
      border
      stripe
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
    >
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50"
      >
      </el-table-column>
      <el-table-column
        prop="companyName"
        header-align="center"
        align="center"
        width="120"
        :show-overflow-tooltip="true"
        label="公司名称"
      >
      </el-table-column>
      <el-table-column
        prop="companyAddress"
        header-align="center"
        align="center"
        width="150"
        :show-overflow-tooltip="true"
        label="公司地址"
      >
      </el-table-column>
      <el-table-column
        prop="openingBank"
        header-align="center"
        align="center"
        width="150"
        label="公司开户行"
      >
      </el-table-column>
      <el-table-column
        prop="bankAccount"
        header-align="center"
        align="center"
        width="150"
        :show-overflow-tooltip="true"
        label="银行账号"
      >
      </el-table-column>
      <el-table-column
        prop="creditLv"
        header-align="center"
        align="center"
        width="150"
        label="信用等级"
      >
      </el-table-column>
      <el-table-column
        prop="paymentDays"
        header-align="center"
        align="center"
        label="账期天数"
      >
      </el-table-column>
      <el-table-column
        prop="linkMan"
        header-align="center"
        align="center"
        label="联系人"
      >
      </el-table-column>
      <el-table-column
        prop="linkPhone"
        header-align="center"
        align="center"
        width="150"
        label="联系电话"
      >
      </el-table-column>
      <el-table-column
        prop="fax"
        header-align="center"
        align="center"
        label="传真"
      >
      </el-table-column>
      <el-table-column
        prop="email"
        header-align="center"
        align="center"
        label="email"
      >
      </el-table-column>
      <el-table-column
        prop="headOffice"
        header-align="center"
        align="center"
        width="150"
        label="总公司名称"
      >
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="130"
        label="操作"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="addOrUpdateHandle(scope.row,2)"
            v-hasPermi="['fleet:companyMsg:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row.id)"
            v-hasPermi="['fleet:companyMsg:remove']"
          >删除
          </el-button>
        </template>

      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="dataForm.current"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="dataForm.size"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
      @refreshDataList="getDataList"
      :dataForm="editModel"
    ></add-or-update>

  </div>
</template>

<script>
import { listFtmsorderbills, deleted } from '@/api/fleet/companyMsg'
import AddOrUpdate from './companyMsg-add-or-update'

export default {
  data() {
    return {
      dataForm: {
        companyName: '',
        linkMan: '',
        linkPhone: '',
        current: 1,
        size: 10
      },
      editModel: {},
      dataList: [],
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false
    }
  },
  components: {
    AddOrUpdate
  },
  activated() {
    this.getDataList()
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      listFtmsorderbills(this.dataForm).then(data => {
        console.log(data)
        if (data && data.code === 200) {
          this.dataList = data.rows
          this.totalPage = data.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })

      // this.$http({
      //   url: this.$http.adornUrl('/fleet/companyMsg/page'),
      //   method: 'get',
      //   params: this.$http.adornParams(this.dataForm)
      // }).then(({ data }) => {
      //
      // })
    },
    resetQuery() {
      this.dataForm = {
        companyName: '',
        linkMan: '',
        linkPhone: ''
      }
    },
    // 每页数
    sizeChangeHandle(val) {
      this.dataForm.pagesize = val
      // this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.dataForm.current = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val
    },
    // 新增 / 修改
    addOrUpdateHandle(row, count) {
      this.addOrUpdateVisible = true
      if (row) {
        this.editModel = row
      } else {
        this.editModel = {
          id: null,
          companyName: null,
          companyAddress: null,
          openingBank: null,
          bankAccount: null,
          creditLv: null,
          paymentDays: null,
          carNum: null,
          linkMan: null,
          linkPhone: null,
          fax: null,
          email: null,
          headOffice: null,
          registerdCapital: null,
          legalPerson: null,
          insdustry: null,
          creditNum: null,
          taxpayerNum: null,
          industryCommerceNum: null,
          organizationNum: null,
          registerOrganization: null,
          dateOfEstablishment: null,
          companyType: null,
          businessDeadline: null,
          businessArea: null,
          annualDate: null,
          registerdAddress: null,
          manageScope: null,
          creatTime: null,
          modificationTime: null,
          pwd: null,
          loginAccount: null,
          pwd2: null
        }
      }
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init()
      })
    },
    // 删除
    deleteHandle(id) {
      var companyMsgIds = id ? [id] : this.dataListSelections.map(item => {
        return item.userId
      })
      this.$confirm(`确定对[id=${companyMsgIds.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleted(companyMsgIds).then(data => {
          console.log(data)
          if (data && data.code === 200) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList()
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      }).catch(() => {
      })
    }
  }
}
</script>
