add.vue 4.94 KB
<template>
  <div class="add-wrap">
    <div class="container edit-container" style="min-height: 520px !important">
      <p class="edit-title" id="basic">新增门店</p>
      <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="handleRelateStoreClose">选择门店</el-button>
          <div class="merchantNameLabel" v-if="editForm.merchantName">
            <p>所属门店</p>
            <div class="merchantName ellipsis-1">{{ editForm.merchantName }}</div>
          </div>
          <div class="el-form-item__error mrt5" v-if="merchantFlag">请选择门店</div>
        </div>
        <div slot="channelHtml">
          <el-checkbox-group v-model="editForm.channelIds" @change="handleCheckedChannelChange">
            <el-checkbox v-for="channel in channelList" :label="channel.id" :key="channel.id">{{ channel.name }}</el-checkbox>
          </el-checkbox-group>
        </div>
      </glsx-combi-form>
    </div>
    <select-store v-if="relateStoreVisible" ref="relateStore" :dialogVisible="relateStoreVisible" :storeSelected="selectedList" :merchantInfo="editForm.merchantId" @handleRelateStoreConfirm="handleRelateStoreConfirm" @handleRelateStoreClose="handleRelateStoreClose"></select-store>
    <GLFooter>
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary" @click="handleSave">确定</el-button>
    </GLFooter>
  </div>
</template>
<script>
import selectStore from './components/selectStore'
export default {
  components: {
    selectStore
  },
  data() {
    return {
      size: 'small',
      editChildRef: 'editChildRef',
      editForm: {
        channelIds: []
      },
      merchantFlag: false,
      editFormData: [
        {
          label: '选择门店',
          name: 'merchantId',
          addHtml: 'merchantHtml'
        },
        {
          label: '频道名称',
          name: 'channel',
          addHtml: 'channelHtml'
        }
      ],
      selectedList: [],
      channelList: [
        { name: '新车专区', id: 1 },
        { name: '膜类专区', id: 2 },
        { name: '限时众筹', id: 3 },
        { name: '定保专区', id: 4 }
      ],
      relateStoreVisible: false, // 选择门店
      editRule: {
        channelIds: [{ required: true, message: '请选择频道名称', trigger: 'change' }]
      }
    }
  },
  created() {

  },
  methods: {
    handleCancel() {
      this.$router.go(-1)
    },
    handleSave() {
      this.$refs.editFormRef.$refs[this.editChildRef].validate(valid => {
        if (!this.editForm.merchantName) {
          this.merchantFlag = true
          return
        }
        if (valid) {
          let params = {
            merchantId: this.editForm.merchantId,
            merchantName: this.editForm.merchantName,
            channelIds: this.editForm.channelIds
          }
          this.loading = true
          this.$apis.store.configMerchant(params).then(res => {
            if (res.code == 0) {
              this.loading = false
              this.$router.go(-1)
            }

            this.$message({
              message: res.code == '0' ? '编辑成功' : res.message,
              type: res.code == '0' ? 'success' : 'error'
            })
          })
        }
      })
    },
    handleCheckedChannelChange(val) {
      // console.log(this.editForm.channelIds)
    },
    // 选择门店
    handleRelateStoreClose() {
      this.relateStoreVisible = !this.relateStoreVisible
    },
    handleRelateStoreConfirm(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.handleRelateStoreClose()
    }
  }
}
</script>
<style scoped lang='scss'>
.add-wrap {
  .container {
    min-height: 680px;
    padding: 0px 0px 20px;
    margin-bottom: 16px;
  }
  .edit-title {
    font-size: 16px;
    font-weight: 600;
    height: 58px;
    line-height: 58px;
    border-bottom: 1px solid #e7eaec;
    margin: 0 0;
    padding: 0 0 0 20px;
  }
  .edit-form-container {
    margin-top: 20px;
  }
  .assignLabel {
    color: #5850ff;
  }
  .merchantNameLabel {
    width: 510px;
    color: #1d1d1d;
    // margin-left: 50px;
    padding: 16px;
    margin-top: 8px;
    border: 1px solid #e6e6e6;
    border-radius: 8rpx;
    background: #f9f9f9;
    .merchantName {
      box-sizing: border-box;
      width: 284px;
      height: 32px;
      background: #ffffff;
      border: 1px solid #e6e6e6;
      border-radius: 4px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      font-size: 14px;
      color: #999999;
      line-height: 32px;
      padding: 0 8px;
    }
  }
}
</style>