<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="直播ID" prop="liveId">
        <el-input
          v-model="queryParams.liveId"
          placeholder="请输入直播ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺ID" prop="storeId">
        <el-input
          v-model="queryParams.storeId"
          placeholder="请输入店铺ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单ID" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="退款金额" prop="refundAmount">
        <el-input
          v-model="queryParams.refundAmount"
          placeholder="请输入退款金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务类型0仅退款1退货退款" prop="refundType">
        <el-select v-model="queryParams.refundType" placeholder="请选择服务类型0仅退款1退货退款" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="物流公司编码" prop="deliveryCode">
        <el-input
          v-model="queryParams.deliveryCode"
          placeholder="请输入物流公司编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物流单号" prop="deliverySn">
        <el-input
          v-model="queryParams.deliverySn"
          placeholder="请输入物流单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物流名称" prop="deliveryName">
        <el-input
          v-model="queryParams.deliveryName"
          placeholder="请输入物流名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态 0已提交等待平台审核 1平台已审核 等待用户发货 2 用户已发货待仓库审核 3财务审核 4退款成功" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态 0已提交等待平台审核 1平台已审核 等待用户发货 2 用户已发货待仓库审核 3财务审核 4退款成功" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="售后状态 0售后中 1用户取消2商家拒绝 3已完成" prop="salesStatus">
        <el-select v-model="queryParams.salesStatus" placeholder="请选择售后状态 0售后中 1用户取消2商家拒绝 3已完成" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="订单状态" prop="orderStatus">
        <el-select v-model="queryParams.orderStatus" placeholder="请选择订单状态" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="用户id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商家收货人" prop="consignee">
        <el-input
          v-model="queryParams.consignee"
          placeholder="请输入商家收货人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商家手机号" prop="phoneNumber">
        <el-input
          v-model="queryParams.phoneNumber"
          placeholder="请输入商家手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商家地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入商家地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商家地址" prop="companyId">
        <el-input
          v-model="queryParams.companyId"
          placeholder="请输入商家地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商家地址" prop="companyUserId">
        <el-input
          v-model="queryParams.companyUserId"
          placeholder="请输入商家地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门id" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入部门id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </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="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['live:liveAfteraSales:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['live:liveAfteraSales:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['live:liveAfteraSales:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['live:liveAfteraSales:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="liveAfteraSalesList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="部门id" align="center" prop="id" />
      <el-table-column label="直播ID" align="center" prop="liveId" />
      <el-table-column label="店铺ID" align="center" prop="storeId" />
      <el-table-column label="订单ID" align="center" prop="orderId" />
      <el-table-column label="退款金额" align="center" prop="refundAmount" />
      <el-table-column label="服务类型0仅退款1退货退款" align="center" prop="refundType" />
      <el-table-column label="申请原因" align="center" prop="reasons" />
      <el-table-column label="说明" align="center" prop="explains" />
      <el-table-column label="说明图片-&gt;多个用逗号分割" align="center" prop="explainImg" />
      <el-table-column label="物流公司编码" align="center" prop="deliveryCode" />
      <el-table-column label="物流单号" align="center" prop="deliverySn" />
      <el-table-column label="物流名称" align="center" prop="deliveryName" />
      <el-table-column label="状态 0已提交等待平台审核 1平台已审核 等待用户发货 2 用户已发货待仓库审核 3财务审核 4退款成功" align="center" prop="status" />
      <el-table-column label="售后状态 0售后中 1用户取消2商家拒绝 3已完成" align="center" prop="salesStatus" />
      <el-table-column label="订单状态" align="center" prop="orderStatus" />
      <el-table-column label="逻辑删除" align="center" prop="isDel" />
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="商家收货人" align="center" prop="consignee" />
      <el-table-column label="商家手机号" align="center" prop="phoneNumber" />
      <el-table-column label="商家地址" align="center" prop="address" />
      <el-table-column label="商家地址" align="center" prop="companyId" />
      <el-table-column label="商家地址" align="center" prop="companyUserId" />
      <el-table-column label="部门id" align="center" prop="deptId" />
      <el-table-column label="操作" align="center" 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="['live:liveAfteraSales:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['live:liveAfteraSales: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-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="直播ID" prop="liveId">
          <el-input v-model="form.liveId" placeholder="请输入直播ID" />
        </el-form-item>
        <el-form-item label="店铺ID" prop="storeId">
          <el-input v-model="form.storeId" placeholder="请输入店铺ID" />
        </el-form-item>
        <el-form-item label="订单ID" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单ID" />
        </el-form-item>
        <el-form-item label="退款金额" prop="refundAmount">
          <el-input v-model="form.refundAmount" placeholder="请输入退款金额" />
        </el-form-item>
        <el-form-item label="服务类型0仅退款1退货退款" prop="refundType">
          <el-select v-model="form.refundType" placeholder="请选择服务类型0仅退款1退货退款">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="申请原因" prop="reasons">
          <el-input v-model="form.reasons" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="说明" prop="explains">
          <el-input v-model="form.explains" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="说明图片-&gt;多个用逗号分割" prop="explainImg">
          <el-input v-model="form.explainImg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="物流公司编码" prop="deliveryCode">
          <el-input v-model="form.deliveryCode" placeholder="请输入物流公司编码" />
        </el-form-item>
        <el-form-item label="物流单号" prop="deliverySn">
          <el-input v-model="form.deliverySn" placeholder="请输入物流单号" />
        </el-form-item>
        <el-form-item label="物流名称" prop="deliveryName">
          <el-input v-model="form.deliveryName" placeholder="请输入物流名称" />
        </el-form-item>
        <el-form-item label="状态 0已提交等待平台审核 1平台已审核 等待用户发货 2 用户已发货待仓库审核 3财务审核 4退款成功">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="售后状态 0售后中 1用户取消2商家拒绝 3已完成">
          <el-radio-group v-model="form.salesStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="订单状态">
          <el-radio-group v-model="form.orderStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="商家收货人" prop="consignee">
          <el-input v-model="form.consignee" placeholder="请输入商家收货人" />
        </el-form-item>
        <el-form-item label="商家手机号" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入商家手机号" />
        </el-form-item>
        <el-form-item label="商家地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入商家地址" />
        </el-form-item>
        <el-form-item label="商家地址" prop="companyId">
          <el-input v-model="form.companyId" placeholder="请输入商家地址" />
        </el-form-item>
        <el-form-item label="商家地址" prop="companyUserId">
          <el-input v-model="form.companyUserId" placeholder="请输入商家地址" />
        </el-form-item>
        <el-form-item label="部门id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门id" />
        </el-form-item>
      </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 { listLiveAfteraSales, getLiveAfteraSales, delLiveAfteraSales, addLiveAfteraSales, updateLiveAfteraSales, exportLiveAfteraSales } from "@/api/live/liveAfteraSales";

