<template>
  <div class="app-container">
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
      :visible.sync="visible"
    >
      <el-form ref="dialogForm" v-loading="loading" :model="formItem" label-width="120px">
        <el-row  :gutter="15">
          <el-col :span="12">
            <el-form-item label="序号" prop="id"
              :rules="[
                { required: true, message:'序号不能为空', trigger:'blur' }
              ]"
            >
              <el-input v-model="formItem.id" size="mini" type="text" placeholder="序号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="openid" prop="openid"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.openid" size="mini" type="text" placeholder="openid" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="昵称" prop="nickname"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.nickname" size="mini" type="text" placeholder="昵称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="过滤后昵称" prop="nicknameTxt"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.nicknameTxt" size="mini" type="text" placeholder="过滤后昵称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注名称" prop="bzname"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.bzname" size="mini" type="text" placeholder="备注名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户头像" prop="headimgurl"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.headimgurl" size="mini" type="text" placeholder="用户头像" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别：'1':男性；'2':女性；'0':未知" prop="sex"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.sex" size="mini" type="text" placeholder="性别：'1':男性；'2':女性；'0':未知" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否关注:'0':未关注；'1':关注" prop="subscribe"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.subscribe" size="mini" type="text" placeholder="是否关注:'0':未关注；'1':关注" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="关注时间" prop="subscribeTime"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.subscribeTime" size="mini" type="text" placeholder="关注时间" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户关注渠道来源" prop="subscribeScene"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.subscribeScene" size="mini" type="text" placeholder="用户关注渠道来源" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号" prop="mobile"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.mobile" size="mini" type="text" placeholder="手机号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="绑定状态：'N':未绑定；'Y':已绑定；'V':绑定中" prop="bindStatus"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.bindStatus" size="mini" type="text" placeholder="绑定状态：'N':未绑定；'Y':已绑定；'V':绑定中" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="绑定时间" prop="bindTime"
              :rules="[
              ]"
            >
              <ec-date v-model="formItem.bindTime" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="标签id" prop="tagidList"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.tagidList" size="mini" type="text" placeholder="标签id" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="省份" prop="province"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.province" size="mini" type="text" placeholder="省份" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="城市" prop="city"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.city" size="mini" type="text" placeholder="城市" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地区" prop="country"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.country" size="mini" type="text" placeholder="地区" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="二维码扫码场景" prop="qrScene"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.qrScene" size="mini" type="text" placeholder="二维码扫码场景" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="二维码扫码常见描述" prop="qrSceneStr"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.qrSceneStr" size="mini" type="text" placeholder="二维码扫码常见描述" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户所在分组id" prop="groupid"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.groupid" size="mini" type="text" placeholder="用户所在分组id" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户的语言，简体中文为zh_CN" prop="language"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.language" size="mini" type="text" placeholder="用户的语言，简体中文为zh_CN" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="UNIONID" prop="unionid"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.unionid" size="mini" type="text" placeholder="UNIONID" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公众号原始id" prop="jwid"
              :rules="[
              ]"
            >
              <el-input v-model="formItem.jwid" size="mini" type="text" placeholder="公众号原始id" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="创建时间" prop="createTime"
              :rules="[
              ]"
            >
              <ec-date v-model="formItem.createTime" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="visible = false">关闭</el-button>
        <el-button v-if="method !== 'view'" type="primary" size="mini" :loading="saveLoading" @click="save">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>

import mixin from 'ecip-web/utils/common-mixin'
import { getById, save, update } from 'ecip-web/api/vue/wx/weixinGzuserApi'

export default {
  name: 'modules.wx.weixinGzuserForm',
  components: {},
  mixins: [...mixin],
  data() {
    return {
      visible: false,
      method: '',
      title: '',
      loading: false, // 页面加载遮罩
      saveLoading: false, //  保存加载
      formItem: {
        id: '',
        openid: '',
        nickname: '',
        nicknameTxt: '',
        bzname: '',
        headimgurl: '',
        sex: '',
        subscribe: '',
        subscribeTime: '',
        subscribeScene: '',
        mobile: '',
        bindStatus: '',
        bindTime: '',
        tagidList: '',
        province: '',
        city: '',
        country: '',
        qrScene: '',
        qrSceneStr: '',
        groupid: '',
        language: '',
        unionid: '',
        jwid: '',
        createTime: ''
      }
    }
  },
  created() {
  },
  methods: {
    init (method, id) {
      this.method = method
      if (method === 'add') {
        this.title = `新建公众号用户`
      } else if (method === 'edit') {
        this.title = '修改公众号用户'
      } else if (method === 'view') {
        this.title = '查看公众号用户'
      }
      this.visible = true
      this.loading = false
      this.$nextTick(() => {
        this.$refs.dialogForm.resetFields()
        if (method === 'edit' || method === 'view') { // 修改或者查看
          this.loading = true
          getById(id).then(res => {
            this.formItem = res.data
            // this.inputForm = this.recover(this.inputForm, res.data)
          }).catch(e => {
            this.$messgae.error(`数据回显失败: ${e}`)
          }).finally(() => {
            this.loading = false
          })
        }
      })
    },
    save() {
      let validFlag
      this.$refs.dialogForm.validate(valid => { validFlag = valid })
      if (!validFlag) {
        return
      }
      this.saveLoading = true
      if (this.method === 'edit') {
        update(this.id, this.formItem).then(res => {
          this.$message.success('保存成功')
          this.$emit('refreshDataList')
          this.visible = false
        }).catch(e => {
          this.$message.error(`保存失败: ${e}`)
        }).finally(() => {
          this.saveLoading = false
        })
      } else {
        save(this.formItem).then(res => {
          this.$message.success('保存成功')
          this.$emit('refreshDataList')
          this.visible = false
        }).catch(e => {
          this.$message.error(`保存失败: ${e}`)
        }).finally(() => {
          this.saveLoading = false
        })
      }
    }
  }
}
</script>

<style scoped>

</style>
