// pages/workBench/components/account/components/updatePhoneModa/index.js
import { alertInfo, alertSuccess } from "../../../../../../utils/index";
import { updateAdminPhone } from "../../../../../../service/tenement";
import request from "../../../../../../utils/request"
const { OK } = request
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    type: String,
    title: String,
    visible: Boolean,
    onCancel: Function,
    park: String,
    tenement: String,
    parentPhone:String, 
    parentName:String, 
    parentId:String, 
  },
  observers: {
    "parentPhone": function (newPhone) {
      this.setData({ phone: newPhone })
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    phone: "",
  },

  /**
   * 组件的方法列表
   */
  methods: {
    async onSubmit() {
      const { phone, tenement, park, type } = this.data;
      if (!phone) {
        alertInfo("请输入手机号")
        return
      }
      const { code, message } = await updateAdminPhone({tenement, phone: phone })
      if (code !== OK) {
        alertInfo(message)
        this.triggerEvent("cancel")
        return;
      }
      alertSuccess("操作成功")
      this.triggerEvent("ok")
      this.setData({ phone: "" })
      return;
      
      
    },
    onChange(e) {

      this.setData({
        phone: e.detail,
      })
    },
    onCancel() {
      this.setData({ phone: "" })
      this.triggerEvent("cancel")
    }
  }
})