<template>
  <ai-list class="list" v-loading="isLoading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading">
    <ai-title
      slot="title"
      title="查找买手"
      isShowBottomBorder>
    </ai-title>
    <template slot="content">
      <div class="content">
        <ai-card title="查找买手" style="padding-bottom: 40px;">
          <div style="text-align: center; display: flex; flex-wrap: nowrap;justify-content: center;">
              <label style="width:90px; height: 25px; font-size: 25px">店铺：</label>
              <el-select style="width:180px;" v-model="form.mallId" placeholder="请选择" clearable size="small">
                <el-option
                  v-for="item in $store.state.mallList"
                  :key="item.mallId"
                  :label="item.mallName"
                  :value="item.mallId">
                </el-option>
              </el-select>
              <label style="width:120px; height: 25px; font-size: 25px">SKC ID：</label>
              <el-input style="width:250px; " clearable size="small"  placeholder="请输入SKC ID" v-model="form.skc"></el-input>
              <el-button style="margin-left: 5px" type="primary" @click="beforeFind">查找</el-button>
          </div>
        </ai-card>
      </div>
    </template>
  </ai-list>
</template>

<script>
import { Message } from 'element-ui'
import {sendChromeAPIMessage} from '@/api/chromeApi'

  export default {
    name: 'FindSeller',

    data () {
      return {
        form: {
          mallId: '',
          skc: ''
        },
        isLoading: false,
      }
    },
    created () {
    },
    methods: {
      beforeFind() {
        this.$userCheck(this.form.mallId).then(() => {
          this.toFind()
        }).catch((err) => {
          this.form.mallId = ''
        })
      },
      async toFind() {
        if (!this.form.mallId) {
          Message.error("请选择店铺")
          return
        }
        if (!this.form.skc || (this.form.skc < 1)) {
          Message.error("请输入SKC")
          return
        }

        this.isLoading = true

        let res = await sendChromeAPIMessage({
          url: 'marvel-mms/cn/api/kiana/venom/sales/management/listWarehouse',
          needMallId: true,
          mallId: this.form.mallId,
          data: {
            pageNo: 1,
            pageSize: 10,
            isLack: 0,
            priceAdjustRecentDays: 7,
            productSkcIdList: [this.form.skc]
        }})
        if (res.errorCode == 1000000) {
          if (res.result.subOrderList.length == 0) {
            Message.error("没有查询结果，请检查店铺和SKC是否正确")
          } else {
            this.$confirm(res.result.subOrderList[0].buyerName, '查询结果', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
              center: true
            }).then(() => {
              
            })
          }
        }
        this.isLoading = false
      }
    }
  }
</script>

<style scoped lang="scss">
  .list {
    .title-right {
      display: flex;
      align-items: center;

      & > div:first-child {
        margin-right: 20px;
      }
    }
    ::v-deep.ai-list {
      .ai-list__content--right-wrapper {
        background: transparent;
        box-shadow: none;
        padding: 0!important;
      }
    }
  }
</style>