<template>
  <a-modal
    centered
    class="importHuoweiModal-modal"
    :footer="null"
    :maskClosable="false"
    title="批量导入货位"
    v-model="isShow"
    @cancle="isShow=false"
    :width="750">
    <div class="importHuoweiModal-con">
      <div class="explain-con">
        <div class="explain-item">
          <div class="explain-tit">
            <span>1</span>下载导入模板
            <p>请按照下载的Excel模板填写数据</p>
            <a :href="filePath" style="padding: 5px 0 0 23px;display: block;">
              <a-icon type="download" style="padding-right: 5px;" />下载导入模板
            </a>
          </div>
        </div>
        <div class="explain-item">
          <div class="explain-tit">
            <span>2</span>准备导入数据
          </div>
          <ul>
            <li>1) 导入的Excel文件中必须包含名为“货位号”、“产品编码”、“销售价”、“结算价”、“最大库容”的列，且名称必须相同，其他列可自定义，不影响数据导入。</li>
            <li>2) 如果“产品编码”列为空，则表示此货位暂时不绑定产品，也可以正常导入货位。</li>
            <li>3) 当“销售价”和“结算价”都为空，系统会自动取该产品的车主价和终端会员价，作为销售价和结算价。</li>
            <li>4) 如果货位已经绑定产品，则不会导入该行。</li>
          </ul>

        </div>
        <div class="explain-item">
          <div class="explain-tit">
            <span>3</span>上传数据文件
          </div>
          <p>目前支持的文件类型*.xls，*.xlsx.</p>
          <div style="overflow: hidden;padding-left: 23px;">
            <Upload
              id="importHuoweiModal-attachList"
              ref="importUpload"
              :maxNums="1"
              fileType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
              uploadType="import"
              :action="attachAction"
              :uploadParams="uploadParams"
              upText="添加文件"
              @change="changeImport"></Upload>
          </div>
        </div>
      </div>
      <!-- 按钮 -->
      <div class="btn-con">
        <a-button
          type="primary"
          id="importHuoweiModal-nextStep"
          size="large"
          class="button-primary"
          @click="handlerNextStep"
          style="padding: 0 60px;">下一步</a-button>
        <a-button
          id="importHuoweiModal-cancel"
          size="large"
          class="button-cancel"
          @click="isShow=false"
          style="padding: 0 60px;margin-left: 15px;">取消</a-button>
      </div>
    </div>
    <!-- 导入 -->
    <chooseImportModal :openModal="openImportModal" :paramsData="paramsData" @close="handleClose" @ok="hanldeOk" />
  </a-modal>
</template>

<script>
import ChooseImportModal from './chooseShelfImportModal.vue'
import { Upload } from '@/components'
export default {
  name: 'ImportHuoweiModalModal',
  components: { ChooseImportModal, Upload },
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    shelfSn: {
      type: [String, Number],
      default: ''
    }
  },
  data () {
    return {
      isShow: this.openModal, //  是否打开弹框
      openImportModal: false, //  导入
      filePath: 'https://jianguan-images.oss-cn-beijing.aliyuncs.com/template/importProductToShelfTpl.xlsx', // 文件地址
      attachAction: process.env.VUE_APP_API_BASE_URL + '/upload',
      paramsData: null,
      uploadParams: {
        savePathType: 'local'
      }
    }
  },
  methods: {
    // 下一步
    handlerNextStep () {
      if (this.paramsData) {
        this.openImportModal = true
      } else {
        this.$message.warning('添加文件后再进行下一步操作！')
      }
    },
    // 上传文件  change
    changeImport (file) {
      if (file) {
        this.paramsData = {
          shelfSn: this.shelfSn || '',
          path: file
        }
        console.log(this.paramsData, 'this.paramsData')
      }
    },
    // 导入
    hanldeOk (obj) {
      if (obj && obj.length > 0) {
        this.$emit('ok', obj)
        this.isShow = false
      }
    },
    // 关闭
    handleClose () {
      this.openImportModal = false
      this.isShow = false
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
        this.paramsData = null
        this.$refs.importUpload.setFileList('')
      }
    }
  }
}
</script>

<style lang="less" scoped>
  .importHuoweiModal-modal{
    .importHuoweiModal-con{
      .explain-con{
        .explain-item{
          margin-bottom: 10px;
          .explain-tit{
            font-weight: bold;
            span{
              display: inline-block;
              width: 18px;
              height: 18px;
              line-height: 16px;
              text-align: center;
              margin-right: 5px;
              border-radius: 50%;
              border: 1px solid rgba(0, 0, 0, 0.3);
            }
          }
          p{
            margin: 8px 0;
            padding-left: 23px;
          }
          ul{
            list-style: none;
            padding: 0;
            padding-left: 23px;
            margin: 0;
            li{
              line-height: 26px;
            }
          }
        }
        #importHuoweiModal-attachList{
          width: 100%;
        }
      }
      .btn-con{
        margin: 10px 0 20px;
        text-align: center;
        .button-cancel{
          font-size: 12px;
        }
      }
    }
  }
</style>
