index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="活动标题" prop="title">
  5. <el-input
  6. v-model="queryParams.title"
  7. placeholder="请输入活动标题"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item>
  14. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  15. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  16. </el-form-item>
  17. </el-form>
  18. <el-row :gutter="10" class="mb8">
  19. <el-col :span="1.5">
  20. <el-button
  21. type="primary"
  22. icon="el-icon-plus"
  23. size="mini"
  24. @click="handleAdd"
  25. v-hasPermi="['store:storeActivity:add']"
  26. >新增</el-button>
  27. </el-col>
  28. <el-col :span="1.5">
  29. <el-button
  30. type="success"
  31. icon="el-icon-edit"
  32. size="mini"
  33. :disabled="single"
  34. @click="handleUpdate"
  35. v-hasPermi="['store:storeActivity:edit']"
  36. >修改</el-button>
  37. </el-col>
  38. <el-col :span="1.5">
  39. <el-button
  40. type="danger"
  41. icon="el-icon-delete"
  42. size="mini"
  43. :disabled="multiple"
  44. @click="handleDelete"
  45. v-hasPermi="['store:storeActivity:remove']"
  46. >删除</el-button>
  47. </el-col>
  48. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  49. </el-row>
  50. <el-tabs type="card" v-model="activeName" @tab-click="handleClick">
  51. <el-tab-pane label="正常" name="1"></el-tab-pane>
  52. <el-tab-pane label="关闭" name="0"></el-tab-pane>
  53. </el-tabs>
  54. <el-table height="500" border v-loading="loading" :data="storeActivityList" @selection-change="handleSelectionChange">
  55. <el-table-column type="selection" width="55" align="center" />
  56. <el-table-column label="ID" align="center" prop="activityId" />
  57. <el-table-column label="活动标题" align="center" prop="title" />
  58. <!-- <el-table-column label="描述" show-overflow-tooltip align="center" prop="descs" /> -->
  59. <el-table-column label="弹框广告图" align="center" width="120">
  60. <template slot-scope="scope">
  61. <el-popover
  62. placement="right"
  63. title=""
  64. trigger="hover"
  65. >
  66. <img slot="reference" :src="scope.row.logoUrl" width="100">
  67. <img :src="scope.row.logoUrl" style="max-width: 150px;">
  68. </el-popover>
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="分享数" align="center" prop="shareNumber" />
  72. <el-table-column label="状态" align="center" prop="status" >
  73. <template slot-scope="scope">
  74. <el-tag prop="status" v-for="(item, index) in statusOptions" v-if="scope.row.status==item.dictValue">{{item.dictLabel}}</el-tag>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  78. <template slot-scope="scope">
  79. <el-button
  80. size="mini"
  81. type="text"
  82. icon="el-icon-edit"
  83. @click="handleUpdate(scope.row)"
  84. v-hasPermi="['store:storeActivity:edit']"
  85. >修改</el-button>
  86. <el-button
  87. size="mini"
  88. type="text"
  89. icon="el-icon-delete"
  90. @click="handleDelete(scope.row)"
  91. v-hasPermi="['store:storeActivity:remove']"
  92. >删除</el-button>
  93. </template>
  94. </el-table-column>
  95. </el-table>
  96. <pagination
  97. v-show="total>0"
  98. :total="total"
  99. :page.sync="queryParams.pageNum"
  100. :limit.sync="queryParams.pageSize"
  101. @pagination="getList"
  102. />
  103. <!-- 添加或修改活动对话框 -->
  104. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
  105. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  106. <el-form-item label="标题" prop="title">
  107. <el-input v-model="form.title" placeholder="请输入标题" />
  108. </el-form-item>
  109. <!-- <el-form-item label="描述" prop="descs">
  110. <el-input v-model="form.descs" type="textarea" placeholder="请输入内容" />
  111. </el-form-item> -->
  112. <el-form-item label="弹框广告图" prop="logoUrl">
  113. <Material v-model="imageArr" type="image" :num="1" :width="150" :height="150" />
  114. <div class="image-size-tip">
  115. <i class="el-icon-info"></i>
  116. <span>建议尺寸:800×640px(比例5:4)</span>
  117. </div>
  118. <div v-if="logoValidation.show" :class="['validation-message', logoValidation.type]">
  119. <i :class="logoValidation.type === 'warning' ? 'el-icon-warning' : 'el-icon-success'"></i>
  120. <span>{{ logoValidation.message }}</span>
  121. </div>
  122. </el-form-item>
  123. <el-form-item label="BANNER图" prop="images">
  124. <Material v-model="photoArr" type="image" :num="10" :width="150" :height="150" />
  125. <div class="image-size-tip">
  126. <i class="el-icon-info"></i>
  127. <span>建议尺寸:1200×600px(比例2:1)</span>
  128. </div>
  129. <div v-if="bannerValidation.show" :class="['validation-message', bannerValidation.type]">
  130. <i :class="bannerValidation.type === 'warning' ? 'el-icon-warning' : 'el-icon-success'"></i>
  131. <span>{{ bannerValidation.message }}</span>
  132. </div>
  133. </el-form-item>
  134. <el-form-item label="活动商品" prop="productIds" >
  135. <el-row >
  136. <el-col >
  137. <el-button plain type="primary" icon="el-icon-plus" @click="handleAddProduct">添加商品</el-button>
  138. </el-col>
  139. </el-row>
  140. <el-table border width="100%" style="margin-top:5px;" :data="products">
  141. <el-table-column label="商品ID" align="center" prop="productId" />
  142. <el-table-column label="商品图片" align="center" width="100">
  143. <template slot-scope="scope">
  144. <el-popover
  145. placement="right"
  146. title=""
  147. trigger="hover"
  148. >
  149. <img slot="reference" :src="scope.row.image" width="50">
  150. <img :src="scope.row.image" style="max-width: 50px;">
  151. </el-popover>
  152. </template>
  153. </el-table-column>
  154. <el-table-column label="商品名称" show-overflow-tooltip align="center" prop="productName" />
  155. <el-table-column label="售价" align="center" prop="price" >
  156. <template slot-scope="scope">
  157. <div v-if="scope.row.price!=null">
  158. {{scope.row.price.toFixed(2)}}
  159. </div>
  160. </template>
  161. </el-table-column>
  162. <el-table-column label="操作" align="center" width="100px" >
  163. <template slot-scope="scope">
  164. <el-button
  165. size="mini"
  166. type="text"
  167. icon="el-icon-delete"
  168. @click="handleProductDelete(scope.row)"
  169. >删除</el-button>
  170. </template>
  171. </el-table-column>
  172. </el-table>
  173. </el-form-item>
  174. <el-form-item label="活动内容">
  175. <editor ref="myeditor" @on-text-change="updateText" />
  176. </el-form-item>
  177. <el-form-item label="状态">
  178. <el-radio-group v-model="form.status">
  179. <el-radio label="1">正常</el-radio>
  180. <el-radio label="0">关闭</el-radio>
  181. </el-radio-group>
  182. </el-form-item>
  183. </el-form>
  184. <div slot="footer" class="dialog-footer">
  185. <el-button type="primary" @click="submitForm">确 定</el-button>
  186. <el-button @click="cancel">取 消</el-button>
  187. </div>
  188. </el-dialog>
  189. <el-dialog :title="product.title" v-if="product.open" :visible.sync="product.open" width="1000px" append-to-body>
  190. <product-select ref="product" @selectProduct="selectProduct" />
  191. </el-dialog>
  192. </div>
  193. </template>
  194. <script>
  195. import { listStoreActivity, getStoreActivity, delStoreActivity, addStoreActivity, updateStoreActivity, exportStoreActivity } from "@/api/hisStore/storeActivity";
  196. import Material from '@/components/Material'
  197. import singleImg from '@/components/Material/single'
  198. import Editor from '@/components/Editor/wang';
  199. import productSelect from "../components/productSelect";
  200. export default {
  201. name: "HisStoreActivity",
  202. components: {
  203. productSelect,
  204. Editor,
  205. Material,
  206. singleImg,
  207. },
  208. watch: {
  209. imageArr: function(val) {
  210. this.form.logoUrl = val.join(',');
  211. // 验证弹框广告图
  212. if (val.length > 0) {
  213. this.validateImage(val[val.length - 1], 'logo');
  214. } else {
  215. this.logoValidation.show = false;
  216. }
  217. },
  218. photoArr: function(val) {
  219. this.form.images = val.join(',');
  220. // 验证BANNER图
  221. if (val.length > 0) {
  222. this.validateImage(val[val.length - 1], 'banner');
  223. } else {
  224. this.bannerValidation.show = false;
  225. }
  226. },
  227. },
  228. data() {
  229. return {
  230. photoArr:[],
  231. products:[],
  232. product:{
  233. open:false,
  234. title:"商品选择"
  235. },
  236. statusOptions:[],
  237. imageArr:[],
  238. activeName:"1",
  239. // 图片验证相关
  240. logoValidation: {
  241. show: false,
  242. type: 'success', // success 或 warning
  243. message: ''
  244. },
  245. bannerValidation: {
  246. show: false,
  247. type: 'success',
  248. message: ''
  249. },
  250. // 尺寸配置
  251. sizeConfig: {
  252. logo: { width: 750, height: 400, tolerance: 0.15 }, // 15%容差
  253. banner: { width: 1200, height: 600, tolerance: 0.15 }
  254. },
  255. // 遮罩层
  256. loading: true,
  257. // 选中数组
  258. ids: [],
  259. // 非单个禁用
  260. single: true,
  261. // 非多个禁用
  262. multiple: true,
  263. // 显示搜索条件
  264. showSearch: true,
  265. // 总条数
  266. total: 0,
  267. // 活动表格数据
  268. storeActivityList: [],
  269. // 弹出层标题
  270. title: "",
  271. // 是否显示弹出层
  272. open: false,
  273. // 查询参数
  274. queryParams: {
  275. pageNum: 1,
  276. pageSize: 10,
  277. title: null,
  278. descs: null,
  279. logoUrl: null,
  280. images: null,
  281. productIds: null,
  282. content: null,
  283. status: null
  284. },
  285. // 表单参数
  286. form: {},
  287. // 表单校验
  288. rules: {
  289. }
  290. };
  291. },
  292. created() {
  293. this.getDicts("common_status").then((response) => {
  294. this.statusOptions = response.data;
  295. });
  296. this.getList();
  297. },
  298. methods: {
  299. selectProduct(row){
  300. for(var i=0;i<this.products.length;i++){
  301. if(this.products[i].productId==row.productId){
  302. return;
  303. }
  304. }
  305. this.products.push(row);
  306. },
  307. handleAddProduct(){
  308. this.product.open=true;
  309. },
  310. handleProductDelete(row){
  311. this.products.splice(this.products.findIndex(item => item.productId === row.productId), 1)
  312. },
  313. updateText(text){
  314. this.form.content=text
  315. },
  316. // 验证图片尺寸
  317. validateImage(imageUrl, type) {
  318. if (!imageUrl) return;
  319. const img = new Image();
  320. const config = this.sizeConfig[type];
  321. const validation = type === 'logo' ? this.logoValidation : this.bannerValidation;
  322. img.onload = () => {
  323. const { width: actualWidth, height: actualHeight } = img;
  324. const { width: expectedWidth, height: expectedHeight, tolerance } = config;
  325. // 计算比例差异
  326. const expectedRatio = expectedWidth / expectedHeight;
  327. const actualRatio = actualWidth / actualHeight;
  328. const ratioDiff = Math.abs(actualRatio - expectedRatio) / expectedRatio;
  329. validation.show = true;
  330. if (ratioDiff <= tolerance) {
  331. validation.type = 'success';
  332. validation.message = `✓ 尺寸符合要求 (实际: ${actualWidth}x${actualHeight}px)`;
  333. } else {
  334. validation.type = 'warning';
  335. validation.message = `⚠ 尺寸不符合要求!实际: ${actualWidth}x${actualHeight}px,建议: ${expectedWidth}x${expectedHeight}px`;
  336. }
  337. };
  338. img.onerror = () => {
  339. validation.show = true;
  340. validation.type = 'warning';
  341. validation.message = '图片加载失败,无法验证尺寸';
  342. };
  343. img.src = imageUrl;
  344. },
  345. handleClick(tab, event) {
  346. this.queryParams.status=tab.name;
  347. this.getList();
  348. },
  349. /** 查询活动列表 */
  350. getList() {
  351. this.loading = true;
  352. listStoreActivity(this.queryParams).then(response => {
  353. this.storeActivityList = response.rows;
  354. this.total = response.total;
  355. this.loading = false;
  356. });
  357. },
  358. // 取消按钮
  359. cancel() {
  360. this.open = false;
  361. this.reset();
  362. },
  363. // 表单重置
  364. reset() {
  365. this.form = {
  366. activityId: null,
  367. title: null,
  368. descs: null,
  369. logoUrl: null,
  370. images: null,
  371. productIds: null,
  372. content: null,
  373. createTime: null,
  374. status: "1"
  375. };
  376. this.imageArr=[];
  377. this.photoArr=[];
  378. this.products=[];
  379. this.products=[];
  380. // 重置验证状态
  381. this.logoValidation = { show: false, type: 'success', message: '' };
  382. this.bannerValidation = { show: false, type: 'success', message: '' };
  383. this.resetForm("form");
  384. },
  385. /** 搜索按钮操作 */
  386. handleQuery() {
  387. this.queryParams.pageNum = 1;
  388. this.getList();
  389. },
  390. /** 重置按钮操作 */
  391. resetQuery() {
  392. this.resetForm("queryForm");
  393. this.handleQuery();
  394. },
  395. // 多选框选中数据
  396. handleSelectionChange(selection) {
  397. this.ids = selection.map(item => item.activityId)
  398. this.single = selection.length!==1
  399. this.multiple = !selection.length
  400. },
  401. /** 新增按钮操作 */
  402. handleAdd() {
  403. this.reset();
  404. this.open = true;
  405. this.title = "添加活动";
  406. setTimeout(() => {
  407. this.$refs.myeditor.setText("");
  408. }, 200);
  409. },
  410. /** 修改按钮操作 */
  411. handleUpdate(row) {
  412. this.reset();
  413. const activityId = row.activityId || this.ids
  414. getStoreActivity(activityId).then(response => {
  415. this.form = response.activity;
  416. this.form.status=this.form.status.toString();
  417. if(this.form.logoUrl!=null){
  418. this.imageArr=this.form.logoUrl.split(',');
  419. }
  420. if(this.form.images!=null){
  421. this.photoArr=this.form.images.split(',');
  422. }
  423. this.products=response.products;
  424. this.open = true;
  425. this.title = "修改活动";
  426. setTimeout(() => {
  427. if(this.form.content==null){
  428. this.$refs.myeditor.setText("");
  429. }
  430. else{
  431. this.$refs.myeditor.setText(this.form.content);
  432. }
  433. }, 200);
  434. });
  435. },
  436. /** 提交按钮 */
  437. submitForm() {
  438. this.$refs["form"].validate(valid => {
  439. if (valid) {
  440. var productIds=[];
  441. this.products.forEach(element => {
  442. productIds.push(element.productId);
  443. });
  444. this.form.productIds=productIds.toString();
  445. const savePromise = this.form.activityId != null
  446. ? updateStoreActivity(this.form)
  447. : addStoreActivity(this.form);
  448. savePromise.then(response => {
  449. if (response.code === 200) {
  450. this.msgSuccess(this.form.activityId != null ? "修改成功" : "新增成功");
  451. this.open = false;
  452. this.getList();
  453. }
  454. }).catch(error => {
  455. // 处理后端返回的图片校验错误
  456. if (error.response && error.response.data && error.response.data.msg) {
  457. const msg = error.response.data.msg;
  458. // 检查是否为图片尺寸验证错误
  459. if (msg.includes("图片") && (msg.includes("尺寸") || msg.includes("比例"))) {
  460. this.$message.error(msg);
  461. return;
  462. }
  463. // 其他业务错误
  464. this.$message.error(msg);
  465. return;
  466. }
  467. // 网络或其他未知错误
  468. this.$message.error("操作失败:" + (error.message || error));
  469. });
  470. }
  471. });
  472. },
  473. /** 删除按钮操作 */
  474. handleDelete(row) {
  475. const activityIds = row.activityId || this.ids;
  476. this.$confirm('是否确认删除活动编号为"' + activityIds + '"的数据项?', "警告", {
  477. confirmButtonText: "确定",
  478. cancelButtonText: "取消",
  479. type: "warning"
  480. }).then(function() {
  481. return delStoreActivity(activityIds);
  482. }).then(() => {
  483. this.getList();
  484. this.msgSuccess("删除成功");
  485. }).catch(function() {});
  486. },
  487. /** 导出按钮操作 */
  488. handleExport() {
  489. const queryParams = this.queryParams;
  490. this.$confirm('是否确认导出所有活动数据项?', "警告", {
  491. confirmButtonText: "确定",
  492. cancelButtonText: "取消",
  493. type: "warning"
  494. }).then(function() {
  495. return exportStoreActivity(queryParams);
  496. }).then(response => {
  497. this.download(response.msg);
  498. }).catch(function() {});
  499. }
  500. }
  501. };
  502. </script>
  503. <style scoped>
  504. .image-size-tip {
  505. margin-top: 5px;
  506. font-size: 12px;
  507. color: #909399;
  508. display: flex;
  509. align-items: center;
  510. }
  511. .image-size-tip i {
  512. margin-right: 5px;
  513. color: #409EFF;
  514. }
  515. .validation-message {
  516. margin-top: 8px;
  517. padding: 6px 10px;
  518. border-radius: 4px;
  519. font-size: 12px;
  520. display: flex;
  521. align-items: center;
  522. animation: fadeIn 0.3s ease-in;
  523. }
  524. .validation-message i {
  525. margin-right: 6px;
  526. font-size: 14px;
  527. }
  528. .validation-message.success {
  529. background-color: #f0f9ff;
  530. border: 1px solid #b3d8ff;
  531. color: #67C23A;
  532. }
  533. .validation-message.success i {
  534. color: #67C23A;
  535. }
  536. .validation-message.warning {
  537. background-color: #fdf6ec;
  538. border: 1px solid #f5dab1;
  539. color: #E6A23C;
  540. }
  541. .validation-message.warning i {
  542. color: #E6A23C;
  543. }
  544. @keyframes fadeIn {
  545. from {
  546. opacity: 0;
  547. transform: translateY(-5px);
  548. }
  549. to {
  550. opacity: 1;
  551. transform: translateY(0);
  552. }
  553. }
  554. </style>