export default {
  name: "LiveAfteraSales",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 售后记录表格数据
      liveAfteraSalesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        liveId: null,
        storeId: null,
        orderId: null,
        refundAmount: null,
        refundType: null,
        reasons: null,
        explains: null,
        explainImg: null,
        deliveryCode: null,
        deliverySn: null,
        deliveryName: null,
        status: null,
        salesStatus: null,
        orderStatus: null,
        isDel: null,
        userId: null,
        consignee: null,
        phoneNumber: null,
        address: null,
        companyId: null,
        companyUserId: null,
        deptId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询售后记录列表 */
    getList() {
      this.loading = true;
      listLiveAfteraSales(this.queryParams).then(response => {
        this.liveAfteraSalesList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        liveId: null,
        storeId: null,
        orderId: null,
        refundAmount: null,
        refundType: null,
        reasons: null,
        explains: null,
        explainImg: null,
        deliveryCode: null,
        deliverySn: null,
        deliveryName: null,
        status: 0,
        salesStatus: 0,
        orderStatus: 0,
        createTime: null,
        isDel: null,
        userId: null,
        consignee: null,
        phoneNumber: null,
        address: null,
        companyId: null,
        companyUserId: null,
        deptId: null
      };
      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
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加售后记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getLiveAfteraSales(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改售后记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateLiveAfteraSales(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLiveAfteraSales(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除售后记录编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delLiveAfteraSales(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有售后记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportLiveAfteraSales(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
