<template>
  <div>
    <el-row style="height: 100%" v-loading="loading">
      <el-col
        :span="24"
        style="padding: 20px;  height: 100%"
      >
        <el-card style="height: 100%; overflow-y: auto">
          <el-col :span="24" class="elrow-main__col-top">
            <div>
              <el-input
                v-model="form.tarcecodeapplyno"
                style="width: 250px;margin:0 15px;"
                placeholder="请输入溯源码编号"
                @keyup.enter.native="handleSearch"
                clearable
              />
              <el-button
                type="primary"
                size="small"
                @click="handleSearch"
                >查询</el-button
              >
            </div>
            <div class="top-left">
              <el-button
                type="primary"
                size="small"
                @click="addAssociation"
                >新增协会</el-button
              ></div>
          </el-col>
          <el-col :span="24" class="elrow-main__col-bottom">
            <img v-if="imgUrl" :src="imgUrl" />
            <b-table
              ref="tableRef"
              :args="{ 'highlight-current-row': true }"
              :data="loadData"
              :columns="columns"
              isShowIndex
            >
              <template #styleImg="scope">
                <el-image
                  :src="scope.row.imgPreview"
                  :preview-src-list="[scope.row.imgPreview]"
                  slot="error"
                  class="image-slot"
                  style="width: 100px; height: 50px"
                >
                  <div slot="error" class="image-slot"></div>
                </el-image>
              </template>
              <template #codeNo="scope">
                <el-link
                  type="primary"
                  :underline="false"
                  @click="goDetail(scope.row)"
                  >{{ scope.row.traceCodeApplyConcat }}</el-link
                >
              </template>
              <template #useNumber="scope">
                {{ scope.row.useNumber + '/' + scope.row.totalNumber }}
              </template>
              <template #finishGoodName="scope">
                {{ scope.row.finishGoodName&&scope.row.finishgoodNo?scope.row.finishGoodName + '-' + scope.row.finishgoodNo:'' }}
              </template>

              <template #operate="scope">
                <el-link
                  size="small"
                  :underline="false"
                  type="primary"
                  style="margin-right: 10px"
                  @click="download(scope.row)"
                  >下载</el-link
                >
                <el-link
                size="small"
                :underline="false"
                type="danger"
                style="margin-right: 10px"
                @click="download(scope.row)"
                >删除</el-link
              >
              </template>
            </b-table>
          </el-col>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import BTable from '@/components/Table/index.vue';
import { assign, omit } from 'lodash-es';

export default {
  name:"report",
  components: { BTable},
  data() {
    return {
      imgUrl: '',
      baseImageUrl: process.env.VUE_APP_BASE_RESOURCE_PREFIX,
      form: {
        productName: ''
      },
      loading: false,
      associationManageShow: false,
      columns: [
        {
          label: '用户协议会名称',
          prop: 'person',
          customRender: '',
          align: 'center'
        },
        {
          label: '管理区域',
          prop: 'area',
          customRender: '',
          align: 'center'
        },
        {
          label: '负责人',
          prop: 'name',
          customRender: '',
          align: 'center'
        },
        {
          label: '电话',
          prop: 'phone',
          customRender: '',
          align: 'center'
        },
        {
          label: '操作',
          customRender: 'operate',
          align: 'center'
        }
      ]
    };
  },
  created() {},
  methods: {
    addAssociation() {
      this.associationManageShow = true
    },
    loadData(parameter) {
      const queryform = this.form;
      const payload = omit(assign({}, parameter, queryform, {orderByColumn:'tarcecodeapplyCreateddate',isAsc:'desc'}), []);
      return this.getTableData(payload);
    },
    getTableData(payload) {
      return Promise.resolve({
        data: [{
            person:"王大虎",
            area: '2016-05-02',
            name: '王小虎',
            phone: 1588888888,
            address: '上海市普陀区金沙江路 1518 弄'
          }, {
            person:"王大虎",
            area: '2016-05-04',
            name: '王小虎',
            phone: 1588888888,
            address: '上海市普陀区金沙江路 1517 弄'
          }, {
            person:"王大虎",
            area: '2016-05-01',
            name: '王小虎',
            phone: 1588888888,
            address: '上海市普陀区金沙江路 1519 弄'
          }, {
            person:"王大虎",
            area: '2016-05-03',
            name: '王小虎',
            phone: 1588888888,
            address: '上海市普陀区金沙江路 1516 弄'
          }]
      })
    },
    handleSearch() {
      this.$refs.tableRef.refresh(true);
    },
    goDetail(row) {
      this.$refs.sourceCodeDetail.open(row.tarcecodeapplyBatchno)
    },
    download(row) {
    }
  }
};
</script>

<style lang="scss" scoped>
.elrow-main__col-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 15px;
  // padding: 20px 10px;
  // background-color: #fff;
  // border-radius: 5px;
  .top-left {
    height: 100%;
    display: flex;
    align-items: center;
    i {
      background-color: #40d5ec;
      height: 45%;
      width: 5px;
      margin-right: 5px;
    }
  }
}
</style>
