| @ -0,0 +1,465 @@ | |||
| <template> | |||
| <a-card :bordered="false"> | |||
| <!-- 查询区域 --> | |||
| <div class="table-page-search-wrapper"> | |||
| <a-form layout="inline" @keyup.enter.native="searchQuery"> | |||
| <a-row :gutter="24"> | |||
| <a-col :xl="6" :lg="7" :md="8" :sm="24"> | |||
| <a-form-item label="订单状态"> | |||
| <j-dict-select-tag placeholder="请选择订单状态" v-model="queryParam.status" dictCode="order_state"/> | |||
| </a-form-item> | |||
| </a-col> | |||
| <a-col :xl="6" :lg="7" :md="8" :sm="24"> | |||
| <a-form-item label="下单用户"> | |||
| <j-search-select-tag placeholder="请选择下单用户" v-model="queryParam.userId" dict="han_hai_member,nick_name,id"/> | |||
| </a-form-item> | |||
| </a-col> | |||
| <a-col :xl="6" :lg="7" :md="8" :sm="24"> | |||
| <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons"> | |||
| <a-button type="primary" @click="searchQuery" icon="search">查询</a-button> | |||
| <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button> | |||
| <a @click="handleToggleSearch" style="margin-left: 8px"> | |||
| {{ toggleSearchStatus ? '收起' : '展开' }} | |||
| <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/> | |||
| </a> | |||
| </span> | |||
| </a-col> | |||
| </a-row> | |||
| </a-form> | |||
| </div> | |||
| <!-- 查询区域-END --> | |||
| <!-- 操作按钮区域 --> | |||
| <div class="table-operator"> | |||
| <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> | |||
| <a-button type="primary" icon="download" @click="handleExportXls('订单信息表')">导出</a-button> | |||
| <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel"> | |||
| <a-button type="primary" icon="import">导入</a-button> | |||
| </a-upload> | |||
| <!-- 高级查询区域 --> | |||
| <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query> | |||
| <a-dropdown v-if="selectedRowKeys.length > 0"> | |||
| <a-menu slot="overlay"> | |||
| <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item> | |||
| </a-menu> | |||
| <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button> | |||
| </a-dropdown> | |||
| </div> | |||
| <!-- table区域-begin --> | |||
| <div> | |||
| <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;"> | |||
| <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项 | |||
| <a style="margin-left: 24px" @click="onClearSelected">清空</a> | |||
| </div> | |||
| <a-table | |||
| ref="table" | |||
| size="middle" | |||
| rowKey="id" | |||
| class="j-table-force-nowrap" | |||
| :scroll="{x:true}" | |||
| :columns="columns" | |||
| :dataSource="dataSource" | |||
| :pagination="ipagination" | |||
| :loading="loading" | |||
| :expandedRowKeys="expandedRowKeys" | |||
| @change="handleTableChange" | |||
| @expand="handleExpand" | |||
| v-bind="tableProps"> | |||
| <template slot="imgSlot" slot-scope="text,record"> | |||
| <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span> | |||
| <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/> | |||
| </template> | |||
| <template slot="fileSlot" slot-scope="text"> | |||
| <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span> | |||
| <a-button | |||
| v-else | |||
| :ghost="true" | |||
| type="primary" | |||
| icon="download" | |||
| size="small" | |||
| @click="downloadFile(text)"> | |||
| 下载 | |||
| </a-button> | |||
| </template> | |||
| <span slot="action" slot-scope="text, record"> | |||
| <a @click="handleEdit(record)" v-if="record.pid == '0' | |||
| && record.status == 1">发货</a> | |||
| <!-- <a-divider type="vertical" />--> | |||
| <!-- <a-dropdown>--> | |||
| <!-- <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>--> | |||
| <!-- <a-menu slot="overlay">--> | |||
| <!-- <a-menu-item>--> | |||
| <!-- <a @click="handleAddChild(record)">添加下级</a>--> | |||
| <!-- </a-menu-item>--> | |||
| <!-- <a-menu-item>--> | |||
| <!-- <a-popconfirm title="确定删除吗?" @confirm="() => handleDeleteNode(record.id)" placement="topLeft">--> | |||
| <!-- <a>删除</a>--> | |||
| <!-- </a-popconfirm>--> | |||
| <!-- </a-menu-item>--> | |||
| <!-- </a-menu>--> | |||
| <!-- </a-dropdown>--> | |||
| </span> | |||
| </a-table> | |||
| </div> | |||
| <commonOrder-modal ref="modalForm" @ok="modalFormOk"></commonOrder-modal> | |||
| </a-card> | |||
| </template> | |||
| <script> | |||
| import { getAction, deleteAction } from '@/api/manage' | |||
| import { JeecgListMixin } from '@/mixins/JeecgListMixin' | |||
| import CommonOrderModal from './modules/CommonOrderModal' | |||
| import {filterMultiDictText} from '@/components/dict/JDictSelectUtil' | |||
| import { filterObj } from '@/utils/util'; | |||
| export default { | |||
| name: "CommonOrderList", | |||
| mixins:[JeecgListMixin], | |||
| components: { | |||
| CommonOrderModal | |||
| }, | |||
| data () { | |||
| return { | |||
| description: '订单信息表管理页面', | |||
| // 表头 | |||
| columns: [ | |||
| { | |||
| title:'订单标题', | |||
| align:"left", | |||
| dataIndex: 'title' | |||
| }, | |||
| { | |||
| title:'创建日期', | |||
| align:"left", | |||
| dataIndex: 'createTime' | |||
| }, | |||
| { | |||
| title:'订单状态', | |||
| align:"left", | |||
| dataIndex: 'status_dictText' | |||
| }, | |||
| { | |||
| title:'支付方式', | |||
| align:"left", | |||
| dataIndex: 'payType_dictText' | |||
| }, | |||
| { | |||
| title:'下单用户', | |||
| align:"left", | |||
| dataIndex: 'userId_dictText' | |||
| }, | |||
| { | |||
| title:'订单图片', | |||
| align:"left", | |||
| dataIndex: 'image', | |||
| scopedSlots: {customRender: 'imgSlot'} | |||
| }, | |||
| { | |||
| title:'客户姓名', | |||
| align:"left", | |||
| dataIndex: 'name' | |||
| }, | |||
| { | |||
| title:'联系电话', | |||
| align:"left", | |||
| dataIndex: 'phone' | |||
| }, | |||
| { | |||
| title:'订单价格', | |||
| align:"left", | |||
| dataIndex: 'price' | |||
| }, | |||
| { | |||
| title:'配送地址', | |||
| align:"left", | |||
| dataIndex: 'address' | |||
| }, | |||
| { | |||
| title:'地址明细', | |||
| align:"left", | |||
| dataIndex: 'addressDetail' | |||
| }, | |||
| { | |||
| title:'直推佣金', | |||
| align:"left", | |||
| dataIndex: 'oneMoney' | |||
| }, | |||
| { | |||
| title:'间推佣金', | |||
| align:"left", | |||
| dataIndex: 'twoMoney' | |||
| }, | |||
| { | |||
| title:'数量', | |||
| align:"left", | |||
| dataIndex: 'num' | |||
| }, | |||
| { | |||
| title:'材质', | |||
| align:"left", | |||
| dataIndex: 'material' | |||
| }, | |||
| { | |||
| title:'标识', | |||
| align:"left", | |||
| dataIndex: 'shopId' | |||
| }, | |||
| { | |||
| title:'送货图', | |||
| align:"left", | |||
| dataIndex: 'deliveryPicture', | |||
| scopedSlots: {customRender: 'imgSlot'} | |||
| }, | |||
| { | |||
| title: '操作', | |||
| dataIndex: 'action', | |||
| align:"center", | |||
| fixed:"right", | |||
| width:147, | |||
| scopedSlots: { customRender: 'action' }, | |||
| } | |||
| ], | |||
| url: { | |||
| list: "/CommonOrder/commonOrder/rootList", | |||
| childList: "/CommonOrder/commonOrder/childList", | |||
| getChildListBatch: "/CommonOrder/commonOrder/getChildListBatch", | |||
| delete: "/CommonOrder/commonOrder/delete", | |||
| deleteBatch: "/CommonOrder/commonOrder/deleteBatch", | |||
| exportXlsUrl: "/CommonOrder/commonOrder/exportXls", | |||
| importExcelUrl: "CommonOrder/commonOrder/importExcel", | |||
| }, | |||
| expandedRowKeys:[], | |||
| hasChildrenField:"hasChild", | |||
| pidField:"pid", | |||
| dictOptions: {}, | |||
| loadParent: false, | |||
| superFieldList:[], | |||
| } | |||
| }, | |||
| created() { | |||
| this.getSuperFieldList(); | |||
| }, | |||
| computed: { | |||
| importExcelUrl(){ | |||
| return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`; | |||
| }, | |||
| tableProps() { | |||
| let _this = this | |||
| return { | |||
| // 列表项是否可选择 | |||
| rowSelection: { | |||
| selectedRowKeys: _this.selectedRowKeys, | |||
| onChange: (selectedRowKeys) => _this.selectedRowKeys = selectedRowKeys | |||
| } | |||
| } | |||
| } | |||
| }, | |||
| methods: { | |||
| loadData(arg){ | |||
| if(arg==1){ | |||
| this.ipagination.current=1 | |||
| } | |||
| this.loading = true | |||
| let params = this.getQueryParams() | |||
| params.hasQuery = 'true' | |||
| getAction(this.url.list,params).then(res=>{ | |||
| if(res.success){ | |||
| let result = res.result | |||
| if(Number(result.total)>0){ | |||
| this.ipagination.total = Number(result.total) | |||
| this.dataSource = this.getDataByResult(res.result.records) | |||
| return this.loadDataByExpandedRows(this.dataSource) | |||
| }else{ | |||
| this.ipagination.total=0 | |||
| this.dataSource=[] | |||
| } | |||
| }else{ | |||
| this.$message.warning(res.message) | |||
| } | |||
| }).finally(()=>{ | |||
| this.loading = false | |||
| }) | |||
| }, | |||
| // 根据已展开的行查询数据(用于保存后刷新时异步加载子级的数据) | |||
| loadDataByExpandedRows(dataList) { | |||
| if (this.expandedRowKeys.length > 0) { | |||
| return getAction(this.url.getChildListBatch,{ parentIds: this.expandedRowKeys.join(',') }).then(res=>{ | |||
| if (res.success && res.result.records.length>0) { | |||
| //已展开的数据批量子节点 | |||
| let records = res.result.records | |||
| const listMap = new Map(); | |||
| for (let item of records) { | |||
| let pid = item[this.pidField]; | |||
| if (this.expandedRowKeys.join(',').includes(pid)) { | |||
| let mapList = listMap.get(pid); | |||
| if (mapList == null) { | |||
| mapList = []; | |||
| } | |||
| mapList.push(item); | |||
| listMap.set(pid, mapList); | |||
| } | |||
| } | |||
| let childrenMap = listMap; | |||
| let fn = (list) => { | |||
| if(list) { | |||
| list.forEach(data => { | |||
| if (this.expandedRowKeys.includes(data.id)) { | |||
| data.children = this.getDataByResult(childrenMap.get(data.id)) | |||
| fn(data.children) | |||
| } | |||
| }) | |||
| } | |||
| } | |||
| fn(dataList) | |||
| } | |||
| }) | |||
| } else { | |||
| return Promise.resolve() | |||
| } | |||
| }, | |||
| getQueryParams(arg) { | |||
| //获取查询条件 | |||
| let sqp = {} | |||
| let param = {} | |||
| if(this.superQueryParams){ | |||
| sqp['superQueryParams']=encodeURI(this.superQueryParams) | |||
| sqp['superQueryMatchType'] = this.superQueryMatchType | |||
| } | |||
| if(arg){ | |||
| param = Object.assign(sqp, this.isorter ,this.filters); | |||
| }else{ | |||
| param = Object.assign(sqp, this.queryParam, this.isorter ,this.filters); | |||
| } | |||
| if(JSON.stringify(this.queryParam) === "{}" || arg){ | |||
| param.hasQuery = 'false' | |||
| }else{ | |||
| param.hasQuery = 'true' | |||
| } | |||
| param.field = this.getQueryField(); | |||
| param.pageNo = this.ipagination.current; | |||
| param.pageSize = this.ipagination.pageSize; | |||
| return filterObj(param); | |||
| }, | |||
| searchReset() { | |||
| //重置 | |||
| this.expandedRowKeys = [] | |||
| this.queryParam = {} | |||
| this.loadData(1); | |||
| }, | |||
| getDataByResult(result){ | |||
| if(result){ | |||
| return result.map(item=>{ | |||
| //判断是否标记了带有子节点 | |||
| if(item[this.hasChildrenField]=='1'){ | |||
| let loadChild = { id: item.id+'_loadChild', name: 'loading...', isLoading: true } | |||
| item.children = [loadChild] | |||
| } | |||
| return item | |||
| }) | |||
| } | |||
| }, | |||
| handleExpand(expanded, record){ | |||
| // 判断是否是展开状态 | |||
| if (expanded) { | |||
| this.expandedRowKeys.push(record.id) | |||
| if (record.children.length>0 && record.children[0].isLoading === true) { | |||
| let params = this.getQueryParams(1);//查询条件 | |||
| params[this.pidField] = record.id | |||
| params.hasQuery = 'false' | |||
| params.superQueryParams="" | |||
| getAction(this.url.childList,params).then((res)=>{ | |||
| if(res.success){ | |||
| if(res.result.records){ | |||
| record.children = this.getDataByResult(res.result.records) | |||
| this.dataSource = [...this.dataSource] | |||
| }else{ | |||
| record.children='' | |||
| record.hasChildrenField='0' | |||
| } | |||
| }else{ | |||
| this.$message.warning(res.message) | |||
| } | |||
| }) | |||
| } | |||
| }else{ | |||
| let keyIndex = this.expandedRowKeys.indexOf(record.id) | |||
| if(keyIndex>=0){ | |||
| this.expandedRowKeys.splice(keyIndex, 1); | |||
| } | |||
| } | |||
| }, | |||
| handleAddChild(record){ | |||
| this.loadParent = true | |||
| let obj = {} | |||
| obj[this.pidField] = record['id'] | |||
| this.$refs.modalForm.add(obj); | |||
| }, | |||
| handleDeleteNode(id) { | |||
| if(!this.url.delete){ | |||
| this.$message.error("请设置url.delete属性!") | |||
| return | |||
| } | |||
| var that = this; | |||
| deleteAction(that.url.delete, {id: id}).then((res) => { | |||
| if (res.success) { | |||
| that.loadData(1) | |||
| } else { | |||
| that.$message.warning(res.message); | |||
| } | |||
| }); | |||
| }, | |||
| batchDel(){ | |||
| if(this.selectedRowKeys.length<=0){ | |||
| this.$message.warning('请选择一条记录!'); | |||
| return false; | |||
| }else{ | |||
| let ids = ""; | |||
| let that = this; | |||
| that.selectedRowKeys.forEach(function(val) { | |||
| ids+=val+","; | |||
| }); | |||
| that.$confirm({ | |||
| title:"确认删除", | |||
| content:"是否删除选中数据?", | |||
| onOk: function(){ | |||
| that.handleDeleteNode(ids) | |||
| that.onClearSelected(); | |||
| } | |||
| }); | |||
| } | |||
| }, | |||
| getSuperFieldList(){ | |||
| let fieldList=[]; | |||
| fieldList.push({type:'datetime',value:'createTime',text:'创建日期'}) | |||
| fieldList.push({type:'string',value:'status',text:'订单状态',dictCode:'order_state'}) | |||
| fieldList.push({type:'sel_search',value:'userId',text:'下单用户',dictTable:"han_hai_member", dictText:'nick_name', dictCode:'id'}) | |||
| fieldList.push({type:'Text',value:'image',text:'订单图片',dictCode:''}) | |||
| fieldList.push({type:'string',value:'title',text:'订单标题',dictCode:''}) | |||
| fieldList.push({type:'string',value:'name',text:'客户姓名',dictCode:''}) | |||
| fieldList.push({type:'string',value:'phone',text:'联系电话',dictCode:''}) | |||
| fieldList.push({type:'BigDecimal',value:'price',text:'订单价格',dictCode:''}) | |||
| fieldList.push({type:'Text',value:'address',text:'配送地址',dictCode:''}) | |||
| fieldList.push({type:'Text',value:'addressDetail',text:'地址明细',dictCode:''}) | |||
| fieldList.push({type:'BigDecimal',value:'oneMoney',text:'直推佣金',dictCode:''}) | |||
| fieldList.push({type:'BigDecimal',value:'twoMoney',text:'间推佣金',dictCode:''}) | |||
| fieldList.push({type:'int',value:'num',text:'数量',dictCode:''}) | |||
| fieldList.push({type:'string',value:'material',text:'材质',dictCode:''}) | |||
| fieldList.push({type:'string',value:'pid',text:'父级节点',dictCode:''}) | |||
| fieldList.push({type:'string',value:'shopId',text:'标识',dictCode:''}) | |||
| fieldList.push({type:'string',value:'deliveryPicture',text:'送货图',dictCode:''}) | |||
| this.superFieldList = fieldList | |||
| } | |||
| } | |||
| } | |||
| </script> | |||
| <style scoped> | |||
| @import '~@assets/less/common.less'; | |||
| </style> | |||
| @ -0,0 +1,196 @@ | |||
| <template> | |||
| <j-modal | |||
| :title="title" | |||
| :width="width" | |||
| :visible="visible" | |||
| :confirmLoading="confirmLoading" | |||
| switchFullscreen | |||
| @ok="handleOk" | |||
| @cancel="handleCancel" | |||
| cancelText="关闭"> | |||
| <a-spin :spinning="confirmLoading"> | |||
| <a-form-model ref="form" :model="model" :rules="validatorRules"> | |||
| <a-form-model-item label="订单状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status"> | |||
| <j-dict-select-tag type="list" v-model="model.status" disabled dictCode="order_state" placeholder="请选择订单状态" /> | |||
| </a-form-model-item> | |||
| <a-form-model-item label="下单用户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId"> | |||
| <j-search-select-tag v-model="model.userId" dict="han_hai_member,nick_name,id" disabled/> | |||
| </a-form-model-item> | |||
| <!-- <a-form-model-item label="订单图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="image">--> | |||
| <!-- <j-image-upload isMultiple v-model="model.image" disabled></j-image-upload>--> | |||
| <!-- </a-form-model-item>--> | |||
| <a-form-model-item label="订单标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="title"> | |||
| <a-input v-model="model.title" placeholder="请输入订单标题" disabled></a-input> | |||
| </a-form-model-item> | |||
| <a-form-model-item label="客户姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name"> | |||
| <a-input v-model="model.name" placeholder="请输入客户姓名" disabled></a-input> | |||
| </a-form-model-item> | |||
| <a-form-model-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phone"> | |||
| <a-input v-model="model.phone" placeholder="请输入联系电话" disabled></a-input> | |||
| </a-form-model-item> | |||
| <a-form-model-item label="订单价格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="price"> | |||
| <a-input-number v-model="model.price" placeholder="请输入订单价格" style="width: 100%" disabled/> | |||
| </a-form-model-item> | |||
| <a-form-model-item label="配送地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="address"> | |||
| <a-input v-model="model.address" placeholder="请输入配送地址" disabled></a-input> | |||
| </a-form-model-item> | |||
| <a-form-model-item label="地址明细" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="addressDetail"> | |||
| <a-input v-model="model.addressDetail" placeholder="请输入地址明细" disabled ></a-input> | |||
| </a-form-model-item> | |||
| <a-form-model-item label="直推佣金" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="oneMoney"> | |||
| <a-input-number v-model="model.oneMoney" placeholder="请输入直推佣金" style="width: 100%" disabled/> | |||
| </a-form-model-item> | |||
| <a-form-model-item label="间推佣金" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="twoMoney"> | |||
| <a-input-number v-model="model.twoMoney" placeholder="请输入间推佣金" style="width: 100%" disabled/> | |||
| </a-form-model-item> | |||
| <a-form-model-item label="数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="num"> | |||
| <a-input-number v-model="model.num" placeholder="请输入数量" style="width: 100%" disabled/> | |||
| </a-form-model-item> | |||
| <a-form-model-item label="材质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="material"> | |||
| <a-input v-model="model.material" placeholder="请输入材质" disabled></a-input> | |||
| </a-form-model-item> | |||
| <a-form-model-item label="父级节点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pid"> | |||
| <j-tree-select | |||
| ref="treeSelect" | |||
| placeholder="请选择父级节点" | |||
| v-model="model.pid" | |||
| dict="common_order,title,id" | |||
| pidField="pid" | |||
| pidValue="0" | |||
| hasChildField="has_child" | |||
| disabled | |||
| > | |||
| </j-tree-select> | |||
| </a-form-model-item> | |||
| <a-form-model-item label="标识" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shopId"> | |||
| <a-input v-model="model.shopId" placeholder="请输入标识" disabled></a-input> | |||
| </a-form-model-item> | |||
| <a-form-model-item label="送货图" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deliveryPicture"> | |||
| <j-image-upload isMultiple v-model="model.deliveryPicture" ></j-image-upload> | |||
| </a-form-model-item> | |||
| </a-form-model> | |||
| </a-spin> | |||
| </j-modal> | |||
| </template> | |||
| <script> | |||
| import { httpAction } from '@/api/manage' | |||
| import { validateDuplicateValue } from '@/utils/util' | |||
| export default { | |||
| name: "CommonOrderModal", | |||
| components: { | |||
| }, | |||
| data () { | |||
| return { | |||
| title:"操作", | |||
| width:800, | |||
| visible: false, | |||
| model:{ | |||
| }, | |||
| labelCol: { | |||
| xs: { span: 24 }, | |||
| sm: { span: 5 }, | |||
| }, | |||
| wrapperCol: { | |||
| xs: { span: 24 }, | |||
| sm: { span: 16 }, | |||
| }, | |||
| confirmLoading: false, | |||
| validatorRules: { | |||
| }, | |||
| url: { | |||
| add: "/CommonOrder/commonOrder/add", | |||
| edit: "/CommonOrder/commonOrder/edit", | |||
| }, | |||
| expandedRowKeys:[], | |||
| pidField:"pid" | |||
| } | |||
| }, | |||
| created () { | |||
| //备份model原始值 | |||
| this.modelDefault = JSON.parse(JSON.stringify(this.model)); | |||
| }, | |||
| methods: { | |||
| add (obj) { | |||
| this.modelDefault.pid='' | |||
| this.edit(Object.assign(this.modelDefault , obj)); | |||
| }, | |||
| edit (record) { | |||
| this.model = Object.assign({}, record); | |||
| this.visible = true; | |||
| }, | |||
| close () { | |||
| this.$emit('close'); | |||
| this.visible = false; | |||
| this.$refs.form.clearValidate() | |||
| }, | |||
| handleOk () { | |||
| const that = this; | |||
| // 触发表单验证 | |||
| this.$refs.form.validate(valid => { | |||
| if (valid) { | |||
| that.confirmLoading = true; | |||
| let httpurl = ''; | |||
| let method = ''; | |||
| if(!this.model.id){ | |||
| httpurl+=this.url.add; | |||
| method = 'post'; | |||
| }else{ | |||
| httpurl+=this.url.edit; | |||
| method = 'put'; | |||
| } | |||
| if(this.model.id && this.model.id === this.model[this.pidField]){ | |||
| that.$message.warning("父级节点不能选择自己"); | |||
| that.confirmLoading = false; | |||
| return; | |||
| } | |||
| httpAction(httpurl,this.model,method).then((res)=>{ | |||
| if(res.success){ | |||
| that.$message.success(res.message); | |||
| this.$emit('ok'); | |||
| }else{ | |||
| that.$message.warning(res.message); | |||
| } | |||
| }).finally(() => { | |||
| that.confirmLoading = false; | |||
| that.close(); | |||
| }) | |||
| }else{ | |||
| return false | |||
| } | |||
| }) | |||
| }, | |||
| handleCancel () { | |||
| this.close() | |||
| }, | |||
| submitSuccess(formData,flag){ | |||
| if(!formData.id){ | |||
| let treeData = this.$refs.treeSelect.getCurrTreeData() | |||
| this.expandedRowKeys=[] | |||
| this.getExpandKeysByPid(formData[this.pidField],treeData,treeData) | |||
| this.$emit('ok',formData,this.expandedRowKeys.reverse()); | |||
| }else{ | |||
| this.$emit('ok',formData,flag); | |||
| } | |||
| }, | |||
| getExpandKeysByPid(pid,arr,all){ | |||
| if(pid && arr && arr.length>0){ | |||
| for(let i=0;i<arr.length;i++){ | |||
| if(arr[i].key==pid){ | |||
| this.expandedRowKeys.push(arr[i].key) | |||
| this.getExpandKeysByPid(arr[i]['parentId'],all,all) | |||
| }else{ | |||
| this.getExpandKeysByPid(pid,arr[i].children,all) | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| </script> | |||
| @ -0,0 +1,84 @@ | |||
| package org.jeecg.api.wxUtils.order; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.TypeReference; | |||
| import org.jeecg.api.wxUtils.HttpClientUtil; | |||
| import org.springframework.beans.factory.annotation.Value; | |||
| import org.springframework.stereotype.Component; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| /** | |||
| * 微信公众平台订单物流配送工具 | |||
| */ | |||
| @Component | |||
| public class WxOrderLogisticsUtil { | |||
| @Value("${wechat.mpAppId}") | |||
| private String appid; | |||
| @Value("${wechat.mpAppSecret}") | |||
| private String secret;// | |||
| @Value("${pay.mchId}") | |||
| private String mchId;// | |||
| private static String shipmentUrl = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token="; | |||
| /** | |||
| * 订单发货 | |||
| * @param out_trade_no 商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一 | |||
| * @param out_trade_no 商品信息,例如:微信红包抱枕*1个,限120个字以内 | |||
| * @param openid 用户标识,用户在小程序appid下的唯一标识 | |||
| */ | |||
| // logistics_type 物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提 | |||
| public void doShipmentOneself(String out_trade_no, String item_desc, String openid){ | |||
| HashMap<String, Object> map = new HashMap<>(); | |||
| HashMap<String, Object> payer = new HashMap<>(); | |||
| payer.put("openid", openid); | |||
| HashMap<String, Object> order_key = new HashMap<>(); | |||
| order_key.put("mchid", mchId); | |||
| order_key.put("out_trade_no", out_trade_no); | |||
| order_key.put("order_number_type", 1); | |||
| ArrayList<HashMap<String, Object>> shipping_list = new ArrayList<>(); | |||
| HashMap<String, Object> shipping_item = new HashMap<>(); | |||
| shipping_item.put("item_desc", item_desc); | |||
| shipping_list.add(shipping_item); | |||
| map.put("payer", payer); | |||
| map.put("order_key", order_key); | |||
| map.put("logistics_type", 2);//用户自提 | |||
| map.put("delivery_mode", 1);//统一发货 | |||
| map.put("shipping_list", shipping_list);//商品列表 | |||
| map.put("upload_time", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(new Date()));//上传时间,RFC 3339格式 | |||
| String s = HttpClientUtil.doPostJson(shipmentUrl + getAccessToken(), JSON.toJSONString(map)); | |||
| System.out.println("============================================="); | |||
| System.out.println(s); | |||
| System.out.println("============================================="); | |||
| } | |||
| /** | |||
| * 获取令牌 | |||
| * | |||
| * @return | |||
| */ | |||
| private String getAccessToken() { | |||
| String requestUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret; | |||
| String doGet2 = HttpClientUtil.doGet2(requestUrl); | |||
| Map<String, String> map = JSON.parseObject(doGet2, new TypeReference<Map<String, String>>() { | |||
| }); | |||
| return map.get("access_token"); | |||
| } | |||
| } | |||
| @ -1,19 +1,215 @@ | |||
| package org.jeecg.modules.commonOrder.service.impl; | |||
| import org.jeecg.api.wxUtils.order.WxOrderLogisticsUtil; | |||
| import org.jeecg.common.exception.JeecgBootException; | |||
| import org.jeecg.common.util.oConvertUtils; | |||
| import org.jeecg.modules.commonOrder.entity.CommonOrder; | |||
| import org.jeecg.modules.commonOrder.mapper.CommonOrderMapper; | |||
| import org.jeecg.modules.commonOrder.service.ICommonOrderService; | |||
| import org.jeecg.modules.hanHaiMember.entity.HanHaiMember; | |||
| import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import java.util.ArrayList; | |||
| import java.util.Arrays; | |||
| import java.util.List; | |||
| import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
| /** | |||
| * @Description: 订单信息表 | |||
| * @Author: jeecg-boot | |||
| * @Date: 2025-05-07 | |||
| * @Date: 2025-06-23 | |||
| * @Version: V1.0 | |||
| */ | |||
| @Service | |||
| public class CommonOrderServiceImpl extends ServiceImpl<CommonOrderMapper, CommonOrder> implements ICommonOrderService { | |||
| @Autowired | |||
| private WxOrderLogisticsUtil wxOrderLogisticsUtil; | |||
| @Autowired | |||
| private IHanHaiMemberService hanHaiMemberService; | |||
| @Override | |||
| public void addCommonOrder(CommonOrder commonOrder) { | |||
| //新增时设置hasChild为0 | |||
| commonOrder.setHasChild(ICommonOrderService.NOCHILD); | |||
| if(oConvertUtils.isEmpty(commonOrder.getPid())){ | |||
| commonOrder.setPid(ICommonOrderService.ROOT_PID_VALUE); | |||
| }else{ | |||
| //如果当前节点父ID不为空 则设置父节点的hasChildren 为1 | |||
| CommonOrder parent = baseMapper.selectById(commonOrder.getPid()); | |||
| if(parent!=null && !"1".equals(parent.getHasChild())){ | |||
| parent.setHasChild("1"); | |||
| baseMapper.updateById(parent); | |||
| } | |||
| } | |||
| baseMapper.insert(commonOrder); | |||
| } | |||
| @Override | |||
| public void updateCommonOrder(CommonOrder commonOrder) { | |||
| CommonOrder entity = this.getById(commonOrder.getId()); | |||
| if(entity==null) { | |||
| throw new JeecgBootException("未找到对应实体"); | |||
| } | |||
| String old_pid = entity.getPid(); | |||
| String new_pid = commonOrder.getPid(); | |||
| if(!old_pid.equals(new_pid)) { | |||
| updateOldParentNode(old_pid); | |||
| if(oConvertUtils.isEmpty(new_pid)){ | |||
| commonOrder.setPid(ICommonOrderService.ROOT_PID_VALUE); | |||
| } | |||
| if(!ICommonOrderService.ROOT_PID_VALUE.equals(commonOrder.getPid())) { | |||
| baseMapper.updateTreeNodeStatus(commonOrder.getPid(), ICommonOrderService.HASCHILD); | |||
| } | |||
| } | |||
| //发货 | |||
| if ("1".equals(commonOrder.getStatus())){ | |||
| commonOrder.setStatus("2"); | |||
| if("1".equals(commonOrder.getPayType())){ | |||
| HanHaiMember member = hanHaiMemberService.getById(commonOrder.getUserId()); | |||
| wxOrderLogisticsUtil.doShipmentOneself(commonOrder.getId(), commonOrder.getTitle(), member.getAppletOpenid()); | |||
| } | |||
| } | |||
| baseMapper.updateById(commonOrder); | |||
| } | |||
| @Override | |||
| @Transactional(rollbackFor = Exception.class) | |||
| public void deleteCommonOrder(String id) throws JeecgBootException { | |||
| //查询选中节点下所有子节点一并删除 | |||
| id = this.queryTreeChildIds(id); | |||
| if(id.indexOf(",")>0) { | |||
| StringBuffer sb = new StringBuffer(); | |||
| String[] idArr = id.split(","); | |||
| for (String idVal : idArr) { | |||
| if(idVal != null){ | |||
| CommonOrder commonOrder = this.getById(idVal); | |||
| String pidVal = commonOrder.getPid(); | |||
| //查询此节点上一级是否还有其他子节点 | |||
| List<CommonOrder> dataList = baseMapper.selectList(new QueryWrapper<CommonOrder>().eq("pid", pidVal).notIn("id",Arrays.asList(idArr))); | |||
| if((dataList == null || dataList.size()==0) && !Arrays.asList(idArr).contains(pidVal) | |||
| && !sb.toString().contains(pidVal)){ | |||
| //如果当前节点原本有子节点 现在木有了,更新状态 | |||
| sb.append(pidVal).append(","); | |||
| } | |||
| } | |||
| } | |||
| //批量删除节点 | |||
| baseMapper.deleteBatchIds(Arrays.asList(idArr)); | |||
| //修改已无子节点的标识 | |||
| String[] pidArr = sb.toString().split(","); | |||
| for(String pid : pidArr){ | |||
| this.updateOldParentNode(pid); | |||
| } | |||
| }else{ | |||
| CommonOrder commonOrder = this.getById(id); | |||
| if(commonOrder==null) { | |||
| throw new JeecgBootException("未找到对应实体"); | |||
| } | |||
| updateOldParentNode(commonOrder.getPid()); | |||
| baseMapper.deleteById(id); | |||
| } | |||
| } | |||
| @Override | |||
| public List<CommonOrder> queryTreeListNoPage(QueryWrapper<CommonOrder> queryWrapper) { | |||
| List<CommonOrder> dataList = baseMapper.selectList(queryWrapper); | |||
| List<CommonOrder> mapList = new ArrayList<>(); | |||
| for(CommonOrder data : dataList){ | |||
| String pidVal = data.getPid(); | |||
| //递归查询子节点的根节点 | |||
| if(pidVal != null && !"0".equals(pidVal)){ | |||
| CommonOrder rootVal = this.getTreeRoot(pidVal); | |||
| if(rootVal != null && !mapList.contains(rootVal)){ | |||
| mapList.add(rootVal); | |||
| } | |||
| }else{ | |||
| if(!mapList.contains(data)){ | |||
| mapList.add(data); | |||
| } | |||
| } | |||
| } | |||
| return mapList; | |||
| } | |||
| /** | |||
| * 根据所传pid查询旧的父级节点的子节点并修改相应状态值 | |||
| * @param pid | |||
| */ | |||
| private void updateOldParentNode(String pid) { | |||
| if(!ICommonOrderService.ROOT_PID_VALUE.equals(pid)) { | |||
| Long count = baseMapper.selectCount(new QueryWrapper<CommonOrder>().eq("pid", pid)); | |||
| if(count==null || count<=1) { | |||
| baseMapper.updateTreeNodeStatus(pid, ICommonOrderService.NOCHILD); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * 递归查询节点的根节点 | |||
| * @param pidVal | |||
| * @return | |||
| */ | |||
| private CommonOrder getTreeRoot(String pidVal){ | |||
| CommonOrder data = baseMapper.selectById(pidVal); | |||
| if(data != null && !"0".equals(data.getPid())){ | |||
| return this.getTreeRoot(data.getPid()); | |||
| }else{ | |||
| return data; | |||
| } | |||
| } | |||
| /** | |||
| * 根据id查询所有子节点id | |||
| * @param ids | |||
| * @return | |||
| */ | |||
| private String queryTreeChildIds(String ids) { | |||
| //获取id数组 | |||
| String[] idArr = ids.split(","); | |||
| StringBuffer sb = new StringBuffer(); | |||
| for (String pidVal : idArr) { | |||
| if(pidVal != null){ | |||
| if(!sb.toString().contains(pidVal)){ | |||
| if(sb.toString().length() > 0){ | |||
| sb.append(","); | |||
| } | |||
| sb.append(pidVal); | |||
| this.getTreeChildIds(pidVal,sb); | |||
| } | |||
| } | |||
| } | |||
| return sb.toString(); | |||
| } | |||
| /** | |||
| * 递归查询所有子节点 | |||
| * @param pidVal | |||
| * @param sb | |||
| * @return | |||
| */ | |||
| private StringBuffer getTreeChildIds(String pidVal,StringBuffer sb){ | |||
| List<CommonOrder> dataList = baseMapper.selectList(new QueryWrapper<CommonOrder>().eq("pid", pidVal)); | |||
| if(dataList != null && dataList.size()>0){ | |||
| for(CommonOrder tree : dataList) { | |||
| if(!sb.toString().contains(tree.getId())){ | |||
| sb.append(",").append(tree.getId()); | |||
| } | |||
| this.getTreeChildIds(tree.getId(),sb); | |||
| } | |||
| } | |||
| return sb; | |||
| } | |||
| } | |||
| @ -1,154 +0,0 @@ | |||
| <template> | |||
| <a-spin :spinning="confirmLoading"> | |||
| <j-form-container :disabled="formDisabled"> | |||
| <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail"> | |||
| <a-row> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="订单状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status"> | |||
| <j-dict-select-tag type="list" v-model="model.status" dictCode="order_state" placeholder="请选择订单状态" /> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="下单用户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId"> | |||
| <j-search-select-tag v-model="model.userId" dict="han_hai_member,nick_name,id" /> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="订单图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="image"> | |||
| <j-image-upload isMultiple v-model="model.image" ></j-image-upload> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="订单标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="title"> | |||
| <a-input v-model="model.title" placeholder="请输入订单标题" ></a-input> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="客户姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name"> | |||
| <a-input v-model="model.name" placeholder="请输入客户姓名" ></a-input> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phone"> | |||
| <a-input v-model="model.phone" placeholder="请输入联系电话" ></a-input> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="订单价格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="price"> | |||
| <a-input-number v-model="model.price" placeholder="请输入订单价格" style="width: 100%" /> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="配送地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="address"> | |||
| <a-input v-model="model.address" placeholder="请输入配送地址" ></a-input> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="地址明细" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="addressDetail"> | |||
| <a-input v-model="model.addressDetail" placeholder="请输入地址明细" ></a-input> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="直推佣金" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="oneMoney"> | |||
| <a-input-number v-model="model.oneMoney" placeholder="请输入直推佣金" style="width: 100%" /> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="间推佣金" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="twoMoney"> | |||
| <a-input-number v-model="model.twoMoney" placeholder="请输入间推佣金" style="width: 100%" /> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| </a-row> | |||
| </a-form-model> | |||
| </j-form-container> | |||
| </a-spin> | |||
| </template> | |||
| <script> | |||
| import { httpAction, getAction } from '@/api/manage' | |||
| import { validateDuplicateValue } from '@/utils/util' | |||
| export default { | |||
| name: 'CommonOrderForm', | |||
| components: { | |||
| }, | |||
| props: { | |||
| //表单禁用 | |||
| disabled: { | |||
| type: Boolean, | |||
| default: false, | |||
| required: false | |||
| } | |||
| }, | |||
| data () { | |||
| return { | |||
| model:{ | |||
| }, | |||
| labelCol: { | |||
| xs: { span: 24 }, | |||
| sm: { span: 5 }, | |||
| }, | |||
| wrapperCol: { | |||
| xs: { span: 24 }, | |||
| sm: { span: 16 }, | |||
| }, | |||
| confirmLoading: false, | |||
| validatorRules: { | |||
| }, | |||
| url: { | |||
| add: "/commonOrder/commonOrder/add", | |||
| edit: "/commonOrder/commonOrder/edit", | |||
| queryById: "/commonOrder/commonOrder/queryById" | |||
| } | |||
| } | |||
| }, | |||
| computed: { | |||
| formDisabled(){ | |||
| return this.disabled | |||
| }, | |||
| }, | |||
| created () { | |||
| //备份model原始值 | |||
| this.modelDefault = JSON.parse(JSON.stringify(this.model)); | |||
| }, | |||
| methods: { | |||
| add () { | |||
| this.edit(this.modelDefault); | |||
| }, | |||
| edit (record) { | |||
| this.model = Object.assign({}, record); | |||
| this.visible = true; | |||
| }, | |||
| submitForm () { | |||
| const that = this; | |||
| // 触发表单验证 | |||
| this.$refs.form.validate(valid => { | |||
| if (valid) { | |||
| that.confirmLoading = true; | |||
| let httpurl = ''; | |||
| let method = ''; | |||
| if(!this.model.id){ | |||
| httpurl+=this.url.add; | |||
| method = 'post'; | |||
| }else{ | |||
| httpurl+=this.url.edit; | |||
| method = 'put'; | |||
| } | |||
| httpAction(httpurl,this.model,method).then((res)=>{ | |||
| if(res.success){ | |||
| that.$message.success(res.message); | |||
| that.$emit('ok'); | |||
| }else{ | |||
| that.$message.warning(res.message); | |||
| } | |||
| }).finally(() => { | |||
| that.confirmLoading = false; | |||
| }) | |||
| } | |||
| }) | |||
| }, | |||
| } | |||
| } | |||
| </script> | |||
| @ -1,84 +0,0 @@ | |||
| <template> | |||
| <a-drawer | |||
| :title="title" | |||
| :width="width" | |||
| placement="right" | |||
| :closable="false" | |||
| @close="close" | |||
| destroyOnClose | |||
| :visible="visible"> | |||
| <common-order-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" normal></common-order-form> | |||
| <div class="drawer-footer"> | |||
| <a-button @click="handleCancel" style="margin-bottom: 0;">关闭</a-button> | |||
| <a-button v-if="!disableSubmit" @click="handleOk" type="primary" style="margin-bottom: 0;">提交</a-button> | |||
| </div> | |||
| </a-drawer> | |||
| </template> | |||
| <script> | |||
| import CommonOrderForm from './CommonOrderForm' | |||
| export default { | |||
| name: 'CommonOrderModal', | |||
| components: { | |||
| CommonOrderForm | |||
| }, | |||
| data () { | |||
| return { | |||
| title:"操作", | |||
| width:800, | |||
| visible: false, | |||
| disableSubmit: false | |||
| } | |||
| }, | |||
| methods: { | |||
| add () { | |||
| this.visible=true | |||
| this.$nextTick(()=>{ | |||
| this.$refs.realForm.add(); | |||
| }) | |||
| }, | |||
| edit (record) { | |||
| this.visible=true | |||
| this.$nextTick(()=>{ | |||
| this.$refs.realForm.edit(record); | |||
| }); | |||
| }, | |||
| close () { | |||
| this.$emit('close'); | |||
| this.visible = false; | |||
| }, | |||
| submitCallback(){ | |||
| this.$emit('ok'); | |||
| this.visible = false; | |||
| }, | |||
| handleOk () { | |||
| this.$refs.realForm.submitForm(); | |||
| }, | |||
| handleCancel () { | |||
| this.close() | |||
| } | |||
| } | |||
| } | |||
| </script> | |||
| <style lang="less" scoped> | |||
| /** Button按钮间距 */ | |||
| .ant-btn { | |||
| margin-left: 30px; | |||
| margin-bottom: 30px; | |||
| float: right; | |||
| } | |||
| .drawer-footer{ | |||
| position: absolute; | |||
| bottom: -8px; | |||
| width: 100%; | |||
| border-top: 1px solid #e8e8e8; | |||
| padding: 10px 16px; | |||
| text-align: right; | |||
| left: 0; | |||
| background: #fff; | |||
| border-radius: 0 0 2px 2px; | |||
| } | |||
| </style> | |||
| @ -1,162 +1,272 @@ | |||
| <template> | |||
| <div> | |||
| <div class="p-4"> | |||
| <!--引用表格--> | |||
| <BasicTable @register="registerTable" :rowSelection="rowSelection"> | |||
| <!--插槽:table标题--> | |||
| <BasicTable @register="registerTable" :rowSelection="rowSelection" :expandedRowKeys="expandedRowKeys" @expand="handleExpand" @fetch-success="onFetchSuccess"> | |||
| <!--插槽:table标题--> | |||
| <template #tableTitle> | |||
| <a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button> | |||
| <a-button type="primary" @click="handleCreate" preIcon="ant-design:plus-outlined"> 新增</a-button> | |||
| <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button> | |||
| <j-upload-button type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button> | |||
| <a-dropdown v-if="checkedKeys.length > 0"> | |||
| <template #overlay> | |||
| <a-menu> | |||
| <a-menu-item key="1" @click="batchHandleDelete"> | |||
| <Icon icon="ant-design:delete-outlined"></Icon> | |||
| 删除 | |||
| </a-menu-item> | |||
| </a-menu> | |||
| </template> | |||
| <a-button>批量操作 | |||
| <Icon icon="mdi:chevron-down"></Icon> | |||
| </a-button> | |||
| <a-dropdown v-if="selectedRowKeys.length > 0"> | |||
| <template #overlay> | |||
| <a-menu> | |||
| <a-menu-item key="1" @click="batchHandleDelete"> | |||
| <Icon icon="ant-design:delete-outlined"></Icon> | |||
| 删除 | |||
| </a-menu-item> | |||
| </a-menu> | |||
| </template> | |||
| <a-button>批量操作 | |||
| <Icon icon="ant-design:down-outlined"></Icon> | |||
| </a-button> | |||
| </a-dropdown> | |||
| </template> | |||
| <!--操作栏--> | |||
| <!--操作栏--> | |||
| <template #action="{ record }"> | |||
| <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)"/> | |||
| </template> | |||
| <!--字段回显插槽--> | |||
| <template #htmlSlot="{text}"> | |||
| <div v-html="text"></div> | |||
| </template> | |||
| <template #fileSlot="{text}"> | |||
| <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span> | |||
| <a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(text)">下载</a-button> | |||
| <TableAction :actions="getTableAction(record)"/> | |||
| </template> | |||
| </BasicTable> | |||
| <!-- 表单区域 --> | |||
| <CommonOrderModal @register="registerModal" @success="handleSuccess"></CommonOrderModal> | |||
| <!--字典弹窗--> | |||
| <CommonOrderModal @register="registerModal" @success="handleSuccess"/> | |||
| </div> | |||
| </template> | |||
| <script lang="ts" name="commonOrder-commonOrder" setup> | |||
| import {ref, computed, unref} from 'vue'; | |||
| import {BasicTable, useTable, TableAction} from '/@/components/Table'; | |||
| import {useModal} from '/@/components/Modal'; | |||
| <script lang="ts" name="CommonOrder-commonOrder" setup> | |||
| //ts语法 | |||
| import {ref, computed, unref, toRaw, nextTick} from 'vue'; | |||
| import {BasicTable, useTable, TableAction} from '/src/components/Table'; | |||
| import {useModal} from '/src/components/Modal'; | |||
| import { useListPage } from '/@/hooks/system/useListPage' | |||
| import CommonOrderModal from './components/CommonOrderModal.vue' | |||
| import {columns, searchFormSchema} from './commonOrder.data'; | |||
| import {list, deleteOne, batchDelete, getImportUrl,getExportUrl} from './commonOrder.api'; | |||
| const checkedKeys = ref<Array<string | number>>([]); | |||
| //注册model | |||
| import CommonOrderModal from './components/CommonOrderModal.vue'; | |||
| import {columns} from './CommonOrder.data'; | |||
| import {list, deleteCommonOrder, batchDeleteCommonOrder, getExportUrl,getImportUrl, getChildList,getChildListBatch} from './CommonOrder.api'; | |||
| const expandedRowKeys = ref([]); | |||
| //字典model | |||
| const [registerModal, {openModal}] = useModal(); | |||
| //注册table数据 | |||
| //注册table数据 | |||
| const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({ | |||
| tableProps:{ | |||
| title: '订单信息表', | |||
| api: list, | |||
| columns, | |||
| canResize:false, | |||
| formConfig: { | |||
| labelWidth: 120, | |||
| schemas: searchFormSchema, | |||
| autoSubmitOnEnter:true, | |||
| showAdvancedButton:true, | |||
| fieldMapToTime: [ | |||
| ], | |||
| }, | |||
| actionColumn: { | |||
| width: 120, | |||
| }, | |||
| }, | |||
| exportConfig: { | |||
| name:"订单信息表", | |||
| url: getExportUrl, | |||
| tableProps:{ | |||
| title: '订单信息表', | |||
| columns, | |||
| canResize:false, | |||
| actionColumn: { | |||
| width: 120, | |||
| }, | |||
| importConfig: { | |||
| url: getImportUrl | |||
| }, | |||
| }) | |||
| }, | |||
| exportConfig: { | |||
| name:"订单信息表", | |||
| url: getExportUrl, | |||
| }, | |||
| importConfig: { | |||
| url: getImportUrl, | |||
| success: importSuccess | |||
| }, | |||
| }) | |||
| const [registerTable, {reload},{ rowSelection, selectedRowKeys }] = tableContext | |||
| const [registerTable, {reload, collapseAll, updateTableDataRecord, findTableDataRecord,getDataSource},{ rowSelection, selectedRowKeys }] = tableContext | |||
| /** | |||
| * 新增事件 | |||
| */ | |||
| function handleAdd() { | |||
| openModal(true, { | |||
| isUpdate: false, | |||
| showFooter: true, | |||
| }); | |||
| /** | |||
| * 新增事件 | |||
| */ | |||
| function handleCreate() { | |||
| openModal(true, { | |||
| isUpdate: false, | |||
| }); | |||
| } | |||
| /** | |||
| * 编辑事件 | |||
| */ | |||
| function handleEdit(record: Recordable) { | |||
| openModal(true, { | |||
| record, | |||
| isUpdate: true, | |||
| showFooter: true, | |||
| }); | |||
| } | |||
| /** | |||
| * 详情 | |||
| /** | |||
| * 编辑事件 | |||
| */ | |||
| async function handleEdit(record) { | |||
| openModal(true, { | |||
| record, | |||
| isUpdate: true, | |||
| }); | |||
| } | |||
| /** | |||
| * 详情 | |||
| */ | |||
| async function handleDetail(record) { | |||
| openModal(true, { | |||
| record, | |||
| isUpdate: true, | |||
| hideFooter: true, | |||
| }); | |||
| } | |||
| /** | |||
| * 删除事件 | |||
| */ | |||
| function handleDetail(record: Recordable) { | |||
| openModal(true, { | |||
| record, | |||
| isUpdate: true, | |||
| showFooter: false, | |||
| }); | |||
| } | |||
| /** | |||
| * 删除事件 | |||
| */ | |||
| async function handleDelete(record) { | |||
| await deleteOne({id: record.id}, reload); | |||
| } | |||
| /** | |||
| * 批量删除事件 | |||
| */ | |||
| await deleteCommonOrder({id: record.id}, importSuccess); | |||
| } | |||
| /** | |||
| * 批量删除事件 | |||
| */ | |||
| async function batchHandleDelete() { | |||
| await batchDelete({ids: checkedKeys.value}, reload); | |||
| } | |||
| /** | |||
| * 成功回调 | |||
| */ | |||
| function handleSuccess() { | |||
| reload(); | |||
| } | |||
| /** | |||
| * 操作栏 | |||
| */ | |||
| function getTableAction(record){ | |||
| return [ | |||
| { | |||
| label: '编辑', | |||
| onClick: handleEdit.bind(null, record), | |||
| } | |||
| ] | |||
| } | |||
| /** | |||
| * 下拉操作栏 | |||
| */ | |||
| function getDropDownAction(record){ | |||
| return [ | |||
| { | |||
| label: '详情', | |||
| onClick: handleDetail.bind(null, record), | |||
| }, { | |||
| label: '删除', | |||
| popConfirm: { | |||
| title: '是否确认删除', | |||
| confirm: handleDelete.bind(null, record), | |||
| } | |||
| } | |||
| ] | |||
| } | |||
| const ids = selectedRowKeys.value.filter(item => !item.includes('loading')) | |||
| await batchDeleteCommonOrder({ids: ids}, importSuccess); | |||
| } | |||
| /** | |||
| * 导入 | |||
| */ | |||
| function importSuccess() { | |||
| reload() && (expandedRowKeys.value = []); | |||
| } | |||
| /** | |||
| * 添加下级 | |||
| */ | |||
| function handleAddSub(record) { | |||
| openModal(true, { | |||
| record, | |||
| isUpdate: false, | |||
| }); | |||
| } | |||
| /** | |||
| * 成功回调 | |||
| */ | |||
| async function handleSuccess({isUpdate, values, expandedArr}) { | |||
| if (isUpdate) { | |||
| //编辑回调 | |||
| updateTableDataRecord(values.id, values); | |||
| } else { | |||
| if(!values['pid']){ | |||
| //新增根节点 | |||
| reload(); | |||
| }else{ | |||
| //新增子集 | |||
| expandedRowKeys.value = []; | |||
| for (let key of unref(expandedArr)) { | |||
| await expandTreeNode(key) | |||
| } | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * 接口请求成功后回调 | |||
| */ | |||
| function onFetchSuccess(result) { | |||
| getDataByResult(result.items)&&loadDataByExpandedRows(); | |||
| } | |||
| /** | |||
| * 根据已展开的行查询数据(用于保存后刷新时异步加载子级的数据) | |||
| */ | |||
| async function loadDataByExpandedRows() { | |||
| if (unref(expandedRowKeys).length > 0) { | |||
| const res = await getChildListBatch({ parentIds: unref(expandedRowKeys).join(',')}); | |||
| if (res.success && res.result.records.length>0) { | |||
| //已展开的数据批量子节点 | |||
| let records = res.result.records | |||
| const listMap = new Map(); | |||
| for (let item of records) { | |||
| let pid = item['pid']; | |||
| if (unref(expandedRowKeys).includes(pid)) { | |||
| let mapList = listMap.get(pid); | |||
| if (mapList == null) { | |||
| mapList = []; | |||
| } | |||
| mapList.push(item); | |||
| listMap.set(pid, mapList); | |||
| } | |||
| } | |||
| let childrenMap = listMap; | |||
| let fn = (list) => { | |||
| if(list) { | |||
| list.forEach(data => { | |||
| if (unref(expandedRowKeys).includes(data.id)) { | |||
| data.children = getDataByResult(childrenMap.get(data.id)) | |||
| fn(data.children) | |||
| } | |||
| }) | |||
| } | |||
| }; | |||
| fn(getDataSource()) | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * 处理数据集 | |||
| */ | |||
| function getDataByResult(result){ | |||
| if(result && result.length>0){ | |||
| return result.map(item=>{ | |||
| //判断是否标记了带有子节点 | |||
| if(item["hasChild"]=='1'){ | |||
| let loadChild = { id: item.id+'_loadChild', name: 'loading...', isLoading: true } | |||
| item.children = [loadChild] | |||
| } | |||
| return item | |||
| }) | |||
| } | |||
| } | |||
| /** | |||
| *树节点展开合并 | |||
| * */ | |||
| async function handleExpand(expanded, record) { | |||
| // 判断是否是展开状态,展开状态(expanded)并且存在子集(children)并且未加载过(isLoading)的就去查询子节点数据 | |||
| if (expanded) { | |||
| expandedRowKeys.value.push(record.id) | |||
| if (record.children.length > 0 && !!record.children[0].isLoading) { | |||
| let result = await getChildList({pid: record.id}); | |||
| result=result.records?result.records:result; | |||
| if (result && result.length > 0) { | |||
| record.children = getDataByResult(result); | |||
| } else { | |||
| record.children = null | |||
| record.hasChild = '0' | |||
| } | |||
| } | |||
| } else { | |||
| let keyIndex = expandedRowKeys.value.indexOf(record.id) | |||
| if (keyIndex >= 0) { | |||
| expandedRowKeys.value.splice(keyIndex, 1); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| *操作表格后处理树节点展开合并 | |||
| * */ | |||
| async function expandTreeNode(key) { | |||
| let record = findTableDataRecord(key) | |||
| expandedRowKeys.value.push(key); | |||
| let result = await getChildList({pid: key}); | |||
| if (result && result.length > 0) { | |||
| record.children = getDataByResult(result); | |||
| } else { | |||
| record.children = null | |||
| record.hasChild = '0' | |||
| } | |||
| updateTableDataRecord(key, record); | |||
| } | |||
| /** | |||
| * 操作栏 | |||
| */ | |||
| function getTableAction(record) { | |||
| return [ | |||
| { | |||
| label: '编辑', | |||
| onClick: handleEdit.bind(null, record), | |||
| }, | |||
| { | |||
| label: '删除', | |||
| popConfirm: { | |||
| title: '确定删除吗?', | |||
| confirm: handleDelete.bind(null, record), | |||
| }, | |||
| }, | |||
| { | |||
| label: '添加下级', | |||
| onClick: handleAddSub.bind(null, {pid: record.id}), | |||
| } | |||
| ] | |||
| } | |||
| </script> | |||
| <style scoped> | |||
| </style> | |||
| </style> | |||
| @ -1,58 +1,87 @@ | |||
| <template> | |||
| <BasicModal v-bind="$attrs" @register="registerModal" :title="title" @ok="handleSubmit"> | |||
| <BasicForm @register="registerForm"/> | |||
| <BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit"> | |||
| <BasicForm @register="registerForm"/> | |||
| </BasicModal> | |||
| </template> | |||
| <script lang="ts" setup> | |||
| import {ref, computed, unref} from 'vue'; | |||
| import {BasicModal, useModalInner} from '/@/components/Modal'; | |||
| import {BasicForm, useForm} from '/@/components/Form/index'; | |||
| import {formSchema} from '../commonOrder.data'; | |||
| import {saveOrUpdate} from '../commonOrder.api'; | |||
| // Emits声明 | |||
| const emit = defineEmits(['register','success']); | |||
| const isUpdate = ref(true); | |||
| //表单配置 | |||
| const [registerForm, {setProps,resetFields, setFieldsValue, validate}] = useForm({ | |||
| labelWidth: 150, | |||
| schemas: formSchema, | |||
| showActionButtonGroup: false, | |||
| }); | |||
| //表单赋值 | |||
| const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => { | |||
| //重置表单 | |||
| await resetFields(); | |||
| setModalProps({confirmLoading: false,showCancelBtn:!!data?.showFooter,showOkBtn:!!data?.showFooter}); | |||
| isUpdate.value = !!data?.isUpdate; | |||
| if (unref(isUpdate)) { | |||
| //表单赋值 | |||
| await setFieldsValue({ | |||
| ...data.record, | |||
| }); | |||
| } | |||
| // 隐藏底部时禁用整个表单 | |||
| setProps({ disabled: !data?.showFooter }) | |||
| import {ref, computed, unref} from 'vue'; | |||
| import {BasicModal, useModalInner} from '/src/components/Modal'; | |||
| import {BasicForm, useForm} from '/src/components/Form'; | |||
| import {formSchema} from '../commonOrder.data'; | |||
| import {loadTreeData, saveOrUpdateDict} from '../commonOrder.api'; | |||
| // 获取emit | |||
| const emit = defineEmits(['register', 'success']); | |||
| const isUpdate = ref(true); | |||
| const expandedRowKeys = ref([]); | |||
| const treeData = ref([]); | |||
| //表单配置 | |||
| const [registerForm, {resetFields, setFieldsValue, validate, updateSchema}] = useForm({ | |||
| schemas: formSchema, | |||
| showActionButtonGroup: false, | |||
| labelCol: { | |||
| xs: { span: 24 }, | |||
| sm: { span: 4 }, | |||
| }, | |||
| wrapperCol: { | |||
| xs: { span: 24 }, | |||
| sm: { span: 18 }, | |||
| }, | |||
| }); | |||
| //表单赋值 | |||
| const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => { | |||
| //重置表单 | |||
| await resetFields(); | |||
| expandedRowKeys.value = []; | |||
| setModalProps({confirmLoading: false, minHeight: 80}); | |||
| isUpdate.value = !!data?.isUpdate; | |||
| if (data?.record) { | |||
| //表单赋值 | |||
| await setFieldsValue({ | |||
| ...data.record, | |||
| }); | |||
| } | |||
| //父级节点树信息 | |||
| treeData.value = await loadTreeData({'async': false,'pcode':''}); | |||
| updateSchema({ | |||
| field: 'pid', | |||
| componentProps: {treeData}, | |||
| }); | |||
| //设置标题 | |||
| const title = computed(() => (!unref(isUpdate) ? '新增' : '编辑')); | |||
| //表单提交事件 | |||
| async function handleSubmit(v) { | |||
| try { | |||
| let values = await validate(); | |||
| setModalProps({confirmLoading: true}); | |||
| //提交表单 | |||
| await saveOrUpdate(values, isUpdate.value); | |||
| //关闭弹窗 | |||
| closeModal(); | |||
| //刷新列表 | |||
| emit('success'); | |||
| } finally { | |||
| setModalProps({confirmLoading: false}); | |||
| }); | |||
| //设置标题 | |||
| const getTitle = computed(() => (!unref(isUpdate) ? '新增字典' : '编辑字典')); | |||
| /** | |||
| * 根据pid获取展开的节点 | |||
| * @param pid | |||
| * @param arr | |||
| */ | |||
| function getExpandKeysByPid(pid,arr){ | |||
| if(pid && arr && arr.length>0){ | |||
| for(let i=0;i<arr.length;i++){ | |||
| if(arr[i].key==pid && unref(expandedRowKeys).indexOf(pid)<0){ | |||
| expandedRowKeys.value.push(arr[i].key); | |||
| getExpandKeysByPid(arr[i]['parentId'],unref(treeData)) | |||
| }else{ | |||
| getExpandKeysByPid(pid,arr[i].children) | |||
| } | |||
| } | |||
| } | |||
| } | |||
| //表单提交事件 | |||
| async function handleSubmit() { | |||
| try { | |||
| let values = await validate(); | |||
| setModalProps({confirmLoading: true}); | |||
| //提交表单 | |||
| await saveOrUpdateDict(values, isUpdate.value); | |||
| //关闭弹窗 | |||
| closeModal(); | |||
| //展开的节点信息 | |||
| await getExpandKeysByPid(values['pid'],unref(treeData)) | |||
| //刷新列表(isUpdate:是否编辑;values:表单信息;expandedArr:展开的节点信息) | |||
| emit('success', {isUpdate: unref(isUpdate), values:{...values},expandedArr: unref(expandedRowKeys).reverse()}); | |||
| } finally { | |||
| setModalProps({confirmLoading: false}); | |||
| } | |||
| } | |||
| </script> | |||
| <style lang="less" scoped> | |||
| </style> | |||