<template>
  <div class="m-container">
    <h2>
      <div class="squrt"></div>
      零星管理
    </h2>
    <div class="m-core">
      <!-- v-permission="'sporadicChargeInfo/add'" -->
      <save-form
        :inline="true"
        :model="searchForm"
        @submit="search"
        @reset="onReSet"
      >
        <el-form-item>
          <el-input
            placeholder="标题或学生姓名"
            clearable
            v-model.trim="searchForm.search"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model.trim="searchForm.organId"
            placeholder="请选择分部"
            clearable
            filterable
          >
            <el-option
              v-for="(item, index) in selects.branchs"
              :key="index"
              :value="item.id"
              :label="item.name"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model.trim="searchForm.chargeType"
            placeholder="请选择收费类型"
            clearable
          >
            <el-option
              v-for="item in orderType"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model.trim="searchForm.openFlag"
            placeholder="收费状态"
            clearable
          >
            <el-option label="关闭" value="1"></el-option>
            <el-option label="开启" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model.trim="searchForm.type"
            placeholder="请选择订单类型"
            clearable
          >
            <el-option label="个人" value="personal"></el-option>
            <el-option label="公用" value="common"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="danger" native-type="submit">搜索</el-button>
          <el-button native-type="reset" type="primary">重置</el-button>
          <el-button
            @click="exportSporad"
            v-permission="'export/sporadicChargeInfo'"
            >导出</el-button
          >
        </el-form-item>
      </save-form>
      <el-button
        v-permission="'sporadicChargeInfo/add'"
        @click="newVisible"
        type="primary"
        style="margin-bottom: 20px"
      >
        新增公用收费
      </el-button>
      <el-button
        v-permission="'sporadicChargeInfo/add'"
        @click="newVisible1"
        type="primary"
        style="margin-bottom: 20px"
      >
        新增个人收费
      </el-button>
      <div class="tableWrap">
        <el-table
          :data="tableList"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
        >
          <el-table-column align="center" label="分部" prop="organName">
            <template slot-scope="scope">
              <div>
                <copy-text>{{ scope.row.organName }}</copy-text>
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="收费类型">
            <template slot-scope="scope">
              <div>
                {{ scope.row.chargeType | chargeTypeFilter }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="标题" prop="title">
            <template slot-scope="scope">
              <div>
                <copy-text>{{ scope.row.title }}</copy-text>
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="学生姓名" prop="userName">
            <template slot-scope="scope">
              <copy-text>{{ scope.row.userName }}</copy-text>
            </template>
          </el-table-column>
          <el-table-column align="center" label="收费状态">
            <template slot-scope="scope">
              <div>
                {{ scope.row.openFlag ? "关闭" : "开启" }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="金额" prop="amount">
            <template slot-scope="scope">
              <div>
                {{ scope.row.amount | moneyFormat }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="时间">
            <template slot-scope="scope">
              <div>
                {{ scope.row.createTime | formatTimer }}
              </div>
            </template>
          </el-table-column>

          <el-table-column align="center" label="订单类型">
            <template slot-scope="scope">
              {{ scope.row.userId ? "个人" : "公用" }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="创建人" prop="operatorName">
          </el-table-column>
          <el-table-column align="center" label="操作">
            <template slot-scope="scope">
              <div>
                <el-button
                  type="text"
                  v-if="scope.row.chargeType == 12"
                  key="update"
                  v-permission="'sporadicChargeInfo/update'"
                  @click="lookVisible(scope.row)"
                  >修改</el-button
                >
                <el-button
                  type="text"
                  v-else
                  key="update"
                  v-permission="'sporadicChargeInfo/look'"
                  @click="lookVisible(scope.row)"
                  >查看</el-button
                >

                <el-button
                  type="text"
                  v-permission="'sporadicChargeInfo/delete'"
                  @click="removeItem(scope.row)"
                  >删除</el-button
                >
                <el-button
                  type="text"
                  v-if="scope.row.openFlag"
                  v-permission="'sporadicChargeInfo/updateOpenFlag'"
                  @click="setSporadic(scope.row)"
                  >开启</el-button
                >
                <el-button
                  type="text"
                  v-else
                  v-permission="'sporadicChargeInfo/updateOpenFlag'"
                  @click="setSporadic(scope.row)"
                  >关闭</el-button
                >
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          sync
          :total.sync="pageInfo.total"
          :page.sync="pageInfo.page"
          :limit.sync="pageInfo.limit"
          :page-sizes="pageInfo.page_size"
          @pagination="getList"
        />
      </div>
    </div>
    <el-dialog
      :title="title"
      :visible.sync="zeroVisible"
      @close="onFormClose('maskForm')"
      width="650px"
    >
      <el-form
        :model="maskForm"
        :rules="maskRules"
        label-width="110px"
        label-position="right"
        :inline="true"
        ref="maskForm"
      >
        <el-form-item label="标题" prop="title">
          <el-input
            v-model.trim="maskForm.title"
            maxlength="50"
            :disabled="!isNew"
          ></el-input>
        </el-form-item>
        <el-form-item label="收费类型" prop="type">
          <el-select
            v-model.trim="maskForm.type"
            :disabled="!isNew"
            clearable
            filterable
            style="width: 180px !important"
          >
            <el-option
              v-for="item in isNew ? orderType1 : orderType"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="金额" prop="money">
          <el-input
            v-model.trim="maskForm.money"
            type="number"
            @mousewheel.native.prevent
            :disabled="!isNew"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="是否开启限制"
          prop="openMaxTerm"
          :rules="[
            {
              required: true,
              message: '请选择是否开启目标金额',
              trigger: 'change'
            }
          ]"
          v-if="maskForm.type == 12"
        >
          <el-select v-model.trim="maskForm.openMaxTerm" clearable>
            <el-option :value="1" label="是"></el-option>
            <el-option :value="0" label="否"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="目标金额"
          prop="maxAmount"
          :rules="[{ required: true, validator: validMaxNum, trigger: 'blur' }]"
          v-if="maskForm.type == 12"
        >
          <el-input
            v-model.trim="maskForm.maxAmount"
            type="number"
            @mousewheel.native.prevent
          ></el-input>
        </el-form-item>
        <el-form-item label="减免金额" v-if="maskForm.type == 6" prop="money">
          <el-input
            v-model.trim="maskForm.subMoney"
            type="number"
            @mousewheel.native.prevent
            :disabled="!isNew"
          ></el-input>
        </el-form-item>
        <el-form-item label="分部" prop="organId">
          <el-select
            v-model.trim="maskForm.organId"
            :disabled="!isNew"
            clearable
            @change="onMusicGroupChange"
            filterable
            multiple
            collapse-tags
            style="width: 180px !important"
          >
            <el-option
              v-for="(item, index) in selects.branchs"
              :key="index"
              :value="item.id"
              :label="item.name"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="所属乐团"
          v-if="maskForm.type != 12"
          prop="musicGroupId"
        >
          <el-select
            v-model.trim="maskForm.musicGroupId"
            :disabled="!isNew || !maskForm.organId"
            clearable
            filterable
            style="width: 180px !important"
          >
            <el-option
              v-for="item in maskMusicList"
              :key="item.musicGroupId"
              :value="item.musicGroupId"
              :label="item.musicGroupName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="查看链接" v-if="!isNew">
          <el-input
            style="width: 400px !important"
            :disabled="!isNew"
            v-model.trim="maskForm.code"
          ></el-input>
          <el-button type="danger" @click="qrcodeStatus = true"
            >二维码</el-button
          >
        </el-form-item>
        <el-form-item label="收费详情" prop="desc">
          <el-input
            type="textarea"
            :disabled="!isNew"
            v-model.trim="maskForm.desc"
            style="width: 490px"
            maxlength="300"
            :autosize="{ minRows: 5 }"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="zeroVisible = false">取 消</el-button>
        <el-button type="primary" v-if="isNew" @click="addZero"
          >确 定</el-button
        >
        <el-button v-if="!isNew" type="primary" @click="updateZero"
          >确定</el-button
        >
      </span>
    </el-dialog>

    <el-dialog
      :title="title1"
      :visible.sync="zeroVisible1"
      @close="onFormClose('maskForm1')"
      width="650px"
    >
      <el-form
        :model="maskForm1"
        :rules="maskRules1"
        label-width="100px"
        label-position="right"
        :inline="true"
        ref="maskForm1"
      >
        <el-form-item label="标题" prop="title">
          <el-input
            v-model.trim="maskForm1.title"
            maxlength="50"
            :disabled="!isNew1"
          ></el-input>
        </el-form-item>
        <el-form-item label="收费类型" prop="type">
          <el-select
            v-model.trim="maskForm1.type"
            :disabled="!isNew1"
            clearable
            filterable
            style="width: 180px !important"
          >
            <template v-for="item in isNew1 ? orderType1 : orderType">
              <el-option
                v-if="item.value != 12"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </template>
          </el-select>
        </el-form-item>
        <el-form-item label="学员编号" prop="studentId">
          <el-input
            v-model.trim="maskForm1.studentId"
            @blur="onStudentChange"
            type="number"
            maxlength="10"
            @mousewheel.native.prevent
            :disabled="!isNew1"
          ></el-input>
        </el-form-item>
        <el-form-item label="金额" prop="money">
          <el-input
            v-model.trim="maskForm1.money"
            type="number"
            @mousewheel.native.prevent
            :disabled="!isNew1"
          ></el-input>
        </el-form-item>
        <el-form-item label="学员姓名" prop="studentName">
          <el-input
            v-model.trim="maskForm1.studentName"
            :disabled="true"
          ></el-input>
        </el-form-item>
        <el-form-item label="所属乐团" prop="musicGroupId">
          <el-select
            v-model.trim="maskForm1.musicGroupId"
            :disabled="!isNew1"
            clearable
            filterable
            style="width: 180px !important"
          >
            <el-option
              v-for="(item, index) in maskMusicList1"
              :key="index"
              :value="item.musicGroupId"
              :label="item.musicGroupName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="查看链接" v-if="!isNew1">
          <el-input
            style="width: 400px !important"
            :disabled="!isNew1"
            v-model.trim="maskForm1.code"
          ></el-input>
          <el-button type="danger" @click="qrcodeStatus = true"
            >二维码</el-button
          >
        </el-form-item>
        <el-form-item label="收费详情" prop="desc">
          <el-input
            type="textarea"
            :disabled="!isNew1"
            v-model.trim="maskForm1.desc"
            style="width: 490px"
            maxlength="300"
            :autosize="{ minRows: 5 }"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="zeroVisible1 = false">取 消</el-button>
        <el-button type="primary" v-if="isNew1" @click="addZero1"
          >确 定</el-button
        >
        <el-button v-if="!isNew1" type="primary" @click="zeroVisible1 = false"
          >确定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      :visible.sync="qrcodeStatus"
      center
      width="300px"
      title="缴费链接"
    >
      <div class="right-code">
        <!-- <h2 class="title">缴费链接</h2> -->
        <vue-qr :text="qrCodeUrl" style="width: 100%" :margin="0"></vue-qr>

        <!-- <div id="qrcode"
             class="qrcode code"
             ref="qrCodeUrl"></div> -->
        <!-- <p class="code-url"
           v-if="codeUrl2">{{ codeUrl2 }}</p> -->
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getAgreement } from "@/api/buildTeam";
import pagination from "@/components/Pagination/index";
import { vaildStudentUrl } from "@/utils/validate";
import cleanDeep from "clean-deep";
import {
  addZero,
  getZero,
  updateZero,
  removeZero,
  getBasic,
  updateOpenFlag,
  queryOrganMusicInfos,
  queryUserMusicInfos
} from "@/api/zeroManager";
import axios from "axios";
import qs from "qs";
import { getToken, getTenantId } from "@/utils/auth";
import load from "@/utils/loading";
// import QRCode from 'qrcodejs2'
import vueQr from "vue-qr";
let validMaxNum = (rule, value, callback) => {
  if ((value == "" && typeof value == "string") || value == null) {
    callback(new Error("请输入缴费金额"));
  } else if (value < 0) {
    callback(new Error("输入缴费金额必须大于0"));
  } else {
    callback();
  }
};
export default {
  name: "sporadicList",
  components: { pagination, vueQr },
  data() {
    return {
      validMaxNum: validMaxNum,
      zeroVisible: false,
      qrCodeUrl: null,
      searchForm: {
        organId: null,
        chargeType: null,
        type: null,
        search: null,
        openFlag: null
      },
      tableList: [],
      organList: [],
      orderType: [
        // { label: "考级", value: 1 },
        { label: "声部更改", value: 2 },
        { label: "乐器更换", value: 3 },
        { label: "配件销售", value: 4 },
        { label: "维修费", value: 5 },
        { label: "福袋活动", value: 6 },
        { label: "双十一活动", value: 12 },
        { label: "上门费", value: 7 },
        { label: "账户充值", value: 9 },
        // { label: "乐保服务", value: 10 },
        // { label: "网基课活动", value: 13 },
        // { label: "云教练购买", value: 15 },
        { label: "其它", value: 11 }
      ],
      orderType1: [
        // { label: "考级", value: 1 },
        // { label: "声部更改", value: 2 },
        // { label: '乐器更换', value: 3 },
        // { label: '配件销售', value: 4 },
        // { label: '双十一活动', value: 12 },
        { label: "上门费", value: 7 },
        { label: "账户充值", value: 9 },
        { label: "其它", value: 11 }
        // { label: "乐保服务", value: 10 },
        // { label: "网基课活动", value: 13 },
        // { label: "云教练购买", value: 15 },
      ],
      maskForm: {
        organId: [],
        type: "",
        money: "",
        desc: "",
        title: "",
        code: "",
        musicGroupId: "",
        maxAmount: null,
        openMaxTerm: null,
        subMoney: ""
      },
      maskMusicList: [],
      maskRules: {
        organId: [{ required: true, message: "请选择分部", trigger: "change" }],
        // musicGroupId: [{ required: true, message: '请选择所属乐团', trigger: 'change' }],
        type: [
          { required: true, message: "请选择收费类型", trigger: "change" }
        ],
        money: [
          { required: true, message: "请输入收费金额", trigger: "change" }
        ],
        title: [
          { required: true, message: "请输入标题名称", trigger: "change" }
        ],
        desc: [{ required: true, message: "请输入收费详情" }]
      },
      pageInfo: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      },
      isNew: false,
      title: "新增收费",
      qrcodeStatus: false,
      qrcodes: true,
      activeRow: null,
      title1: "新增收费",
      activeRow1: null,
      zeroVisible1: false,
      maskForm1: {
        type: null,
        money: null,
        desc: null,
        title: null,
        code: null,
        musicGroupId: null,
        studentId: null,
        studentName: null
      },
      isNew1: false,
      maskMusicList1: [],
      maskRules1: {
        organId: [{ required: true, message: "请选择分部", trigger: "change" }],
        // musicGroupId: [{ required: true, message: '请选择所属乐团', trigger: 'change' }],
        type: [
          { required: true, message: "请选择收费类型", trigger: "change" }
        ],
        money: [
          { required: true, message: "请输入收费金额", trigger: "change" }
        ],
        title: [
          { required: true, message: "请输入标题名称", trigger: "change" }
        ],
        studentId: [
          { required: true, message: "请输入学员编号", trigger: "blur" }
        ],
        desc: [{ required: true, message: "请输入收费详情" }]
      }
    };
  },
  mounted() {
    // getEmployeeOrgan().then(res => {
    //   if (res.code == 200) {
    //     this.organList = res.data;
    //   }
    // })
    this.$store.dispatch("setBranchs");
    this.getList();
    this.getAgreement();
  },
  methods: {
    search() {
      this.pageInfo.page = 1;
      this.getList();
    },
    onReSet() {
      this.searchForm = {
        organId: null,
        chargeType: null,
        type: null,
        search: null
      };
      this.search();
    },
    getList() {
      let searchForm = this.searchForm;
      let params = {
        organId: searchForm.organId ? searchForm.organId : null,
        chargeType: searchForm.chargeType ? searchForm.chargeType : null,
        type: searchForm.type ? searchForm.type : null,
        search: searchForm.search ? searchForm.search : null,
        openFlag: searchForm.openFlag ? searchForm.openFlag * 1 : null,
        page: this.pageInfo.page,
        rows: this.pageInfo.limit
      };

      getZero(params).then(res => {
        if (res.code == 200) {
          this.tableList = res.data.rows;
          this.pageInfo.total = res.data.total;
        }
      });
    },
    onFormClose(formName) {
      // 关闭弹窗重置验证
      if (formName == "maskForm") {
        this.maskForm = {
          organId: [],
          musicGroupId: null,
          type: null,
          money: null,
          maxAmount: null,
          openMaxTerm: null,
          desc: null,
          title: null,
          code: null
        };
      } else if (formName == "maskForm1") {
        this.maskForm1 = {
          type: null,
          musicGroupId: null,
          money: null,
          desc: null,
          title: null,
          code: null,
          studentId: null,
          studentName: null
        };
      }
      if (this.$refs[formName]) {
        this.$refs[formName].resetFields();
      }
    },
    newVisible() {
      this.isNew = true;
      this.zeroVisible = true;
      this.title = "新增公用收费";
    },
    newVisible1() {
      this.isNew1 = true;
      this.zeroVisible1 = true;
      this.title1 = "新增个人收费";
    },
    async getAgreement() {
      try {
        const res = await getAgreement();
        if (!res.data) {
          this.$bus.$emit("showguide", ["agreement"]);
        }
      } catch (e) {}
    },
    lookVisible(row) {
      let maskForm = null;
      if (row.userId) {
        maskForm = this.maskForm1;
        this.isNew1 = false;
        this.zeroVisible1 = true;
        this.title1 = "查看个人收费";
        let url =
          vaildStudentUrl() +
          `/#/sporadicPay?id=${row.id}&userId=${row.userId}`;
        this.qrCodeUrl = url;
        maskForm.code = url;
        maskForm.studentId = row.userId;
        maskForm.studentName = row.userName;
      } else {
        maskForm = this.maskForm;
        this.isNew = false;
        this.zeroVisible = true;
        this.title = "查看公用收费";
        let url = vaildStudentUrl() + `/#/sporadicLogin?id=${row.id}`;
        this.qrCodeUrl = url;
        maskForm.code = url;
      }
      maskForm.type = parseInt(row.chargeType);
      maskForm.id = row.id;
      maskForm.desc = row.detail;
      maskForm.title = row.title;
      maskForm.organId = row.organId;
      maskForm.money = row.amount;
      maskForm.subMoney = row.discountAmount;
      maskForm.maxAmount = row.maxAmount;
      maskForm.openMaxTerm = row.openMaxTerm;
      maskForm.musicGroupId = row.musicGroupId ? row.musicGroupId : null;
      if (row.userId) {
        queryUserMusicInfos({ userId: row.userId }).then(studentInfo => {
          if (studentInfo.code == 200) {
            this.maskMusicList1 = studentInfo.data;
          }
        });
      } else {
        this.onMusicGroupChange(true);
      }
    },
    onMusicGroupChange(status) {
      let maskForm = this.maskForm;
      if (!maskForm.organId) {
        return;
      }
      if (!status) {
        maskForm.musicGroupId = null; // 重置可能已经选中的乐团
      }
      queryOrganMusicInfos({ organId: maskForm.organId.join(",") }).then(
        res => {
          if (res.code == 200) {
            this.maskMusicList = res.data;
          }
        }
      );
    },
    updateZero() {
      let maskForm = this.maskForm;
      if (maskForm.type != 12) {
        this.zeroVisible = false;
        return;
      }
      this.$refs["maskForm"].validate(item => {
        if (item) {
          updateZero(
            cleanDeep({
              id: maskForm.id,
              maxAmount: maskForm.maxAmount,
              openMaxTerm: maskForm.openMaxTerm
            })
          ).then(res => {
            if (res.code == 200) {
              this.$message.success("更新成功");
              this.zeroVisible = false;
              this.getList();
            }
          });
        }
      });
    },
    addZero() {
      this.$refs["maskForm"].validate(item => {
        if (item) {
          let maskForm = this.maskForm;
          let obj = {
            chargeType: maskForm.type,
            detail: maskForm.desc,
            title: maskForm.title,
            organId: maskForm.organId ? maskForm.organId.join(",") : "",
            amount: maskForm.money,
            musicGroupId: maskForm.musicGroupId,
            discountAmount: maskForm.subMoney
          };

          if (maskForm.type == 12) {
            (obj.maxAmount = maskForm.maxAmount),
              (obj.openMaxTerm = maskForm.openMaxTerm);
          }
          addZero(obj).then(res => {
            if (res.code == 200) {
              this.$message.success("新增成功");
              this.zeroVisible = false;
              this.getList();
            }
          });
        }
      });
    },
    addZero1() {
      this.$refs["maskForm1"].validate(item => {
        if (item) {
          let maskForm1 = this.maskForm1;
          if (!maskForm1.studentName) {
            this.$message.error("学员信息不存在");
            return;
          }
          let obj = {
            chargeType: maskForm1.type,
            detail: maskForm1.desc,
            title: maskForm1.title,
            musicGroupId: this.maskForm1.musicGroupId,
            userId: maskForm1.studentId,
            amount: maskForm1.money
          };
          addZero(obj).then(res => {
            if (res.code == 200) {
              this.$message.success("新增成功");
              this.zeroVisible1 = false;
              this.getList();
            }
          });
        }
      });
    },
    async onStudentChange() {
      let studentId = this.maskForm1.studentId;
      // 判断学生编号是否存在
      if (!studentId) {
        return;
      }

      if (studentId.length > 10) {
        this.$message.error("学员编号不合法");
        return;
      }

      await getBasic({ userId: studentId }).then(res => {
        if (res.code == 200) {
          if (res.data) {
            this.maskForm1.studentName = res.data.name;
            queryUserMusicInfos({ userId: studentId }).then(studentInfo => {
              if (studentInfo.code == 200) {
                this.maskMusicList1 = studentInfo.data;
              }
            });
          } else {
            this.maskForm1.studentName = null;
          }
        }
      });
    },
    removeItem(row) {
      this.$confirm("是否删除该收费", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          removeZero({ id: row.id }).then(res => {
            if (res.code == 200) {
              this.$message.success("删除成功");
              this.zeroVisible = false;
              this.getList();
            }
          });
        })
        .catch(() => {});
    },
    setSporadic(row) {
      // openFlag
      let str = "";
      let openFlag = "";
      if (row.openFlag) {
        // 关闭=>开启 1是关闭
        openFlag = 0;
        str = "开启";
      } else {
        // 开启=>关闭 0是开启
        openFlag = 1;
        str = "关闭";
      }

      this.$confirm(`是否${str}该收费`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          updateOpenFlag({ sporadicId: row.id, openFlag }).then(res => {
            if (res.code == 200) {
              this.$message.success(`${str}成功`);
              this.getList();
            }
          });
        })
        .catch(() => {});
    },
    exportSporad() {
      let url = "/api-web/export/sporadicChargeInfo";
      let data = this.searchForm;
      const options = {
        method: "get",
        headers: {
          Authorization: getToken(),
          tenantId: getTenantId()
        },
        params: data,
        url,
        responseType: "blob"
      };
      this.$confirm("您确定导出零星缴费列表", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          load.startLoading();
          axios(options)
            .then(res => {
              let blob = new Blob([res.data], {
                // type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'
                type: "application/vnd.ms-excel;charset=utf-8"
                //word文档为application/msword,pdf文档为application/pdf,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8
              });

              let text = new Response(blob).text();
              text.then(res => {
                // 判断是否报错
                if (res.indexOf("code") != -1) {
                  let json = JSON.parse(res);
                  if (json.code == 403) {
                    this.$message.error(`登录过期，请重新登录！`);
                    setTimeout(() => {
                      this.$store.dispatch("user/resetToken").then(() => {
                        location.reload();
                      });
                    }, 1000);
                    return;
                  }
                  this.$message.error(json.msg);
                } else {
                  let objectUrl = URL.createObjectURL(blob);
                  let link = document.createElement("a");
                  let nowTime = new Date();
                  let ymd =
                    nowTime.getFullYear() +
                    "" +
                    (nowTime.getMonth() + 1) +
                    "" +
                    nowTime.getDate();
                  let fname = ymd + "零星缴费.xls"; //下载文件的名字
                  link.href = objectUrl;
                  link.setAttribute("download", fname);
                  document.body.appendChild(link);
                  link.click();
                }
              });
              load.endLoading();
            })
            .catch(error => {
              this.$message.error("导出数据失败，请联系管理员");
              load.endLoading();
            });
        })
        .catch(() => {});
    }
  },
  watch: {
    zeroVisible(val) {
      if (!val) {
        this.maskForm = {
          organId: "",
          type: "",
          money: "",
          desc: "",
          title: "",
          maxAmount: null,
          openMaxTerm: null,
          code: ""
        };
        // this.$refs['maskForm'].resetFields()
        // console.log(this.$refs['zeroForm'].resetFields)
      }
    }
  },
  filters: {
    chargeTypeFilter(val) {
      let template = {
        1: "考级",
        2: "声部更改",
        3: "乐器更换",
        4: "配件销售",
        5: "维修费",
        6: "福袋活动",
        7: "上门费",
        9: "账户充值",
        10: "乐保服务",
        11: "其它",
        12: "双十一活动",
        13: "网基课活动",
        15: "云教练购买"
      };
      return template[val];
    }
  }
};
</script>
<style lang="scss" scoped>
.right-code {
  // width: 50%;
  // float: left;
  .title {
    font-size: 18px;
    text-align: center;
    padding-bottom: 8px;
  }
}
.newBand {
  display: inline-block;
}

.el-input {
  width: 180px !important;
}
::v-deep .el-select {
  width: auto !important;
}
</style>
