<template>
  <div class="common-page-shadow">
    <div class="common-search-container" ref="contentPanel">
      <el-form
        ref="form"
        :model="searchForm"
        label-width="auto"
        label-position="right "
        :inline="true"
        type="flex"
        justify="left"
      >
        <el-form-item label="销售企业">
          <el-input
            size="small"
            v-model="searchForm.code"
            clearable
            placeholder="请输入销售企业"
          ></el-input>
        </el-form-item>
        <el-form-item label="购货企业">
          <el-input
            size="small"
            v-model="searchForm.name"
            clearable
            placeholder="请输入购货企业"
          ></el-input>
        </el-form-item>
        <el-form-item label="物料名称">
          <el-input
            size="small"
            v-model="searchForm.name"
            clearable
            placeholder="请输入物料名称"
          ></el-input>
        </el-form-item>
      </el-form>
      <div class="container-btn">
        <el-button
          size="small"
          icon="el-icon-search"
          type="danger"
          class="btn btn-plus"
          @click="handleSearch"
        >
          搜索
        </el-button>
        <el-button
          size="small"
          icon="el-icon-refresh-right"
          class="btn btn-plus"
          @click="clearSearchForm"
        >
          重置
        </el-button>
      </div>
    </div>
    <el-row
      class="common-table-container flex searchPanel"
      :style="SearchPanel"
    >
      <el-col :span="24" class="common-table-wrapper">
        <div class="common-btn-group">
          <el-button
            size="small"
            icon="el-icon-s-custom"
            type="primary"
            class="btn btn-plus"
            @click="handleNotExecuted"
          >
            成交不执行
          </el-button>
        </div>
        <!-- LJ：表格高度自适应需配合样式  btn-pagenation 有按钮有分页  btngroup只有按钮  pagenation只有分页 -->
        <div class="common-table-content btn-pagenation">
          <el-table
            :border="true"
            stripe
            fit
            size="mini"
            v-loading="tableLoading"
            ref="multipleSelection"
            :data="tableData"
            @row-dblclick="handleDetail"
            @selection-change="handleSelectionChange"
          >
            <!-- @row-dblclick="handleDetail" -->
            <el-table-column type="selection" min-width="5%" align="center">
            </el-table-column>
            <el-table-column
              prop="companyName"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="销售企业"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="companyName1"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="购货企业"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="companyName3"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="购货企业联系方式"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="companyName3"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="物料名称"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="companyName4"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="物料编号"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="companyName5"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="预计数量"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="companyName6"
              show-overflow-tooltip
              min-width="8%"
              align="center"
              label="单位"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="companyName7"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="成交单价(元)"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="companyName8"
              show-overflow-tooltip
              min-width="8%"
              align="center"
              label="税率(%)"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="companyName8"
              show-overflow-tooltip
              min-width="12%"
              align="center"
              label="交易服务费(%)"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="companyName8"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="成交总价(元)"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="companyName8"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="价格截止执行日期"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="companyName8"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="地址"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="companyName8"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="备注"
              resizable
            >
            </el-table-column>
          </el-table>
        </div>
        <div class="common-pagenation">
          <el-pagination
            ref="paginationPanel"
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="params.pageBean.page"
            :page-sizes="[20, 30, 40, 50]"
            :page-size="params.pageBean.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="params.pageBean.total"
          >
          </el-pagination>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import pagination from '@/components/pagination'
