<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--艺术家收益数据-->
      <el-col :span="20" :xs="24">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
          <el-form-item label="结算流水号" prop="orderNo">
            <el-input
              v-model="queryParams.orderNo"
              placeholder="请输入流水号"
              clearable
              style="width: 200px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="搜索码" prop="scanCode">
            <el-input
              v-model="queryParams.scanCode"
              placeholder="请输入搜索码"
              clearable
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="来源平台" prop="source" label-width="80px">
        <el-select v-model="queryParams.source" placeholder="来源渠道" clearable>
          <el-option
            v-for="item in source"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="应用类型" prop="appType" label-width="80px">
        <el-select v-model="queryParams.appType" placeholder="应用类型" clearable>
          <el-option
            v-for="item in appType"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="收益类型" prop="type" label-width="80px">
        <el-select v-model="queryParams.type" placeholder="收益类型" clearable>
          <el-option
            v-for="item in type"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
       <el-form-item label="收益状态" prop="status" label-width="80px">
        <el-select v-model="queryParams.status" placeholder="收益状态" clearable>
          <el-option
            v-for="item in status"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
       <el-form-item label="确认收益方式" prop="confirmType" label-width="100px">
        <el-select v-model="queryParams.confirmType" placeholder="确认收益方式" clearable>
          <el-option
            v-for="item in confirmType"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="确认收益状态" prop="confirmStatus" label-width="100px">
        <el-select v-model="queryParams.confirmStatus" placeholder="确认收益状态" clearable>
          <el-option
            v-for="item in confirmStatus"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否显示" prop="isShow" label-width="80px">
        <el-select v-model="queryParams.isShow" placeholder="是否显示" clearable>
          <el-option
            v-for="item in isShow"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
         </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['img:creatorProfit:remove']"
            >删除</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="creatorProfitList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="编号" align="center" key="id" prop="id" v-if="columns[0].visible" />
          <el-table-column label="结算流水号" align="center" key="orderNo" prop="orderNo" v-if="columns[1].visible" width="190"/>
          <el-table-column label="艺术家id" align="center" key="creatorId" prop="creatorId" v-if="columns[2].visible" :show-overflow-tooltip="true" />
          <el-table-column label="搜索码" align="center" key="scanCode" prop="scanCode" v-if="columns[3].visible" :show-overflow-tooltip="true" />
          <el-table-column label="图片" align="center" key="img" prop="img" v-if="columns[4].visible" width="120">
            <template slot-scope="scope">
              <el-image :src="scope.row.bannerImg" :preview-src-list="bigImgList" @click="getBigImg(scope.row)" style="width: 60px; height: 60px"/>
            </template>
          </el-table-column>
          <el-table-column label="结算收益" align="center" key="profit" prop="profit" v-if="columns[5].visible" :show-overflow-tooltip="true" />
          <el-table-column label="结算平台" align="center" key="platform" prop="platform" v-if="columns[6].visible">
            <template slot-scope="scope">
              {{scope.row.platform == '0' ? "抖音" : scope.row.platform == '1' ? "快手": scope.row.platform == '2' ? "微信": scope.row.platform == '3' ? "uniapp": ''}}
            </template>
          </el-table-column>
          <el-table-column label="应用类型" align="center" key="appType" prop="appType" v-if="columns[7].visible" width="100">
            <template slot-scope="scope">
              {{scope.row.appType == '0' ? "bnyer壁纸" :''}}
            </template>
          </el-table-column>
          <el-table-column label="收益类型" align="center" key="type" prop="type" v-if="columns[8].visible">
            <template slot-scope="scope">
              {{scope.row.type == '0' ? "广告浏览" : scope.row.type == '1' ? "邀请": scope.row.type == '2' ? "会员":''}}
            </template>
          </el-table-column>
          <el-table-column label="收益状态" align="center" key="status" prop="status" v-if="columns[9].visible">
            <template slot-scope="scope">
              {{scope.row.status == '0' ? "即将到账" : scope.row.status == '1' ? "已到账": scope.row.status == '2' ? "转入钱包":''}}
            </template>
          </el-table-column>
          <el-table-column label="确认收益方式" align="center" key="confirmType" prop="confirmType" v-if="columns[10].visible" width="100">
            <template slot-scope="scope">
              {{scope.row.confirmType == '0' ? "系统自动" : scope.row.confirmType == '1' ? "艺术家手动":'暂未确认'}}
            </template>
          </el-table-column>
          <el-table-column label="确认收益状态" align="center" key="confirmStatus" prop="confirmStatus" v-if="columns[11].visible" width="100">
            <template slot-scope="scope">
              {{scope.row.confirmStatus == '0' ? "待确认" : scope.row.confirmType == '1' ? "已确认":''}}
            </template>
          </el-table-column>
          <el-table-column label="下载次数" align="center" key="downloadNum" prop="downloadNum" v-if="columns[12].visible" :show-overflow-tooltip="true" />
          <el-table-column label="结算收益时间" align="center" prop="incomeTime" v-if="columns[13].visible" width="160">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.incomeTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="确认收益时间" align="center" prop="confirmTime" v-if="columns[14].visible" width="160">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.confirmTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="转入钱包时间" align="center" prop="walletTime" v-if="columns[15].visible" width="160">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.walletTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="序号" align="center" key="sort" prop="sort" v-if="columns[16].visible"/>
          <el-table-column label="是否显示" align="center" key="isShow" v-if="columns[17].visible">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.isShow"
                active-value="1"
                inactive-value="0"
                @change="handleStatusChange(scope.row)"
              ></el-switch>
            </template>
          </el-table-column>
          <el-table-column label="创建时间" align="center" prop="createTime" v-if="columns[18].visible" width="160">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="更新时间" align="center" prop="updateTime" v-if="columns[19].visible" width="160">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.updateTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="160"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <!-- <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['img:creatorProfit:edit']"
              >修改</el-button> -->
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['img:creatorProfit:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>

    <!-- 修改艺术家收益对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="banner名称" prop="bannerName">
              <el-input v-model="form.bannerName" placeholder="请输入banner名称" maxlength="30" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="跳转地址" prop="bannerUrl">
              <el-input v-model="form.bannerUrl" placeholder="请输入跳转地址" maxlength="100" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="来源平台" prop="source" label-width="80px">
        <el-select v-model="form.source" placeholder="来源平台" clearable>
          <el-option
            v-for="item in source"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import {  listCreatorProfit,editCreatorProfit,delCreatorProfit,getCreatorProfitDetails,changeStatus } from "@/api/img/creatorProfit";

export default {
  name: "CreatorProfit",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 艺术家收益列表数据
      creatorProfitList: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //大图列表
      bigImgList:[],
      //来源渠道
      source: [
        { value:'0',label:'通用'},
        { value:'1',label:'抖音'},
        { value:'2',label:'快手'},
        { value:'3',label:'微信'},
      ],
       //应用类型
      appType: [
          { value: '0', label: `bnyer壁纸`}
        ],
      //收益类型
      type: [
        { value:'0',label:'广告浏览'},
        { value:'1',label:'邀请'},
        { value:'2',label:'会员'}
      ],
      //收益状态
      status: [
          { value: '0', label: `即将到账`},
          { value: '1', label: `已到账`},
          { value: '2', label: `转入钱包`}
      ],
      //确认收益方式
      confirmType: [
          { value: '0', label: `系统自动`},
          { value: '1', label: `艺术家手动`}
      ],
      //确认收益状态
      confirmStatus: [
          { value: '0', label: `待确认`},
          { value: '1', label: `已确认`}
      ],
      //是否显示
      isShow: [
          { value: '0', label: `否`},
          { value: '1', label: `是`}
      ],
      // 表单参数
      form: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: undefined,
        scanCode: undefined,
        platform: undefined,
        appType: undefined,
        type: undefined,
        status: undefined,
        confirmType: undefined,
        confirmStatus: undefined,
        isShow: undefined
      },
      // 列信息
      columns: [
        { key: 0, label: `编号`, visible: true },
        { key: 1, label: `结算流水号`, visible: true },
        { key: 2, label: `艺术家id`, visible: true },
        { key: 3, label: `搜索码`, visible: true },
        { key: 4, label: `图片`, visible: true },
        { key: 5, label: `结算收益`, visible: true },
        { key: 6, label: `结算平台`, visible: true },
        { key: 7, label: `应用类型`, visible: true },
        { key: 8, label: `收益类型`, visible: true },
        { key: 9, label: `收益状态`, visible: true },
        { key: 10, label: `确认收益方式`, visible: true },
        { key: 11, label: `确认收益状态`, visible: true },
        { key: 12, label: `下载次数`, visible: true },
        { key: 13, label: `结算收益时间`, visible: true },
        { key: 14, label: `确认收益时间`, visible: true },
        { key: 15, label: `转入钱包时间`, visible: true },
        { key: 16, label: `序号`, visible: true },
        { key: 17, label: `是否显示`, visible: true },
        { key: 18, label: `创建时间`, visible: true },
        { key: 19, label: `更新时间`, visible: true },
      ],
      // 表单校验
      // rules: {
      //   bannerName: [
      //     { required: true, message: "banner名称不能为空", trigger: "blur" },
      //     { min: 2, max: 20, message: 'banner名称长度必须介于 2 和 20 之间', trigger: 'blur' }
      //   ],
      //   bannerUrl: [
      //     { required: true, message: "bannerUrl不能为空", trigger: "blur" },
      //   ],
      // }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询banner列表 */
    getList() {
      this.loading = true;
      listCreatorProfit(this.queryParams).then(response => {
          this.creatorProfitList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 状态修改
    handleStatusChange(row) {
      let text = row.isShow === "1" ? "显示" : "隐藏";
      this.$modal.confirm('确认要' + text + 'id为' + row.id + '的艺术家收益吗？').then(function() {
        let data = {
          id: row.id,
          status: row.isShow
        }
        return changeStatus(data);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.isShow = row.isShow === "0" ? "1" : "0";
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        bannerName: undefined,
        bannerUrl: undefined,
        bannerImg: undefined,
        source: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 查看大图 */
    getBigImg(row){
      this.bigImgList.push(row.bannerImg)
    },
    /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const id = row.id || this.ids;
    //   getCreatorProfitDetails(id).then(response => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改艺术家收益";
    //   });
    // },
    /** 提交按钮 */
    // submitForm: function() {
    //   this.$refs["form"].validate(valid => {
    //     if (valid) {
    //       if (this.form.id != undefined) {
    //         editCreatorProfit(this.form).then(response => {
    //           this.$modal.msgSuccess("修改成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       } 
    //     }
    //   });
    // },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id || this.ids;
      this.$modal.confirm('是否确认删除编号为"' + id + '"的艺术家收益吗？').then(function() {
        return delCreatorProfit(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  }
};
</script>