<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :span="6">
            <a-form-item label="">
              <a-input
                placeholder="商品名称"
                v-model="queryParam.goodsName"
              ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="3">
            <span>
              <a-button type="primary" @click="searchQuery" icon="search"
                >查询</a-button
              >
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
        :rowSelection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange,
        }"
      >
        <template slot="avatar" slot-scope="text">
          <a-avatar v-if="text" :src="text" />
          <a-avatar v-else icon="user" />
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic"
            >无图片</span
          >
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic"
            >无文件</span
          >
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)"
          >
            下载
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleSelect(record)">选择</a>
        </span>
      </a-table>
    </div>
  </a-card>
</template>

<script>
import "@/assets/less/TableExpand.less";
import { mixinDevice } from "@/utils/mixin";
import { JeecgListMixin } from "@/mixins/JeecgListMixin";
import { httpAction } from "@/api/manage";
import { getAction } from "@/api/manage";
export default {
  name: "BusMemberCardList",
  mixins: [JeecgListMixin, mixinDevice],
  props: {
    supplierId: {
      type: String,
      default: "",
    },
    depositoryId: {
      default: "",
    },
  },
  data() {
    const hotelInfo = JSON.parse(localStorage.getItem("storeInfo"));
    return {
      datetime: [],
      hotelId: "",
      num: 1,
      description: "PickingGoodsOrder",
      // 表头
      columns: [
        {
          title: "商品名称",
          align: "center",
          dataIndex: "goodsName",
        },
        // {
        //   title: "商品类别",
        //   align: "center",
        //   dataIndex: "goodTypeName",
        // },
        {
          title: "商品规格",
          align: "center",
          dataIndex: "goodsSpec",
        },
        {
          title: "库存数量",
          align: "center",
          dataIndex: "num",
        },
        {
          title: "单位",
          align: "center",
          dataIndex: "goodsUnitName",
        },
      ],
      url: {
        list: '/kc/kcDepositoryInGoods/list?depositoryId=' + this.depositoryId,
        delete: "/kc/kcSupplierInGoods/delete",
        deleteBatch: "/kc/kcSupplierInGoods/deleteBatch",
        exportXlsUrl: "/kc/kcSupplierInGoods/exportXls",
        importExcelUrl: "/kc/kcSupplierInGoods/importExcel",
      },
      dictOptions: {},
      superFieldList: [],
      orderGoodsDetailList: [],
      selectOrderInfo: {},
    };
  },
  created() {},
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG["domianURL"]}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    handleSelect(row) {
      this.$emit("ok", row);
    },
    submitForm() {
      const that = this;
      console.log(this.selectedRowKeys);
      if (this.selectedRowKeys.length === 0) {
        this.$message.warning("请先选择商品");
        return;
      }
      let arr = this.dataSource.filter((item) => {
        return this.selectedRowKeys.includes(item.id);
      });
      arr.forEach(element => {
        element.stockNum = element.num;
        // element.price = element.costPrice
      });
      arr = arr.map(ele=>({
        ...ele,
        name:ele.goodsName,
        spec:ele.goodsSpec,
        goodUnit:ele.goodsUnitName,
      }))
      this.$emit("ok", arr);
      // that.confirmLoading = true;
      // let httpurl = "/kc/kcStock/add";
      // let method = "post";
      // var model = {
      //   supplierId: this.supplierId,
      //   goodsIds: this.selectedRowKeys,
      // };
      // var _info = JSON.parse(localStorage.getItem("storeInfo"));
      // if (_info) {
      //   model.hotelId = _info.id;
      // }
      // httpAction(httpurl, model, method)
      //   .then((res) => {
      //     if (res.success) {
      //       that.$message.success(res.message);
      //       that.$emit("ok");
      //     } else {
      //       that.$message.warning(res.message);
      //     }
      //   })
      //   .finally(() => {
      //     that.confirmLoading = false;
      //   });
    },
  },
};
</script>
<style scoped>
@import "~@assets/less/common.less";
/deep/ .ant-input-search-button {
  background-color: #ff4d4f;
  border-color: #ff4d4f;
}
/deep/ .ant-input-search-button[disabled]:hover {
  opacity: 0.7;
  background-color: #ff4d4f;
  border-color: #ff4d4f;
}
/deep/ .ant-input-search-button[disabled] {
  opacity: 0.7;
  color: #ffffff;
}
</style>