import {TableMixin} from '@/mixins/tableMixin'
import routerManagement from '@/api/BasicDataManagement/routerManagement.js'
import req from '@/request.js'
import utils from '@/utils.js'
const portal = window.context.portal
export default {
  name: 'inquiryContract',
  components: {
    pagination
  },
  mixins: [TableMixin],
  data() {
    return {
      currentPage: 1,
      tableMaxHeight: 400,
      loading: false,
      tableLoading: false,
      tableData: [],

      multipleSelection: [],

      params: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0
        }
      },

      searchForm: {}, // 顶部搜索对象
      deleteIds: '', // 是否选中列表解锁删除按钮
      activeCollapse1: ['1', '2'],
      fileList: [], // 文件上传
      edit: false, // 是否是修改功能
      currentDataDel: [], // 删除时排查是否有在审核的数据
      rules: {
        code: {
          required: true,
          message: '请输入路线编号',
          trigger: 'blur'
        },
        name: {
          required: true,
          message: '请选择路线名称',
          trigger: 'blur'
        }
      }
    }
  },
  mounted() {},
  created() {
    if (this.$route.params.pageBean) {
      this.params = this.$route.params.pageBean
      this.pageResult = this.$route.params.pageBean.pageBean
    }
    // this.loadData(this.params)
  },
  methods: {
    // 成交不执行
    handleNotExecuted() {
      let selection = this.$refs.multipleSelection.selection
      if (selection.length !== 0) {
        this.$confirm('确定成交不执行吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message.success('执行成功！')
        })
      } else {
        this.$message.info('请选择要执行的数据！')
      }
    },
    getDictName(code, value) {
      return utils.getDictName(code, value)
    },
    //获取数据
    loadData(params) {
      this.tableLoading = true
      routerManagement.queryEventsList(params).then(res => {
        console.log(res, 'res')
        this.tableLoading = false
        const data = (res && res.data) || {}
        this.tableData = data.value.rows || []
        console.log('返回的表格数据', this.tableData)
        this.pageResult = {
          page: data.value.page,
          pageSize: data.value.pageSize,
          total: data.value.total
        }
      })
    },
    // //添加
    // handleAdd() {
    //   this.$router.push('inquiryContractAddDialog')
    // },
    // // 编辑
    // handleEdit(rows) {
    //   this.$refs.form.clearValidate()
    //   this.$router.push({
    //     name: 'inquiryContractAddDialog',
    //     query: {editRows: rows, pageBean: this.params}
    //   })
    // },
    // 详情
    handleDetail(rows) {
      this.$router.push({
        name: 'conSingleDetail',
        query: {detailRows: rows, pageBean: this.params}
      })
    },

    // 删除
    handleDelete() {
      this.$confirm(this.$t('common.sureDelete'), this.$t('common.tips'), {
        confirmButtonText: this.$t('common.confirm'),
        cancelButtonText: this.$t('common.cancel'),
        type: 'warning'
      }).then(() => {
        routerManagement.batchDelete(this.deleteIds).then(res => {
          this.loadData(this.params)
        })
      })
    },

    // 顶部搜索
    handleSearch(searchForm) {
      let obj = searchForm
      console.log(obj)
      let querys = []
      for (let i in obj) {
        if (obj[i]) {
          querys.push({
            group: 'main',
            operation:
              i == 'name' || i == 'code' || i == 'companyName'
                ? 'LIKE'
                : 'EQUAL',
            parentGroup: '',
            property: i,
            relation: 'AND',
            value: obj[i]
          })
        }
      }
      console.log(querys, 'querys')
      this.params.querys = querys
      console.log(this.params, 'params')
      this.loadData(this.params)
    },
    // 表单提交保存
    submit(status) {
      this.dialogForm.status = status
      // 删除approvalComments参数确保能够保存
      Reflect.deleteProperty(this.dialogForm, 'approvalComments')
      this.$refs.form.validate(valid => {
        if (valid) {
          this.loading = true
          routerManagement
            .batchSubmit(this.dialogForm)
            .then(res => {
              console.log('res', res)
              if (res.data.state) {
                this.dialog.visible = false
                this.loadData(this.params)
              }
              if (!res.errorMsg) {
                this.$message({
                  message: !this.edit ? '添加成功' : '修改成功',
                  type: 'success'
                })
                this.editVisible = false
              }
              this.loading = false
            })
            .catch(() => {
              this.loading = false
            })
        } else {
          return false
        }
      })
    },
    handleSelectionChange(currentData) {
      this.currentDataDel = currentData
      if (currentData.length === 0) return (this.deleteIds = '')
      let ids = []
      currentData.forEach(item => {
        ids.push(item.id)
      })
      // this.$message.error(`【${item.demandTopic}】已上报待审核不能删除！`)
      this.deleteIds = ids.join(',')
    },
    handleCurrentChange(page) {
      this.params.pageBean = {...this.params.pageBean, page}
      this.loadData(this.params)
    },
    handleSizeChange(pageSize) {
      this.params.pageBean = {...this.params.pageBean, pageSize}
      this.loadData(this.params)
    }
  },
  computed: {
    SearchPanel() {
      return {
        '--searchPanel': this.searchPanel + 'px'
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.common-table-content.btn-pagenation {
  height: calc(100% - 100px);
}
.cloumn-btn {
  border: 1px solid #2761ff;
  padding: 3px 10px;
  border-radius: 5px;
  &:nth-child(1) {
    margin-right: 5px;
  }
  &:nth-child(2) {
    margin-right: 5px;
  }
  &:nth-child(1):hover {
    background-color: #2761ff;
    color: #fff;
  }
  &:nth-child(2):hover {
    background-color: #2761ff;
    color: #fff;
  }
  /deep/ i,
  span {
    font-size: 16px;
  }
}

/deep/ .el-tree-node__content {
  padding: 5px 0;
}

/deep/ .el-table thead tr th {
  background-color: #eee !important;
  border-right: 1px solid #dfe2e8 !important;
}
/deep/ .el-table {
  border-collapse: collapse !important;
}
</style>
