label-bind-dialog.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <script>
  2. import {
  3. add,
  4. bindList,
  5. removeBind,
  6. removeAllBind,
  7. classifyTree,
  8. } from "@/api/material/label";
  9. export default {
  10. name: "BindDialog",
  11. data() {
  12. const initDict = {
  13. labelType: [
  14. { label: "类别", value: 1 },
  15. { label: "标签", value: 2 },
  16. ],
  17. parentId: [],
  18. };
  19. const initColumns = () => [
  20. {
  21. type: "text",
  22. prop: "materialCode",
  23. label: "物料编码",
  24. required: true,
  25. showOverflowTooltip: true,
  26. },
  27. {
  28. type: "select",
  29. prop: "materialName",
  30. label: "物料名称",
  31. required: true,
  32. showOverflowTooltip: true,
  33. },
  34. {
  35. type: "text",
  36. prop: "materialClassifyId",
  37. label: "物料分类",
  38. required: false,
  39. showOverflowTooltip: true,
  40. },
  41. {
  42. type: "text",
  43. prop: "materialState",
  44. label: "物料状态",
  45. required: false,
  46. showOverflowTooltip: true,
  47. },
  48. {
  49. type: "text",
  50. prop: "createTime",
  51. label: "创建时间",
  52. required: false,
  53. showOverflowTooltip: true,
  54. },
  55. {
  56. type: "text",
  57. prop: "bindTime",
  58. label: "绑定时间",
  59. required: false,
  60. showOverflowTooltip: true,
  61. },
  62. ];
  63. const initForm = () => {
  64. let form = {};
  65. initColumns().forEach((item) => (form[item.prop] = ""));
  66. return form;
  67. };
  68. return {
  69. loading: false,
  70. dialogFormVisible: false,
  71. autoInnerVisible: false,
  72. handInnerVisible: false,
  73. form: initForm(),
  74. columns: initColumns(),
  75. tableData: [],
  76. page: { pageNum: 1, pageSize: 25, total: 0 },
  77. dict: initDict,
  78. filterText: "",
  79. options: [],
  80. innerForm: {},
  81. };
  82. },
  83. methods: {
  84. async fetchList(prop) {
  85. this.loading = true;
  86. let { pageNum, pageSize } = this.page;
  87. await bindList({ ...prop, pageNum, pageSize })
  88. .then((res) => {
  89. this.tableData = res.rows;
  90. })
  91. .finally(() => {
  92. this.loading = false;
  93. });
  94. },
  95. async fetchItem(prop) {
  96. // console.log(prop);
  97. // return;
  98. this.dialogFormVisible = true;
  99. this.form = { ...this.form, ...prop };
  100. await this.fetchList({ labelId: this.form.id });
  101. },
  102. async fetchClassifyTree() {
  103. let data = await classifyTree();
  104. this.options = data;
  105. },
  106. onAutoBindLabel(prop) {
  107. this.$parent.$children
  108. .find((el) => el.$vnode.tag.indexOf("AutoBindDialog") > -1)
  109. .fetchItem(prop);
  110. },
  111. onHandBindLabel(prop) {
  112. this.$parent.$children
  113. .find((el) => el.$vnode.tag.indexOf("HandBindDialog") > -1)
  114. .fetchItem(prop);
  115. },
  116. async onUnbind(prop) {
  117. const { materialId: id } = prop;
  118. await removeBind({ id });
  119. await this.fetchList({ labelId: this.form.id });
  120. },
  121. async onAllUnbind(prop) {
  122. const { id } = prop;
  123. await removeAllBind({ id });
  124. await this.fetchList({ labelId: id });
  125. },
  126. onSubmit(formName) {
  127. this.$refs[formName].validate((valid) => {
  128. if (valid) {
  129. this.loading = true;
  130. if (this.form.labelType === 1) this.form.parentId = 0;
  131. add(this.form)
  132. .then((res) => {
  133. let { code } = res;
  134. if (code === 200) {
  135. this.dialogFormVisible = false;
  136. this.$message.success("success");
  137. this.$parent.$children[0].fetchList();
  138. this.form = {};
  139. }
  140. })
  141. .finally(() => {
  142. this.loading = false;
  143. });
  144. } else {
  145. console.log("error submit!!");
  146. return false;
  147. }
  148. });
  149. },
  150. },
  151. created() {},
  152. };
  153. </script>
  154. <template>
  155. <el-dialog destroy-on-close title="绑定" :visible.sync="dialogFormVisible">
  156. <el-button :disabled="loading" @click="onAutoBindLabel(form)">
  157. 自动绑定
  158. </el-button>
  159. <el-button :disabled="loading" @click="onHandBindLabel(form)">
  160. 手动绑定
  161. </el-button>
  162. <el-button :disabled="loading" @click="onAllUnbind(form)">
  163. 全部解绑
  164. </el-button>
  165. <el-table
  166. v-loading="loading"
  167. lazy
  168. border
  169. row-key="id"
  170. :data="tableData"
  171. style="margin-top: 16px"
  172. >
  173. <el-table-column
  174. v-for="column in columns"
  175. :key="column.prop"
  176. :prop="column.prop"
  177. :label="column.label"
  178. :show-overflow-tooltip="column.showOverflowTooltip"
  179. >
  180. </el-table-column>
  181. <el-table-column fixed="right" label="操作" width="225">
  182. <template slot-scope="scope">
  183. <el-button @click.native.prevent="onUnbind(scope.row)" size="small">
  184. 解绑
  185. </el-button>
  186. </template>
  187. </el-table-column>
  188. </el-table>
  189. <div slot="footer" class="dialog-footer">
  190. <el-button :disabled="loading" @click="dialogFormVisible = false"
  191. >取 消</el-button
  192. >
  193. <el-button type="primary" :disabled="loading" @click="onSubmit('addForm')"
  194. >确 定</el-button
  195. >
  196. </div>
  197. </el-dialog>
  198. </template>
  199. <style scoped></style>