dialog.edit.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <div class="rule-type">
  3. <DialogCom
  4. :title="id ? '编辑安全责任书存档记录' : '新增安全责任书存档记录'"
  5. :visible.sync="isShow"
  6. @close="onHide"
  7. width="1200px"
  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="180px"
  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: 'shortName' }"
  26. placeholder="请选择乙方所属机构"
  27. />
  28. </el-form-item>
  29. <el-form-item label="所属年度:" prop="year">
  30. <el-date-picker
  31. v-model="formData.year"
  32. :clearable="timeClearable"
  33. type="year"
  34. placeholder="请选择责任书所属年度"
  35. value-format="yyyy"
  36. >
  37. </el-date-picker>
  38. </el-form-item>
  39. <el-form-item prop="type" label="签署责任书类型:">
  40. <el-select
  41. v-model="formData.type"
  42. style="width: 100%"
  43. placeholder="请选择签署责任书类型"
  44. >
  45. <el-option
  46. v-for="dict in dict.type.safety_book_type"
  47. :key="dict.value"
  48. :label="dict.label"
  49. :value="`${dict.value}`"
  50. ></el-option>
  51. </el-select>
  52. </el-form-item>
  53. </el-form>
  54. <el-button @click="openSelect">上传签署文件</el-button>
  55. <el-table
  56. :data="tableData"
  57. style="width: 100%; margin-top: 10px"
  58. height="500px"
  59. >
  60. <!-- <el-table-column prop="names" label="签署人">
  61. <template slot-scope="scope">
  62. <template v-for="item in scope.row.names">
  63. {{ item }}
  64. <br />
  65. </template>
  66. </template>
  67. </el-table-column> -->
  68. <el-table-column prop="partyA" label="甲方"> </el-table-column>
  69. <el-table-column prop="partyAOrg" label="甲方机构"> </el-table-column>
  70. <el-table-column prop="partyB" label="乙方"> </el-table-column>
  71. <el-table-column prop="partyBOrg" label="乙方机构"> </el-table-column>
  72. <el-table-column prop="time" label="签署时间">
  73. <template slot-scope="r">
  74. {{ r.row.time ? dayjs(r.row.time).format("YYYY年MM月DD日") : "" }}
  75. </template>
  76. </el-table-column>
  77. <el-table-column prop="files" width="400px" label="签署文件">
  78. <template slot-scope="r">
  79. <div
  80. v-for="(file, index) in r.row.files"
  81. :key="index"
  82. class="container"
  83. >
  84. <el-image
  85. class="item"
  86. v-if="isPic(file.url)"
  87. :src="file.url"
  88. :preview-src-list="[file.url]"
  89. fit="contain"
  90. ></el-image>
  91. <div v-else="isPic(file.url)">
  92. <el-link :href="file.url" :underline="false" target="_blank">
  93. <span class="el-icon-document"> {{ file.name }} </span>
  94. </el-link>
  95. </div>
  96. </div>
  97. </template>
  98. </el-table-column>
  99. <el-table-column prop="names" label="操作">
  100. <template v-slot="{ row }">
  101. <el-button type="text" @click="editII(row)">编辑</el-button>
  102. <el-button type="text" @click="removeRow(row)">删除</el-button>
  103. </template>
  104. </el-table-column>
  105. </el-table>
  106. </div>
  107. <div slot="footer" class="dialog-footer" style="margin-top: 10px">
  108. <el-button @click="isShow = false">取消</el-button>
  109. <el-button type="primary" @click="onSubmit">确定</el-button>
  110. </div>
  111. </DialogCom>
  112. <DialogSelect ref="DialogSelect" @success="getSign"></DialogSelect>
  113. </div>
  114. </template>
  115. <script>
  116. import { mapState, mapMutations } from "vuex";
  117. import { mapGetters } from "vuex";
  118. import {
  119. listSafetyBook,
  120. getSafetyBook,
  121. editOrAdd,
  122. delSafetyBook,
  123. } from "@/api/safetyBook/index";
  124. import { deptTreeSelect } from "@/api/system/public";
  125. import DialogSelect from "./dialog.sign";
  126. import dayjs from "dayjs";
  127. export default {
  128. dicts: ["safety_book_type"],
  129. data() {
  130. return {
  131. id: null,
  132. isShow: false,
  133. timeClearable: true,
  134. formData: this.reset(),
  135. tableData: [],
  136. //修改新增中的机构树
  137. deptOptions: [],
  138. formDataRules: {
  139. orgId: [
  140. {
  141. required: true,
  142. message: "请选择签署责任人所在机构",
  143. trigger: "blur",
  144. },
  145. ],
  146. type: [{ required: true, message: "请选择签署责任书类型" }],
  147. year: [{ required: true, message: "请选择所属年度" }],
  148. },
  149. };
  150. },
  151. watch: {},
  152. computed: {
  153. ...mapState([]),
  154. ...mapGetters(["orgId", "orgName"]),
  155. },
  156. methods: {
  157. ...mapMutations([]),
  158. isPic(url) {
  159. if (url.endsWith("jpg") || url.endsWith("png")) {
  160. return true;
  161. }
  162. return false;
  163. },
  164. // getUrl(files) {
  165. // console.log(files, "eeee");
  166. // let arr = [];
  167. // files.forEach((item) => {
  168. // arr.push(JSON.parse(item));
  169. // });
  170. // console.log(
  171. // arr.map((e) => e.url),
  172. // "dataaa"
  173. // );
  174. // // return arr.map((e) => e.url);
  175. // return arr;
  176. // },
  177. // showHow(files) {
  178. // let file = files.split(",");
  179. // if (file[0].endsWith(".jpg")) {
  180. // return true;
  181. // }
  182. // return false;
  183. // },
  184. dayjs,
  185. //添加签署后回调
  186. getSign(data, row) {
  187. this.tableData = this.tableData.filter((item) => item !== row);
  188. this.tableData.push(data);
  189. // console.log(data, "ddd");
  190. // console.log(row, "row");
  191. },
  192. editII(row) {
  193. // console.log(row,"wwwwwww")
  194. this.$refs.DialogSelect.show(row);
  195. // this.tableData = this.tableData.filter((item) => item !== row);
  196. },
  197. //新增签署
  198. openSelect() {
  199. this.$refs.DialogSelect.show();
  200. },
  201. /** 查询机构树数据 */
  202. getDeptTree() {
  203. deptTreeSelect().then((response) => {
  204. this.deptOptions = response.data;
  205. });
  206. },
  207. /** treeSelect组件自定义数据*/
  208. tenantIdnormalizer(node, instanceId) {
  209. if (node.children && !node.children.length) {
  210. delete node.children;
  211. }
  212. return {
  213. id: node.id,
  214. label: node.shortName,
  215. children: node.children,
  216. };
  217. },
  218. removeRow(row) {
  219. this.$modal
  220. .confirm("是否确认删除?")
  221. .then(function () {})
  222. .then(() => {
  223. this.tableData = this.tableData.filter((item) => item !== row);
  224. this.$modal.msgSuccess("删除成功");
  225. });
  226. // this.tableData.splice(index, 1);
  227. },
  228. reset() {
  229. return {
  230. id: null,
  231. type: null,
  232. year: null,
  233. };
  234. },
  235. async refresh(id) {
  236. if (id != null && id != undefined) {
  237. await getSafetyBook(id).then((res) => {
  238. // console.log(res.data,"res")
  239. this.formData = res.data;
  240. this.tableData = res.data.bookUsers;
  241. });
  242. }
  243. },
  244. async show(id) {
  245. // console.log(id, "id");
  246. this.getDeptTree();
  247. this.formData = this.reset();
  248. this.tableData = [];
  249. this.id = id;
  250. await this.refresh(id);
  251. if (id) {
  252. } else {
  253. // console.log(this.orgId,"this.orgId")
  254. this.formData.orgId = this.orgId;
  255. }
  256. this.isShow = true;
  257. },
  258. // 事件
  259. onHide() {
  260. this.formData = this.reset();
  261. this.$refs.form.resetFields();
  262. },
  263. onSubmit() {
  264. // console.log(this.formData,"this.formData")
  265. this.$refs.form.validate(async (isValidate) => {
  266. if (!isValidate) return;
  267. this.formData.bookUsers = this.tableData;
  268. await editOrAdd(this.formData);
  269. this.$emit("success");
  270. this.isShow = false;
  271. });
  272. },
  273. // 事件
  274. //apimark//
  275. },
  276. mounted() {},
  277. components: { DialogSelect },
  278. };
  279. </script>
  280. <style lang="scss" scoped>
  281. .brand_info {
  282. .el-form {
  283. width: 600px;
  284. padding-top: 40px;
  285. }
  286. }
  287. .container {
  288. width: 50px;
  289. height: 50px;
  290. float: left;
  291. .item {
  292. width: 100%;
  293. height: 100%;
  294. }
  295. .item img {
  296. width: 100% !important;
  297. object-fit: cover !important;
  298. }
  299. }
  300. </style>