<template>
  <el-dialog
    v-dialogDrag
    title="查看销售明细"
    :visible.sync="open"
    width="1200px"
    append-to-body
    @open="dialogOpen"
  >
    <!-- 操作工具栏 -->

    <!-- 列表 -->
    <el-table
      v-loading="loading"
      :data="list"
      border
      size="mini"
    >
      <!-- <el-table-column label="明细排序" align="center" prop="detailNumber" /> -->
      <el-table-column label="物料编号" align="center" prop="materialNo" />
      <el-table-column
        label="物料名称"
        align="center"
        prop="materialName"
        width="150"
        show-overflow-tooltip
      />
      <el-table-column label="物料数量" align="center" prop="materialQty" />
      <el-table-column
        label="物料规格型号"
        align="center"
        prop="materialModels"
        width="120"
      />
      <el-table-column
        label="物料单位名称"
        align="center"
        prop="unitName"
        width="100"
      />
      <el-table-column
        label="交货日期"
        align="center"
        prop="deliveryTime"
        width="160"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deliveryTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="已出货数量"
        align="center"
        prop="deliveredQty"
        width="120"
      />
      <el-table-column
        label="应出货数量"
        align="center"
        prop="shouldDeliveredQty"
        width="120"
      />
      <!-- <el-table-column
        label="发货状态"
        align="center"
        prop="status"
        width="120"
      >
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.WMS_SALE_ORDER_DELIVER_STATUS" :value="scope.row.status" />
        </template>
      </el-table-column> -->
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="税率" align="center" prop="taxRate" />
      <el-table-column label="折扣率%" align="center" prop="discountAte" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="160"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 对话框(添加 / 修改) -->
  </el-dialog>
</template>

<script>
import { getSaleOrderDetailPage, exportSaleOrderDetailExcel } from '@/api/wms/orders/sale'

export default {
  name: 'SaleOrderDetail',
  components: {

  },
  data() {
    return {

      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 销售订单明细列表
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        detailErpId: null,
        saleOrderId: null,
        erpSaleOrderId: null,
        erpSaleOrderIdNo: null,
        detailNumber: null,
        materialNo: null,
        materialName: null,
        materialQty: null,
        materialModels: null,
        unitName: null,
        deliveryTime: [],
        price: null,
        taxPrice: null,
        deliveredQty: null,
        shouldDeliveredQty: null,
        status: null,
        remark: null,
        money: null,
        allAmount: null,
        taxRate: null,
        discountAte: null,
        createTime: [],
        erpMark: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      // 执行查询
      getSaleOrderDetailPage(this.queryParams).then(response => {
        this.list = response.data.list
        this.total = response.data.total
      }).finally(() => {
        this.loading = false
      })
    },
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        detailErpId: undefined,
        saleOrderId: undefined,
        erpSaleOrderId: undefined,
        erpSaleOrderIdNo: undefined,
        detailNumber: undefined,
        materialNo: undefined,
        materialName: undefined,
        materialQty: undefined,
        materialModels: undefined,
        unitName: undefined,
        deliveryTime: undefined,
        price: undefined,
        taxPrice: undefined,
        deliveredQty: undefined,
        shouldDeliveredQty: undefined,
        status: undefined,
        remark: undefined,
        money: undefined,
        allAmount: undefined,
        taxRate: undefined,
        discountAte: undefined,
        erpMark: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      const params = { ...this.queryParams }
      params.pageNo = undefined
      params.pageSize = undefined
      this.$modal.confirm('是否确认导出所有销售订单明细数据项?').then(() => {
        this.exportLoading = true
        return exportSaleOrderDetailExcel(params)
      }).then(response => {
        this.$download.excel(response, '销售订单明细.xls')
        this.exportLoading = false
      }).catch(() => {})
    },
    dialogOpen() {
      this.getList()
    }
  }
}
</script>

