<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="orderId">-->
<!--        <el-input-->
<!--          v-model="queryParams.orderId"-->
<!--          placeholder="请输入订单主键ID"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="订单号" prop="orderNo">-->
<!--        <el-input-->
<!--          v-model="queryParams.orderNo"-->
<!--          placeholder="请输入订单号"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="商品名称" prop="goodsName">-->
<!--        <el-input-->
<!--          v-model="queryParams.goodsName"-->
<!--          placeholder="请输入商品名称"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="商品规格" prop="goodsProduct">-->
<!--        <el-input-->
<!--          v-model="queryParams.goodsProduct"-->
<!--          placeholder="请输入商品规格"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="商品单位" prop="goodsUnit">-->
<!--        <el-input-->
<!--          v-model="queryParams.goodsUnit"-->
<!--          placeholder="请输入商品单位"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="商品单价" prop="goodsPrice">-->
<!--        <el-input-->
<!--          v-model="queryParams.goodsPrice"-->
<!--          placeholder="请输入商品单价"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="商品数量" prop="goodsTotal">-->
<!--        <el-input-->
<!--          v-model="queryParams.goodsTotal"-->
<!--          placeholder="请输入商品数量"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="总金额" prop="totalPrice">-->
<!--        <el-input-->
<!--          v-model="queryParams.totalPrice"-->
<!--          placeholder="请输入总金额"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="提成" prop="commissionPrice">-->
<!--        <el-input-->
<!--          v-model="queryParams.commissionPrice"-->
<!--          placeholder="请输入提成"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="退货数量" prop="returnTotal">-->
<!--        <el-input-->
<!--          v-model="queryParams.returnTotal"-->
<!--          placeholder="请输入退货数量"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="退货状态：0-无，1-退货中，2-已退货，3-已拒绝，4-取消退货" prop="returnStatus">-->
<!--        <el-select v-model="queryParams.returnStatus" placeholder="请选择退货状态：0-无，1-退货中，2-已退货，3-已拒绝，4-取消退货" clearable size="small">-->
<!--          <el-option label="请选择字典生成" value="" />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="删除标记：0-正常，1-删除" prop="delFlag">-->
<!--        <el-input-->
<!--          v-model="queryParams.delFlag"-->
<!--          placeholder="请输入删除标记：0-正常，1-删除"-->
<!--          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="['mall:mallAppOrderGoods: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="['mall:mallAppOrderGoods: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="['mall:mallAppOrderGoods: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="['mall:mallAppOrderGoods:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

    <el-table v-loading="loading" :data="mallAppOrderGoodsList" @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="orderId" />-->
<!--      <el-table-column label="订单号" align="center" prop="orderNo" />-->
<!--      <el-table-column label="商品图片" align="center" prop="goodsImg" />-->
      <el-table-column label="商品名称" align="center" prop="goodsName" />
      <el-table-column label="商品规格" align="center" prop="goodsProduct" />
      <el-table-column label="商品单位" align="center" prop="goodsUnit" />
      <el-table-column label="商品单价" align="center" prop="goodsPrice" />
      <el-table-column label="商品数量" align="center" prop="goodsTotal" />
      <el-table-column label="总金额" align="center" prop="totalPrice" />
      <el-table-column label="提成" align="center" prop="commissionPrice" v-if="checkPermi(['mall:mallAppOrderGoods:commission'])" />
<!--      <el-table-column label="退货数量" align="center" prop="returnTotal" />-->
<!--      <el-table-column label="退货状态：0-无，1-退货中，2-已退货，3-已拒绝，4-取消退货" align="center" prop="returnStatus" />-->
<!--      <el-table-column label="备注" align="center" prop="remarks" />-->
<!--      <el-table-column label="内容" align="center" prop="content" />-->
<!--      <el-table-column label="删除标记：0-正常，1-删除" align="center" prop="delFlag" />-->
<!--      <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="['mall:mallAppOrderGoods:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['mall:mallAppOrderGoods: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"
    />

    <!-- 添加或修改app-线下订单商品对话框 -->
    <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="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单主键ID" />
        </el-form-item>
        <el-form-item label="订单号" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="商品图片" prop="goodsImg">
          <el-input v-model="form.goodsImg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="商品名称" prop="goodsName">
          <el-input v-model="form.goodsName" placeholder="请输入商品名称" />
        </el-form-item>
        <el-form-item label="商品规格" prop="goodsProduct">
          <el-input v-model="form.goodsProduct" placeholder="请输入商品规格" />
        </el-form-item>
        <el-form-item label="商品单位" prop="goodsUnit">
          <el-input v-model="form.goodsUnit" placeholder="请输入商品单位" />
        </el-form-item>
        <el-form-item label="商品单价" prop="goodsPrice">
          <el-input v-model="form.goodsPrice" placeholder="请输入商品单价" />
        </el-form-item>
        <el-form-item label="商品数量" prop="goodsTotal">
          <el-input v-model="form.goodsTotal" placeholder="请输入商品数量" />
        </el-form-item>
        <el-form-item label="总金额" prop="totalPrice">
          <el-input v-model="form.totalPrice" placeholder="请输入总金额" />
        </el-form-item>
        <el-form-item label="提成" prop="commissionPrice">
          <el-input v-model="form.commissionPrice" placeholder="请输入提成" />
        </el-form-item>
        <el-form-item label="退货数量" prop="returnTotal">
          <el-input v-model="form.returnTotal" placeholder="请输入退货数量" />
        </el-form-item>
        <el-form-item label="退货状态：0-无，1-退货中，2-已退货，3-已拒绝，4-取消退货">
          <el-radio-group v-model="form.returnStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="内容">
          <editor v-model="form.content" :min-height="192"/>
        </el-form-item>
        <el-form-item label="删除标记：0-正常，1-删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标记：0-正常，1-删除" />
        </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 { listMallAppOrderGoods, getMallAppOrderGoods, delMallAppOrderGoods, addMallAppOrderGoods, updateMallAppOrderGoods, exportMallAppOrderGoods } from "@/api/mall/mallAppOrderGoods";
import { checkPermi } from '@/utils/permission'

export default {
  name: "MallAppOrderGoods",
  props: {
    // 0-订单商品，1-订单性情
    pageType: {
      type: Number,
      default: 0,
    },
    // 订单id
    orderId: {
      type: Number,
      default: '',
    },
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // app-线下订单商品表格数据
      mallAppOrderGoodsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        orderNo: null,
        goodsImg: null,
        goodsName: null,
        goodsProduct: null,
        goodsUnit: null,
        goodsPrice: null,
        goodsTotal: null,
        totalPrice: null,
        commissionPrice: null,
        returnTotal: null,
        returnStatus: null,
        remarks: null,
        content: null,
        delFlag: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderId: [
          { required: true, message: "订单主键ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    checkPermi,
    /** 查询app-线下订单商品列表 */
    getList() {
      this.loading = true;
      this.queryParams.orderId = this.orderId;
      listMallAppOrderGoods(this.queryParams).then(response => {
        this.mallAppOrderGoodsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderId: null,
        orderNo: null,
        goodsImg: null,
        goodsName: null,
        goodsProduct: null,
        goodsUnit: null,
        goodsPrice: null,
        goodsTotal: null,
        totalPrice: null,
        commissionPrice: null,
        returnTotal: null,
        returnStatus: "0",
        remarks: null,
        content: null,
        delFlag: 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 = "添加app-线下订单商品";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getMallAppOrderGoods(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改app-线下订单商品";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateMallAppOrderGoods(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMallAppOrderGoods(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除app-线下订单商品编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delMallAppOrderGoods(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有app-线下订单商品数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportMallAppOrderGoods(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
