<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main animate__animated animate__backInRight">
        <el-col :span="24" class="one">
          <data-table @query="search" :fields="fields" :opera="opera" :data="list" :total="total" @view="toView" @receive="torEceive">
            <template #selfbtn>
              <el-button type="primary" size="mini" @click="toAdd()">添加信息</el-button>
            </template>
          </data-table>
        </el-col>
      </el-col>
    </el-row>
    <e-dialog :dialog="dialog" @toClose="toClose">
      <template slot="info">
        <form-1 :form="form" v-if="dialog.type == '1'" @toSave="toSave" @orderSave="orderSave" @orderDelete="orderDelete"></form-1>
        <info-1 :form="form" v-else-if="dialog.type == '2'"></info-1>
      </template>
    </e-dialog>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
export default {
  name: 'index',
  props: {},
  components: {
    form1: () => import('./parts/form-1.vue'),
    info1: () => import('./parts/info-1.vue'),
  },
  data: function () {
    return {
      // 数据项
      fields: [
        { label: '联系人', prop: 'user_name', filter: true },
        { label: '联系电话', prop: 'user_phone', filter: true },
        { label: '审核时间', prop: 'examine_date' },
        { label: '审核状态', prop: 'status_name' },
      ],
      //操作项
      opera: [
        { label: '详情', method: 'view' },
        { label: '领取确定', method: 'receive', type: 'success', confirm: true, display: (i) => i.status == '2' },
      ],
      //表格数据
      list: [
        {
          id: '111',
          user_name: '法外狂徒张三',
          user_phone: '12345678901',
          examine_name: '李四',
          examine_date: '2022-5-18',
          status_name: '待审',
          examine_desc: '我想不同意，但我还是同意了',
          order: [{ name: '小洋人', num: '121', desc: '别卖太便宜了，赔钱' }],
          status: '1',
        },
        {
          id: '123',
          user_name: '法外狂徒张三',
          user_phone: '12345678901',
          examine_name: '李四',
          examine_date: '2022-5-18',
          status_name: '待审',
          examine_desc: '我想不同意，但我还是同意了',
          order: [{ name: '小洋人', num: '121', desc: '别卖太便宜了，赔钱' }],
          status: '2',
        },
      ],
      // 列表数据总数
      total: 0,
      //弹框
      dialog: { title: '详细信息', show: false, type: '1' },
      form: { order: [] },
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    //查询数据
    async search({ skip = 0, limit = 10, ...info } = {}) {},
    //详细信息
    async toView({ data }) {
      this.$set(this, `form`, data);
      this.dialog = { title: '详细信息', show: true, type: '2', widths: '40%' };
    },
    //领取确定
    async torEceive({ data }) {
      console.log(data);
    },
    // 添加
    toAdd() {
      this.dialog = { title: '添加信息', show: true, type: '1', widths: '40%' };
    },
    // 提交保存
    async toSave({ data }) {
      console.log(data);
    },
    //关闭
    toClose() {
      this.form = { order: [] };
      this.dialog = { title: '详细信息', show: false, type: '1' };
      this.search();
    },
    // 商品信息保存
    orderSave({ data }) {
      this.form.order.push(data);
    },
    // 删除商品信息
    orderDelete({ index }) {
      this.form.order.splice(index, 1);
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
/deep/.el-dialog__body {
  min-height: 400px;
}
</style>
