baseInfo.vue 12.9 KB
<template>
  <div class="base-info">
    <el-form ref="baseForm" :model="accountAddForm" class="account-body-form" label-width="120px" :rules="baseRules">
      <el-row>
        <el-col :span="12">
          <el-form-item label="商户名称" prop="merchantName">
            <el-input size="small" v-model="accountAddForm.merchantName" placeholder="请输入商户名称"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="商户简称">
            <el-input size="small" v-model="accountAddForm.merchantAbbreviation" placeholder="请输入商户简称"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item size="small" label="商户类型" class="merchant-row">
            <el-input v-model="accountAddForm.merchantOrgcode" placeholder="请输入组织机构号码" v-if="accountAddForm.merchantType == 2" maxlength="50">
              <el-select v-model="accountAddForm.merchantType" slot="prepend" placeholder="请选择">
                <el-option label="个人" :value="1"></el-option>
                <el-option label="企业" :value="2"></el-option>
              </el-select>
            </el-input>
            <el-input size="small" maxlength="18" class="card-input" v-model="accountAddForm.merchantOrgcode" placeholder="请输入正确的身份证号" v-if="accountAddForm.merchantType == 1">
              <el-select v-model="accountAddForm.merchantType" slot="prepend" placeholder="请选择">
                <el-option label="个人" :value="1"></el-option>
                <el-option label="企业" :value="2"></el-option>
              </el-select>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item size="small" label="商户地址" class="form-row">
            <el-input readonly v-model="accountAddForm.merchantAddress"></el-input>
            <el-button type="primary" class="form-btn" @click="hanleSelectMap">选择地址</el-button>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="联系电话" prop="merchantLegalPersonPhone">
            <el-input maxlength="11" size="small" v-model="accountAddForm.merchantLegalPersonPhone" placeholder="请输入联系电话"></el-input>
            <el-checkbox v-model="accountAddForm.isloginName">联系电话同时作为登录账户名</el-checkbox>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系人">
            <el-input size="small" v-model="accountAddForm.merchantLegalPerson" placeholder="请输入联系人"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="驻店联系人">
            <el-input maxlength="11" size="small" v-model="accountAddForm.residentContact" placeholder="请输入驻店联系人"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="驻店电话">
            <el-input maxlength="11" size="small" class="phone-input" v-model="accountAddForm.residentPhone" placeholder="请输入驻店电话"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="营业范围">
            <el-checkbox-group v-model="accountAddForm.businessScope">
              <el-checkbox v-for="item in businessOption" :label="item.dictValue" :key="item">{{ item.dictLabel }}</el-checkbox>
            </el-checkbox-group>
            <div class="scrm-flex-center" v-for="(item, index) in businessScopeCustomize" :key="index">
              <el-input size="small" v-model="businessScopeCustomize[index].name" placeholder="请自定义营业范围,建议不超过10个"></el-input>
              <i class="el-icon-circle-plus el-icon-btn" @click="addBusinessScope" v-if="index == businessScopeCustomize.length - 1"></i>
              <i class="el-icon-remove el-icon-btn" @click="removeBusinessScope" v-else></i>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="营业时间" class="open-time">
            <el-time-picker size="small" value-format="HH:mm:ss" is-range v-model="accountAddForm.bussinessTime" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" placeholder="选择时间范围"></el-time-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="主营品牌">
            <el-input size="small" v-model="filterText"></el-input>
            <div class="brand-tree">
              <el-tree :data="brandData" show-checkbox default-expand-all node-key="id" ref="brandTree" highlight-current :props="defaultProps" :filter-node-method="filterNode" @check="clickDeal"></el-tree>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="门店照片">
            <div class="store-upload-list">
              <template v-if="accountAddForm.merchantFiles && accountAddForm.merchantFiles.length > 0">
                <div :key="index" v-for="(item, index) in accountAddForm.merchantFiles" class="store-border" @mouseenter="imgIndex = index" @mouseleave="imgIndex = ''">
                  <img :src="item.fileUrl" />
                  <div class="uploader-del-icon" v-if="imgIndex === index">
                    <i class="el-icon-delete-solid" @click.stop="delImg(index)"></i>
                  </div>
                </div>
              </template>
              <el-upload action="" class="image-uploader" :show-file-list="false" list-type="picture-card" v-loading="loadingImg" :before-upload="upLoadImg">
                <i class="el-icon-plus"></i>
              </el-upload>
            </div>

            <div class="tips">图片格式仅支持JPG,PNG格式,大小1M</div>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-dialog :visible.sync="dialogMapVisible" width="60%">
      <map-view ref="mapForm" :mapHeight="mapHeight"></map-view>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogMapVisible = false">取 消</el-button>
        <el-button type="primary" @click="getAddress">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import util from '@/utils/util'
