<template>
  <div class="app-container">
    <h3 style="margin-bottom: 30px">团长设置</h3>

    <div class="screen-container">
      <el-form ref="screenForm" :model="screenForm" label-width="70px" size="small" label-position="left">
        <el-row :gutter="20">
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="团长名称" prop="name">
              <el-input v-model="screenForm.name" placeholder="请输入团长名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="手机号码" prop="phone">
              <el-input v-model="screenForm.phone" placeholder="请输入手机号码"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="团长价格" prop="price">
              <el-input v-model="screenForm.price" placeholder="请输入团长价格"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="团长分佣" prop="amount">
              <el-input v-model="screenForm.amount" placeholder="请输入团长分佣"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="24" class="tr">
            <el-form-item label="">
              <el-button size="small" @click="resetScreenForm">清空</el-button>
              <el-button size="small" type="primary" @click="submitScreenForm">搜索</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <div class="mymain-container">
      <div class="table">
        <el-table v-loading="listLoading" :data="dataList" element-loading-text="Loading" border fit highlight-current-row stripe>
          <el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
          <el-table-column align="center" label="团长名称" prop="userName" min-width="120" show-overflow-tooltip></el-table-column>
          <el-table-column align="center" label="手机号码" prop="userPhone" min-width="120"></el-table-column>
          <el-table-column align="center" label="划线价格" prop="orgGoodsPrice" min-width="140">
            <template slot-scope="scope">
              <el-input type="number" v-model="scope.row.orgGoodsPrice" disabled></el-input>
            </template>
          </el-table-column>
          <el-table-column align="center" label="统一拼团价" prop="comGroupPrice" min-width="140">
            <template slot-scope="scope">
              <el-input type="number" v-model="scope.row.comGroupPrice" disabled></el-input>
            </template>
          </el-table-column>
          <el-table-column align="center" label="统一团长分佣" prop="comShareAmount" min-width="140">
            <template slot-scope="scope">
              <el-input type="number" v-model="scope.row.comShareAmount" disabled></el-input>
            </template>
          </el-table-column>
          <el-table-column align="center" label="团长价格" prop="groupPrice" min-width="140">
            <template slot-scope="scope">
              <el-input type="number" v-model="scope.row.groupPrice"></el-input>
            </template>
          </el-table-column>
          <el-table-column align="center" label="团长分佣" prop="shareAmount" min-width="140">
            <template slot-scope="scope">
              <el-input type="number" v-model="scope.row.shareAmount"></el-input>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <div class="page-footer">
      <div class="footer" :class="classObj">
        <el-button type="primary" @click="submitMainForm" :loading="formLoading">{{ formLoading ? '提交中 ...' : '提 交' }}</el-button>
        <el-button @click="goBack">关 闭</el-button>
      </div>
    </div>

  </div>
</template>

<script>
import { getHeadList, editHead } from '@/api/groupbuy'

export default {
  data() {
    return {
      id: '',
      dataList: null, // 列表数据
      listLoading: true, // 列表加载loading
      screenForm: { // 筛选表单数据
        name: '',
        phone: '',
        price: '',
        amount: '',
      },
      formLoading: false,
      
    }
  },
  computed: {
    sidebar() {
      return this.$store.state.app.sidebar
    },
    classObj() {
      return {
        hideSidebar: !this.sidebar.opened,
        openSidebar: this.sidebar.opened
      }
    },
  },
  created() {
    const { id } = this.$route.query;
    this.id = id;

    this.getList();
  },
  methods: {
    goBack() {
      this.$router.go(-1)
    },

    // 获取列表
    getList() {
      this.listLoading = true;

      let params = {
        promotionGroupSpecId: this.id,
        name: this.screenForm.name,
        phone: this.screenForm.phone,
        groupPrice: this.screenForm.price,
        shareAmount: this.screenForm.amount,
      }

      getHeadList(params).then(res => {
        this.dataList = res.data;
        this.listLoading = false;
      })
    },

    // 提交筛选表单
    submitScreenForm() {
      this.getList()
    },

    // 重置筛选表单
    resetScreenForm() {
      this.$refs.screenForm.resetFields()
      this.getList()
    },

    // 提交
    submitMainForm() {
      this.formLoading = true;

      editHead(this.dataList).then(res => {
        this.formLoading = false;
        this.$successMsg('编辑成功');
        setTimeout(()=>{
          this.goBack();
        }, 1000)
      }).catch(err => {
        this.formLoading = false;
      })
    },
  },

}
</script>

<style scoped lang="scss">
  .dialog-container {
    .left {
      width: 140px;
      height: 350px;
      overflow-y: scroll;
      .group {
        margin-top: 10px;
      }
      .child {
        margin-top: 5px;
        .item {
          padding-left: 18px;
        }
      }
      .item {
        cursor: pointer;
        line-height: 24px;
      }
    }
    .right {
      width: calc(100% - 140px);
      height: 350px;
      box-sizing: border-box;
      padding-left: 20px;
    }
  }
</style>