<style>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 100%;
  }
</style>


<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="销售单号" prop="receiptNo">
        <el-input
          v-model="queryParams.receiptNo"
          placeholder="请输入销售单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="料件号" prop="ematouCode">
        <el-input
          v-model="queryParams.ematouCode"
          placeholder="请输入料件号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品主条码" prop="barcode">
        <el-input
          v-model="queryParams.barcode"
          placeholder="请输入商品主条码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" 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"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['biz:salesdetail:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['biz:salesdetail:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['biz:salesdetail:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['biz:salesdetail:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="salesdetailList" @selection-change="handleSelectionChange" height="700">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商户编号" align="center" prop="merchSn" />
      <el-table-column label="商户名称" align="center" prop="merchSnName" />
      <el-table-column label="第三方商户编号" align="center" prop="thirdMerchSn" />
      <el-table-column label="第三方商户名称" align="center" prop="thirdMerchSnName" />
      <el-table-column label="销售单号" align="center" prop="receiptNo" />
      <el-table-column label="门店名称" align="center" prop="storeName" />
      <el-table-column label="门店编号" align="center" prop="storeNameSn" />
      <el-table-column label="收银台" align="center" prop="cashRegisterNo" />
      <el-table-column label="销售时间" align="center" prop="timeStamp" width="200">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.timeStamp, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收银员id" align="center" prop="staffId" />
      <el-table-column label="收银员姓名" align="center" prop="staffName" />
      <el-table-column label="支付方式" align="center" prop="payFlag" />
      <el-table-column label="支付状态" align="center" prop="orderStatus" />
      <el-table-column label="微信流水号" align="center" prop="orderSnWx" />
      <el-table-column label="支付宝流水号" align="center" prop="orderSnAli" />
      <el-table-column label="海关商品编码" align="center" prop="hsCode" />
      <el-table-column label="品类名称" align="center" prop="hsCodeName" />
      <el-table-column label="料件号" align="center" prop="ematouCode" />
      <el-table-column label="PLU" align="center" prop="plu" />
      <el-table-column label="MychemID" align="center" prop="mychemId" />
      <el-table-column label="商品名称(英文)" align="center" prop="productNameEn" />
      <el-table-column label="商品名称(中文)" align="center" prop="productNameCn" />
      <el-table-column label="商品主条码" align="center" prop="barcode" />
      <el-table-column label="规格" align="center" prop="packSize" />
      <el-table-column label="单位" align="center" prop="productSpec" />
      <el-table-column label="品牌" align="center" prop="brand" />
      <el-table-column label="日常价" align="center" prop="edlp" />
      <el-table-column label="实际销售价" align="center" prop="currentPrice" />
      <el-table-column label="进货价" align="center" prop="costPrice" />
      <el-table-column label="税费" align="center" prop="taxPrice" />
      <el-table-column label="综合税率" align="center" prop="taxRate" />
      <el-table-column label="商品类型" align="center" prop="productCategory" />
      <el-table-column label="主供应商名称" align="center" prop="supplierName" />
      <el-table-column label="销售类型" align="center" prop="transactionType" />
      <el-table-column label="退货类型" align="center" prop="saleReturnType" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="创建人编号" align="center" prop="createrSn" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.timeStamp, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改人编号" align="center" prop="moderSn" />
      <el-table-column label="修改时间" align="center" prop="modTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.timeStamp, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <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="['biz:salesdetail:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['biz:salesdetail: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"
    />

    <!-- 添加或修改kmall销售数据对话框 -->
    <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="商户编号" prop="merchSn">
          <el-input v-model="form.merchSn" placeholder="请输入商户编号" />
        </el-form-item>
        <el-form-item label="商户名称" prop="merchSnName">
          <el-input v-model="form.merchSnName" placeholder="请输入商户名称" />
        </el-form-item>
        <el-form-item label="第三方商户编号" prop="thirdMerchSn">
          <el-input v-model="form.thirdMerchSn" placeholder="请输入第三方商户编号" />
        </el-form-item>
        <el-form-item label="第三方商户名称" prop="thirdMerchSnName">
          <el-input v-model="form.thirdMerchSnName" placeholder="请输入第三方商户名称" />
        </el-form-item>
        <el-form-item label="销售单号" prop="receiptNo">
          <el-input v-model="form.receiptNo" placeholder="请输入销售单号" />
        </el-form-item>
        <el-form-item label="门店名称" prop="storeName">
          <el-input v-model="form.storeName" placeholder="请输入门店名称" />
        </el-form-item>
        <el-form-item label="门店编号" prop="storeNameSn">
          <el-input v-model="form.storeNameSn" placeholder="请输入门店编号" />
        </el-form-item>
        <el-form-item label="收银台" prop="cashRegisterNo">
          <el-input v-model="form.cashRegisterNo" placeholder="请输入收银台" />
        </el-form-item>
        <el-form-item label="销售时间" prop="timeStamp">
          <el-date-picker clearable size="small"
            v-model="form.timeStamp"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择销售时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="收银员id" prop="staffId">
          <el-input v-model="form.staffId" placeholder="请输入收银员id" />
        </el-form-item>
        <el-form-item label="收银员姓名" prop="staffName">
          <el-input v-model="form.staffName" placeholder="请输入收银员姓名" />
        </el-form-item>
        <el-form-item label="支付方式" prop="payFlag">
          <el-input v-model="form.payFlag" placeholder="请输入支付方式" />
        </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="微信流水号" prop="orderSnWx">
          <el-input v-model="form.orderSnWx" placeholder="请输入微信流水号" />
        </el-form-item>
        <el-form-item label="支付宝流水号" prop="orderSnAli">
          <el-input v-model="form.orderSnAli" placeholder="请输入支付宝流水号" />
        </el-form-item>
        <el-form-item label="海关商品编码" prop="hsCode">
          <el-input v-model="form.hsCode" placeholder="请输入海关商品编码" />
        </el-form-item>
        <el-form-item label="品类名称" prop="hsCodeName">
          <el-input v-model="form.hsCodeName" placeholder="请输入品类名称" />
        </el-form-item>
        <el-form-item label="料件号" prop="ematouCode">
          <el-input v-model="form.ematouCode" placeholder="请输入料件号" />
        </el-form-item>
        <el-form-item label="PLU" prop="plu">
          <el-input v-model="form.plu" placeholder="请输入PLU" />
        </el-form-item>
        <el-form-item label="MychemID" prop="mychemId">
          <el-input v-model="form.mychemId" placeholder="请输入MychemID" />
        </el-form-item>
        <el-form-item label="商品名称(英文)" prop="productNameEn">
          <el-input v-model="form.productNameEn" placeholder="请输入商品名称(英文)" />
        </el-form-item>
        <el-form-item label="商品名称(中文)" prop="productNameCn">
          <el-input v-model="form.productNameCn" placeholder="请输入商品名称(中文)" />
        </el-form-item>
        <el-form-item label="商品主条码" prop="barcode">
          <el-input v-model="form.barcode" placeholder="请输入商品主条码" />
        </el-form-item>
        <el-form-item label="规格" prop="packSize">
          <el-input v-model="form.packSize" placeholder="请输入规格" />
        </el-form-item>
        <el-form-item label="单位" prop="productSpec">
          <el-input v-model="form.productSpec" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item label="品牌" prop="brand">
          <el-input v-model="form.brand" placeholder="请输入品牌" />
        </el-form-item>
        <el-form-item label="日常价" prop="edlp">
          <el-input v-model="form.edlp" placeholder="请输入日常价" />
        </el-form-item>
        <el-form-item label="实际销售价" prop="currentPrice">
          <el-input v-model="form.currentPrice" placeholder="请输入实际销售价" />
        </el-form-item>
        <el-form-item label="进货价" prop="costPrice">
          <el-input v-model="form.costPrice" placeholder="请输入进货价" />
        </el-form-item>
        <el-form-item label="税费" prop="taxPrice">
          <el-input v-model="form.taxPrice" placeholder="请输入税费" />
        </el-form-item>
        <el-form-item label="综合税率" prop="taxRate">
          <el-input v-model="form.taxRate" placeholder="请输入综合税率" />
        </el-form-item>
        <el-form-item label="商品类型" prop="productCategory">
          <el-input v-model="form.productCategory" placeholder="请输入商品类型" />
        </el-form-item>
        <el-form-item label="主供应商名称" prop="supplierName">
          <el-input v-model="form.supplierName" placeholder="请输入主供应商名称" />
        </el-form-item>
        <el-form-item label="销售类型" prop="transactionType">
          <el-input v-model="form.transactionType" placeholder="请输入销售类型" />
        </el-form-item>
        <el-form-item label="退货类型" prop="saleReturnType">
          <el-input v-model="form.saleReturnType" placeholder="请输入退货类型" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </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 { listSalesdetail, getSalesdetail, delSalesdetail, addSalesdetail, updateSalesdetail, exportSalesdetail } from "@/api/mall/salesdetail";

export default {
  name: "Salesdetail",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // kmall销售数据表格数据
      salesdetailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        receiptNo: null,
        ematouCode: null,
        barcode: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询kmall销售数据列表 */
    getList() {
      this.loading = true;
      listSalesdetail(this.queryParams).then(response => {
        this.salesdetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        merchSn: null,
        merchSnName: null,
        thirdMerchSn: null,
        thirdMerchSnName: null,
        receiptNo: null,
        storeName: null,
        storeNameSn: null,
        cashRegisterNo: null,
        timeStamp: null,
        staffId: null,
        staffName: null,
        payFlag: null,
        orderStatus: 0,
        orderSnWx: null,
        orderSnAli: null,
        hsCode: null,
        hsCodeName: null,
        ematouCode: null,
        plu: null,
        mychemId: null,
        productNameEn: null,
        productNameCn: null,
        barcode: null,
        packSize: null,
        productSpec: null,
        brand: null,
        edlp: null,
        currentPrice: null,
        costPrice: null,
        taxPrice: null,
        taxRate: null,
        productCategory: null,
        supplierName: null,
        transactionType: null,
        saleReturnType: null,
        remark: null,
        createrSn: null,
        createTime: null,
        moderSn: null,
        modTime: null,
        tstm: 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 = "添加kmall销售数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSalesdetail(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改kmall销售数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSalesdetail(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSalesdetail(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除kmall销售数据编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delSalesdetail(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有kmall销售数据数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportSalesdetail(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
