batchCopyDialog.vue 4.27 KB
<template>
  <d2-dialog title="批量复制"
             :is-visible.sync="batchCopyVisible"
             width="600px"
             btn-ok-label="确定"
             @confirmDialog="handleBatchCopyConfirm"
             @closeDialog="handleBatchCopyClose"
             class="relateStore">
    <el-form label-width="120px" :rules="rules" :model="selectData" ref="batchCopyForm">
      <el-form-item label="业务场景:">
        <el-input style="width: 370px;" v-model="sceneList[selectedScene]" disabled></el-input>
      </el-form-item>
      <el-form-item label="复制门店:" prop="selectMerchantObj">
        <el-select v-model="selectData.selectMerchantObj" remote reserve-keyword multiple collapse-tags
                   placeholder="请选择复制门店" @visible-change="visibleChange" :remote-method="remoteMethod"
                   v-el-select-loadmore="interestsLoadmore" style="width: 370px;" value-key="merchantId" filterable>
          <el-option v-for="subItem in storeData" :key="subItem.merchantId"
                     :label="subItem.merchantName" :value="subItem" />
        </el-select>
      </el-form-item>
    </el-form>
    <div class="tips">
      说明:批量复制至新门店后,系统自动按操作商品,自动更新补充商品对应的上架门店
    </div>
  </d2-dialog>
</template>
<script>
import { getList, getAccountMerchantList } from '@/api/merchant'
import { sceneList } from '@/common/constants.js'
export default {
  name: 'RelateStoreDialog',
  data() {
    return {
      storeData: [],
      // 分页
      total: 0,
      currentPage: 1,
      pageSize: 20,
      searchMerchantName: '',
      sceneList,
      selectData: {},
      rules: { selectMerchantObj: [{ required: true, message: '请选择复制门店', trigger: 'blur' }] }
    }
  },
  directives: {
    'el-select-loadmore': {
      bind(el, binding) {
        setTimeout(() => {
          const SELECTWRAP_DOM = el.querySelector(
            '.el-select-dropdown .el-select-dropdown__wrap'
          )
          SELECTWRAP_DOM.addEventListener('scroll', function () {
            const condition =
              this.scrollHeight - this.scrollTop <= this.clientHeight
            if (condition) {
              binding.value()
            }
          })
        }, 100)
      }
    }
  },
  props: {
    batchCopyVisible: {
      type: Boolean,
      default: false
    },
    selectedScene: {
      type: Number
    }
  },

  mounted() {
    this.getList()
  },

  methods: {
    getList() {
      const storeApi = [1, 2, 3].includes(this.selectedScene) ? getList : getAccountMerchantList // 会员权益/积分商城场景 上架门店是账户中心所有门店
      storeApi({
        // merchantIdName: ![1, 2, 3].includes(this.selectedScene) ? this.searchMerchantName : '',
        merchantName: this.searchMerchantName,
        currentPage: this.currentPage,
        pageSize: this.pageSize,
        scene: this.selectedScene
      }).then(res => {
        res?.list?.forEach(val => { // 账户中心门店返回商户号字段是merchantNo
          if (val.merchantNo) val.merchantId = val.merchantNo
        })
        this.storeData = this.storeData.concat(res.list)
      })
    },
    // 获取上架门店
    remoteMethod(query) {
      this.searchMerchantName = query
      this.currentPage = 1
      this.storeData = []
      this.getList() // 请求接口
    },
    visibleChange(data) {
      // 获取焦点重新渲染下拉框数据
      if (data) {
        if (this.searchMerchantName) {
          this.searchMerchantName = ''
          this.currentPage = 1
          this.storeData = []
          this.getList()
        }
      }
    },
    // 获取更多上架门店
    interestsLoadmore() {
      setTimeout(() => {
        this.currentPage = this.currentPage + 1
        if (this.allPages < this.currentPage) {
          this.currentPage = this.allPages
          return
        }
        this.getList()
      }, 10)
    },
    handleBatchCopyConfirm() {
      this.$refs.batchCopyForm.validate((valid) => {
        if (valid) {
          this.$emit('handleBatchCopyConfirm', this.selectData?.selectMerchantObj)
        }
      })
    },
    handleBatchCopyClose() {
      this.$emit('handleBatchCopyClose')
    }
  }
}

</script>
<style lang="scss">
.tips{
  font-size: 14px;
  color: #999;
}
</style>