<template>
  <div id="">
    <el-row>
      <el-col :span="24">
        <el-form-item label="选择推送机构" prop="tenantList">
          <p>
            <el-button type="primary" @click="activeTenant">新增</el-button>
          </p>
          <el-table :data="ruleForm.tenantList" border style="width: 100%">
            <el-table-column
              align="center"
              v-for="(item, index) in mechanismSet"
              :key="index"
              :prop="item.prop"
              :label="item.label"
              :width="item.width"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <div v-if="item.scope === 'options'">
                  <template v-for="(itemt, indext) in item.options">
                    <span v-if="itemt.value === scope.row[item.prop]">{{
                      itemt.label
                    }}</span>
                  </template>
                </div>
                <span v-else>{{ scope.row[item.prop] }}</span>
              </template>
            </el-table-column>
            <el-table-column
              fixed="right"
              label="操作"
              width="100"
              align="center"
            >
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="small"
                  @click="ruleForm.tenantList.splice(scope.$index, 1)"
                  >删除</el-button
                >
              </template>
            </el-table-column></el-table
          >
        </el-form-item>
        <el-form-item label="描述" prop="remark">
          <el-input
            type="textarea"
            :rows="6"
            v-model="ruleForm.remark"
          ></el-input>
          <p style="color: rgba(134, 144, 156, 1); font-size: 14px">
            说明：<br />1.
            当订单完成以后，该链路上所有推广者根据其相应等级进行分佣，每个推广者的分佣金额或比例不会超过商品的最大限额<br />2.
            考虑到商品退款情况，商品金额需要完全入账方可解冻对应佣金，具体时间需与业务部门沟通<br />3.
            选择固定数值时请注意商品成本
          </p>
        </el-form-item>
      </el-col>
    </el-row>
    <tenant ref="tenant" v-on="$listeners"></tenant>
  </div>
</template>

<script>
import tenant from "./tenant";
export default {
  components: { tenant },
  props: {
    ruleForm: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      mechanismSet: [
        {
          label: "租户ID",
          prop: "tenantId",
        },
        {
          label: "租户名称",
          prop: "tenantName",
        },
        {
          label: "地址",
          prop: "address",
        },
        {
          label: "状态",
          prop: "status",
          scope: "options",
          options: [
            {
              label: "启用",
              value: 1,
            },
            {
              label: "失效",
              value: 0,
            },
          ],
        },
      ],
    };
  },
  methods: {
    activeTenant() {
      const array = this.ruleForm.tenantList.map((item) => item.tenantId);
      this.$refs.tenant.showBox(array);
    },
  },
};
</script>

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