dialog.edit.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <div class="rule-type">
  3. <el-dialog
  4. :title="id ? '编辑安全责任书' : '新增安全责任书'"
  5. :visible.sync="isShow"
  6. @close="onHide"
  7. width="700px"
  8. >
  9. <div class="page-body">
  10. <el-form
  11. :model="formData"
  12. :rules="formDataRules"
  13. size="small"
  14. ref="form"
  15. label-position="right"
  16. label-width="130px"
  17. label-prefix=":"
  18. >
  19. <el-form-item prop="orgId" label="签署责任人所在机构:">
  20. <tree-select
  21. v-model="formData.orgId"
  22. :options="deptOptions"
  23. :show-count="true"
  24. :normalizer="tenantIdnormalizer"
  25. :props="{ checkStrictly: true, label: 'name' }"
  26. placeholder="请选择签署责任人所在机构"
  27. />
  28. </el-form-item>
  29. <el-form-item prop="type" label="签署责任书类型:">
  30. <el-select
  31. v-model="formData.type"
  32. style="width: 100%"
  33. placeholder="请选择签署责任书类型"
  34. >
  35. <el-option
  36. v-for="dict in dict.type.safety_book_type"
  37. :key="dict.value"
  38. :label="dict.label"
  39. :value="`${dict.value}`"
  40. ></el-option>
  41. </el-select>
  42. </el-form-item>
  43. </el-form>
  44. <el-button @click="openSelect">新增签署</el-button>
  45. <el-table :data="tableData" style="width: 100%" height="400px">
  46. <el-table-column prop="names" label="姓名">
  47. <template slot-scope="scope">
  48. <template v-for="item in scope.row.names">
  49. {{ item }}
  50. <br />
  51. </template>
  52. </template>
  53. </el-table-column>
  54. <el-table-column prop="time" label="签署时间"> </el-table-column>
  55. <el-table-column prop="files" label="签署文件"> </el-table-column>
  56. <el-table-column prop="names" label="操作">
  57. <template v-slot="{ row }">
  58. <el-button type="text" @click="removeRow(row)">删除</el-button>
  59. </template>
  60. </el-table-column>
  61. </el-table>
  62. </div>
  63. <div slot="footer" class="dialog-footer">
  64. <el-button @click="isShow = false">取消</el-button>
  65. <el-button type="primary" @click="onSubmit">确定</el-button>
  66. </div>
  67. </el-dialog>
  68. <DialogSelect ref="DialogSelect" @success="getSign"></DialogSelect>
  69. </div>
  70. </template>
  71. <script>
  72. import { mapState, mapMutations } from "vuex";
  73. import {
  74. listSafetyBook,
  75. getSafetyBook,
  76. editOrAdd,
  77. delSafetyBook,
  78. } from "@/api/safetyBook/index";
  79. import { deptTreeSelect } from "@/api/system/public";
  80. import DialogSelect from "./dialog.sign";
  81. export default {
  82. dicts: ["safety_book_type"],
  83. data() {
  84. return {
  85. id: null,
  86. isShow: false,
  87. formData: this.reset(),
  88. tableData: [],
  89. //修改新增中的机构树
  90. deptOptions: [],
  91. formDataRules: {
  92. orgId: [{ required: true, message: "请选择签署责任人所在机构" }],
  93. type: [{ required: true, message: "请选择签署责任书类型" }],
  94. },
  95. };
  96. },
  97. watch: {},
  98. computed: {
  99. ...mapState([]),
  100. },
  101. methods: {
  102. ...mapMutations([]),
  103. //添加签署后回调
  104. getSign(data) {
  105. this.tableData.push(data);
  106. // console.log(data, "ddd");
  107. },
  108. //新增签署
  109. openSelect() {
  110. this.$refs.DialogSelect.show();
  111. },
  112. /** 查询机构树数据 */
  113. getDeptTree() {
  114. deptTreeSelect().then((response) => {
  115. this.deptOptions = response.data;
  116. });
  117. },
  118. /** treeSelect组件自定义数据*/
  119. tenantIdnormalizer(node, instanceId) {
  120. if (node.children && !node.children.length) {
  121. delete node.children;
  122. }
  123. return {
  124. id: node.id,
  125. label: node.shortName,
  126. children: node.children,
  127. };
  128. },
  129. removeRow(row) {
  130. this.tableData = this.tableData.filter((item) => item !== row);
  131. },
  132. reset() {
  133. return {
  134. id: null,
  135. type: null,
  136. };
  137. },
  138. async refresh(id) {
  139. if(id!=null&&id!=undefined){
  140. await getSafetyBook(id).then((res) => {
  141. // console.log(res.data,"res")
  142. this.formData=res.data;
  143. this.tableData=res.data.bookUsers;
  144. });
  145. }
  146. },
  147. async show(id) {
  148. // console.log(id, "id");
  149. this.getDeptTree();
  150. this.formData=this.reset();
  151. this.tableData=[];
  152. this.id = id;
  153. await this.refresh(id);
  154. this.isShow = true;
  155. },
  156. // 事件
  157. onHide() {
  158. this.formData = this.reset();
  159. this.$refs.form.resetFields();
  160. },
  161. onSubmit() {
  162. console.log(this.formData,"this.formData")
  163. this.$refs.form.validate(async (isValidate) => {
  164. if (!isValidate) return;
  165. this.formData.bookUsers=this.tableData;
  166. await editOrAdd(this.formData);
  167. this.$emit("success");
  168. this.isShow = false;
  169. });
  170. },
  171. // 事件
  172. //apimark//
  173. },
  174. mounted() {},
  175. components: { DialogSelect },
  176. };
  177. </script>
  178. <style lang="scss" scoped>
  179. .brand_info {
  180. .el-form {
  181. width: 600px;
  182. padding-top: 40px;
  183. }
  184. }
  185. </style>