updateSeal.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <template>
  2. <el-card class="update-seal-card">
  3. <el-form
  4. ref="sealForm"
  5. :model="sealForm"
  6. :rules="sealRules"
  7. label-width="120px"
  8. >
  9. <div class="one-part">
  10. <div class="box">
  11. <el-form-item label="用印用途:" prop="Use">
  12. <el-select v-model.trim="sealForm.Use" clearable>
  13. <el-option
  14. v-for="item in purposeOptions"
  15. :key="item.value"
  16. :label="item.label"
  17. :value="item.label"
  18. ></el-option>
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item label="客户名称:" prop="CompanyName">
  22. <el-autocomplete
  23. ref="companySelector"
  24. popper-class="custom-autocomplete"
  25. placeholder="请输入用户名称"
  26. :fetch-suggestions="querySearch"
  27. :trigger-on-focus="false"
  28. @select="selectHandel"
  29. @focus="$refs.companySelector.suggestions = []"
  30. v-model.trim="sealForm.CompanyName"
  31. >
  32. <template slot-scope="{ item }">
  33. <h5 class="name">{{ item.CompanyName }}</h5>
  34. <p class="item">合同编号:{{ item.ContractCode }}</p>
  35. <p class="item">合同类型:{{ item.ContractType }}</p>
  36. <p class="item">合同金额:{{ item.Price }}</p>
  37. </template>
  38. </el-autocomplete>
  39. </el-form-item>
  40. <el-form-item label="合同类型:" prop="ServiceType">
  41. <el-select
  42. v-model="sealForm.ServiceType"
  43. :disabled="sealForm.source === '系统合同'"
  44. clearable
  45. >
  46. <el-option
  47. v-for="item in ServiceTypeOptions"
  48. :key="item.value"
  49. :label="item.label"
  50. :value="item.label"
  51. ></el-option>
  52. </el-select>
  53. </el-form-item>
  54. <el-form-item
  55. :class="{ required: sealForm.Use === '代付合同' }"
  56. label="实际使用方:"
  57. prop="UseCompanyName"
  58. ><el-input
  59. class="form-input"
  60. placeholder="请填写实际使用方名称"
  61. v-model.trim="sealForm.UseCompanyName"
  62. :disabled="sealForm.source === '系统合同'"
  63. ></el-input
  64. ></el-form-item>
  65. <el-form-item label="加盖何种印章:" prop="SealType">
  66. <el-select v-model="sealForm.SealType" multiple clearable>
  67. <el-option
  68. v-for="item in SealTypeOptions"
  69. :key="item.value"
  70. :label="item.label"
  71. :value="item.label"
  72. ></el-option>
  73. </el-select>
  74. </el-form-item>
  75. </div>
  76. <div class="box">
  77. <el-form-item label="合同来源:" prop="source">
  78. <el-radio-group v-model="sealForm.source">
  79. <el-radio label="系统合同" border>系统合同</el-radio>
  80. <el-radio label="上传附件" border>上传附件</el-radio>
  81. </el-radio-group>
  82. </el-form-item>
  83. <el-form-item label="社会信用码:" prop="CreditCode"
  84. ><el-input
  85. class="form-input"
  86. placeholder="请填写统一社会信用码"
  87. v-model.trim="sealForm.CreditCode"
  88. :disabled="sealForm.source === '系统合同'"
  89. ></el-input
  90. ></el-form-item>
  91. <el-form-item label="文件份数:" prop="FileNum"
  92. ><el-input-number
  93. :min="1"
  94. v-model="sealForm.FileNum"
  95. ></el-input-number
  96. ></el-form-item>
  97. </div>
  98. </div>
  99. <div class="two-part">
  100. <el-form-item label="审批备注:" prop="Remark"
  101. ><el-input
  102. placeholder="请填写备注"
  103. v-model="sealForm.Remark"
  104. ></el-input
  105. ></el-form-item>
  106. <el-form-item label="合同附件:" prop="fileList">
  107. <!-- 需求更改 可上传多个附件 crm_8.7 -->
  108. <el-upload
  109. list-type="picture-card"
  110. :file-list="sealForm.fileList"
  111. action="#"
  112. multiple
  113. :class="{ disabled: isUploadShow }"
  114. :on-change="changeFile"
  115. :before-upload="beforeUpload"
  116. :http-request="upload"
  117. :disabled="sealForm.source === '系统合同'"
  118. accept=".pdf,.doc,.docx"
  119. >
  120. <i class="el-icon-plus" />
  121. <div slot="file" slot-scope="{ file }">
  122. <img
  123. class="el-upload-list__item-thumbnail"
  124. :src="fileTypeIcon(file)"
  125. alt=""
  126. />
  127. <span class="el-upload-list__item-actions">
  128. <span
  129. class="el-upload-list__item-preview"
  130. @click="preview(file)"
  131. >
  132. <i class="el-icon-zoom-in"></i>
  133. </span>
  134. <span
  135. v-if="sealForm.source !== '系统合同'"
  136. class="el-upload-list__item-delete"
  137. @click="handleRemove(file)"
  138. >
  139. <i class="el-icon-delete"></i>
  140. </span>
  141. </span>
  142. </div>
  143. </el-upload>
  144. </el-form-item>
  145. </div>
  146. <div class="btn-group">
  147. <el-button @click="$router.go(-1)">取消</el-button>
  148. <el-button type="primary" @click="onSubmit">提交</el-button>
  149. </div>
  150. </el-form>
  151. </el-card>
  152. </template>
  153. <script>
  154. import { contractInterface, sealInterence } from "@/api/api.js";
  155. export default {
  156. name: "UpdateSeal",
  157. data() {
  158. // 实际使用方校验规则
  159. const ValidateUseCompanyName = (rule, val, cb) => {
  160. return this.sealForm.Use === "代付合同" && val === ""
  161. ? cb(new Error("请填写实际使用方"))
  162. : cb();
  163. };
  164. return {
  165. sealForm: {
  166. //表单数据
  167. Use: "", //用印用途
  168. CompanyName: "", //客户名称
  169. ServiceType: "", //合同类型
  170. UseCompanyName: "", //实际使用方
  171. SealType: [], //加盖何种印章
  172. source: "系统合同", //合同来源
  173. CreditCode: "", //社会信用码
  174. FileNum: 1, //文件份数
  175. Remark: "", //审批备注
  176. fileList: [], //合同附件
  177. ContractId: 0, //合同id(默认为0)
  178. },
  179. sealRules: {
  180. //表单校验规则
  181. Use: [{ required: true, message: "请选择用印用途", trigger: "blur" }],
  182. CompanyName: [
  183. { required: true, message: "请选择客户名称", trigger: "blur" },
  184. ],
  185. ServiceType: [
  186. { required: true, message: "请选择合同类型", trigger: "change" },
  187. ],
  188. UseCompanyName: [
  189. { validator: ValidateUseCompanyName, trigger: "change" },
  190. ],
  191. SealType: [
  192. { required: true, message: "请选择加盖何种印章", trigger: "blur" },
  193. ],
  194. CreditCode: [
  195. { required: true, message: "请填写社会信用码", trigger: "change" },
  196. ],
  197. fileList: [
  198. { required: true, message: "请上传合同附件", trigger: "change" },
  199. ],
  200. },
  201. purposeOptions: [
  202. //用印用途选项
  203. { label: "销售合同", value: 1 },
  204. { label: "代付合同", value: 2 },
  205. { label: "渠道合同", value: 3 },
  206. { label: "付款通知函", value: 4 },
  207. { label: "招投标", value: 5 },
  208. { label: "战略合作协议", value: 6 },
  209. { label: "总对总协议", value: 7 },
  210. ],
  211. ServiceTypeOptions: [
  212. //合同类型选项
  213. { label: "新签合同", value: 1 },
  214. { label: "续约合同", value: 2 },
  215. { label: "补充协议", value: 3 },
  216. { label: "代付合同", value: 4 },
  217. ],
  218. SealTypeOptions: [
  219. //加盖何种印章选项
  220. { label: "合同章", value: 1 },
  221. { label: "公章", value: 2 },
  222. { label: "法人章", value: 3 },
  223. ],
  224. isWatch: true, // 控制watch是否触发
  225. };
  226. },
  227. created() {
  228. // 如果是编辑页面先获取用印详情信息
  229. if (this.sealId) {
  230. this.getsealApprovalDetail();
  231. }
  232. },
  233. computed: {
  234. // 用印id,有则表示编辑,无表示新增
  235. sealId() {
  236. return this.$route.query.id || null;
  237. },
  238. // 判断上传控件是否显示
  239. isUploadShow() {
  240. return (
  241. // this.sealForm.fileList.length === 1 ||
  242. this.sealForm.source === "系统合同"
  243. );
  244. },
  245. },
  246. methods: {
  247. // 获取用印详情
  248. async getsealApprovalDetail() {
  249. try {
  250. const res = await sealInterence.sealApprovalDetail({
  251. SealId: this.sealId,
  252. });
  253. if (res.Ret === 200) {
  254. // 关闭监听
  255. this.isWatch = false;
  256. const SealDetail = res.Data.SealDetail;
  257. this.sealForm.Use = SealDetail.Use;
  258. this.sealForm.CreditCode = SealDetail.CreditCode;
  259. this.sealForm.ContractId = SealDetail.ContractId;
  260. this.sealForm.CompanyName = SealDetail.CompanyName;
  261. this.sealForm.FileNum = SealDetail.FileNum;
  262. // 返回数据改为多个文件url的数组 FileUrls
  263. // this.sealForm.fileList.push({ FileUrl: SealDetail.FileUrl });
  264. SealDetail.FileUrls.map(i =>{
  265. this.sealForm.fileList.push({FileUrl:i})
  266. })
  267. this.sealForm.Remark = SealDetail.Remark;
  268. this.sealForm.SealType = SealDetail.SealType.split(",");
  269. this.sealForm.ServiceType = SealDetail.ServiceType;
  270. this.sealForm.UseCompanyName = SealDetail.UseCompanyName;
  271. this.sealForm.source =
  272. SealDetail.ContractId > 0 ? "系统合同" : "上传附件";
  273. // 打开监听
  274. this.$nextTick(() => {
  275. this.isWatch = true;
  276. });
  277. }
  278. } catch (err) {
  279. console.log(err);
  280. }
  281. },
  282. // 合同预览
  283. preview(file) {
  284. const fileType = this.fileType(file.FileUrl);
  285. let href = "";
  286. if (fileType === "word") {
  287. href =
  288. "https://view.officeapps.live.com/op/view.aspx?src=" + file.FileUrl;
  289. } else {
  290. href = file.FileUrl;
  291. }
  292. window.open(href, "_blank");
  293. },
  294. // 合同移除
  295. handleRemove(file) {
  296. this.sealForm.fileList = this.sealForm.fileList.filter(
  297. (item) => item.uid !== file.uid
  298. );
  299. },
  300. // 修改文件时触发 [选择了文件,上传成功,上传失败]
  301. changeFile(file, fileList) {
  302. this.fileList = fileList.map((item) => item);
  303. },
  304. // 上传之前的钩子
  305. beforeUpload(file) {
  306. // 检查文件类型
  307. if (this.fileType(file.name) === "other") {
  308. this.$message.error("上传文件只能是 PDF、DOC、DOCX 格式!");
  309. return false;
  310. }
  311. // 检查大小
  312. // const maxSize = 10 * 1024 * 1024
  313. // if (maxSize < file.size) {
  314. // this.$message.error('图片大小最大不能超过5M')
  315. // return false
  316. // }
  317. return true; // 最后一定要return true
  318. },
  319. // 上传事件
  320. async upload(params) {
  321. if (!params.file) return;
  322. const fd = new FormData();
  323. fd.append("file", params.file);
  324. try {
  325. const res = await sealInterence.resourceUpload(fd);
  326. if (res.Ret === 200) {
  327. // this.sealForm.fileList = [];
  328. this.sealForm.fileList.push({ FileUrl: res.Data.ResourceUrl });
  329. // 单独清除合同附件的校验
  330. this.$refs.sealForm.clearValidate("fileList");
  331. this.$message.success("上传成功");
  332. }
  333. } catch (err) {
  334. console.log(err);
  335. }
  336. },
  337. // 关键字联想
  338. async querySearch(queryString, cb) {
  339. // 合同来源为上传附件时不进行联想
  340. if (this.sealForm.source === "上传附件" || queryString === "")
  341. return cb([]);
  342. let results = [];
  343. try {
  344. const res = await sealInterence.getContractListBySeal({
  345. Keyword: queryString,
  346. });
  347. if (res.Ret === 200) {
  348. results = res.Data;
  349. }
  350. } catch (err) {
  351. console.log(err);
  352. }
  353. if (!results.length) this.sealForm.ContractId = 0;
  354. // 调用 callback 返回建议列表的数据
  355. cb(results);
  356. },
  357. // 选择事件
  358. selectHandel(item) {
  359. this.sealForm.CompanyName = item.CompanyName;
  360. this.sealForm.UseCompanyName =
  361. item.ContractBusinessType === "代付合同"
  362. ? item.UserCompanyName
  363. : item.CompanyName;
  364. this.sealForm.ContractId = item.ContractId;
  365. this.sealForm.ServiceType = item.ContractType;
  366. this.sealForm.CreditCode = item.CreditCode;
  367. this.sealForm.fileList = [];
  368. this.sealForm.fileList.push({ FileUrl: item.FileUrl });
  369. // 单独清除合同附件的校验
  370. this.$refs.sealForm.clearValidate("fileList");
  371. },
  372. // 表单提交
  373. async onSubmit() {
  374. try {
  375. await this.$refs.sealForm.validate();
  376. const formData = {
  377. CompanyName: this.sealForm.CompanyName,
  378. ContractId: this.sealForm.ContractId,
  379. CreditCode: this.sealForm.CreditCode,
  380. FileNum: this.sealForm.FileNum,
  381. FileUrls: this.sealForm.fileList.map(item => item.FileUrl),
  382. Remark: this.sealForm.Remark,
  383. SealType: this.sealForm.SealType.join(","),
  384. ServiceType: this.sealForm.ServiceType,
  385. Use: this.sealForm.Use,
  386. UseCompanyName: this.sealForm.UseCompanyName,
  387. };
  388. let res = {};
  389. if (this.sealId) {
  390. // 编辑用印
  391. formData.SealId = this.sealId * 1;
  392. res = await sealInterence.sealEditSealApproval(formData);
  393. } else {
  394. // 新增用印
  395. res = await sealInterence.sealApplySealApproval(formData);
  396. }
  397. // 成功
  398. if (res.Ret === 200) {
  399. this.$message.success(res.Msg);
  400. this.$router.go(-1);
  401. }
  402. } catch (err) {
  403. console.log(err);
  404. }
  405. },
  406. // 根据文件返回文件图标
  407. fileTypeIcon(file) {
  408. if (!file.FileUrl) return "";
  409. const fileType = this.fileType(file.FileUrl);
  410. return fileType === "word"
  411. ? require("@/assets/img/constract/word-icon.png")
  412. : require("@/assets/img/constract/pdf.png");
  413. },
  414. // 根据fileUrl判断文件类型
  415. fileType(fileUrl) {
  416. if (/^.+(\.pdf)$/i.test(fileUrl)) {
  417. return "pdf";
  418. } else if (/^.+(\.doc|\.docx)$/i.test(fileUrl)) {
  419. return "word";
  420. } else {
  421. return "other";
  422. }
  423. },
  424. },
  425. watch: {
  426. // 切换合同来源时清空表单
  427. "sealForm.source"(val) {
  428. if (!this.isWatch) return;
  429. this.sealForm = {
  430. Use: "", //用印用途
  431. CompanyName: "", //客户名称
  432. ServiceType: "", //合同类型
  433. UseCompanyName: "", //实际使用方
  434. SealType: [], //加盖何种印章
  435. source: val, //合同来源
  436. CreditCode: "", //社会信用码
  437. FileNum: 1, //文件份数
  438. Remark: "", //审批备注
  439. fileList: [], //合同附件
  440. ContractId: 0, //合同id(默认为0)
  441. };
  442. // 清除校验提示
  443. this.$nextTick(() => {
  444. this.$refs.sealForm.clearValidate();
  445. });
  446. },
  447. },
  448. };
  449. </script>
  450. <style lang='scss'>
  451. .update-seal-card {
  452. .one-part {
  453. display: flex;
  454. .box {
  455. flex: 1;
  456. }
  457. .el-select,
  458. .el-autocomplete,
  459. .form-input {
  460. width: 300px;
  461. }
  462. .el-input-number {
  463. width: 120px;
  464. .el-input .el-input__inner {
  465. pointer-events: none;
  466. }
  467. }
  468. .required .el-form-item__label {
  469. &::before {
  470. content: "*";
  471. color: #f56c6c;
  472. margin-right: 4px;
  473. }
  474. }
  475. }
  476. .two-part {
  477. .disabled .el-upload--picture-card {
  478. visibility: hidden;
  479. }
  480. .el-upload-list {
  481. // position: absolute;
  482. .el-upload-list__item {
  483. border: 0;
  484. }
  485. }
  486. }
  487. .btn-group {
  488. display: flex;
  489. justify-content: center;
  490. }
  491. }
  492. .custom-autocomplete {
  493. .item {
  494. line-height: 20px;
  495. }
  496. }
  497. </style>