uploadExcel.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. <template>
  2. <el-dialog
  3. title="提示"
  4. :visible.sync="uploadVisible"
  5. width="85%"
  6. :close-on-click-modal="false"
  7. @close="handleClose"
  8. v-dialogDrag
  9. >
  10. <span>
  11. <div
  12. style="
  13. display: flex;
  14. justify-content: space-between;
  15. "
  16. >
  17. <div style="display: flex;;margin-bottom: 10px;">
  18. <el-upload
  19. :action="actionUrl"
  20. multiple
  21. :on-progress="progress"
  22. :headers="headers"
  23. :show-file-list="false"
  24. :on-success="
  25. (res) => {
  26. handleSucces(res);
  27. }
  28. "
  29. >
  30. <el-button size="small" type="primary">导入Excel</el-button>
  31. </el-upload>
  32. <el-button
  33. v-if="false"
  34. size="small"
  35. type="primary"
  36. @click="bathHandle"
  37. :disabled="selection.length != 1"
  38. style="margin-left:10px"
  39. >批量处理属性(详情)</el-button
  40. >
  41. </div>
  42. <div style="margin: 0 10px">
  43. <el-button
  44. icon="el-icon-setting"
  45. size="mini"
  46. circle
  47. @click="showSetting = !showSetting"
  48. ></el-button>
  49. </div>
  50. </div>
  51. <el-table :data="excelList" @selection-change="Selectinventory" v-loading="loading" element-loading-text="努力加载中">
  52. <el-table-column type="selection" width="50" align="center" fixed />
  53. <el-table-column
  54. label="序号"
  55. type="index"
  56. width="50"
  57. fixed
  58. align="center"
  59. />
  60. <el-table-column
  61. v-for="(item, index) in getRowList"
  62. :key="index"
  63. :label="item.name"
  64. :width="item.width"
  65. :prop="item.label"
  66. align="center"
  67. :fixed="item.fixed"
  68. sortable
  69. >
  70. <template slot-scope="scope">
  71. <span v-if="item.label == 'fBsdate'">
  72. <el-date-picker
  73. v-model="scope.row.fBsdate"
  74. type="date"
  75. style="width: 100%"
  76. value-format="timestamp"
  77. placeholder="入库日期"
  78. @change="dateSelected(scope,'fBsdate')"
  79. >
  80. </el-date-picker>
  81. </span>
  82. <span v-else-if="item.label == 'fGoodsid'">
  83. <el-select
  84. filterable
  85. v-model="scope.row.fGoodsid"
  86. style="width: 100%"
  87. placeholder="请选择品名"
  88. @change="dateSelected(scope,'fGoodsid')"
  89. >
  90. <el-option
  91. v-for="(item, index) in goodsOptions"
  92. :key="index.fId"
  93. :label="item.fName"
  94. :value="item.fId"
  95. ></el-option>
  96. </el-select>
  97. </span>
  98. <span v-else-if="item.label == 'fBusinessType'">
  99. <el-select
  100. filterable
  101. v-model="scope.row.fBusinessType"
  102. style="width: 100%"
  103. placeholder="请选择商品属性"
  104. @change="dateSelected(scope,'fBusinessType')"
  105. >
  106. <el-option
  107. v-for="(item, index) in fStorageTypeOptions"
  108. :key="index.dictValue"
  109. :label="item.dictLabel"
  110. :value="item.dictValue"
  111. />
  112. </el-select>
  113. </span>
  114. <span v-else-if="item.label == 'fMarks'">
  115. <el-input
  116. v-model="scope.row.fMarks"
  117. style="width: 100%"
  118. placeholder="请填写属性描述"
  119. @change="dateSelected(scope,'fMarks')"
  120. />
  121. </span>
  122. <span v-else-if="item.label == 'fWarehouseInformation'">
  123. <el-input
  124. placeholder="请选择"
  125. v-model="scope.row.fWarehouseInformation"
  126. @focus="getTreeselect(scope)"
  127. >
  128. </el-input>
  129. </span>
  130. <span v-else-if="item.label == 'fQty'">
  131. <el-input
  132. v-input-limit="0"
  133. v-model.number="scope.row.fQty"
  134. style="width: 100%"
  135. placeholder="件数"
  136. />
  137. </span>
  138. <span v-else-if="item.label == 'fGrossweight'">
  139. <el-input
  140. v-model.number="scope.row.fGrossweight"
  141. v-input-limit="2"
  142. style="width: 100%"
  143. placeholder="毛重"
  144. />
  145. </span>
  146. <span v-else-if="item.label == 'fNetweight'">
  147. <el-input
  148. v-model.number="scope.row.fNetweight"
  149. v-input-limit="2"
  150. style="width: 100%"
  151. placeholder="净重"
  152. />
  153. </span>
  154. <span v-else-if="item.label == 'fPackagespecs'">
  155. <el-input
  156. v-model="scope.row.fPackagespecs"
  157. style="width: 100%"
  158. placeholder="包装规格"
  159. />
  160. </span>
  161. <span v-else-if="item.label == 'fELabel'">
  162. <el-input
  163. v-model="scope.row.fELabel"
  164. style="width: 100%"
  165. placeholder="电子标签"
  166. />
  167. </span>
  168. <span v-else-if="item.label == 'fCntrno'">
  169. <el-input
  170. v-model="scope.row.fCntrno"
  171. style="width: 100%"
  172. placeholder="箱号"
  173. v-Alphabet
  174. @change="unRepeat(scope.row.fCntrno, scope.$index)"
  175. />
  176. </span>
  177. <span v-else-if="item.label == 'fTruckno'">
  178. <el-input
  179. v-model="scope.row.fTruckno"
  180. style="width: 100%"
  181. placeholder="车号"
  182. v-Alphabet
  183. />
  184. </span>
  185. <span v-else>{{ scope.row[item.label] }}</span>
  186. </template>
  187. </el-table-column>
  188. </el-table>
  189. <el-dialog
  190. title="自定义列显示"
  191. :visible.sync="showSetting"
  192. width="700px"
  193. v-dialogDrag
  194. :close-on-click-modal="false"
  195. append-to-body
  196. >
  197. <template slot="title">
  198. <div class="avue-crud__dialog__header">
  199. <span class="el-dialog__title">
  200. <span
  201. style="
  202. display: inline-block;
  203. width: 3px;
  204. height: 20px;
  205. margin-right: 5px;
  206. float: left;
  207. margin-top: 2px;
  208. "
  209. ></span>
  210. </span>
  211. </div>
  212. </template>
  213. <div>配置排序列数据(拖动调整顺序)</div>
  214. <div style="margin-left: 17px">
  215. <el-checkbox
  216. v-model="allCheck"
  217. label="全选"
  218. @change="allChecked"
  219. ></el-checkbox>
  220. </div>
  221. <div style="padding: 4px; display: flex; justify-content: center">
  222. <draggable
  223. v-model="setRowList"
  224. group="site"
  225. animation="300"
  226. @start="onStart"
  227. @end="onEnd"
  228. handle=".indraggable"
  229. >
  230. <transition-group>
  231. <div
  232. v-for="item in setRowList"
  233. :key="item.surface"
  234. class="listStyle"
  235. >
  236. <div style="width: 500px" class="indraggable">
  237. <div class="progress" :style="{ width: item.width + 'px' }">
  238. <el-checkbox
  239. :label="item.name"
  240. v-model="item.checked"
  241. :true-label="0"
  242. :false-label="1"
  243. >{{ item.name }}
  244. </el-checkbox>
  245. </div>
  246. </div>
  247. <el-input-number
  248. v-model.number="item.width"
  249. controls-position="right"
  250. :min="1"
  251. :max="500"
  252. size="mini"
  253. ></el-input-number>
  254. </div>
  255. </transition-group>
  256. </draggable>
  257. </div>
  258. <span slot="footer" class="dialog-footer">
  259. <el-button @click="showSetting = false">取 消</el-button>
  260. <el-button @click="delRow" type="danger">重 置</el-button>
  261. <el-button type="primary" @click="save()">确 定</el-button>
  262. </span>
  263. </el-dialog>
  264. </span>
  265. <span slot="footer" class="dialog-footer">
  266. <el-button @click="uploadVisible = false">取 消</el-button>
  267. <el-button type="primary" @click="importData">确 定</el-button>
  268. </span>
  269. <el-dialog
  270. title="选择库位"
  271. :data="treeselectList"
  272. :visible.sync="choiceWarehouse"
  273. width="30%"
  274. :close-on-click-modal="false"
  275. append-to-body
  276. >
  277. <treeselect
  278. v-model="treeselectList.fWarehouselocid"
  279. @select="getAlltree"
  280. :options="fWarehouseidOptions"
  281. :show-count="true"
  282. :disable-branch-nodes="true"
  283. placeholder="请选择归属库区"
  284. />
  285. <span slot="footer" class="dialog-footer">
  286. <el-button @click="choiceWarehouse = false">取 消</el-button>
  287. <el-button type="primary" @click="confirm">确 定</el-button>
  288. </span>
  289. </el-dialog>
  290. </el-dialog>
  291. </template>
  292. <script>
  293. import { getToken } from "@/utils/auth";
  294. import Cookies from "js-cookie";
  295. import { addSet, select, resetModule } from "@/api/system/set";
  296. import draggable from "vuedraggable";
  297. import Treeselect from "@riophae/vue-treeselect";
  298. import { listGoods } from "@/api/basicdata/goods";
  299. import { treeselect } from "@/api/basicdata/warehouse";
  300. export default {
  301. name: "inStock",
  302. props: {
  303. uploadExcelVisible: {
  304. type: Boolean,
  305. default: false,
  306. },
  307. },
  308. components: {
  309. draggable,
  310. Treeselect,
  311. },
  312. data() {
  313. return {
  314. headers: {
  315. Authorization: "Bearer " + getToken(),
  316. },
  317. actionUrl:
  318. process.env.VUE_APP_BASE_API +
  319. "/warehouseBusiness/inStock/importInstock", // 上传的图片服务器地址
  320. uploadVisible: false,
  321. excelList: [],
  322. drag: false,
  323. loading:false,
  324. setRowList: [],
  325. getRowList: [],
  326. allCheck: false,
  327. showSetting: false,
  328. tableDate: [
  329. {
  330. surface: "1",
  331. label: "fBsdate",
  332. name: "入库日期",
  333. checked: 0,
  334. width: 100,
  335. },
  336. {
  337. surface: "2",
  338. label: "fGoodsid",
  339. name: "品名",
  340. checked: 0,
  341. width: 100,
  342. },
  343. {
  344. surface: "3",
  345. label: "fBusinessType",
  346. name: "货物属性",
  347. checked: 0,
  348. width: 100,
  349. },
  350. {
  351. surface: "4",
  352. label: "fMarks",
  353. name: "属性详情",
  354. checked: 0,
  355. width: 100,
  356. },
  357. {
  358. surface: "5",
  359. label: "fWarehouseInformation",
  360. name: "库区",
  361. checked: 0,
  362. width: 100,
  363. },
  364. {
  365. surface: "6",
  366. label: "fQty",
  367. name: "件数",
  368. checked: 0,
  369. width: 100,
  370. },
  371. {
  372. surface: "7",
  373. label: "fGrossweight",
  374. name: "毛重(kg)",
  375. checked: 0,
  376. width: 100,
  377. },
  378. {
  379. surface: "8",
  380. label: "fNetweight",
  381. name: "净重(kg)",
  382. checked: 0,
  383. width: 100,
  384. },
  385. {
  386. surface: "9",
  387. label: "fPackagespecs",
  388. name: "包装规格",
  389. checked: 0,
  390. width: 100,
  391. },
  392. {
  393. surface: "10",
  394. label: "fELabel",
  395. name: "电子标签",
  396. checked: 0,
  397. width: 100,
  398. },
  399. {
  400. surface: "11",
  401. label: "fCntrno",
  402. name: "箱号",
  403. checked: 0,
  404. width: 100,
  405. },
  406. {
  407. surface: "12",
  408. label: "fTruckno",
  409. name: "车号",
  410. checked: 0,
  411. width: 100,
  412. },
  413. ],
  414. goodsOptions: [],
  415. fStorageTypeOptions: [],
  416. fWarehouseidOptions: [],
  417. treeselectList: {
  418. fWarehouselocid: null,
  419. },
  420. choiceWarehouse: false,
  421. oldList: [],
  422. form: {},
  423. selection: [],
  424. };
  425. },
  426. created() {
  427. this.setRowList = this.tableDate;
  428. this.getRowList = this.tableDate;
  429. listGoods({ fStatus: 0, delFlag: 0 }).then((response) => {
  430. this.goodsOptions = response.rows;
  431. });
  432. this.getDicts("storage_type").then((response) => {
  433. this.fStorageTypeOptions = response.data;
  434. });
  435. this.getRow();
  436. },
  437. methods: {
  438. dateSelected(scope,name){
  439. if (name === 'fBsdate'){
  440. this.excelList.forEach(item => {
  441. if (!item.fBsdate) this.$set(item,'fBsdate',scope.row.fBsdate)
  442. })
  443. }else if (name === 'fGoodsid'){
  444. this.excelList.forEach(item => {
  445. if (!item.fGoodsid) this.$set(item,'fGoodsid',scope.row.fGoodsid)
  446. })
  447. }else if (name === 'fBusinessType'){
  448. this.excelList.forEach(item => {
  449. if (!item.fBusinessType) this.$set(item,'fBusinessType',scope.row.fBusinessType)
  450. })
  451. }else if (name === 'fMarks'){
  452. this.excelList.forEach(item => {
  453. if (!item.fMarks) this.$set(item,'fMarks',scope.row.fMarks)
  454. })
  455. }
  456. },
  457. init(row, list) {
  458. this.oldList = [];
  459. this.form = null;
  460. this.excelList = [];
  461. this.oldList = list;
  462. this.form = row;
  463. treeselect(row.fWarehouseid).then((response) => {
  464. this.fWarehouseidOptions = response.data;
  465. });
  466. },
  467. progress(event, file, fileList){
  468. this.loading = true
  469. },
  470. handleSucces(res) {
  471. this.loading = false
  472. if (res.code) {
  473. if (res.data.length) {
  474. res.data.map((e) => {
  475. e.fBsdate = this.form.fBsdate;
  476. e.fGoodsid = this.form.fGoodsid;
  477. });
  478. }
  479. this.excelList = res.data;
  480. }
  481. },
  482. //列设置全选
  483. allChecked() {
  484. if (this.allCheck == true) {
  485. this.setRowList.map((e) => {
  486. return (e.checked = 0);
  487. });
  488. } else {
  489. this.setRowList.map((e) => {
  490. return (e.checked = 1);
  491. });
  492. }
  493. },
  494. //查询列数据
  495. getRow() {
  496. let that = this;
  497. this.data = {
  498. tableName: "上传Excel",
  499. userId: Cookies.get("userName"),
  500. };
  501. select(this.data).then((res) => {
  502. if (res.data.length != 0) {
  503. this.getRowList = res.data.filter((e) => e.checked == 0);
  504. this.setRowList = res.data;
  505. this.setRowList = this.setRowList.reduce((res, item) => {
  506. res.push({
  507. surface: item.surface,
  508. label: item.label,
  509. name: item.name,
  510. checked: item.checked,
  511. width: item.width,
  512. fixed: item.fixed,
  513. });
  514. return res;
  515. }, []);
  516. }
  517. });
  518. },
  519. //重置列表
  520. delRow() {
  521. this.data = {
  522. tableName: "上传Excel",
  523. userId: Cookies.get("userName"),
  524. };
  525. resetModule(this.data).then((res) => {
  526. if (res.code == 200) {
  527. this.showSetting = false;
  528. this.setRowList = this.$options.data().tableDate;
  529. this.getRowList = this.$options.data().tableDate;
  530. }
  531. });
  532. },
  533. //保存列设置
  534. save() {
  535. this.showSetting = false;
  536. this.data = {
  537. tableName: "上传Excel",
  538. userId: Cookies.get("userName"),
  539. sysTableSetList: this.setRowList,
  540. };
  541. addSet(this.data).then((res) => {
  542. if (res.code == 200) {
  543. this.showSetting = false;
  544. this.getRowList = this.setRowList.filter((e) => e.checked == 0);
  545. }
  546. });
  547. },
  548. //开始拖拽事件
  549. onStart() {
  550. this.drag = true;
  551. },
  552. //拖拽结束事件F
  553. onEnd() {
  554. this.drag = false;
  555. },
  556. getAlltree(tree) {
  557. this.information = tree.fWarehouseInformation;
  558. },
  559. importData() {
  560. if (this.excelList.length == 0) {
  561. return this.$message.error("请上传Excel文件,并完善数据");
  562. }
  563. for (let item in this.excelList) {
  564. if (this.excelList[item].fBsdate == null) {
  565. return this.$message.error(
  566. "请选择第" + (Number(item) + 1) + "行的入库日期"
  567. );
  568. }
  569. if (this.excelList[item].fGoodsid == null) {
  570. return this.$message.error(
  571. "请选择第" + (Number(item) + 1) + "行的品名"
  572. );
  573. }
  574. if (this.excelList[item].fBusinessType == null) {
  575. return this.$message.error(
  576. "请选择第" + (Number(item) + 1) + "行的货物属性"
  577. );
  578. }
  579. if (this.excelList[item].fMarks == null) {
  580. return this.$message.error(
  581. "请输入第" + (Number(item) + 1) + "行的属性详情"
  582. );
  583. }
  584. // if (this.excelList[item].fWarehouseInformation == null) {
  585. // return this.$message.error(
  586. // "请选择第" + (Number(item) + 1) + "行的库区"
  587. // );
  588. // }
  589. if (this.excelList[item].fQty == null) {
  590. return this.$message.error(
  591. "请输入第" + (Number(item) + 1) + "行的件数"
  592. );
  593. }
  594. if (this.excelList[item].fGrossweight == null) {
  595. return this.$message.error(
  596. "请输入第" + (Number(item) + 1) + "行的毛重"
  597. );
  598. }
  599. if (this.excelList[item].fNetweight == null) {
  600. return this.$message.error(
  601. "请输入第" + (Number(item) + 1) + "行的净重"
  602. );
  603. }
  604. // if (this.excelList[item].fPackagespecs == null) {
  605. // return this.$message.error(
  606. // "请输入第" + (Number(item) + 1) + "行的包装规格"
  607. // );
  608. // }
  609. if (this.excelList[item].fCntrno == null) {
  610. return this.$message.error(
  611. "请输入第" + (Number(item) + 1) + "行的箱号"
  612. );
  613. }
  614. }
  615. this.$emit("adddetailList", this.excelList);
  616. this.uploadVisible = false;
  617. },
  618. unRepeat(row, index) {
  619. this.oldList.map((e) => {
  620. if (row == e.fCntrno) {
  621. this.excelList[index].fCntrno = null;
  622. this.$message.error("该箱号和明细表上的存在重复");
  623. }
  624. });
  625. this.excelList.map((e, i) => {
  626. if (index != i) {
  627. if (row && row == e.fCntrno) {
  628. this.excelList[index].fCntrno = null;
  629. this.$message.error("该箱号存在重复");
  630. }
  631. }
  632. });
  633. },
  634. handleClose() {
  635. this.$emit("changeShow", false);
  636. },
  637. getTreeselect(row) {
  638. this.treeselectList.fWarehouselocid = row.row.fWarehouselocid
  639. ? row.row.fWarehouselocid
  640. : null;
  641. this.TreeIndex = row.$index;
  642. this.choiceWarehouse = true;
  643. },
  644. confirm() {
  645. this.$set(
  646. this.excelList[this.TreeIndex],
  647. "fWarehouseInformation",
  648. this.information
  649. );
  650. this.$set(
  651. this.excelList[this.TreeIndex],
  652. "fWarehouselocid",
  653. this.treeselectList.fWarehouselocid
  654. );
  655. this.choiceWarehouse = false;
  656. },
  657. Selectinventory(selection) {
  658. this.selection = selection;
  659. },
  660. bathHandle() {
  661. this.excelList.map((e) => {
  662. e.fBusinessType = this.selection[0].fBusinessType
  663. ? this.selection[0].fBusinessType
  664. : null;
  665. e.fMarks = this.selection[0].fMarks ? this.selection[0].fMarks : null;
  666. });
  667. },
  668. },
  669. watch: {
  670. uploadExcelVisible() {
  671. this.uploadVisible = this.uploadExcelVisible;
  672. },
  673. },
  674. };
  675. </script>