viewArea.vue 7.3 KB

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