uploadExcel.vue 17 KB

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