<template>
    <div>
        <Form ref="webuserForm" :model="webuser" :rules="formRule" :label-width="100">
          <Form-item label="配送中心名"  prop="name_center" v-if="!updatewebuser">
              <Input type="text" v-model="centerinfo.name_center">
              </Input>
          </Form-item>
          <Form-item label="显示图片"  prop="show_img">
              <Input type="text" v-model="centerinfo.show_img">
              </Input>
          </Form-item>
          <Form-item label="地址"  prop="address" v-if="!updatewebuser">
              <Input type="text" v-model="centerinfo.address">
              </Input>
          </Form-item>
          <Form-item label="状态"  prop="is_active" v-if="!updatewebuser">
              <Input type="text" v-model="centerinfo.is_active">
              </Input>
          </Form-item>
        </Form>
        <div slot="footer">
            <Button type="primary" @click="savewebuser">保存</Button>
        </div>
    </div>
</template>
<script>
import { getmealcenterinfobyid } from '@/api/data'
import { gao } from '@/api/gode.js'
export default {
  name: 'editcenter',
  data () {
    var self = this
    return {
      centerinfo: {
        id: 0
      },
      isadd: true,
      formRule: {
        title: [
          { type: 'string', required: true, message: '商品名称必填', trigger: 'blur' }
        ],
        type_id: [
          { type: 'number', required: true, message: '商品品类必填', trigger: 'change' }
        ],
        good_img: [
          { type: 'string', required: true, message: '产品主图必填', trigger: 'change' }
        ],
        content: [
          { type: 'string', required: true, message: '详细不能为空', trigger: 'change' }
        ],
        user_scores: [
          { type: 'number', required: true, message: '用户积分必填', trigger: 'blur', transform: (value) => { return Number(value) } }
        ]
      }
    }
  },
  computed: {
    onQuery: function () {
      return this.$route.query
    }
  },
  watch: {
    'onQuery' (old, newValue) {
      if (old.mcid) {
        this.getinfo(old.mcid)
      }
    },
    address (old, newValue) {
      var result = gao(old)
      if (result['status'] !== 1) {
        this.$Message.error(result.info)
      }
      this.centerinfo.gcj_long = result.locationArr[0]
      this.centerinfo.gcj_lat = result.locationArr[1]
    }
  },
  methods: {
    getinfo () {
      getmealcenterinfobyid().then(res => {
        const data = res.data
        if (data.code !== 200) {
          this.$Message.error(data.msg)
          this.list = []
          this.pagedata.total = 0
          this.pagedata.current = 1
        } else {
          const usedata = data.data
          this.pagedata.total = usedata.count
          this.list = usedata.list
        }
      })
    }
  },
  mounted () {
    if (this.$route.query.gid) {
      const mcid = this.$route.query.mcid
      this.getinfo(mcid)
    }
  }

}
</script>
