viewArea.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <div>
  3. <el-dialog title="查看库区" :visible.sync="dialogVisible" append-to-body width="60%" :before-close="handleClose">
  4. <avue-crud
  5. v-if="dialogVisible"
  6. :option="option"
  7. :table-loading="loading"
  8. :data="data"
  9. ref="crud"
  10. id="out-table"
  11. :header-cell-class-name="headerClassName"
  12. >
  13. <template slot-scope="{ scope, row }" slot="menuLeft">
  14. <div style="display: flex;">
  15. <el-button type="primary" size="small" @click="addRow">新增</el-button>
  16. <dic-select
  17. v-if="dialogVisible"
  18. style="width: 300px;"
  19. v-model="query.dot"
  20. placeholder="批次号"
  21. label="dot"
  22. :disabled="disabled || query.historyList.length"
  23. :url="'/blade-sales-part/stockDesc/dotList?storageId=' + form.storageId + '&goodsId=' + query.goodsId"
  24. :filterable="true"
  25. :allowCreate="true"
  26. ></dic-select>
  27. <el-tag type="danger" style="margin-left: 10px;">入库数量:{{ qtyMax }}</el-tag>
  28. </div>
  29. </template>
  30. <template slot="reservoirAreaName" slot-scope="{ row }">
  31. <dic-select
  32. v-model="row.reservoirAreaName"
  33. placeholder="库区"
  34. label="cname"
  35. res="records"
  36. :url="'/blade-sales-part/reservoirarea/list?current=1&size=5&storageId=' + form.storageId"
  37. :filterable="true"
  38. :remote="true"
  39. dataName="cname"
  40. :disabled="disabled"
  41. @selectChange="rowDicChange('reservoirAreaName', $event, row)"
  42. :slotRight="true"
  43. rightLabel="balanceQuantity"
  44. ></dic-select>
  45. </template>
  46. <template slot="quantity" slot-scope="{ row }">
  47. <el-input-number
  48. v-model="row.quantity"
  49. size="small"
  50. :controls="false"
  51. style="width: 100%"
  52. :disabled="disabled"
  53. @change="qtyChange(row)"
  54. />
  55. </template>
  56. <template slot-scope="{ row, index }" slot="menu">
  57. <el-button icon="el-icon-delete" :disabled="disabled" size="small" type="text" @click="rowDel(row, index)">删除 </el-button>
  58. </template>
  59. </avue-crud>
  60. <span slot="footer" class="dialog-footer">
  61. <el-button @click="dialogVisible = false" size="mini">取 消</el-button>
  62. <el-button type="primary" @click="submit" size="mini">确 认</el-button>
  63. </span>
  64. </el-dialog>
  65. </div>
  66. </template>
  67. <script>
  68. import dicSelect from "@/components/dicSelect/main";
  69. import { itemRemove } from "@/api/tirePartsMall/salesManagement/outboundWorkOrder";
  70. export default {
  71. props: {
  72. disabled: {
  73. type: Boolean,
  74. default: false
  75. }
  76. },
  77. components: {
  78. dicSelect
  79. },
  80. data() {
  81. return {
  82. data: [],
  83. dialogVisible: false,
  84. loading: false,
  85. option: {
  86. height: 500,
  87. calcHeight: 30,
  88. menuWidth: 80,
  89. border: true,
  90. index: true,
  91. addBtn: false,
  92. viewBtn: false,
  93. delBtn: false,
  94. editBtn: false,
  95. refreshBtn: false,
  96. columnBtn: false,
  97. // menu: false,
  98. // header: false,
  99. column: [
  100. {
  101. label: "库区",
  102. prop: "reservoirAreaName",
  103. overHidden: true
  104. },
  105. {
  106. label: "库存",
  107. prop: "balanceQuantity",
  108. overHidden: true
  109. },
  110. {
  111. label: "本次数量",
  112. prop: "quantity",
  113. overHidden: true
  114. }
  115. ]
  116. },
  117. form: {},
  118. query: {},
  119. index: 0,
  120. qtyMax: 0
  121. };
  122. },
  123. async created() {},
  124. methods: {
  125. rowDel(row, index) {
  126. this.$confirm("确定删除数据?", {
  127. confirmButtonText: "确定",
  128. cancelButtonText: "取消",
  129. type: "warning"
  130. }).then(() => {
  131. if (row.id) {
  132. itemRemove({ ids: row.id }).then(res => {
  133. this.data.splice(index, 1);
  134. this.$message.success("操作成功!");
  135. });
  136. } else {
  137. this.data.splice(index, 1);
  138. this.$message.success("操作成功!");
  139. }
  140. });
  141. },
  142. addRow() {
  143. this.data.push({
  144. quantity: 0
  145. });
  146. },
  147. rowDicChange(name, row, el) {
  148. if (name == "reservoirAreaName") {
  149. if (row) {
  150. el.reservoirAreaId = row.id;
  151. el.balanceQuantity = row.balanceQuantity;
  152. } else {
  153. el.reservoirAreaId = null;
  154. el.reservoirAreaName = null;
  155. el.balanceQuantity = null;
  156. }
  157. }
  158. },
  159. qtyChange(row) {
  160. let sum = 0;
  161. for (let item of this.data) {
  162. sum += Number(item.quantity);
  163. }
  164. if (sum > this.qtyMax) {
  165. return this.$message.error("总数量不能超过" + this.qtyMax);
  166. }
  167. },
  168. openDialog(form, row, index) {
  169. this.form = {};
  170. this.query = {};
  171. this.index = null;
  172. this.data = [];
  173. this.qtyMax = 0;
  174. this.form = form;
  175. this.query = row;
  176. this.index = index;
  177. this.data = this.deepClone(row.historyList);
  178. this.qtyMax = row.remainingNum;
  179. this.dialogVisible = true;
  180. },
  181. submit() {
  182. let sum = 0;
  183. for (let item of this.data) {
  184. if (!item.reservoirAreaId) {
  185. return this.$message.error("请选择库区");
  186. }
  187. if (!item.quantity) {
  188. return this.$message.error("本次数量不能为0");
  189. }
  190. sum += Number(item.quantity);
  191. }
  192. for (let item of this.data.filter(item => item.quantity > 0)) {
  193. if (this.data.filter(item => item.quantity > 0)[0].dot != item.dot) {
  194. return this.$message.error("请选择一种批次号");
  195. }
  196. }
  197. if (!this.query.dot) {
  198. this.query.dot = this.data.filter(item => item.quantity > 0)[0].dot;
  199. }
  200. if (sum > this.qtyMax) {
  201. return this.$message.error("总数量不能超过" + this.qtyMax);
  202. }
  203. if (Number(sum) != Number(this.qtyMax)) {
  204. return this.$message.error("本次数量合计必须达到:" + this.qtyMax);
  205. }
  206. let obj = {
  207. ...this.query,
  208. sendNum: sum,
  209. historyList: this.data
  210. };
  211. this.$emit("areaData", obj, this.index);
  212. this.dialogVisible = false;
  213. },
  214. //自定义列保存
  215. async saveColumn(ref, option, optionBack, code) {
  216. /**
  217. * 已定义全局方法,直接使用,saveColumnData保存列数据方法,参数传值(表格名称,当前表格的option数据)
  218. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  219. * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
  220. */
  221. const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
  222. if (inSave) {
  223. this.$message.success("保存成功");
  224. //关闭窗口
  225. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  226. this.searchReset();
  227. }
  228. },
  229. //自定义列重置
  230. async resetColumn(ref, option, optionBack, code) {
  231. this[option] = this[optionBack];
  232. const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
  233. if (inSave) {
  234. this.$message.success("重置成功");
  235. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  236. }
  237. },
  238. // 更改表格颜色
  239. headerClassName(tab) {
  240. //颜色间隔
  241. let back = "";
  242. if (tab.columnIndex >= 0 && tab.column.level === 1) {
  243. if (tab.columnIndex % 2 === 0) {
  244. back = "back-one";
  245. } else if (tab.columnIndex % 2 === 1) {
  246. back = "back-two";
  247. }
  248. }
  249. return back;
  250. }
  251. }
  252. };
  253. </script>
  254. <style scoped>
  255. ::v-deep#out-table .back-one {
  256. background: #ecf5ff !important;
  257. text-align: center;
  258. padding: 4px 0;
  259. }
  260. ::v-deep#out-table .back-two {
  261. background: #ecf5ff !important;
  262. text-align: center;
  263. padding: 4px 0;
  264. }
  265. </style>