index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="120px">
  4. <el-form-item label="商品名称" prop="goodsName">
  5. <el-input
  6. v-model="queryParams.goodsName"
  7. placeholder="请输入商品名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="商品分类" prop="goodsType">
  14. <el-select v-model="queryParams.goodsType" placeholder="请选择商品分类" clearable size="small">
  15. <el-option
  16. v-for="dict in goodsTypeOptions"
  17. :key="dict.dictValue"
  18. :label="dict.dictLabel"
  19. :value="dict.dictValue"
  20. />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="状态" prop="status">
  24. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
  25. <el-option
  26. v-for="dict in statusOptions"
  27. :key="dict.dictValue"
  28. :label="dict.dictLabel"
  29. :value="dict.dictValue"
  30. />
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item label="状态" prop="status">
  34. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
  35. <el-option
  36. v-for="dict in statusOptions"
  37. :key="dict.dictValue"
  38. :label="dict.dictLabel"
  39. :value="dict.dictValue"
  40. />
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item label="所属小程序" prop="appId">
  44. <el-select style="width: 240px" v-model="queryParams.appId" placeholder="请选择所属小程序" clearable size="small">
  45. <el-option
  46. v-for="dict in appMallOptions"
  47. :key="dict.appid"
  48. :label="dict.name + '(' + dict.appid + ')'"
  49. :value="dict.appid"
  50. />
  51. </el-select>
  52. </el-form-item>
  53. <el-form-item>
  54. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  55. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  56. </el-form-item>
  57. </el-form>
  58. <el-row :gutter="10" class="mb8">
  59. <el-col :span="1.5">
  60. <el-button
  61. type="primary"
  62. plain
  63. icon="el-icon-plus"
  64. size="mini"
  65. @click="handleAdd"
  66. v-hasPermi="['his:integralGoods:add']"
  67. >新增</el-button>
  68. </el-col>
  69. <el-col :span="1.5">
  70. <el-button
  71. type="success"
  72. plain
  73. icon="el-icon-edit"
  74. size="mini"
  75. :disabled="single"
  76. @click="handleUpdate"
  77. v-hasPermi="['his:integralGoods:edit']"
  78. >修改</el-button>
  79. </el-col>
  80. <el-col :span="1.5">
  81. <el-button
  82. type="danger"
  83. plain
  84. icon="el-icon-delete"
  85. size="mini"
  86. :disabled="multiple"
  87. @click="handleDelete"
  88. v-hasPermi="['his:integralGoods:remove']"
  89. >删除</el-button>
  90. </el-col>
  91. <el-col :span="1.5">
  92. <el-button
  93. type="warning"
  94. plain
  95. icon="el-icon-download"
  96. size="mini"
  97. :loading="exportLoading"
  98. @click="handleExport"
  99. v-hasPermi="['his:integralGoods:export']"
  100. >导出</el-button>
  101. </el-col>
  102. <el-col :span="1.5">
  103. <el-button
  104. type="info"
  105. plain
  106. icon="el-icon-upload2"
  107. size="mini"
  108. @click="handleImport"
  109. v-hasPermi="['his:integralGoods:handleImport']"
  110. >导入</el-button>
  111. </el-col>
  112. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  113. </el-row>
  114. <el-table v-loading="loading" border :data="integralGoodsList" @selection-change="handleSelectionChange">
  115. <el-table-column type="selection" width="55" align="center" />
  116. <el-table-column label="封面图" align="center" prop="imgUrl" >
  117. <template slot-scope="scope">
  118. <el-popover
  119. placement="right"
  120. title=""
  121. trigger="hover"
  122. >
  123. <img slot="reference" :src="scope.row.imgUrl" width="100">
  124. <img :src="scope.row.imgUrl" style="max-width: 150px;">
  125. </el-popover>
  126. </template>
  127. </el-table-column>
  128. <el-table-column label="商品名称" align="center" prop="goodsName" />
  129. <el-table-column label="原价" align="center" prop="otPrice" />
  130. <el-table-column label="商品分类" align="center" prop="goodsType">
  131. <template slot-scope="scope">
  132. <dict-tag :options="goodsTypeOptions" :value="scope.row.goodsType"/>
  133. </template>
  134. </el-table-column>
  135. <el-table-column label="状态" align="center" prop="status">
  136. <template slot-scope="scope">
  137. <dict-tag :options="statusOptions" :value="scope.row.status"/>
  138. </template>
  139. </el-table-column>
  140. <el-table-column label="所需积分" align="center" prop="integral" />
  141. <!-- <el-table-column label="需支付金额" align="center" prop="cash" />-->
  142. <el-table-column label="排序" align="center" prop="sort" />
  143. <el-table-column label="库存" align="center" prop="stock" />
  144. <el-table-column label="创建时间" align="center" prop="createTime" width="180"/>
  145. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="150">
  146. <template slot-scope="scope">
  147. <el-button
  148. size="mini"
  149. type="text"
  150. icon="el-icon-edit"
  151. @click="handleUpdate(scope.row)"
  152. v-hasPermi="['his:integralGoods:edit']"
  153. >修改</el-button>
  154. <el-button
  155. size="mini"
  156. type="text"
  157. @click="handledetails(scope.row)"
  158. >详情
  159. </el-button>
  160. <el-button
  161. size="mini"
  162. type="text"
  163. icon="el-icon-delete"
  164. @click="handleDelete(scope.row)"
  165. v-hasPermi="['his:integralGoods:remove']"
  166. >删除</el-button>
  167. </template>
  168. </el-table-column>
  169. </el-table>
  170. <pagination
  171. v-show="total>0"
  172. :total="total"
  173. :page.sync="queryParams.pageNum"
  174. :limit.sync="queryParams.pageSize"
  175. @pagination="getList"
  176. />
  177. <!-- 添加或修改积分商品对话框 -->
  178. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
  179. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  180. <el-form-item label="商品名称" prop="goodsName">
  181. <el-input v-model="form.goodsName" placeholder="请输入商品名称" />
  182. </el-form-item>
  183. <el-form-item label="商品分类" prop="goodsType">
  184. <el-select v-model="form.goodsType" placeholder="请选择商品分类">
  185. <el-option
  186. v-for="dict in goodsTypeOptions"
  187. :key="dict.dictValue"
  188. :label="dict.dictLabel"
  189. :value="parseInt(dict.dictValue)"
  190. ></el-option>
  191. </el-select>
  192. </el-form-item>
  193. <el-form-item label="商品图片" prop="imgUrl">
  194. <Material v-model="imageArr" type="image" :num="1" :width="150" :height="150" />
  195. </el-form-item>
  196. <el-form-item label="轮播图" prop="images">
  197. <Material v-model="photoArr" type="image" :num="10" :width="150" :height="150" />
  198. </el-form-item>
  199. <el-form-item label="原价" prop="otPrice">
  200. <el-input-number v-model="form.otPrice" :precision="2" :step="0.1" ></el-input-number>
  201. </el-form-item>
  202. <el-form-item label="所需积分" prop="integral">
  203. <el-input-number v-model="form.integral" :min="0" label="所需积分"></el-input-number>
  204. </el-form-item>
  205. <!-- <el-form-item label="支付金额" prop="cash">-->
  206. <!-- <el-input-number v-model="form.cash" :min="0" :precision="2" :step="0.1" label="需支付金额"></el-input-number>-->
  207. <!-- </el-form-item>-->
  208. <el-form-item label="商品编号" prop="barCode">
  209. <el-input v-model="form.barCode" placeholder="请输入商品编号" style="width: 200px;"/>
  210. </el-form-item>
  211. <el-form-item label="排序" prop="sort">
  212. <el-input-number v-model="form.sort" :min="0" label="排序"></el-input-number>
  213. </el-form-item>
  214. <el-form-item label="详情">
  215. <Editor ref="myeditor" @on-text-change="updateText"/>
  216. </el-form-item>
  217. <el-form-item label="库存" prop="stock">
  218. <el-input-number v-model="form.stock" :min="0" label="库存"></el-input-number>
  219. </el-form-item>
  220. <el-form-item label="状态">
  221. <el-radio-group v-model="form.status">
  222. <el-radio
  223. v-for="dict in statusOptions"
  224. :key="dict.dictValue"
  225. :label="parseInt(dict.dictValue)"
  226. >{{dict.dictLabel}}</el-radio>
  227. </el-radio-group>
  228. </el-form-item>
  229. <el-form-item label="所属小程序" prop="appIds">
  230. <el-select style="width: 240px" v-model="appIds" placeholder="请选择所属小程序" clearable size="small" multiple>
  231. <el-option
  232. v-for="dict in appMallOptions"
  233. :key="dict.appid"
  234. :label="dict.name + '(' + dict.appid + ')'"
  235. :value="dict.appid"
  236. />
  237. </el-select>
  238. </el-form-item>
  239. </el-form>
  240. <div slot="footer" class="dialog-footer">
  241. <el-button type="primary" @click="submitForm">确 定</el-button>
  242. <el-button @click="cancel">取 消</el-button>
  243. </div>
  244. </el-dialog>
  245. <el-drawer
  246. :with-header="false"
  247. size="75%"
  248. :title="show.title" :visible.sync="show.open">
  249. <integralGoodsDetails ref="Details" />
  250. </el-drawer>
  251. <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
  252. <el-upload
  253. ref="upload"
  254. :limit="1"
  255. accept=".xlsx, .xls"
  256. :headers="upload.headers"
  257. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  258. :disabled="upload.isUploading"
  259. :on-progress="handleFileUploadProgress"
  260. :on-success="handleFileSuccess"
  261. :auto-upload="false"
  262. drag
  263. >
  264. <i class="el-icon-upload"></i>
  265. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  266. <div class="el-upload__tip text-center" slot="tip">
  267. <div class="el-upload__tip" slot="tip">
  268. <!-- <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的数据 -->
  269. </div>
  270. <span>仅允许导入xls、xlsx格式文件。</span>
  271. <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
  272. </div>
  273. </el-upload>
  274. <div slot="footer" class="dialog-footer">
  275. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  276. <el-button @click="upload.open = false">取 消</el-button>
  277. </div>
  278. </el-dialog>
  279. </div>
  280. </template>
  281. <script>
  282. import { importTemplate,listIntegralGoods, getIntegralGoods, delIntegralGoods, addIntegralGoods, updateIntegralGoods, exportIntegralGoods } from "@/api/hisStore/integralGoods";
  283. import Material from '@/components/Material';
  284. import Editor from '@/components/Editor/wang';
  285. import { getToken } from "@/utils/auth";
  286. import integralGoodsDetails from '../components/integralGoodsDetails';
  287. import { list as getAppMallOptions } from '@/api/course/coursePlaySourceConfig'
  288. export default {
  289. name: "HisIntegralGoods",
  290. components: {Material,Editor,integralGoodsDetails},
  291. watch: {
  292. imageArr: function(val) {
  293. this.form.imgUrl = val.join(',')
  294. },
  295. photoArr: function(val) {
  296. this.form.images = val.join(',')
  297. }
  298. },
  299. data() {
  300. return {
  301. appIds:[], // 选择的小程序
  302. // 小程序列表
  303. appMallOptions:[],
  304. show:{
  305. open:false,
  306. },
  307. upload: {
  308. // 是否显示弹出层
  309. open: false,
  310. // 弹出层标题
  311. title: "",
  312. // 是否禁用上传
  313. isUploading: false,
  314. // 是否更新已经存在的用户数据
  315. updateSupport: 0,
  316. // 设置上传的请求头部
  317. headers: { Authorization: "Bearer " + getToken() },
  318. // 上传的地址
  319. url: process.env.VUE_APP_BASE_API + "/his/integralGoods/importData"
  320. },
  321. photoArr:[],
  322. imageArr:[],
  323. // 遮罩层
  324. loading: true,
  325. // 导出遮罩层
  326. exportLoading: false,
  327. // 选中数组
  328. ids: [],
  329. // 非单个禁用
  330. single: true,
  331. // 非多个禁用
  332. multiple: true,
  333. // 显示搜索条件
  334. showSearch: true,
  335. // 总条数
  336. total: 0,
  337. // 积分商品表格数据
  338. integralGoodsList: [],
  339. // 弹出层标题
  340. title: "",
  341. // 是否显示弹出层
  342. open: false,
  343. // 商品分类字典
  344. goodsTypeOptions: [],
  345. // 状态字典
  346. statusOptions: [],
  347. // 查询参数
  348. queryParams: {
  349. pageNum: 1,
  350. pageSize: 10,
  351. goodsName: null,
  352. goodsType: null,
  353. status: null,
  354. appId: null,
  355. integral: null,
  356. createTime: null
  357. },
  358. // 表单参数
  359. form: {},
  360. // 表单校验
  361. rules: {
  362. imgUrl: [
  363. { required: true, message: "封面图不能为空", trigger: "submit" }
  364. ],
  365. goodsName: [
  366. { required: true, message: "商品名称不能为空", trigger: "submit" }
  367. ],
  368. }
  369. };
  370. },
  371. created() {
  372. this.getList();
  373. // 查询小程序
  374. this.getAppMallOptions();
  375. this.getDicts("sys_integral_goods_type").then(response => {
  376. this.goodsTypeOptions = response.data;
  377. });
  378. this.getDicts("sys_company_status").then(response => {
  379. this.statusOptions = response.data;
  380. });
  381. },
  382. methods: {
  383. getAppMallOptions() {
  384. getAppMallOptions({pageNum:1,pageSize:100}).then(response => {
  385. this.appMallOptions = response.rows;
  386. })
  387. },
  388. handledetails(row){
  389. this.show.open=true;
  390. setTimeout(() => {
  391. this.$refs.Details.getDetails(row.goodsId);
  392. }, 1);
  393. },
  394. /** 导入按钮操作 */
  395. handleImport() {
  396. this.upload.title = "导入";
  397. this.upload.open = true;
  398. },
  399. /** 下载模板操作 */
  400. importTemplate() {
  401. importTemplate().then(response => {
  402. this.download(response.msg);
  403. });
  404. },
  405. // 文件上传中处理
  406. handleFileUploadProgress(event, file, fileList) {
  407. this.upload.isUploading = true;
  408. },
  409. // 文件上传成功处理
  410. handleFileSuccess(response, file, fileList) {
  411. this.upload.open = false;
  412. this.upload.isUploading = false;
  413. this.$refs.upload.clearFiles();
  414. this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
  415. this.getList();
  416. },
  417. // 提交上传文件
  418. submitFileForm() {
  419. this.$refs.upload.submit();
  420. },
  421. /** 查询积分商品列表 */
  422. getList() {
  423. this.loading = true;
  424. listIntegralGoods(this.queryParams).then(response => {
  425. this.integralGoodsList = response.rows;
  426. this.total = response.total;
  427. this.loading = false;
  428. });
  429. },
  430. updateText(text){
  431. this.form.descs=text
  432. },
  433. // 取消按钮
  434. cancel() {
  435. this.open = false;
  436. this.reset();
  437. },
  438. // 表单重置
  439. reset() {
  440. this.form = {
  441. goodsId: null,
  442. imgUrl: null,
  443. images: null,
  444. goodsName: null,
  445. otPrice: null,
  446. goodsType: null,
  447. status: 0,
  448. cash: 0,
  449. integral: null,
  450. sort: null,
  451. stock: null,
  452. descs: null,
  453. createTime: null
  454. };
  455. this.imageArr = [];
  456. this.photoArr = [];
  457. this.resetForm("form");
  458. },
  459. /** 搜索按钮操作 */
  460. handleQuery() {
  461. this.queryParams.pageNum = 1;
  462. this.getList();
  463. },
  464. /** 重置按钮操作 */
  465. resetQuery() {
  466. this.resetForm("queryForm");
  467. this.handleQuery();
  468. },
  469. // 多选框选中数据
  470. handleSelectionChange(selection) {
  471. this.ids = selection.map(item => item.goodsId)
  472. this.single = selection.length!==1
  473. this.multiple = !selection.length
  474. },
  475. /** 新增按钮操作 */
  476. handleAdd() {
  477. this.reset();
  478. this.open = true;
  479. this.title = "添加积分商品";
  480. //新增
  481. setTimeout(() => {
  482. this.$refs.myeditor.setText("");
  483. }, 500);
  484. },
  485. /** 修改按钮操作 */
  486. handleUpdate(row) {
  487. this.reset();
  488. const goodsId = row.goodsId || this.ids
  489. getIntegralGoods(goodsId).then(response => {
  490. this.form = response.data;
  491. this.open = true;
  492. this.title = "修改积分商品";
  493. if(this.form.imgUrl!=null){
  494. this.imageArr=this.form.imgUrl.split(",");
  495. }
  496. if(this.form.images!=null){
  497. this.photoArr=this.form.images.split(",");
  498. }
  499. this.appIds = this.form.appIds ? this.form.appIds.split(',') : [];
  500. //修改按钮
  501. setTimeout(() => {
  502. if(this.form.descs==null){
  503. this.$refs.myeditor.setText("");
  504. }
  505. else{
  506. this.$refs.myeditor.setText(this.form.descs);
  507. }
  508. }, 1);
  509. });
  510. },
  511. /** 提交按钮 */
  512. submitForm() {
  513. this.$refs["form"].validate(valid => {
  514. if (valid) {
  515. // 小程序
  516. const params = {
  517. ...this.form,
  518. appIds: this.appIds.join(',') // 数组转字符串
  519. };
  520. if (this.form.goodsId != null) {
  521. updateIntegralGoods(params).then(response => {
  522. this.msgSuccess("修改成功");
  523. this.open = false;
  524. this.reset();
  525. this.getList();
  526. });
  527. } else {
  528. addIntegralGoods(params).then(response => {
  529. this.msgSuccess("新增成功");
  530. this.open = false;
  531. this.reset();
  532. this.getList();
  533. });
  534. }
  535. }
  536. });
  537. },
  538. /** 删除按钮操作 */
  539. handleDelete(row) {
  540. const goodsIds = row.goodsId || this.ids;
  541. this.$confirm('是否确认删除积分商品编号为"' + goodsIds + '"的数据项?', "警告", {
  542. confirmButtonText: "确定",
  543. cancelButtonText: "取消",
  544. type: "warning"
  545. }).then(function() {
  546. return delIntegralGoods(goodsIds);
  547. }).then(() => {
  548. this.getList();
  549. this.msgSuccess("删除成功");
  550. }).catch(() => {});
  551. },
  552. /** 导出按钮操作 */
  553. handleExport() {
  554. const queryParams = this.queryParams;
  555. this.$confirm('是否确认导出所有积分商品数据项?', "警告", {
  556. confirmButtonText: "确定",
  557. cancelButtonText: "取消",
  558. type: "warning"
  559. }).then(() => {
  560. this.exportLoading = true;
  561. return exportIntegralGoods(queryParams);
  562. }).then(response => {
  563. this.download(response.msg);
  564. this.exportLoading = false;
  565. }).catch(() => {});
  566. }
  567. }
  568. };
  569. </script>