AddDialog.vue 5.64 KB
<!-- 新增商户 -->
<template>
  <div class="newBusiness">
    <gl-dialog
      :title="title"
      :visible.sync="isVisible"
      :before-close="handleClose"
      :width="diaWidth"
      :close-on-click-modal="false"
    >
      <gl-form
        label-width="90px"
        :model="merchantForm"
        :rules="rules"
      >
        <gl-form-item label="商户名称" prop="merchantName">
          <gl-input
            v-model="merchantForm.merchantName"
            placeholder="请输入商户名称"
            name="name"
            data-vv-as="商户名称"
            v-validate="'required|max:128'"
            clearable
          ></gl-input>
          <span v-show="errorBags.has('name')" class="error">{{ errorBags.first('name') }}</span>
        </gl-form-item>
        <gl-form-item label="商户地址" prop="address">
          <city-area
            ref="c"
            :showCity="showCity"
            :validateCity="validateCity"
            :eventBus="eventBus"
            @cityArea="getCityArea">
          </city-area>
        </gl-form-item>
        <gl-form-item label="">
          <gl-input
          v-model="merchantForm.address"
          placeholder="请输入详细地址"
          name="address"
          data-vv-as="详细地址"
          v-validate="'required|max:256'"
          clearable
          >
          </gl-input>
          <span v-show="errorBags.has('address')" class="error">{{ errorBags.first('address') }}</span>
        </gl-form-item>
        <gl-form-item label="商户渠道" prop="merchantChannel">
          <gl-select
            v-model="merchantForm.merchantChannel"
            placeholder="请选择"
            name="merchantChannel"
            data-vv-as="商户渠道"
            v-validate="'required'"
          >
          <gl-option
            v-for="item in channelList"
            :key="item.confId"
            :label="item.confKey"
            :value="item.confId">
          </gl-option>
          </gl-select>
          <span v-show="errorBags.has('merchantChannel')" class="error">{{ errorBags.first('merchantChannel') }}</span>
        </gl-form-item>
        <gl-form-item label="联系人" prop="contactor">
          <gl-input
            v-model="merchantForm.contactor"
            placeholder="请输入联系人姓名"
            name="contactor"
            data-vv-as="联系人姓名"
            v-validate="'required|max:64'"
            clearable
          ></gl-input>
          <span v-show="errorBags.has('contactor')" class="error">{{ errorBags.first('contactor') }}</span>
        </gl-form-item>
        <gl-form-item label="手机号码" prop="contactPhone">
          <gl-input
            v-model="merchantForm.contactPhone"
            placeholder="请输入联系人手机号码"
            name="contactPhone"
            data-vv-as="联系人手机号码"
            v-validate="'required|is_phone'"
            clearable
          ></gl-input>
          <span v-show="errorBags.has('contactPhone')" class="error">{{ errorBags.first('contactPhone') }}</span>
        </gl-form-item>
      </gl-form>
      <span slot="footer">
        <el-button
          type="primary"
          @click="handleComfrim"
        >确 定</el-button>
        <el-button @click="handleClose">取 消</el-button>
      </span>
    </gl-dialog>
  </div>
</template>

<script>
import notice from '@/common/notice'
import { CityArea } from '../components'
import { businessManagenMethods, request } from '@/api'
const isPhone = {
  validate: (value, args) => {
    return value.length === 11 && /^1[345789]\d{9}$/.test(value)
  }
}
export default {
  name: 'AddDialog',
  data() {
    return {
      title: '新增商户',
      channelList: [],
      // 省市区组件-配置
      eventBus: null,
      showCity: [1, 1, 1],
      validateCity: [1, 1, 1],
      areaInfo: {},
      // phoneFixed: 11,
      rules: {
        merchantName: [{ required: true }],
        address: [{ required: true }],
        merchantChannel: [{ required: true }],
        contactor: [{ required: true }],
        contactPhone: [{ required: true, isPhone: true }]
      }
    }
  },
  props: {
    isVisible: {
      type: Boolean,
      default: false
    },
    diaWidth: {
      type: String,
      default: '40%'
    },
    merchantForm: Object
  },
  components: {
    CityArea
  },
  watch: {
    isVisible(val) {
      this.$validator.errors.clear()
      val && this.getChannel()
      if (!val) {
        this.eventBus.$emit('reset')
        this.areaInfo = {}
      }
    }
  },
  mounted() {
    this.$validator.extend('is_phone', isPhone)
    this.eventBus = this.$root.eventBus
  },
  methods: {
    handleClose() {
      this.$emit('hideDialog')
    },
    handleComfrim() {
      Promise.all([
        this.$refs['c'].$validator.validateAll(),
        this.$validator.validateAll()
      ]).then((result) => {
        if (result[0] && result[1]) {
          this.$emit('comfirmDialog', this.areaInfo)
        }
      })
    },
    getChannel() {
      const params = {}
      params.method = businessManagenMethods.Channel
      request.req(params).then(res => {
        this.channelList = res.merchantDictList
      }).catch(err => {
        notice.errorTips(err)
      })
    },
    getCityArea(params) {
      params[0] && (this.areaInfo.provinceId = params[0])
      params[1] && (this.areaInfo.cityId = params[1])
      params[2] && (this.areaInfo.areaId = params[2])
      params[3] && (this.areaInfo.provinceName = params[3])
      params[4] && (this.areaInfo.cityName = params[4])
      params[5] && (this.areaInfo.areaName = params[5])
    }
  }
}

</script>
<style>
.newBusiness .el-dialog__body {
  padding: 0 20px;
}
.newBusiness .el-select {
  width: 100%;
}
</style>