DistributionStore.vue 4.25 KB
<template>
  <div class="container">
    <glsx-combi-form class="edit-form-container" ref="editFormRef" :isEdit="true" :isBlock="true"
                     :formRef="editChildRef" :formObj="editForm" :formData="editFormData" :formRules="editRule">
      <div slot="merchantHtml">
        <el-button type="default" class="el-icon-plus" v-if="!isDisabled" @click="handleOpen">分配门店</el-button>
        <div class="mer-des">请选择门店分配旅程模版</div>
        <GLTable ref="memberCenterRef"
                 :tableData="tableData"
                 :hasPage="false"
                 :tableParams="tableParams">
          <div class="table-btns" slot="auth-button" slot-scope="scope">
            <GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope" :buttonNum="3"></GLTableButton>
          </div>

        </GLTable>
      </div>
    </glsx-combi-form>
    <MerchantStore v-if="relateStoreVisible" ref="relateStore" :dialogVisible="relateStoreVisible"
                   :storeSelected="selectedList" :merchantInfo="editForm"
                   @handleRelateStoreConfirm="handleRelateStoreConfirm"
                   @handleRelateStoreClose="handleRelateStoreClose"></MerchantStore>
  </div>
</template>

<script>
import MerchantStore from "views/journeyConfig/components/merchantStore";

export default {
  name: "DistributionStore",
  components: {
    MerchantStore
  },
  data() {
    return {
      editChildRef: 'editChildRef',
      editForm: {
        merchantId: '',
        merchantName: ''
      },
      editFormData: [
        {
          label: '可见商户',
          name: 'merchantId',
          addHtml: 'merchantHtml'
        }
      ],
      editRule: {
        merchantId: [{
          required: true, validator: (rule, value, callback) => {
            if (this.editForm.merchantId) {
              callback()
            } else {
              callback(new Error(`请选择门店`))
            }
          }, trigger: 'change'
        }],
      },
      selectedList: [],
      tableData: [],
      relateStoreVisible: false,
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '商户号',
            prop: 'groupId',
          },
          {
            label: '商户名称',
            prop: 'groupName',
          }

        ],
      },
      // 表格按钮
      tableButtonList: [
        {
          type: 'el-button',
          name: '删除',
          attrs: {
            type: 'text'
          },
          listeners: {
            click: () => {
              this.tableData = []
              this.editForm={
                merchantId: '',
                merchantName: ''
              }
            }
          }
        }
      ],
    }
  },
  methods: {
    handleOpen() {
      this.tableData = []
      this.relateStoreVisible = !this.relateStoreVisible
    },
    //搜索门店table
    handleSearchStore() {
      this.$refs.relateStore.handleCurrentChange(1)
    },
    handleRelateStoreConfirm(selectedData) {
      if (!selectedData.merchantId && !selectedData.merchantName){
        this.$message.error('请选择门店')
        return
      }
      this.editForm = selectedData
      this.$refs.editFormRef.$refs[this.editChildRef].clearValidate('merchantId')
      selectedData.merchantId && (this.editForm.merchantId = selectedData.merchantId)
      selectedData.merchantName && ((this.editForm.merchantName = selectedData.merchantName), (this.merchantFlag = false))
      this.tableData.push({
        groupId: selectedData.merchantId,
        groupName: selectedData.merchantName,
      })
      this.handleRelateStoreClose()
    },
    handleRelateStoreClose() {
      this.relateStoreVisible = false
    },
    handleVertify() {
      this.$refs.editFormRef.$refs[this.editChildRef]?.validate(valid => {
        if (!this.editForm.merchantName) {
          this.merchantFlag = true
          return
        }
        this.$bus.$emit('saveEvent', {isNext: valid, sopTplGrants: this.tableData})
      })
    }
  },
  mounted() {
    this.$bus.$on('vertifyMerchant', data => {
      this.handleVertify()
    })
  }
}
</script>

<style lang="scss" scoped>
/deep/ .el-form-item__content {
  width: 80% !important;
}
.mer-des{
  color: #C6C6C6;
  font-size: 12px;
}

</style>