<template>
  <div id="index">
    <data-form :span="12" :fields="fields" :rules="rules" v-model="form" labelWidth="150px" @save="toSave">
      <template #status>
        <el-option v-for="i in statusList" :key="i.model" :label="i.label" :value="i.value"></el-option>
      </template>
    </data-form>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: selfShop } = createNamespacedHelpers('selfShop');
const { mapActions: shop } = createNamespacedHelpers('shop');
export default {
  name: 'index',
  props: {},
  components: {},
  data: function () {
    return {
      fields: [
        { label: '店铺logo', model: 'logo', type: 'upload', limit: 1, url: '/files/point/shopLogo/upload' },
        { label: '商店名称', model: 'name' },
        { label: '店主', model: 'person' },
        { label: '联系电话', model: 'phone' },
        { label: '地址', model: 'address' },
        { label: '证件照片', model: 'file', type: 'upload', url: '/files/point/shopFile/upload' },
      ],
      rules: {},
      form: {},
    };
  },
  computed: {
    ...mapState(['user']),
  },
  created() {
    this.search();
  },
  methods: {
    ...selfShop(['getInfo']),
    ...shop(['update']),
    //执行查询
    async search() {
      const res = await this.getInfo();
      if (this.$checkRes(res)) {
        this.$set(this, `form`, res.data);
      }
    },
    async toSave({ data }) {
      const res = await this.update(data);
      this.$checkRes(res, '操作成功', '操作失败');
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
};
</script>

<style lang="less" scoped></style>
