| @ -0,0 +1,307 @@ | |||||
| <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-search-select-tag | |||||
| v-model="queryParam.userId" | |||||
| dict="han_hai_member,nick_name,id" | |||||
| placeholder="请选择用户" | |||||
| /> | |||||
| </a-form-item> | |||||
| </a-col> | |||||
| <a-col :xl="6" :lg="7" :md="8" :sm="24"> | |||||
| <a-form-item label="审核状态"> | |||||
| <j-dict-select-tag type="list" v-model="queryParam.status" dictCode="order_type" placeholder="请选择审核状态" /> | |||||
| </a-form-item> | |||||
| </a-col> | |||||
| <a-col :xl="6" :lg="7" :md="8" :sm="24"> | |||||
| <a-form-item label="类型"> | |||||
| <j-dict-select-tag type="list" v-model="queryParam.type" dictCode="is_xc" placeholder="请选择类型" /> | |||||
| </a-form-item> | |||||
| </a-col> | |||||
| <a-col :xl="6" :lg="7" :md="8" :sm="24"> | |||||
| <a-form-item label="是否支付"> | |||||
| <a-select placeholder="请选择是否支付" v-model="queryParam.isPay" style="width: 100%" allowClear> | |||||
| <a-select-option value="Y">是</a-select-option> | |||||
| <a-select-option value="N">否</a-select-option> | |||||
| </a-select> | |||||
| </a-form-item> | |||||
| </a-col> | |||||
| <a-col :xl="6" :lg="7" :md="8" :sm="24"> | |||||
| <a-form-item label="创建时间"> | |||||
| <a-range-picker | |||||
| style="width: 100%" | |||||
| v-model="createTimeRange" | |||||
| format="YYYY-MM-DD" | |||||
| :placeholder="['开始日期', '结束日期']" | |||||
| @change="onDateChange" | |||||
| /> | |||||
| </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> | |||||
| </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" :scroll="{ x: true }" bordered rowKey="id" :columns="columns" | |||||
| :dataSource="dataSource" :pagination="ipagination" :loading="loading" | |||||
| :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" | |||||
| class="j-table-force-nowrap" @change="handleTableChange"> | |||||
| <template slot="htmlSlot" slot-scope="text"> | |||||
| <div v-html="text"></div> | |||||
| </template> | |||||
| <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)">审核</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="handleDetail(record)">详情</a> | |||||
| </a-menu-item> | |||||
| <a-menu-item> | |||||
| <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)"> | |||||
| <a>删除</a> | |||||
| </a-popconfirm> | |||||
| </a-menu-item> | |||||
| </a-menu> | |||||
| </a-dropdown> --> | |||||
| </span> | |||||
| </a-table> | |||||
| </div> | |||||
| <common-add-order-modal ref="modalForm" @ok="modalFormOk" :shopOptions="shopOptions"></common-add-order-modal> | |||||
| </a-card> | |||||
| </template> | |||||
| <script> | |||||
| import '@/assets/less/TableExpand.less' | |||||
| import { mixinDevice } from '@/utils/mixin' | |||||
| import { JeecgListMixin } from '@/mixins/JeecgListMixin' | |||||
| import CommonAddOrderModal from './modules/CommonAddOrderModal' | |||||
| import { filterMultiDictText } from '@/components/dict/JDictSelectUtil' | |||||
| import JDictSelectTag from '@/components/dict/JDictSelectTag.vue' | |||||
| import JSearchSelectTag from '@/components/dict/JSearchSelectTag.vue' | |||||
| import { getAction } from '@/api/manage' | |||||
| export default { | |||||
| name: 'CommonAddOrderList', | |||||
| mixins: [JeecgListMixin, mixinDevice], | |||||
| components: { | |||||
| CommonAddOrderModal, | |||||
| JDictSelectTag, | |||||
| JSearchSelectTag | |||||
| }, | |||||
| data() { | |||||
| return { | |||||
| description: '快捷下单订单管理页面', | |||||
| createTimeRange: [], | |||||
| // 表头 | |||||
| columns: [ | |||||
| { | |||||
| title: '#', | |||||
| dataIndex: '', | |||||
| key: 'rowIndex', | |||||
| width: 60, | |||||
| align: "center", | |||||
| customRender: function (t, r, index) { | |||||
| return parseInt(index) + 1; | |||||
| } | |||||
| }, | |||||
| { | |||||
| title: '创建日期', | |||||
| align: "center", | |||||
| dataIndex: 'createTime' | |||||
| }, | |||||
| { | |||||
| title: '提交用户', | |||||
| align: "center", | |||||
| dataIndex: 'userId_dictText' | |||||
| }, | |||||
| { | |||||
| title: '内容图片', | |||||
| align: "center", | |||||
| dataIndex: 'imageUrl', | |||||
| scopedSlots: { customRender: 'imgSlot' } | |||||
| }, | |||||
| { | |||||
| title: '语音图片', | |||||
| align: "center", | |||||
| dataIndex: 'voiceUrl', | |||||
| scopedSlots: { customRender: 'fileSlot' } | |||||
| }, | |||||
| { | |||||
| title: '类型', | |||||
| align: "center", | |||||
| dataIndex: 'type_dictText' | |||||
| }, | |||||
| { | |||||
| title: '审核状态', | |||||
| align: "center", | |||||
| dataIndex: 'status_dictText' | |||||
| }, | |||||
| { | |||||
| title: '推荐商品', | |||||
| align: "center", | |||||
| dataIndex: 'shopId_dictText' | |||||
| }, | |||||
| { | |||||
| title: '是否支付', | |||||
| align: "center", | |||||
| dataIndex: 'isPay', | |||||
| customRender: (text) => (text ? filterMultiDictText(this.dictOptions['isPay'], text) : ''), | |||||
| }, | |||||
| { | |||||
| title: '操作', | |||||
| dataIndex: 'action', | |||||
| align: "center", | |||||
| fixed: "right", | |||||
| width: 147, | |||||
| scopedSlots: { customRender: 'action' } | |||||
| } | |||||
| ], | |||||
| url: { | |||||
| list: "/commonAddOrder/commonAddOrder/list", | |||||
| delete: "/commonAddOrder/commonAddOrder/delete", | |||||
| deleteBatch: "/commonAddOrder/commonAddOrder/deleteBatch", | |||||
| exportXlsUrl: "/commonAddOrder/commonAddOrder/exportXls", | |||||
| importExcelUrl: "commonAddOrder/commonAddOrder/importExcel", | |||||
| }, | |||||
| dictOptions: {}, | |||||
| superFieldList: [], | |||||
| shopOptions: [], // 商品选项数据 | |||||
| } | |||||
| }, | |||||
| created() { | |||||
| this.$set(this.dictOptions, 'isPay', [{ text: '是', value: 'Y' }, { text: '否', value: 'N' }]) | |||||
| this.getSuperFieldList(); | |||||
| this.loadShopOptions(); | |||||
| }, | |||||
| computed: { | |||||
| importExcelUrl: function () { | |||||
| return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`; | |||||
| }, | |||||
| }, | |||||
| methods: { | |||||
| initDictConfig() { | |||||
| }, | |||||
| onDateChange(date, dateString) { | |||||
| if (date && dateString && dateString.length === 2) { | |||||
| this.queryParam.createTime_begin = dateString[0]; | |||||
| this.queryParam.createTime_end = dateString[1]; | |||||
| } else { | |||||
| this.queryParam.createTime_begin = ''; | |||||
| this.queryParam.createTime_end = ''; | |||||
| } | |||||
| }, | |||||
| searchReset() { | |||||
| this.queryParam = { | |||||
| userId: '', | |||||
| status: '', | |||||
| type: '', | |||||
| isPay: '', | |||||
| shopId: '', | |||||
| shopQuantity: null, | |||||
| createTime_begin: '', | |||||
| createTime_end: '' | |||||
| } | |||||
| this.createTimeRange = []; | |||||
| this.loadData(1); | |||||
| }, | |||||
| getSuperFieldList() { | |||||
| let fieldList = []; | |||||
| fieldList.push({ type: 'datetime', value: 'createTime', text: '创建日期' }) | |||||
| fieldList.push({ type: 'sel_search', value: 'userId', text: '提交用户', dictTable: "han_hai_member", dictText: 'nick_name', dictCode: 'id' }) | |||||
| fieldList.push({ type: 'Text', value: 'imageUrl', text: '内容图片', dictCode: '' }) | |||||
| fieldList.push({ type: 'Text', value: 'voiceUrl', text: '语音图片', dictCode: '' }) | |||||
| fieldList.push({ type: 'string', value: 'type', text: '类型', dictCode: 'is_xc' }) | |||||
| fieldList.push({ type: 'string', value: 'status', text: '审核状态', dictCode: 'order_type' }) | |||||
| fieldList.push({ type: 'list_multi', value: 'shopId', text: '推荐商品', dictTable: "common_shop", dictText: 'name', dictCode: 'id' }) | |||||
| fieldList.push({ type: 'switch', value: 'isPay', text: '是否支付' }) | |||||
| this.superFieldList = fieldList | |||||
| }, | |||||
| // 加载商品选项数据 | |||||
| async loadShopOptions() { | |||||
| try { | |||||
| const res = await getAction('/commonShop/commonShop/list', { | |||||
| pageNo: 1, | |||||
| pageSize: 10000000, | |||||
| }); | |||||
| if (res.success) { | |||||
| this.shopOptions = res.result.records.map(item => ({ | |||||
| text: item.name, // 商品名称 | |||||
| value: item.id, // 商品ID | |||||
| num: item.num || 0 // 商品数量 | |||||
| })); | |||||
| console.log('商品选项加载成功:', this.shopOptions); | |||||
| } else { | |||||
| console.warn('商品数据加载失败:', res); | |||||
| } | |||||
| } catch (error) { | |||||
| console.error('加载商品选项失败:', error); | |||||
| } | |||||
| }, | |||||
| // 覆盖默认的handleEdit方法,确保获取完整数据 | |||||
| handleEdit(record) { | |||||
| this.$refs.modalForm.edit(record); | |||||
| this.$refs.modalForm.title = "审核"; | |||||
| this.$refs.modalForm.disableSubmit = false; | |||||
| } | |||||
| } | |||||
| } | |||||
| </script> | |||||
| <style scoped> | |||||
| @import '~@assets/less/common.less'; | |||||
| </style> | |||||
| @ -0,0 +1,377 @@ | |||||
| <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="userId"> | |||||
| <j-search-select-tag v-model="model.userId" dict="han_hai_member,nick_name,id" disabled /> | |||||
| </a-form-model-item> | |||||
| </a-col> | |||||
| <a-col :span="24"> | |||||
| <a-form-model-item label="内容图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imageUrl"> | |||||
| <j-image-upload isMultiple v-model="model.imageUrl" disabled></j-image-upload> | |||||
| </a-form-model-item> | |||||
| </a-col> | |||||
| <a-col :span="24"> | |||||
| <a-form-model-item label="语音图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="voiceUrl"> | |||||
| <j-upload v-model="model.voiceUrl" disabled></j-upload> | |||||
| </a-form-model-item> | |||||
| </a-col> | |||||
| <a-col :span="24"> | |||||
| <a-form-model-item label="类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type"> | |||||
| <j-dict-select-tag type="list" v-model="model.type" dictCode="is_xc" placeholder="请选择类型" | |||||
| disabled /> | |||||
| </a-form-model-item> | |||||
| </a-col> | |||||
| <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_type" | |||||
| placeholder="请选择审核状态" /> | |||||
| </a-form-model-item> | |||||
| </a-col> | |||||
| <a-col :span="24"> | |||||
| <a-form-model-item label="是否支付" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isPay"> | |||||
| <j-switch v-model="model.isPay" disabled></j-switch> | |||||
| </a-form-model-item> | |||||
| </a-col> | |||||
| <a-col :span="24"> | |||||
| <a-form-model-item label="推荐商品" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shopId"> | |||||
| <j-multi-select-tag type="list_multi" v-model="model.shopId" dictCode="common_shop,name,id" | |||||
| placeholder="请选择推荐商品" /> | |||||
| </a-form-model-item> | |||||
| </a-col> | |||||
| <a-col :span="24" v-if="selectedShops.length > 0"> | |||||
| <a-form-model-item label="推荐数量配置" :labelCol="labelCol" :wrapperCol="wrapperCol"> | |||||
| <div class="shop-recommend-config"> | |||||
| <div v-for="shop in selectedShops" :key="shop.value" class="shop-recommend-item"> | |||||
| <div class="shop-info"> | |||||
| <span class="shop-name">{{ shop.text }}</span> | |||||
| <span class="shop-stock">库存: {{ shop.num }}个</span> | |||||
| </div> | |||||
| <div class="recommend-input"> | |||||
| <span class="input-label">推荐数量:</span> | |||||
| <a-input-number v-model="shop.recommendCount" :min="1" :max="shop.num || 999" placeholder="推荐数量" | |||||
| style="width: 100px;" @change="updateShopRecommendCount(shop.value, $event)" /> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </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: 'CommonAddOrderForm', | |||||
| components: { | |||||
| }, | |||||
| props: { | |||||
| //表单禁用 | |||||
| disabled: { | |||||
| type: Boolean, | |||||
| default: false, | |||||
| required: false | |||||
| }, | |||||
| // 商品选项数据 | |||||
| shopOptions: { | |||||
| type: Array, | |||||
| default: () => [] | |||||
| } | |||||
| }, | |||||
| data() { | |||||
| return { | |||||
| model: { | |||||
| }, | |||||
| labelCol: { | |||||
| xs: { span: 24 }, | |||||
| sm: { span: 5 }, | |||||
| }, | |||||
| wrapperCol: { | |||||
| xs: { span: 24 }, | |||||
| sm: { span: 16 }, | |||||
| }, | |||||
| confirmLoading: false, | |||||
| validatorRules: { | |||||
| }, | |||||
| url: { | |||||
| add: "/commonAddOrder/commonAddOrder/add", | |||||
| edit: "/commonAddOrder/commonAddOrder/edit", | |||||
| queryById: "/commonAddOrder/commonAddOrder/queryById" | |||||
| }, | |||||
| selectedShops: [] // 存储选中的商品及其推荐数量 | |||||
| } | |||||
| }, | |||||
| computed: { | |||||
| formDisabled() { | |||||
| return this.disabled | |||||
| }, | |||||
| }, | |||||
| watch: { | |||||
| 'model.shopId': { | |||||
| handler(newVal) { | |||||
| this.updateSelectedShops(newVal); | |||||
| }, | |||||
| deep: true | |||||
| }, | |||||
| // 监听shopOptions变化,更新选中商品信息 | |||||
| shopOptions: { | |||||
| handler(newVal) { | |||||
| if (newVal && newVal.length > 0) { | |||||
| this.updateSelectedShopsInfo(); | |||||
| } | |||||
| }, | |||||
| immediate: true | |||||
| } | |||||
| }, | |||||
| created() { | |||||
| //备份model原始值 | |||||
| this.modelDefault = JSON.parse(JSON.stringify(this.model)); | |||||
| }, | |||||
| methods: { | |||||
| // 更新选中的商品列表和推荐数量配置 | |||||
| updateSelectedShops(shopIds) { | |||||
| console.log('shopIds:', shopIds); | |||||
| console.log('当前shopRecommends:', this.model.shopRecommends); | |||||
| // 处理shopIds,支持字符串和数组两种格式 | |||||
| let shopIdArray = []; | |||||
| if (typeof shopIds === 'string' && shopIds) { | |||||
| // 如果是逗号分隔的字符串,转换为数组 | |||||
| shopIdArray = shopIds.split(',').filter(id => id.trim()); | |||||
| } else if (Array.isArray(shopIds)) { | |||||
| shopIdArray = shopIds; | |||||
| } | |||||
| if (!shopIdArray.length) { | |||||
| this.selectedShops = []; | |||||
| return; | |||||
| } | |||||
| // 获取新选中的商品 | |||||
| const newSelectedShops = shopIdArray.map(shopId => { | |||||
| // 查找是否已存在该商品配置,保持原有推荐数量 | |||||
| const existingShop = this.selectedShops.find(shop => shop.value == shopId); | |||||
| if (existingShop) { | |||||
| return existingShop; | |||||
| } | |||||
| // 从商品选项中找到对应的商品信息 | |||||
| const shopOption = this.shopOptions.find(option => option.value == shopId); | |||||
| // 尝试从现有的shopRecommends中获取推荐数量,如果没有则默认为1 | |||||
| let recommendCount = 1; | |||||
| if (this.model.shopRecommends && typeof this.model.shopRecommends === 'object' && this.model.shopRecommends[shopId]) { | |||||
| recommendCount = this.model.shopRecommends[shopId]; | |||||
| console.log(`从shopRecommends恢复商品${shopId}的推荐数量:${recommendCount}`); | |||||
| } | |||||
| return { | |||||
| value: shopId, | |||||
| text: shopOption ? shopOption.text : `商品${shopId}`, | |||||
| num: shopOption ? shopOption.num : 0, | |||||
| recommendCount: recommendCount | |||||
| }; | |||||
| }); | |||||
| this.selectedShops = newSelectedShops; | |||||
| console.log('设置selectedShops后:', this.selectedShops); | |||||
| this.updateModelShopRecommends(); | |||||
| console.log('调用updateModelShopRecommends后:', this.model.shopRecommends); | |||||
| }, | |||||
| // 更新商品推荐数量 | |||||
| updateShopRecommendCount(shopId, count) { | |||||
| const shop = this.selectedShops.find(s => s.value === shopId); | |||||
| if (shop) { | |||||
| shop.recommendCount = count || 1; | |||||
| this.updateModelShopRecommends(); | |||||
| } | |||||
| }, | |||||
| // 更新模型中的商品推荐数据 | |||||
| updateModelShopRecommends() { | |||||
| const shopRecommends = {}; | |||||
| this.selectedShops.forEach(shop => { | |||||
| shopRecommends[shop.value] = shop.recommendCount; | |||||
| }); | |||||
| this.$set(this.model, 'shopRecommends', shopRecommends); | |||||
| }, | |||||
| // 更新已选中商品的名称和库存信息 | |||||
| updateSelectedShopsInfo() { | |||||
| if (this.selectedShops.length > 0 && this.shopOptions.length > 0) { | |||||
| this.selectedShops.forEach(shop => { | |||||
| const shopOption = this.shopOptions.find(option => option.value == shop.value); | |||||
| if (shopOption) { | |||||
| // 更新商品名称和库存信息 | |||||
| shop.text = shopOption.text; | |||||
| shop.num = shopOption.num; | |||||
| } | |||||
| }); | |||||
| console.log('已更新选中商品信息:', this.selectedShops); | |||||
| } | |||||
| }, | |||||
| add() { | |||||
| this.edit(this.modelDefault); | |||||
| }, | |||||
| edit(record) { | |||||
| // 如果传入的是ID,需要通过API查询完整数据 | |||||
| if (typeof record === 'string' || (record && record.id && !record.shopRecommends)) { | |||||
| this.queryRecordById(record.id || record); | |||||
| } else { | |||||
| // 如果传入的是完整数据,直接使用 | |||||
| this.loadRecordData(record); | |||||
| } | |||||
| this.visible = true; | |||||
| }, | |||||
| // 通过ID查询完整的记录数据 | |||||
| async queryRecordById(id) { | |||||
| this.confirmLoading = true; | |||||
| try { | |||||
| const res = await getAction(this.url.queryById, { id: id }); | |||||
| if (res.success) { | |||||
| this.loadRecordData(res.result); | |||||
| } else { | |||||
| this.$message.warning('查询数据失败'); | |||||
| } | |||||
| } catch (error) { | |||||
| console.error('查询数据失败:', error); | |||||
| this.$message.error('查询数据失败'); | |||||
| } finally { | |||||
| this.confirmLoading = false; | |||||
| } | |||||
| }, | |||||
| // 加载记录数据到表单 | |||||
| loadRecordData(record) { | |||||
| this.model = Object.assign({}, record); | |||||
| // 如果 shopRecommends 是 JSON 字符串,先解析为对象 | |||||
| if (this.model.shopRecommends && typeof this.model.shopRecommends === 'string') { | |||||
| try { | |||||
| console.log('解析前的推荐数据:', this.model.shopRecommends); | |||||
| this.model.shopRecommends = JSON.parse(this.model.shopRecommends); | |||||
| console.log('解析后的推荐数据:', this.model.shopRecommends); | |||||
| } catch (error) { | |||||
| console.error('解析商品推荐数据失败:', error); | |||||
| this.model.shopRecommends = {}; | |||||
| } | |||||
| } | |||||
| // 如果编辑时有商品选择,初始化推荐数量配置 | |||||
| if (this.model.shopId && ( | |||||
| (typeof this.model.shopId === 'string' && this.model.shopId.trim()) || | |||||
| (Array.isArray(this.model.shopId) && this.model.shopId.length > 0) | |||||
| )) { | |||||
| // 延迟执行,确保shopOptions已加载 | |||||
| this.$nextTick(() => { | |||||
| this.updateSelectedShops(this.model.shopId); | |||||
| }); | |||||
| } | |||||
| }, | |||||
| 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'; | |||||
| } | |||||
| // 准备提交数据,将 shopRecommends 转换为 JSON 字符串 | |||||
| let submitData = { ...this.model }; | |||||
| if (this.model.shopRecommends && Object.keys(this.model.shopRecommends).length > 0) { | |||||
| console.log('原始推荐数据:', this.model.shopRecommends); | |||||
| submitData.shopRecommends = JSON.stringify(this.model.shopRecommends); | |||||
| console.log('转换后的推荐数据:', submitData.shopRecommends); | |||||
| } | |||||
| httpAction(httpurl, submitData, 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> | |||||
| <style scoped> | |||||
| .shop-recommend-config { | |||||
| border: 1px solid #e8e8e8; | |||||
| border-radius: 6px; | |||||
| padding: 16px; | |||||
| background-color: #fafafa; | |||||
| } | |||||
| .shop-recommend-item { | |||||
| display: flex; | |||||
| justify-content: space-between; | |||||
| align-items: center; | |||||
| margin-bottom: 12px; | |||||
| padding: 12px 16px; | |||||
| background-color: #fff; | |||||
| border-radius: 6px; | |||||
| border: 1px solid #e8e8e8; | |||||
| box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04); | |||||
| } | |||||
| .shop-recommend-item:last-child { | |||||
| margin-bottom: 0; | |||||
| } | |||||
| .shop-info { | |||||
| display: flex; | |||||
| flex-direction: column; | |||||
| flex: 1; | |||||
| } | |||||
| .shop-name { | |||||
| font-weight: 500; | |||||
| color: #333; | |||||
| font-size: 14px; | |||||
| margin-bottom: 4px; | |||||
| } | |||||
| .shop-stock { | |||||
| color: #666; | |||||
| font-size: 12px; | |||||
| } | |||||
| .recommend-input { | |||||
| display: flex; | |||||
| align-items: center; | |||||
| flex-shrink: 0; | |||||
| } | |||||
| .input-label { | |||||
| margin-right: 8px; | |||||
| color: #666; | |||||
| font-size: 13px; | |||||
| } | |||||
| .unit-text { | |||||
| margin-left: 8px; | |||||
| color: #666; | |||||
| font-size: 14px; | |||||
| } | |||||
| </style> | |||||
| @ -0,0 +1,91 @@ | |||||
| <template> | |||||
| <a-drawer | |||||
| :title="title" | |||||
| :width="width" | |||||
| placement="right" | |||||
| :closable="false" | |||||
| @close="close" | |||||
| destroyOnClose | |||||
| :visible="visible"> | |||||
| <common-add-order-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" normal :shopOptions="shopOptions"></common-add-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 CommonAddOrderForm from './CommonAddOrderForm' | |||||
| export default { | |||||
| name: 'CommonAddOrderModal', | |||||
| components: { | |||||
| CommonAddOrderForm | |||||
| }, | |||||
| props: { | |||||
| shopOptions: { | |||||
| type: Array, | |||||
| default: () => [] | |||||
| } | |||||
| }, | |||||
| 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.title = "审核"; | |||||
| 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> | |||||
| @ -0,0 +1,67 @@ | |||||
| <template> | |||||
| <j-modal | |||||
| :title="title" | |||||
| :width="width" | |||||
| :visible="visible" | |||||
| switchFullscreen | |||||
| @ok="handleOk" | |||||
| :okButtonProps="{ class:{'jee-hidden': disableSubmit} }" | |||||
| @cancel="handleCancel" | |||||
| cancelText="关闭"> | |||||
| <common-add-order-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :shopOptions="shopOptions"></common-add-order-form> | |||||
| </j-modal> | |||||
| </template> | |||||
| <script> | |||||
| import CommonAddOrderForm from './CommonAddOrderForm' | |||||
| export default { | |||||
| name: 'CommonAddOrderModal', | |||||
| components: { | |||||
| CommonAddOrderForm | |||||
| }, | |||||
| props: { | |||||
| shopOptions: { | |||||
| type: Array, | |||||
| default: () => [] | |||||
| } | |||||
| }, | |||||
| 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.title = "审核"; | |||||
| this.$nextTick(()=>{ | |||||
| this.$refs.realForm.edit(record); | |||||
| }) | |||||
| }, | |||||
| close () { | |||||
| this.$emit('close'); | |||||
| this.visible = false; | |||||
| }, | |||||
| handleOk () { | |||||
| this.$refs.realForm.submitForm(); | |||||
| }, | |||||
| submitCallback(){ | |||||
| this.$emit('ok'); | |||||
| this.visible = false; | |||||
| }, | |||||
| handleCancel () { | |||||
| this.close() | |||||
| } | |||||
| } | |||||
| } | |||||
| </script> | |||||