index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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="verifyCode">
  5. <el-input
  6. v-model="queryParams.verifyCode"
  7. placeholder="核销码"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <!-- 出库状态筛选 -->
  14. <el-form-item label="出库状态" prop="outboundStatus">
  15. <el-select v-model="queryParams.outboundStatus" placeholder="请选择出库状态" clearable size="small">
  16. <el-option label="未出库" value="0" />
  17. <el-option label="已出库" value="1" />
  18. </el-select>
  19. </el-form-item>
  20. <!-- 核销状态筛选 -->
  21. <el-form-item label="核销状态" prop="verifyStatus">
  22. <el-select v-model="queryParams.verifyStatus" placeholder="请选择核销状态" clearable size="small">
  23. <el-option label="未核销" value="0" />
  24. <el-option label="已核销" value="1" />
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item>
  28. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  29. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  30. </el-form-item>
  31. </el-form>
  32. <el-row :gutter="10" class="mb8">
  33. <el-col :span="1.5">
  34. <el-button
  35. type="primary"
  36. plain
  37. icon="el-icon-plus"
  38. size="mini"
  39. @click="handleAdd"
  40. v-hasPermi="['shop:scrm:add']"
  41. >新增</el-button>
  42. </el-col>
  43. <el-col :span="1.5">
  44. <el-button
  45. type="success"
  46. plain
  47. icon="el-icon-edit"
  48. size="mini"
  49. :disabled="single"
  50. @click="handleUpdate"
  51. v-hasPermi="['shop:scrm:edit']"
  52. >修改</el-button>
  53. </el-col>
  54. <el-col :span="1.5">
  55. <el-button
  56. type="danger"
  57. plain
  58. icon="el-icon-delete"
  59. size="mini"
  60. :disabled="multiple"
  61. @click="handleDelete"
  62. v-hasPermi="['shop:scrm:remove']"
  63. >删除</el-button>
  64. </el-col>
  65. <el-col :span="1.5">
  66. <el-button
  67. type="warning"
  68. plain
  69. icon="el-icon-download"
  70. size="mini"
  71. :loading="exportLoading"
  72. @click="handleExport"
  73. v-hasPermi="['shop:scrm:export']"
  74. >导出</el-button>
  75. </el-col>
  76. <!-- 新增:批量核销按钮 -->
  77. <el-col :span="1.8">
  78. <el-button
  79. type="info"
  80. plain
  81. icon="el-icon-check-circle"
  82. size="mini"
  83. :disabled="multiple || hasWriteOffAll"
  84. @click="handleBatchWriteOff"
  85. v-hasPermi="['shop:scrm:writeOff']"
  86. >批量核销</el-button>
  87. </el-col>
  88. <el-col :span="1.8">
  89. <el-button
  90. icon="el-icon-s-order"
  91. size="mini"
  92. type="warning"
  93. @click="openDeliveryNote"
  94. >批量导入溯源码
  95. </el-button>
  96. </el-col>
  97. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  98. </el-row>
  99. <el-table border v-loading="loading" :data="scrmList" @selection-change="handleSelectionChange">
  100. <el-table-column type="selection" width="55" align="center" />
  101. <el-table-column label="主键ID" align="center" prop="id" />
  102. <el-table-column label="核销码" align="center" prop="verifyCode" />
  103. <el-table-column label="关联商品ID" align="center" prop="productId" />
  104. <el-table-column
  105. label="出库状态"
  106. align="center"
  107. prop="outboundStatus"
  108. :formatter="formatOutboundStatus"
  109. />
  110. <el-table-column
  111. label="核销状态"
  112. align="center"
  113. prop="verifyStatus"
  114. :formatter="formatVerifyStatus"
  115. />
  116. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  117. <template slot-scope="scope">
  118. <el-button
  119. size="mini"
  120. type="text"
  121. icon="el-icon-edit"
  122. @click="handleUpdate(scope.row)"
  123. v-hasPermi="['shop:scrm:edit']"
  124. >修改</el-button>
  125. <el-button
  126. size="mini"
  127. type="text"
  128. icon="el-icon-delete"
  129. @click="handleDelete(scope.row)"
  130. v-hasPermi="['shop:scrm:remove']"
  131. >删除</el-button>
  132. <!-- 新增:单个核销按钮 -->
  133. <el-button
  134. size="mini"
  135. type="text"
  136. icon="el-icon-check"
  137. :disabled="scope.row.verifyStatus === 1"
  138. @click="handleSingleWriteOff(scope.row)"
  139. v-hasPermi="['shop:scrm:writeOff']"
  140. >核销</el-button>
  141. </template>
  142. </el-table-column>
  143. </el-table>
  144. <pagination
  145. v-show="total>0"
  146. :total="total"
  147. :page.sync="queryParams.pageNum"
  148. :limit.sync="queryParams.pageSize"
  149. @pagination="getList"
  150. />
  151. <!-- 添加或修改核销码对话框 -->
  152. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  153. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  154. <!-- 用户自定义核销码 -->
  155. <el-form-item label="核销码" prop="verifyCode">
  156. <el-input v-model="form.verifyCode" placeholder="核销码" />
  157. </el-form-item>
  158. <el-form-item label="出库状态" prop="outboundStatus">
  159. <el-radio-group v-model="form.outboundStatus">
  160. <el-radio :label="0">未出库</el-radio>
  161. <el-radio :label="1">已出库</el-radio>
  162. </el-radio-group>
  163. </el-form-item>
  164. <!-- 核销状态 -->
  165. <el-form-item label="核销状态" prop="verifyStatus">
  166. <el-radio-group v-model="form.verifyStatus">
  167. <el-radio :label="0">未核销</el-radio>
  168. <el-radio :label="1">已核销</el-radio>
  169. </el-radio-group>
  170. </el-form-item>
  171. </el-form>
  172. <div slot="footer" class="dialog-footer">
  173. <el-button type="primary" @click="submitForm">确 定</el-button>
  174. <el-button @click="cancel">取 消</el-button>
  175. </div>
  176. </el-dialog>
  177. <el-dialog
  178. :before-close="handleClose"
  179. :visible.sync="verifyNoteOpen"
  180. center
  181. title="批量导入溯源码"
  182. width="35%"
  183. :append-to-body="true"
  184. >
  185. <span slot="footer" class="dialog-footer">
  186. <el-upload ref="upload" :action="getUploadUrl()" :auto-upload="false" :disabled="verifyUpload.isUploading"
  187. :headers="verifyUpload.headers"
  188. :limit="1" :on-progress="handleFileUploadProgress"
  189. :on-success="handleFileSuccess" accept=".xlsx, .xls" drag
  190. >
  191. <i class="el-icon-upload"></i>
  192. <div class="el-upload__text">
  193. 将文件拖到此处,或
  194. <em>点击上传</em>
  195. </div>
  196. <div slot="tip" class="el-upload__tip">
  197. <el-link style="font-size:12px" type="info" @click="importVerifyNoteTemplate">下载模板</el-link>
  198. </div>
  199. <div slot="tip" class="el-upload__tip" style="color:red">提示:仅允许导入“xls”或“xlsx”格式文件!</div>
  200. </el-upload>
  201. <el-divider></el-divider>
  202. <el-button @click="verifyNoteOpen = false">取 消</el-button>
  203. <el-button type="primary" @click="submitDeliveryNote">确 定</el-button>
  204. </span>
  205. </el-dialog>
  206. </div>
  207. </template>
  208. <script>
  209. import { listScrm, getScrm, delScrm, addScrm, updateScrm, exportScrm ,importVerifyNoteTemplate,writeOff} from "@/api/hisStore/verify";
  210. import { getToken } from '@/utils/auth'
  211. export default {
  212. name: "Scrm",
  213. props: {
  214. productId: {
  215. type: [Number, String],
  216. default: null,
  217. required: false
  218. }
  219. },
  220. data() {
  221. return {
  222. importMsgOpen: false,
  223. importMsg: '',
  224. verifyUpload: {
  225. open: false,
  226. title: '',
  227. isUploading: false,
  228. updateSupport: 0,
  229. headers: {Authorization: 'Bearer ' + getToken()},
  230. url: process.env.VUE_APP_BASE_API + '/shop/scrm/importExpress',
  231. },
  232. verifyNoteOpen: false,
  233. loading: true,
  234. exportLoading: false,
  235. ids: [],
  236. single: true,
  237. multiple: true,
  238. hasWriteOffAll: false,
  239. showSearch: true,
  240. total: 0,
  241. scrmList: [],
  242. title: "",
  243. open: false,
  244. queryParams: {
  245. pageNum: 1,
  246. pageSize: 10,
  247. verifyCode: null,
  248. productId: null,
  249. outboundStatus: null,
  250. verifyStatus: null,
  251. status: null,
  252. isDel: null,
  253. },
  254. form: {},
  255. rules: {
  256. verifyCode: [
  257. { required: true, message: "用户自定义核销码不能为空", trigger: "blur" }
  258. ],
  259. productId: [
  260. { required: true, message: "关联商品ID不能为空", trigger: "blur" }
  261. ],
  262. outboundStatus: [
  263. { required: true, message: "出库状态不能为空", trigger: "blur" }
  264. ],
  265. verifyStatus: [
  266. { required: true, message: "核销状态不能为空", trigger: "blur" }
  267. ],
  268. status: [
  269. { required: true, message: "数据状态不能为空", trigger: "blur" }
  270. ],
  271. isDel: [
  272. { required: true, message: "是否删除不能为空", trigger: "blur" }
  273. ],
  274. createTime: [
  275. { required: true, message: "创建时间不能为空", trigger: "blur" }
  276. ],
  277. updateTime: [
  278. { required: true, message: "更新时间不能为空", trigger: "blur" }
  279. ]
  280. },
  281. };
  282. },
  283. created() {
  284. this.getList();
  285. },
  286. methods: {
  287. fullReset() {
  288. this.reset();
  289. this.queryParams = {
  290. pageNum: 1,
  291. pageSize: 10,
  292. verifyCode: null,
  293. productId: null,
  294. outboundStatus: null,
  295. verifyStatus: null,
  296. status: null,
  297. isDel: null,
  298. };
  299. this.scrmList = [];
  300. this.total = 0;
  301. this.ids = [];
  302. this.single = true;
  303. this.multiple = true;
  304. this.hasWriteOffAll = false;
  305. if (this.$refs.form) {
  306. this.$refs.form.clearValidate();
  307. }
  308. },
  309. // 出库状态翻译
  310. formatOutboundStatus(row) {
  311. return row.outboundStatus === 0 ? "未出库" : "已出库";
  312. },
  313. // 核销状态翻译
  314. formatVerifyStatus(row) {
  315. return row.verifyStatus === 0 ? "未核销" : "已核销";
  316. },
  317. // 是否删除翻译
  318. formatIsDel(row) {
  319. return row.isDel === 0 ? "未删除" : "已删除";
  320. },
  321. /** 查询核销码列表 */
  322. getList() {
  323. this.loading = true;
  324. this.queryParams.productId = this.productId;
  325. console.log("打印pp----------------->", this.productId);
  326. listScrm(this.queryParams).then(response => {
  327. this.scrmList = response.rows;
  328. this.total = response.total;
  329. this.loading = false;
  330. });
  331. },
  332. // 取消按钮
  333. cancel() {
  334. this.open = false;
  335. this.reset();
  336. },
  337. // 表单重置
  338. reset() {
  339. this.form = {
  340. id: null,
  341. verifyCode: null,
  342. productId: this.productId,
  343. outboundStatus: 0,
  344. verifyStatus: 0,
  345. status: 1,
  346. isDel: 0
  347. };
  348. if (this.$refs.form) {
  349. this.$refs.form.resetFields();
  350. }
  351. },
  352. /** 搜索按钮操作 */
  353. handleQuery() {
  354. this.queryParams.pageNum = 1;
  355. this.getList();
  356. },
  357. /** 重置按钮操作 */
  358. resetQuery() {
  359. this.resetForm("queryForm");
  360. this.handleQuery();
  361. },
  362. // 多选框选中数据 - 新增:校验选中行的核销状态
  363. handleSelectionChange(selection) {
  364. this.ids = selection.map(item => item.id);
  365. this.single = selection.length !== 1;
  366. this.multiple = !selection.length;
  367. // 校验选中的行是否全部已核销
  368. this.hasWriteOffAll = selection.every(item => item.verifyStatus === 1);
  369. },
  370. /** 新增按钮操作 */
  371. handleAdd() {
  372. this.reset();
  373. this.open = true;
  374. this.title = "添加核销码";
  375. },
  376. /** 修改按钮操作 */
  377. handleUpdate(row) {
  378. this.reset();
  379. const id = row.id || this.ids
  380. getScrm(id).then(response => {
  381. this.form = response.data;
  382. this.open = true;
  383. this.title = "修改核销码";
  384. });
  385. },
  386. /** 提交按钮 */
  387. submitForm() {
  388. this.$refs["form"].validate(valid => {
  389. if (valid) {
  390. if (this.form.id != null) {
  391. updateScrm(this.form).then(response => {
  392. this.msgSuccess("修改成功");
  393. this.open = false;
  394. this.getList();
  395. });
  396. } else {
  397. addScrm(this.form).then(response => {
  398. this.msgSuccess("新增成功");
  399. this.open = false;
  400. this.getList();
  401. });
  402. }
  403. }
  404. });
  405. },
  406. /** 删除按钮操作 */
  407. handleDelete(row) {
  408. const ids = row.id || this.ids;
  409. this.$confirm('是否确认删除核销码编号为"' + ids + '"的数据项?', "警告", {
  410. confirmButtonText: "确定",
  411. cancelButtonText: "取消",
  412. type: "warning"
  413. }).then(function() {
  414. return delScrm(ids);
  415. }).then(() => {
  416. this.getList();
  417. this.msgSuccess("删除成功");
  418. }).catch(() => {});
  419. },
  420. /** 导出按钮操作 */
  421. handleExport() {
  422. const queryParams = this.queryParams;
  423. this.$confirm('是否确认导出所有核销码数据项?', "警告", {
  424. confirmButtonText: "确定",
  425. cancelButtonText: "取消",
  426. type: "warning"
  427. }).then(() => {
  428. this.exportLoading = true;
  429. return exportScrm(queryParams);
  430. }).then(response => {
  431. this.download(response.msg);
  432. this.exportLoading = false;
  433. }).catch(() => {});
  434. },
  435. openDeliveryNote() {
  436. this.verifyNoteOpen = true
  437. this.getAppList();
  438. },
  439. handleClose(done) {
  440. this.$confirm('确认关闭?')
  441. .then(_ => {
  442. done()
  443. })
  444. .catch(_ => {
  445. })
  446. },
  447. // 文件上传中处理
  448. handleFileUploadProgress(event, file, fileList) {
  449. this.verifyUpload.isUploading = true
  450. },
  451. // 文件上传成功处理
  452. handleFileSuccess(response, file, fileList) {
  453. this.verifyUpload.open = false;
  454. this.verifyUpload.isUploading = false;
  455. this.$refs.upload.clearFiles();
  456. this.importMsgOpen = true;
  457. this.importMsg = response.msg;
  458. console.log("打印请求-----------》",response.msg);
  459. if(response.code == 200) {
  460. this.$message.success(response.msg || '全部数据导入成功');
  461. }
  462. this.getList();
  463. },
  464. //发货单模板下载
  465. importVerifyNoteTemplate() {
  466. importVerifyNoteTemplate().then((response) => {
  467. this.download(response.msg);
  468. });
  469. },
  470. // 提交发货单
  471. submitDeliveryNote() {
  472. const uploadFiles = this.$refs.upload.uploadFiles;
  473. if (uploadFiles.length === 0) {
  474. this.$message.error('请选择要上传的文件');
  475. return;
  476. }
  477. this.$refs.upload.submit();
  478. },
  479. getUploadUrl() {
  480. if (!this.productId) {
  481. this.$message.warning('请先选择商品ID');
  482. return '';
  483. }
  484. return `${this.verifyUpload.url}?productId=${this.productId}`;
  485. },
  486. /** 单个核销操作 */
  487. handleSingleWriteOff(row) {
  488. this.$confirm(
  489. `是否确认核销溯源码【${row.verifyCode}】?`,
  490. "核销确认",
  491. {
  492. confirmButtonText: "确定",
  493. cancelButtonText: "取消",
  494. type: "info"
  495. }
  496. ).then(() => {
  497. return writeOff({ids:[row.id]});
  498. }).then(response => {
  499. if (response.code === 200) {
  500. this.msgSuccess("核销成功!");
  501. this.getList(); // 刷新列表
  502. }
  503. })
  504. },
  505. /** 批量核销操作 */
  506. handleBatchWriteOff() {
  507. this.$confirm(
  508. `是否确认核销选中的${this.ids.length}条溯源码数据?`,
  509. "批量核销确认",
  510. {
  511. confirmButtonText: "确定",
  512. cancelButtonText: "取消",
  513. type: "info"
  514. }
  515. ).then(() => {
  516. // 调用核销接口
  517. return writeOff({ids:this.ids});
  518. }).then(response => {
  519. if (response.code === 200) {
  520. this.msgSuccess(`批量核销成功!共核销${this.ids.length}条数据`);
  521. this.getList();
  522. this.ids = [];
  523. this.hasWriteOffAll = false;
  524. }
  525. })
  526. }
  527. }
  528. };
  529. </script>