<!-- 配置管理 - 钱包配置 - 提现手续费 -->
<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar>
    <div class="main">
      <div class="maintop">
        <div class="mainbtn">
          <el-button size="small" class="thebtn1" @click="adddate()"
             v-has-buttons="['OnSiteConfigAdd']"
            >{{'添加'}}</el-button
          >
        </div>
      </div>
      <div class="maintable">
        <el-table
          :data="tableData"
          v-loading="loading"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
          @selection-change="handleSelectionChange"
        >
          <!-- <el-table-column align="center" prop="" :label="'序号'">
          </el-table-column> -->
          <el-table-column align="center" prop="title" :label="'模板名称'">
          </el-table-column>
          <el-table-column align="center" prop="content" :label="'提示语'">
          </el-table-column>
          <el-table-column align="center" prop="businessTypeVal" :label="'业务类型'">
          </el-table-column>
          <el-table-column align="center" prop="approvalType" :label="'审批类型'">
            <template slot-scope="scope">
              <span v-if="scope.row.approvalType == 1">{{ '待审核' }}</span>
              <span
                v-if="scope.row.approvalType == 2"
                style="color: rgba(0, 155, 88, 1)"
                >{{ '审核通过' }}</span
              >
              <span
                v-if="scope.row.approvalType == 3"
                style="color: rgba(200, 22, 29, 1)"
                >{{ '审核驳回' }}</span
              >
            </template>
          </el-table-column>
          <el-table-column align="center" prop="url" label="URL">
          </el-table-column>
          <el-table-column
            align="center"
            prop="time"
            :label="'操作'"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                @click.native.prevent="update(scope.row)"
                type="text"
                size="small"
                v-has-buttons="['OnSiteConfigUpdate']"
              >
                {{'修改'}}
              </el-button>
              <el-button
                @click.native.prevent="deleteRow(scope.row)"
                type="text"
                size="small"
                style="color: #c73030"
                v-has-buttons="['OnSiteConfigDelete']"
              >
                {{'删除'}}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getWithdrawalProcessList"
    />

    <el-dialog
      :title="updateTitle"
      :visible.sync="updateShow"
      width="40%"
      center
      :before-close="handleClose"
    >
      <el-form ref="form" :rules="rules" :model="form" label-width="100px">
        <el-row>
          <el-col :span="24">
            <el-form-item :label="'模板名称'" prop="title">
              <el-input
                clearable
                v-model="form.title"
                :placeholder="'请输入'"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item :label="'提示语'" prop="content">
              <el-input
                clearable
                v-model="form.content"
                :placeholder="'请输入'"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="'业务类型'" prop="businessType">
              <el-select clearable v-model="form.businessType">
                <el-option
                  v-for="item in noticeBusinessTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'审核类型'" prop="approvalType">
              <el-select clearable v-model="form.approvalType">
                <el-option
                  v-for="item in approiveStatusList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="URL" prop="url">
              <el-input
                clearable
                v-model="form.url"
                :placeholder="'请输入'"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">{{'取消'}}</el-button>
        <el-button type="primary" @click="onSubmit('form')">{{'确认'}}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

    <script>
import topBar from "@/components/topBar";

import * as ons from "@/api/notice";
export default {
  name: "OnSiteConfig",
  components: {
    topBar,
  },
  data() {
    return {
      moren: "onSiteConfig",
      topList: [
        {
          name: '站内信配置',
          path: "onSiteConfig",
        },
      ],
      tableData: [],
      loading:false,
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 50,
      },
      noticeBusinessTypeList: [], //扣除类型
      updateShow: false,
      addOrEdit: "", //添加还是修改 true添加 false修改
      updateTitle: "",
      form: {
        title: "",
        content: "",
        url: "",
        businessType: "",
        approvalType: "",
      },
      approiveStatusList: [],
      rules: {
        // serviceRatio: [
        //   { required: true, message: "请输入手续费值", trigger: "blur" },
        // ],
        // serviceType: [{ required: true, message: '请选择', trigger: "change" }],
        // effectiveDate: [
        //   { required: true, message: '请选择生效时间', trigger: "change" },
        // ],
      },
    };
  },
  created() {
    this.getSearch();
    this.getOthers();
  },
  methods: {
    getOthers() {
      ons.getApproveStatus().then((res) => {
        this.approiveStatusList = res.data;
      });
      ons.getNoticeBusinessType().then((res) => {
        this.noticeBusinessTypeList = res.data;
      });
    },
    getSearch() {
      this.loading = true
      ons.getPlateformList().then((res) => {
        this.loading = false
        this.tableData = res.rows;
        this.total = res.total
      });
    },
    handleClose() {
      this.updateShow = false;
      this.$refs["form"].clearValidate();
      this.$refs["form"].resetFields();
    },
    //点击保存
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.addOrEdit == true) {
            ons.savePlateform(this.form).then((res) => {
              if (res.code == 200) {
                this.updateShow = false;
                this.$message({
                  message: res.msg,
                  type: "success",
                });
                this.getSearch();
              }
            });
          } else {
            ons.updatePlateform(this.form).then((res) => {
              if (res.code == 200) {
                this.updateShow = false;
                this.$message({
                  message: res.msg,
                  type: "success",
                });
                this.getSearch();
              }
            });
          }
        }
      });
    },

    //添加
    adddate() {
      this.updateShow = true;
      this.updateTitle = '添加';
      this.addOrEdit = true;
      if (this.$refs.form) {
        this.form.pkId = null;
        this.$refs.form.clearValidate();
        this.$refs.form.resetFields();
      }
    },
    //修改
    update(row) {
      this.updateTitle = '修改';
      this.addOrEdit = false;
      this.updateShow = true;
      ons.getMessageDetail({pkId:row.pkId}).then((res) => {
        this.form = res.data;
        this.getSearch()
      });
    },
    //删除
    deleteRow(row) {
      this.$confirm('确定删除?').then((_) => {
        ons.deletePlateform({ pkId: row.pkId }).then((res) => {
          if (res.code == 200) {
            this.$message({
              message: res.msg,
              type: "success",
            });
            this.getSearch();
          }
        });
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return "warning-row";
      } else if (rowIndex % 2 == 0) {
        return "success-row";
      }
      return "";
    },
  },
};
</script>

    <style lang="scss" scoped>
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
.tem {
  display: flex;
  align-items: center;
  justify-content: center;
  img {
    width: 28px;
    height: 20px;
    margin-right: 3px;
  }
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    .maintop {
      display: flex;
      // padding: 10px 20px;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          background: #3181e5;
          color: #ffffff;
        }
        .thebtn2 {
          background: #ffad41;
          color: #ffffff;
        }
      }
    }
  }
  .isRed {
    color: #ed1d25;
  }
  .isGreen {
    color: #1ab62b;
  }
}
</style>
