addAccountDialog.vue 5.15 KB
<!-- 驳回 -->
<template>
  <d2-dialog
    :title="detailInfo && detailInfo.id ? '编辑总部账号' : '新建总部账号'"
    :is-visible="visible"
    @closeDialog="handleClose"
    @confirmDialog="handleAddConfirm"
  >
    <div class="reject-dialog">
      <glsx-combi-form
        class="edit-form-container"
        ref="formRef"
        label-width="112px"
        default-width="390px"
        :form-ref="rejectRef"
        :form-obj="accountForm"
        :form-data="formData"
        :form-rules="formRules"
      ></glsx-combi-form>
    </div>
  </d2-dialog>
</template>

<script>
import { createAccount, updateAccount } from "@api/large"
import { Validator } from "@/common/validator"
export default {
  name: "addAccountDialog",
  data() {
    var checkPhoneObj = {
      required: true,
      validator: (rule, value, callback) => {
        Validator.checkPhoneNumber(value)
          ? callback()
          : callback(new Error("你输入的手机号码不正确,请重新输入"))
      },
      trigger: "blur"
    }
    return {
      accountForm: {
        accountName: "",
        accountPhone: "",
        accountPhone: "",
        ownerShipType: "",
        ownerDept: ""
      },
      dialogConfig: {
        title: "提示",
        width: "576px",
        height: "315px"
      },
      rejectRef: "rejectRef",
      formRules: {
        accountName: [
          { required: true, message: "请输入员工姓名", trigger: "blur" }
        ],
        accountPhone: [
          { required: true, message: "请输入手机号码", trigger: "blur" },
          checkPhoneObj
        ],
        ownerPost: [{ required: true, message: "请输入岗位", trigger: "blur" }]
      },
      formData: [
        {
          label: "员工姓名",
          name: "accountName",
          type: "input",
          width: "300px",
          labelWidth: "10px"
        },
        {
          label: "手机号码",
          name: "accountPhone",
          type: "input",
          width: "300px",
          maxlength: "11",
          labelWidth: "10px"
        },
        // {
        //   label: "归属中心",
        //   name: "ownerShipType",
        //   type: "select",
        //   width: "300px",
        //   optionList: [
        //     {
        //       confValue: "总部",
        //       confId: 0
        //     },
        //     {
        //       confValue: "驻店",
        //       confId: 1
        //     }
        //   ],
        //   optionId: "confId",
        //   optionLabel: "confValue",
        //   isDisabled: true
        // },
        // {
        //   label: "归属部门",
        //   name: "deliveryType",
        //   type: "select",
        //   optionList: [],
        //   optionId: "confId",
        //   optionLabel: "confName",
        //   optionsName: "deliveryTypeList"
        // },
        // {
        //   label: "归属中心",
        //   name: "ownerShipType",
        //   type: "input",
        //   width: "300px",
        //   labelWidth: "10px",
        //   isDisabled: true
        // },
        // {
        //   label: "归属部门",
        //   name: "ownerDept",
        //   type: "input",
        //   width: "300px",
        //   labelWidth: "10px",
        //   isDisabled: true
        // },
        {
          label: "岗位",
          name: "ownerPost",
          type: "input",
          width: "300px",
          labelWidth: "10px"
        }
      ],
      baseData: {}
    }
  },

  props: {
    visible: {
      type: Boolean,
      default: false
    },
    detailInfo: {
      type: Object,
      default: () => {}
    }
  },
  computed: {
    isVisible: {
      get() {
        return this.visible
      },
      set(newVal) {}
    }
  },
  watch: {
    detailInfo(val) {
      if (val) {
        this.accountForm = val
      }
    }
  },

  mounted() {},

  methods: {
    handleAddConfirm() {
      this.$refs.formRef.$refs[this.rejectRef].validate(async (valid) => {
        if (valid) {
          let api =
            this.detailInfo && this.detailInfo.id
              ? updateAccount
              : createAccount
          let params = {
            accountName: this.accountForm.accountName,
            accountPhone: this.accountForm.accountPhone,
            ownerPost: this.accountForm.ownerPost,
            ownerShipType: 0,
            ownerDept: this.accountForm.ownerDept,
            ownerCenter: this.accountForm.ownerCenter,
            useStatus: 1
          }
          if (this.detailInfo && this.detailInfo.id) {
            params.id = this.detailInfo.id
            params.useStatus = this.detailInfo.useStatus
            params.ownerShipType = this.accountForm.ownerShipType
          }

          api(params).then((res) => {
            if (res) {
              this.handleClose()
              this.notice.okTips("操作成功")
            }
          })
        }
      })
    },
    handleClose() {
      this.$emit("dialogClose", false)
    }
  }
}
</script>
<style lang="scss" scoped>
.reject-dialog {
  margin: 21px 0 83px;

  ::v-deep .el-textarea__inner {
    height: 70px;
  }
  ::v-deep .el-input__count {
    right: 15px !important;
    bottom: 3px !important;
    font-size: 12px;
    color: #999999;
  }
}
</style>