cancelStockOrderAdd.vue 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <template>
  2. <div class="main-contain">
  3. <div class="position">
  4. <bread-crumb
  5. v-if="this.$route.query.type == 1"
  6. :crumbs="crumbs"
  7. ></bread-crumb>
  8. <bread-crumb
  9. v-if="this.$route.query.type == 2"
  10. :crumbs="crumbs2"
  11. ></bread-crumb>
  12. <div style="float:right;">
  13. <el-button size="small" @click="back()" class="filter-item"
  14. >取 消</el-button
  15. >
  16. <el-button
  17. size="small"
  18. type="primary"
  19. @click="submit()"
  20. class="filter-item"
  21. >保 存</el-button
  22. >
  23. </div>
  24. </div>
  25. <div class="app-container">
  26. <stock-in-dialog
  27. ref="dialog"
  28. :propForm="propForm"
  29. :visibility="isVisibility"
  30. v-on:dialog-comfirm="comfirm"
  31. v-on:dialog-cancle="cancle"
  32. ></stock-in-dialog>
  33. <div class="filter-container">
  34. <div class="cell clearfix">
  35. <label class="title"><span class="name">退库时间</span> : </label>
  36. <el-date-picker
  37. size="small"
  38. v-model="return_time"
  39. prefix-icon="el-icon-date"
  40. :editable="false"
  41. style="width: 196px;"
  42. type="date"
  43. placeholder="选择日期时间"
  44. align="right"
  45. format="yyyy-MM-dd"
  46. value-format="yyyy-MM-dd"
  47. ></el-date-picker>
  48. </div>
  49. </div>
  50. <el-form :rules="tableRules" :model="recordInfo" ref="tableForm">
  51. <el-table
  52. :data="recordInfo.recordData"
  53. :class="signAndWeighBoxPatients"
  54. style="width: 100%"
  55. border
  56. max-height="450"
  57. :header-cell-style="{ backgroundColor: 'rgb(245, 247, 250)' }"
  58. >
  59. <el-table-column align="center" width="250">
  60. <template slot="header" slot-scope="scope">
  61. <span>耗材名称</span>
  62. </template>
  63. <template slot-scope="scope">
  64. <el-autocomplete
  65. class="checkSearch"
  66. popper-class="my-autocomplete"
  67. v-model="scope.row.good_name"
  68. :fetch-suggestions="querySearchAsync"
  69. :trigger-on-focus="false"
  70. placeholder="请输入耗材名称"
  71. @select="handleSelect"
  72. @input="changeGoodName(scope.$index)"
  73. style="width:200px;"
  74. >
  75. <i class="el-icon-search el-input__icon" slot="suffix"></i>
  76. <template slot-scope="{ item }">
  77. <div class="name">{{ item.good_name +" " +item.specification_name + " "+item.manufacturer }}</div>
  78. </template>
  79. </el-autocomplete>
  80. </template>
  81. </el-table-column>
  82. <el-table-column align="center" width="300">
  83. <template slot="header" slot-scope="scope">
  84. <span>规格&单位<span style="color: red">*</span></span>
  85. </template>
  86. <template slot-scope="scope">
  87. <el-form-item style="padding-top: 20px">
  88. <el-input placeholder="请输入规格名称" v-model="scope.row.name"></el-input>
  89. </el-form-item>
  90. </template>
  91. </el-table-column>
  92. <el-table-column width="300" align="center">
  93. <template slot="header" slot-scope="scope">
  94. <span>退库数量<span style="color: red">*</span></span>
  95. </template>
  96. <template slot-scope="scope">
  97. <el-form-item
  98. :prop="'recordData.' + scope.$index + '.return_count'"
  99. :rules="tableRules.return_count"
  100. style="padding-top: 17px"
  101. >
  102. <el-input
  103. placeholder="请输入退库数量"
  104. type="number"
  105. v-model="scope.row.return_count"
  106. ></el-input>
  107. {{scope.row.packing_unit}}
  108. </el-form-item>
  109. </template>
  110. </el-table-column>
  111. <el-table-column label="操作" align="center" min-width="20">
  112. <template slot-scope="scope">
  113. <el-tooltip
  114. class="item"
  115. effect="dark"
  116. content="新增"
  117. placement="top"
  118. >
  119. <el-button
  120. size="mini"
  121. type="primary"
  122. icon="el-icon-circle-plus-outline"
  123. @click="handleEdit(scope.$index, scope.row)"
  124. >
  125. </el-button>
  126. </el-tooltip>
  127. <el-tooltip
  128. class="item"
  129. effect="dark"
  130. content="删除"
  131. placement="top"
  132. >
  133. <el-button
  134. size="mini"
  135. type="danger"
  136. icon="el-icon-delete"
  137. @click="handleDelete(scope.$index, scope.row)"
  138. >
  139. </el-button>
  140. </el-tooltip>
  141. </template>
  142. </el-table-column>
  143. </el-table>
  144. </el-form>
  145. </div>
  146. </div>
  147. </template>
  148. <script>
  149. import { uParseTime } from "@/utils/tools";
  150. import { getCancelStockConfig, postCancelStock,GetAllConfig,GetAllGoodInfoByID,postSearchGoodList } from "@/api/stock";
  151. import BreadCrumb from "../components/bread-crumb";
  152. import StockInDialog from './Dialog/stockInDialog'
  153. export default {
  154. components: { StockInDialog, BreadCrumb },
  155. name: "salesReturnOrderAdd",
  156. data() {
  157. return {
  158. crumbs: [
  159. { path: false, name: "库存管理" },
  160. { path: false, name: "耗材退库单" },
  161. { path: false, name: "新增退库单" }
  162. ],
  163. crumbs2: [
  164. { path: false, name: "库存管理" },
  165. { path: false, name: "其他退库单" },
  166. { path: false, name: "新增退库单" }
  167. ],
  168. type: this.$route.query.type,
  169. signAndWeighBoxPatients: "sign-and-weigh-box-patients",
  170. return_time: "",
  171. currentIndex: 0,
  172. recordInfo: {
  173. recordData: []
  174. },
  175. tableRules: {
  176. return_count: [
  177. { required: true, message: "数量不能为空", trigge: "blur" }
  178. ]
  179. },
  180. ruleForm: {
  181. manufacturer: [
  182. { required: true, message: "请选择厂商", trigger: "change" }
  183. ]
  184. },
  185. // prop
  186. isVisibility: false,
  187. propForm: {
  188. goods: [],
  189. goodType: [],
  190. goodInfo: [],
  191. goodUnit: [],
  192. manufacturer: 0,
  193. dealer: 0
  194. },
  195. form: {
  196. manufacturer: 0,
  197. dealer: 0
  198. },
  199. warehouseOutInfoList: [],
  200. manufacturer: [],
  201. dealer: [],
  202. goodType: [],
  203. goodInfo:[],
  204. };
  205. },
  206. methods: {
  207. comfirm: function(val) {
  208. this.propForm.goodType = []
  209. this.propForm.goods = []
  210. this.$refs.dialog.hide()
  211. if (val.selectedGoodInfo.length > 0) {
  212. for (let i = val.selectedGoodInfo.length - 1; i >= 0; i--) {
  213. if (i == 0) {
  214. this.recordInfo.recordData[this.currentIndex].good_type_id = val.selectedGoodInfo[i].good_type_id
  215. this.recordInfo.recordData[this.currentIndex].good_id = val.selectedGoodInfo[i].id
  216. } else {
  217. const tempForm = {}
  218. tempForm['good_type_id'] =val.selectedGoodInfo[i].good_type_id
  219. tempForm['good_id'] = val.selectedGoodInfo[i].id
  220. tempForm["return_count"] = "";
  221. this.recordInfo.recordData.splice(this.currentIndex + 1, 0, tempForm)
  222. }
  223. }
  224. }
  225. this.currentIndex = -1
  226. },
  227. cancle: function() {
  228. this.$refs.dialog.hide();
  229. this.propForm.goodType = [];
  230. },
  231. GetConfigInfo: function() {
  232. const loading = this.$loading({
  233. lock: true,
  234. text: 'Loading',
  235. spinner: 'el-icon-loading',
  236. background: 'rgba(0, 0, 0, 0.7)'
  237. })
  238. GetAllConfig().then(response => {
  239. if (response.data.state == 0) {
  240. this.$message.error(response.data.msg)
  241. return false
  242. } else {
  243. this.manufacturer = response.data.data.manufacturer
  244. this.dealer = response.data.data.dealer
  245. this.goodType = response.data.data.goodType
  246. this.goodInfo = response.data.data.goodInfo
  247. this.manufacturer.splice(0, 0, { id: 0, manufacturer_name: '全部' })
  248. this.dealer.splice(0, 0, { id: 0, dealer_name: '全部' })
  249. this.manufacturer.splice(0, 0, { id: -1, manufacturer_name: '其他' })
  250. this.dealer.splice(0, 0, { id: -1, dealer_name: '其他' })
  251. this.form.manufacturer = 0
  252. this.form.dealer = 0
  253. }
  254. loading.close()
  255. })
  256. },
  257. typeName: function(good_type_id) {
  258. let name = "";
  259. for (let i = 0; i < this.goodType.length; i++) {
  260. if (this.goodType[i].id == good_type_id) {
  261. name = this.goodType[i].type_name;
  262. }
  263. }
  264. return name;
  265. },
  266. specificationName: function(good_info_id) {
  267. let name = ''
  268. for (let i = 0; i < this.goodInfo.length; i++) {
  269. if (this.goodInfo[i].id == good_info_id) {
  270. name = this.goodInfo[i].specification_name
  271. }
  272. }
  273. return name
  274. },
  275. handleEdit: function(index, row) {
  276. const tempObj = {};
  277. tempObj["good_type_id"] = 0;
  278. tempObj["good_id"] = 0;
  279. tempObj["return_count"] = "";
  280. this.recordInfo.recordData.push(tempObj);
  281. },
  282. handleDelete: function(index, row) {
  283. if (this.recordInfo.recordData.length <= 1) {
  284. this.$message.error("只有一条记录的时候无法删除");
  285. return;
  286. } else {
  287. this.recordInfo.recordData.splice(index, 1);
  288. }
  289. },
  290. calculate: function(val) {
  291. if (val == 0) {
  292. return "";
  293. }
  294. return Math.round(parseFloat(val) * 100) / 100;
  295. },
  296. getTime(val, temp) {
  297. if (val != 0) {
  298. return uParseTime(val, temp);
  299. } else {
  300. return "";
  301. }
  302. },
  303. showDialog(index, row) {
  304. const loading = this.$loading({
  305. lock: true,
  306. text: 'Loading',
  307. spinner: 'el-icon-loading',
  308. background: 'rgba(0, 0, 0, 0.7)'
  309. })
  310. this.currentIndex = index
  311. this.isVisibility = true
  312. const params = {
  313. manufacturer_id: this.form.manufacturer,
  314. dealer_id: this.form.dealer
  315. }
  316. this.propForm.goods = []
  317. GetAllGoodInfoByID(params).then(response => {
  318. if (response.data.state == 0) {
  319. this.$message.error(response.data.msg)
  320. return false
  321. loading.close()
  322. } else {
  323. loading.close()
  324. if (response.data.data.goodInfo.length <= 0) {
  325. this.$message.error('该厂商或经销商没有物品信息')
  326. return
  327. }
  328. this.$refs.dialog.show()
  329. for (let i = 0; i < response.data.data.goodInfo.length; i++) {
  330. this.propForm.goodType.push(response.data.data.goodInfo[i].type)
  331. }
  332. const obj = {}
  333. this.propForm.goodType = this.propForm.goodType.reduce((cur, next) => {
  334. obj[next.id] ? '' : obj[next.id] = true && cur.push(next)
  335. return cur
  336. }, []) // 设置cur默认类型为数组,并且初始值为空的数组
  337. }
  338. for (let i = 0; i < this.propForm.goodType.length; i++) {
  339. let goodInfo = []
  340. let goodObj = {}
  341. for (let a = 0; a < response.data.data.goodInfo.length; a++) {
  342. var respObj = response.data.data.goodInfo[a]
  343. respObj['isSelected'] = false
  344. if (respObj.type.id == this.propForm.goodType[i].id) {
  345. goodInfo.push(respObj)
  346. }
  347. }
  348. const obj = {}
  349. goodInfo = goodInfo.reduce((cur, next) => {
  350. obj[next.id] ? '' : obj[next.id] = true && cur.push(next)
  351. return cur
  352. }, []) // 设置cur默认类型为数组,并且初始值为空的数组
  353. this.$set(goodObj, this.propForm.goodType[i].id, goodInfo)
  354. this.propForm.goods.push(goodObj)
  355. }
  356. }
  357. )
  358. },
  359. back() {
  360. this.$router.go(-1);
  361. },
  362. submit() {
  363. this.$refs["tableForm"].validate(valid => {
  364. if (valid) {
  365. const array = this.recordInfo.recordData;
  366. let total = 0;
  367. for (let i = 0; i < array.length; i++) {
  368. if (array[i].good_type_id == 0) {
  369. this.$message.error("商品类型不能为空");
  370. return;
  371. }
  372. if (array[i].good_id == 0) {
  373. this.$message.error("规格名称不能为空");
  374. return;
  375. }
  376. total = total + array[i].price * array[i].return_count;
  377. }
  378. if (this.recordInfo.recordData.length <= 0) {
  379. this.$message.success("请添加退库商品");
  380. return;
  381. }
  382. const params = {
  383. cancelStock: this.recordInfo.recordData
  384. };
  385. console.log("params",params)
  386. postCancelStock(
  387. params,
  388. this.return_time,
  389. this.form.manufacturer,
  390. this.form.dealer,
  391. this.type
  392. ).then(response => {
  393. if (response.data.state == 0) {
  394. this.$message.error(response.data.msg);
  395. return false;
  396. } else {
  397. var msg = response.data.data.msg
  398. if (msg == 1){
  399. this.$message.error("该耗材无出库记录")
  400. return
  401. }
  402. if(msg == 2){
  403. this.$message.error("退库数量大于出库数量")
  404. }
  405. if(msg == 3){
  406. this.$notify({
  407. title: "成功",
  408. message: "退库成功",
  409. type: "success",
  410. duration: 2000
  411. });
  412. this.recordInfo.recordData = [];
  413. this.$router.back(-1);
  414. }
  415. }
  416. });
  417. } else {
  418. return false;
  419. }
  420. });
  421. },
  422. changeManufacturer(val) {
  423. this.propForm.manufacturer = val;
  424. },
  425. changeDealer(val) {
  426. this.propForm.dealer = val;
  427. },
  428. querySearchAsync(keyword, cb) {
  429. let key = '';
  430. if (keyword != undefined) {
  431. key = keyword
  432. }
  433. postSearchGoodList(key).then(response => {
  434. if (response.data.state == 1) {
  435. var list = response.data.data.list
  436. this.goodList = list
  437. var manufacturerList = response.data.data.manufacturerList
  438. this.manufacturerList = manufacturerList
  439. var dealer = response.data.data.dealerList
  440. this.dealerList = dealer
  441. for(let i=0;i<this.goodList.length;i++){
  442. for(let j=0;j<this.manufacturerList.length;j++){
  443. if(this.goodList[i].manufacturer == this.manufacturerList[j].id){
  444. this.goodList[i].manufacturer = this.manufacturerList[j].manufacturer_name
  445. }
  446. }
  447. }
  448. for(let i=0;i<this.goodList.length;i++){
  449. for(let j=0;j<this.dealerList.length;j++){
  450. if(this.goodList[i].dealer == this.dealerList[j].id){
  451. this.goodList[i].dealer = this.dealerList[j].dealer_name
  452. }
  453. }
  454. }
  455. cb(this.goodList)
  456. } else {
  457. cb([])
  458. }
  459. })
  460. },
  461. changeGoodName(val){
  462. this.currentIndex = val
  463. },
  464. handleSelect(val){
  465. for(let i=0;i<this.recordInfo.recordData.length;i++){
  466. if(this.currentIndex == i){
  467. this.recordInfo.recordData[i].good_type_id = val.id
  468. this.recordInfo.recordData[i].good_name = val.good_name
  469. this.recordInfo.recordData[i].good_type_id = val.good_type_id
  470. this.recordInfo.recordData[i].name = val.specification_name +"/"+val.packing_unit
  471. this.recordInfo.recordData[i].number = val.number
  472. this.recordInfo.recordData[i].manufacturer = val.manufacturer
  473. this.recordInfo.recordData[i].remark = val.remark
  474. if(val.buy_price == 0){
  475. this.recordInfo.recordData[i].price = ""
  476. }else{
  477. this.recordInfo.recordData[i].price = val.buy_price
  478. }
  479. this.recordInfo.recordData[i].specification_name = val.specification_name
  480. this.recordInfo.recordData[i].good_id = val.id
  481. this.recordInfo.recordData[i].packing_unit = val.packing_unit
  482. if(val.dealer == 0){
  483. this.recordInfo.recordData[i].dealer = ""
  484. }else{
  485. this.recordInfo.recordData[i].dealer = val.dealer
  486. }
  487. }
  488. }
  489. }
  490. },
  491. created() {
  492. var nowDate = new Date();
  493. var nowYear = nowDate.getFullYear();
  494. var nowMonth = nowDate.getMonth() + 1;
  495. var nowDay = nowDate.getDate();
  496. this.return_time =
  497. nowYear +
  498. "-" +
  499. (nowMonth < 10 ? "0" + nowMonth : nowMonth) +
  500. "-" +
  501. (nowDay < 10 ? "0" + nowDay : nowDay);
  502. const tempObj = {};
  503. tempObj["good_type_id"] = 0;
  504. tempObj["good_id"] = 0;
  505. tempObj["return_count"] = "";
  506. this.recordInfo.recordData.push(tempObj);
  507. this.GetConfigInfo();
  508. this.propForm.goodUnit = this.$store.getters.good_unit;
  509. }
  510. };
  511. </script>
  512. <style rel="stylesheet/css" lang="scss" scoped>
  513. .information {
  514. border: 1px #dcdfe6 solid;
  515. padding: 30px 20px 30px 20px;
  516. .border {
  517. border-bottom: 1px #dcdfe6 solid;
  518. margin: 0px 0 20px 0;
  519. }
  520. }
  521. .edit_separater {
  522. border-top: 1px solid rgb(233, 233, 233);
  523. margin-top: 15px;
  524. margin-bottom: 15px;
  525. }
  526. </style>
  527. <style>
  528. .sign-and-weigh-box .sign-and-weigh-box-patients .cell {
  529. font-size: 12px;
  530. }
  531. .sign-and-weigh-box .sign-and-weigh-box-patients .current-row > td {
  532. background: #6fb5fa;
  533. }
  534. </style>