import mapView from '@/components/mapView/index'
export default {
  name: 'base',
  components: {
    mapView
  },
  props: {
    accountAddForm: {
      type: Object
    },
    businessOption: {
      type: Array
    },
    brandData: {
      type: Array
    },
    businessScopeCustomize: {
      type: Array
    }
  },
  data() {
    const validatePhone = (rule, value, callback) => {
      if (!util.checkPhone(value)) {
        callback(new Error('请输入正确的手机号'))
      } else {
        callback()
      }
    }
    return {
      imgIndex: '',
      filterText: '',
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      dialogMapVisible: false,
      mapHeight: 380,
      baseRules: {
        merchantName: [{ required: true, message: '请输入商户名称', trigger: 'blur' }],
        merchantLegalPersonPhone: [
          { required: true, message: '请输入联系电话', trigger: 'blur' },
          { validator: validatePhone, trigger: 'blur' }
        ]
      }
    }
  },
  watch: {
    filterText(val) {
      this.$refs.brandTree.filter(val)
    }
  },
  methods: {
    hanleSelectMap() {
      this.dialogMapVisible = true
      this.$nextTick(() => {
        if (this.accountAddForm.merchantAddress && !this.$refs.mapForm.address) {
          this.$refs.mapForm.address = this.accountAddForm.merchantAddress
          this.$refs.mapForm.addMarker([this.accountAddForm.lng, this.accountAddForm.lat])
        }
      })
    },
    clickDeal() {
      this.$parent.editStatus = true
    },
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    getAddress() {
      if (!this.$refs.mapForm.address) {
        this.$message.error('请选择地址')
        return
      }
      this.dialogMapVisible = false
      this.accountAddForm.merchantAddress = this.$refs.mapForm.address
      let lnglat = this.$refs.mapForm.lnglat
      this.accountAddForm.lat = lnglat.lat
      this.accountAddForm.lng = lnglat.lng
    },
    delImg(index) {
      this.accountAddForm.merchantFiles.splice(index, 1)
    },
    addBusinessScope() {
      this.businessScopeCustomize.push({ name: '' })
    },
    removeBusinessScope(index) {
      this.businessScopeCustomize.splice(index, 1)
    },
    upLoadImg(file) {
      let fileName = file.name
      if (file.name.lastIndexOf('.') === -1) {
        this.$message.warning('路径不正确')
        return false
      }
      let AllImgExt = '.jpg|.jpeg|.gif|.bmp|.png|.swf'
      let extName = file.name.substring(file.name.lastIndexOf('.')).toLowerCase()
      if (AllImgExt.indexOf(extName + '|') === -1) {
        this.$message.warning('图片格式不正确')
        return false
      }
      if (this.accountAddForm.merchantFiles.length == 3) {
        this.$message.warning('最多上传3张')
        return false
      }
      // if (fileSize < 3145728) {
      if (window.FileReader) {
        let reader = new FileReader()
        let self = this
        reader.readAsDataURL(file)
        reader.onload = img => {
          console.log(file)
          let type = fileName.split('.')[1]
          let imgUrl = img.target.result.split(',')[1]
          // self.loadingImg = true;
          self.$apis.common
            .pictureUpload({
              file: `${type}@${imgUrl}`
            })
            .then(res => {
              if (res) {
                self.accountAddForm.merchantFiles.push({
                  fileUrl: res,
                  fileName: ''
                })
              }
            })
        }
      }
    }
  },

  mounted() {}
}
</script> 

<style scoped lang="scss">
.base-info {
  /deep/ {
    .el-dialog__body {
      padding: 20px 10px;
    }
  }
  .account-body-form {
    width: 80%;
    margin: 20px auto;
    .form-row {
      /deep/ .el-form-item__content {
        display: flex;
      }
      .form-btn {
        margin-left: 10px;
      }
    }
    .merchant-row {
      /deep/ {
        .el-form-item__content {
          line-height: 1;
        }
        .el-select {
          .el-input {
            width: 80px;
          }
        }
      }
    }
    .store-upload-list {
      display: flex;
      flex-wrap: wrap;
      .store-border {
        position: relative;
        width: 120px;
        height: 80px;
        border-radius: 2px;
        margin-right: 15px;
        margin-bottom: 15px;
      }
      .uploader-del-icon {
        position: absolute;
        top: 0px;
        right: 0px;
        width: 30px;
        height: 30px;
        line-height: 30px;
        background: rgba(0, 0, 0, 0.4);
        border-radius: 0px 0px 0px 100px;
        cursor: pointer;
      }
      .el-icon-delete-solid {
        color: #c5c5c5;
        font-size: 14px;
        margin-left: 12px;
      }
    }
    .image-uploader {
      /deep/ .el-upload {
        width: 120px;
        height: 80px;
        line-height: 80px;
      }
    }
    .brand-tree {
      height: 300px;
      overflow-y: auto;
    }
    .open-time {
      /deep/ {
        .el-range-editor--small.el-input__inner {
          width: 100%;
        }
      }
    }
    .el-icon-btn {
      color: #5850ff;
      font-size: 16px;
      margin-left: 6px;
      cursor: pointer;
    }
    .tips {
      font-size: 14px;
      font-weight: 400;
      color: #999999;
      line-height: 30px;
    }
    .btn-unselect {
      display: inline-block;
      cursor: pointer;
      position: relative;
      height: 30px;
      line-height: 30px;
      margin-top: 6px;
      padding-right: 30px;
      cursor: pointer;
      font-size: 0;
      -webkit-transition: 0.1s linear;
      transition: 0.1s linear;
      box-sizing: border-box;
      &.selectd-type {
        .select-type-title {
          background: #5850ff;
        }
      }
      .select-type-title {
        display: inline-block;
        padding: 0 16px;
        height: 100%;
        font-size: 14px;
        border-radius: 2px 0 0 2px;
        background-color: #d2d2d2;
        color: #fff;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
      .btn-icon {
        display: inline-block;
        position: absolute;
        right: 0;
        top: 0;
        width: 30px;
        height: 28px;
        line-height: 28px;
        border: 1px solid #dcdfe6;
        border-left: none;
        border-radius: 2px 0px 0px 2px;
        color: #5850ff;
        font-size: 20px;
        text-align: center;
      }
    }
  }
}
</style>