<template>
  <div class="edit-add-detail">
    <div class="crumbs">
      <Breadcrumb
        :breadcrumbOpt="breadcrumbOpt"
        svg-name="#icon-wodeqingqiu"
        @breadcrumb-click="handleClose"
      />
    </div>
    <div class="form-content">
      <el-form
        ref="formInfo"
        :model="parameter"
        label-width="auto"
        label-position="right"
        :rules="rules"
        v-loading="loading"
      >
        <template>
          <div class="rows">
            <div class="rows-left">
              <div class="rows-hr"></div>
            </div>
            <div class="rows-title">
              <div class="text-overflow">基本信息</div>
            </div>
          </div>
          <el-row :gutter="24">
            <el-col :span="24">
              <el-form-item label="企业名称" prop="enterpriseName">
                <el-input
                  v-model="parameter.enterpriseName"
                  clearable
                  placeholder="请输入企业名称"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="24">
              <el-form-item label="企业联系人" prop="enterpriseContact">
                <el-input
                  clearable
                  v-model="parameter.enterpriseContact"
                  placeholder="请输入企业联系人"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="24">
              <el-form-item label="企业联系电话" prop="enterpriseContactPhone">
                <el-input
                  v-model="parameter.enterpriseContactPhone"
                  clearable
                  placeholder="请输入企业联系电话"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="24">
              <el-form-item label="送货地址" prop="enterpriseContactAddress">
                <el-input
                  v-model="parameter.enterpriseContactAddress"
                  clearable
                  placeholder="请输入企业送货地址"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="24">
              <el-form-item
                label="是否默认送货地址"
                prop="defaultStatus"
              >
              <dict-select
                  dictCode="qyshdzmrzt"
                  :hasDefaultOption="true"
                  v-model="parameter.defaultStatus"
                  style="width: 100%"
                  clearable
                  placeholder="请选择是否默认送货地址"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </template>
      </el-form>
    </div>
    <div slot="footer" class="footer">
      <el-button @click="handleClose">{{ $t('domestic.cancel') }}</el-button>
      <el-button @click="handleSave" :loading="saveing" type="primary"
        >保存</el-button
      >
    </div>
  </div>
</template>
  
  <script>
import dictUtils from '@/components/dict/DictSelectUtils.js'
import Breadcrumb from '@/components/Breadcrumb/index.vue'
import utils from '@/utils.js'
export default {
  name: 'domesticDialog',
  components: {
    Breadcrumb,
    dictUtils,
  },
  props: {
    editData: Object,
  },
  data() {
    var validateMobile = (rule, value, callback) => {
      if (value === '' || typeof value === 'undefined' || value == null) {
        callback()
      } else {
        let pattern = /^(((\d{3,4}-)?[0-9]{7,8})|(1(3|4|5|6|7|8|9)\d{9}))$/
        if (pattern.test(value) == false) {
          callback(new Error('请输入正确的手机号或者座机'))
        } else {
          callback()
        }
      }
    }
    return {
      saveing: false,
      breadcrumbOpt: [
        {breadcrumbName: '送货地址管理'},
        {breadcrumbName: '新增'},
      ],
      rules: {
        enterpriseContact: [
          {
            required: true,
            message: '请输入企业联系人',
            trigger: ['blur', 'change'],
          },
        ],
        enterpriseName: [
          {
            required: true,
            message: '请输入企业名称',
            trigger: ['blur', 'change'],
          },
        ],
        // enterpriseContactPhone: [
        //   {
        //     required: true,
        //     message: '请输入企业联系电话',
        //     trigger: ['blur', 'change'],
        //   },
        //   {
        //     validator: validateMobile,
        //     trigger: 'blur',
        //   },
        // ],
        enterpriseContactAddress: [
          {
            required: true,
            message: '请输入企业送货地址',
            trigger: ['blur', 'change'],
          },
        ],
        defaultStatus: [
          {
            required: true,
            message: '请选择是否默认送货地址',
            trigger: ['blur', 'change'],
          },
        ],
      },
      parameter: {
        enablingStatus: 1,
        defaultStatus: 0,
      },
      enterpriseList: [],
      supplierList: [],
      loading: false,
    }
  },
  created() {
    this.currentUser = JSON.parse(sessionStorage.getItem('currentUserDetail'))
    this.parameter.enterpriseId = this.currentUser.org[0].orgId
    this.parameter.enterpriseName = this.currentUser.org[0].orgName
    this.parameter.enterpriseCode = this.currentUser.org[0].orgCode
    this.addModifyBtn()
  },
  methods: {
    getByIdData(id) {
        this.loading = true
      this.$http.get('${portal}/bizDeliveryAddress/v1/'+id).then(res=>{
        console.log(res, 'ress')
        this.loading = false
        let data = res.data
        this.parameter = data
      })
    },
    //编辑
    addModifyBtn() {
      let {id} = this.$route.params
      if (id) {
        this.loading = true
        this.getByIdData(id)
        this.breadcrumbOpt[1].breadcrumbName = '编辑'
      } else {
        this.breadcrumbOpt[1].breadcrumbName = '新增'
      }
    },
    // 关闭//面包屑点击
    handleClose() {
      if (this.breadcrumbOpt[1].breadcrumbName === '编辑') {
        this.$router.push({
          name: 'addressManagement',
          params: {
            pageBean: this.$route.query.pageBean,
          },
        })
      } else {
        this.$router.push({
          name: 'addressManagement',
        })
      }
      this.active = 0
      // this.$emit('closeComponent')
      this.parameter = {}
      // this.$refs.formInfo.clearValidate()
    },
    // 保存
    handleSave() {
      this.$refs.formInfo.validate((valid) => {
        if (valid) {
          this.saveing = true
          this.parameter.defaultStatus = Number(this.parameter.defaultStatus)
          this.$http
            .post('${portal}/bizDeliveryAddress/v1/saveOrUpdateEntity', this.parameter)
            .then((res) => {
              this.saveing = false
              this.loading = false
              if (res.data.state) {
                this.$confirm('保存成功，是否返回列表页?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'success',
                }).then(() => {
                  this.$router.push({
                    name: 'addressManagement',
                  })
                })
              }
            })
        }
      })
    },
  },
}
</script>
  
  <style lang="scss"
    scoped>
/deep/ .el-row {
  padding: 0 240px;
}

// 步骤条
.theSteps {
  background-color: white;
  padding: 10px;
  border-radius: 10px;
  display: flex;
  justify-content: center;
  margin-top: 10px;

  /deep/.el-steps {
    width: 50%;
  }

  /deep/.el-steps--simple {
    background-color: rgba($color: #000000, $alpha: 0);
  }
}

.rows {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ebebeb;
  margin-bottom: 16px;
  padding: 10px 0;

  .rows-left {
    margin-right: 10px;

    .rows-hr {
      width: 3px;
      height: 18px;
      background-color: #0e6eff;
      border-radius: 2px;
    }
  }

  .rows-title {
    .text-overflow {
      width: 100%;
      font-size: 16px;
    }
  }
}
</style>
  