porder.vue 11.9 KB
<!-- 评价管理-->
<template>
    <div class="purchase-wrap">
        <div class="container">
            <GLCombiForm ref="showSearch" :rowNumber="1" :formObj="searchForm" :formData="showFormData"
                @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
            <div class="table-header">
                <h2>订单列表</h2>
                <el-button size="small" @click="exportExcel">导出</el-button>
            </div>

            <!-- 表格区域 开始 -->
            <GLTable ref="orderRef" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm"
                :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn"
                @setTableFinishFun="setTableFinishFun">

                <template slot="status" slot-scope="scope">
                    <div>
                        <span v-if="scope.scope.status" :class="Spot[scope.scope.status - 1]"></span>
                        <span> {{ scope.scope.status | orderStatus }}</span>

                    </div>
                </template>
                <div class="table-btns" slot="auth-button" slot-scope="scope">
                    <el-button type="text" v-if="scope.scope.status == 1" @click="handleCancel(scope.scope)">取消</el-button>
                </div>
            </GLTable>
            <!-- 表格区域 end -->
        </div>
    </div>
</template>
  
<script>
import * as dayjs from 'dayjs'
import url from '@/assets/empty.png'
import { statusList } from '@/common/constant.js'
export default {
    name: 'order',
    data() {
        return {
            size: 'small',
            url: url,
            Spot: ['yellowSpot', 'greenSpot',  'ashSpot','redSpot'],
            searchForm: {
                status: '',
                upgradeGoodsName: '',
                type: '',
                merchantName: '',
                sortType: 1,
                orderTimeStr: [],
                placeOrderTimeStr: [],
            },
            tableSearchForm: {},
            paramsObj: {},
            // 查看门店
            detailVisible: false,
            showFormData: [
                {
                    label: '下单时间',
                    name: 'placeOrderTimeStr',
                    type: 'datePicker',
                    isClear: true,
                    pickerOptions: 'beforeRangePickerOptions'
                },
                {
                    label: '下单商户',
                    name: 'merchantName',
                    type: 'input',
                    isClear: true,
                    maxlength: 50
                },

                {
                    label: '商品名称',
                    name: 'upgradeGoodsName',
                    type: 'input',
                    isClear: true,
                    maxlength: 20
                },
                {
                    label: '商品编号',
                    name: 'type',
                    type: 'input',
                    isClear: true,
                    maxlength: 50
                },
                {
                    label: '状态',
                    name: 'status',
                    type: 'select',
                    optionList: [],
                    optionId: 'id',
                    optionLabel: 'label',
                    optionsName: 'statusList'
                },
            ],
            // 表格
            getListApi: this.$apis.purchase.getPurchaseOrderList,
            tableParams: {
                listName: 'list',
                tableOption: false,
                tableColumns: [
                    {
                        label: '下单时间',
                        prop: 'orderTime',
                        formatter: cellValue => {
                            return dayjs(cellValue.orderTime).format('YYYY-MM-DD HH:mm:ss')
                        },
                        width: 180
                    },
                    {
                        label: '下单商户',
                        prop: 'merchantName',
                        line: 1,
                        width: 150
                    },
                    {
                        label: '收货人',
                        prop: 'contactName'
                    },
                    {
                        label: '收货人电话',
                        prop: 'contactPhone',
                        width: 120
                    },
                    {
                        label: '收货地址',
                        prop: 'contactAddress',
                        line: 1,
                        width: 150
                    },
                    {
                        label: '商品名称',
                        prop: 'upgradeGoodsName',
                        line: 1,
                        width: 120
                    },
                    {
                        label: '商品编码',
                        prop: 'type',
                        line: 1,
                        width: 100
                    },
                    {
                        label: '采购数量',
                        prop: 'goodsNumber'
                    },
                    {
                        label: '采购价/元',
                        prop: 'shopPurchasePrice',
                        formatter: cellValue => {
                            return '¥' + cellValue.shopPurchasePrice
                        }
                    },
                    {
                        label: '采购总价/元',
                        prop: 'totalPrice',
                        formatter: cellValue => {
                            return '¥' + cellValue.totalPrice
                        },
                        width: 120
                    },
                    {
                        label: '状态',
                        prop: 'status',
                        addHtml: 'status'
                    },

                    {
                        label: '说明',
                        prop: 'rejectCause',
                    },
                    {
                        label: '操作',
                        width: '80px',
                        addHtml: 'auth-button'
                    }
                ]
            },
            pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' },
            // 基本数据
            baseData: {
                statusList: statusList
            }
        }
    },

    mounted() {
        this.getOptionsList('showFormData')
    },

    methods: {
        getParams() {
            var params = JSON.parse(JSON.stringify(this.searchForm))
            if (this.searchForm.placeOrderTimeStr.length) {
                params.orderTimeStr[0] = new Date(this.searchForm.placeOrderTimeStr[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
                params.orderTimeStr[1] = new Date(this.searchForm.placeOrderTimeStr[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
            }
            params.merchantId = this.$globalState.session.merchantId
            delete params.placeOrderTimeStr
            return params
        },
        beforeSearchFn() {
            return new Promise(resolve => {
                this.tableSearchForm = this.getParams()
                delete this.tableSearchForm.placeOrderTimeStr
                resolve()
            })
        },
        secondConfirm(title, txt, apiModule, apiName, apiParams, fn) {
            this.$confirm(txt, title, {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                callback: action => {
                    if (action == 'confirm') {
                        this.$apis[apiModule][apiName](apiParams).then(res => {
                            this.$message({
                                message: res.code == '0' ? '操作成功' : res.message,
                                type: res.code == '0' ? 'success' : 'error'
                            })
                            if (res.code == '0') {
                                fn && fn()
                                this.handleSearch()
                            }
                        })
                    }
                }
            })
        },
        //取消
        handleCancel(row) {
            this.secondConfirm('取消', '订单取消后即自动作废该订单,且无法撤回。是否确定取消?', 'purchase', 'purchaseOrderCancelOrCheck', { id: row.id,updatedBy:this.$globalState.session.accountName })
        },

        getOptionsList(formName, hasAll = true, refreshSigle) {
            if (refreshSigle) {
                var item = this[formName].find(k => k.name == refreshSigle)
                var index = this[formName].findIndex(k => k.name == refreshSigle)
                this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
                if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
                    const temp = {}
                    temp[this[formName][index].optionId] = ''
                    temp[this[formName][index].optionLabel] = '全部'
                    this[formName][index].optionList.unshift(temp)
                }
            } else {
                this[formName].forEach((item, index) => {
                    if (item.type === 'select' && this.baseData[item.optionsName] && this.baseData[item.optionsName].length) {
                        this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
                        if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
                            const temp = {}
                            temp[this[formName][index].optionId] = ''
                            temp[this[formName][index].optionLabel] = '全部'
                            this[formName][index].optionList.unshift(temp)
                        }
                    }
                })
            }
        },
        setTableFinishFun() {
            //接收到的数据为空
            this.$refs.orderRef.data.length ? (this.$refs.orderRef.tableHeightValues = '') : this.$refs.orderRef.setTableHeightFun()
        },
        exportExcel() {
            var params = this.getParams()
            this.$apis.purchase.exportExcel(params).then(res => {
                window.location.href = res
            })
        },
        handleSearch() {
            this.$refs.orderRef.refreshTable()
        },

        handleReset() {
            this.searchForm = {
                status: '',
                upgradeGoodsName: '',
                type: '',
                merchantName: '',
                sortType: 1,
                orderTimeStr: [],
                placeOrderTimeStr: [],
            }
            this.handleSearch()
        }
    }
}
</script>
  
<style scoped lang="scss">
@mixin dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
}

$color-yellow: #fdb757;
$color-green: #2cca74;
$color-gray: #999;
$color-red: #EB4E4E;

.purchase-wrap {
    background-color: #fff;
    padding: 20px;

    .table-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 10px;
        margin-top: 20px;

        h2 {
            font-weight: 600;
            font-size: 16px;
            color: #333;
        }
    }

    .greenSpot {
        @include dot;
        background: $color-green;
    }

    .yellowSpot {
        @include dot;
        background: $color-yellow;
    }

    .ashSpot {
        @include dot;
        background: $color-gray;
    }

    .redSpot {
        @include dot;
        background: $color-red;
    }

    .table-btns /deep/.el-button--text {
        min-width: 0 !important;
        padding: 0;
    }
}
</style>