<template>
  <div>
  <ContainerQuery v-if="!balanceAdjustment">
    <!-- <el-button slot="left" size="small" type="primary" @click="infoShow = true">
    	新增文章
    </el-button> -->
    <el-table :data="rule_list">
      <el-table-column prop="id" label="文章id" show-overflow-tooltip min-width="155"></el-table-column>
      <el-table-column prop="title" label="文章标题" show-overflow-tooltip min-width="155"></el-table-column>
      <el-table-column prop="createTime" label="添加时间" min-width="140">
        <template #default="{ row }">
          {{ $_common.formatDate(row.createTime) }}
        </template>
      </el-table-column>
      <el-table-column prop="name" label="操作" min-width="120">
        <template slot-scope="scope">
          <el-button v-if="$accessCheck($Access.CommissionRuleEditCommissionRule)" type="text"
            @click="balanceAdjustmentFlag(scope.row)">
            修改
          </el-button>
          <!-- <el-button v-if="$accessCheck($Access.CommissionRuleDelCommissionRule)" type="text"
						@click="delData(scope.row.id)">
						删除
					</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <!-- 		<FooterPage :page-size="pageSize" :total-page.sync="total" :current-page.sync="page" @pageChange="pageChange"
			@sizeChange="sizeChange"></FooterPage> -->

  </ContainerQuery>
 <InfoAdd v-if="infoShow" :is-edit="isEdit" :visible="infoShow" @close="infoShow = false"
 	@confirm="staffConfirm"></InfoAdd>
 <info-update v-if="info_update_show" :visible="true" :art-detail="formData" @close="info_update_show = false"
  	@confirm="updateConfirm"></info-update>
</div>
</template>

<script>
  import {
    Lst,
  } from "@/api/Holders";
  import {
    getArtList,
    getArtDetail,
    getArtUpdate
  } from '@/api/info'

  import InfoAdd from "./components/InfoAdd.vue";
  import InfoUpdate from "./components/infoUpdate.vue";

  export default {
    name: "InfoArticleList",
    components: {
      InfoAdd,
      InfoUpdate
    },
    data() {
      return {
        // 是否显示添加弹窗
        infoShow:false,
        info_update_show: false,
        content: '',
        rule_list: [],
        time: '',
        search_form: {
          start: "",
        },
        total: 0,
        page: 1,
        pageSize: 10,
        balanceAdjustment: false,
        formData: {},
        rules: {
          title: [{
            required: true,
            message: "请输入标题",
            trigger: "blur"
          }],
          content:[{
            required: true,
            message: "请输入内容",
            trigger: "blur"
          }]
        },
      };
    },
    created() {
      this.Lst();
      // this.getArtList()
    },
    activated() {
      if (this.$_isInit()) return;
      this.Lst();
    },
    methods: {
      updateConfirm() {
          this.Lst();
      },
      rechargeMemberBalance() {
        this.$refs.form.validate(async (valid) => {
          if(valid) {
            getArtUpdate(this.formData).then(res => {
              console.log(res)
               this.Lst();
              this.closeBalanceAdjustment()
            })
          }
        })

      },
      closeBalanceAdjustment() {
        this.balanceAdjustment = false
      },
      balanceAdjustmentFlag(row) {
        console.log(row);
        this.formData = {}
        getArtDetail({
          id: row.id
        }).then(({
          data
        }) => {
          this.formData = data;
          this.info_update_show = true;
        })

        // this.formData.name = row.name;
      },
      // 每页数据大小改变
      sizeChange(val) {
        this.pageSize = val;
        this.pageChange(1);
      },
      editData(index) {},
      async Lst() {
        const {
          data,
          pageTotal
        } = await getArtList({
          page: this.page,
          pageSize: this.pageSize,
          // createTime: this.search_form.start,
        });
        this.rule_list = data
        // this.total = pageTotal;
      },
      // 删除
      async delData(id) {
        this.$confirm("是否要将该提成规则删除?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(async () => {
          const data = await deleteRewardRule(id);

          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.getAllRewardRule();
        });
      },
    },
  };
</script>

<style scoped></style>
