EditHomeRegister.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. <template>
  2. <div>
  3. <el-dialog
  4. :title="isView ? '新增' : '编辑'"
  5. :visible.sync="dialogVisible"
  6. :before-close="cancle"
  7. width="60%"
  8. >
  9. <el-form
  10. :inline="true"
  11. :model="ruleForm"
  12. :rules="rules"
  13. ref="ruleForm"
  14. label-width="200px"
  15. class="demo-ruleForm"
  16. >
  17. <el-row>
  18. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  19. <el-form-item label="报告来源" prop="reportSource">
  20. <el-input
  21. v-model="ruleForm.reportSource"
  22. class="inputCom"
  23. placeholder="请输入报告来源"
  24. ></el-input>
  25. </el-form-item>
  26. </el-col>
  27. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  28. <el-form-item label="公司名称" prop="companyName">
  29. <el-input
  30. v-model="ruleForm.companyName"
  31. class="inputCom"
  32. placeholder="请输入公司名称"
  33. ></el-input>
  34. </el-form-item>
  35. </el-col>
  36. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  37. <el-form-item label="公司英文名称" prop="companyEname">
  38. <el-input
  39. v-model="ruleForm.companyEname"
  40. class="inputCom"
  41. placeholder="请输入公司英文名称"
  42. ></el-input>
  43. </el-form-item>
  44. </el-col>
  45. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  46. <el-form-item label="是否展示详细信息" prop="isDetail">
  47. <el-select v-model="ruleForm.isDetail" placeholder="请选择否展示详细信息">
  48. <el-option
  49. :label="item.name"
  50. :value="item.id"
  51. v-for="item in isDetailList"
  52. :key="item.id"
  53. ></el-option>
  54. </el-select>
  55. </el-form-item>
  56. </el-col>
  57. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  58. <el-form-item label="公司logo" prop="logo">
  59. <el-upload
  60. accept=".png, .jpg, .jpeg"
  61. class="avatar-uploader"
  62. name="file"
  63. :action="action"
  64. :show-file-list="false"
  65. :on-success="handleLogoSuccess"
  66. :before-upload="beforeAvatarUpload"
  67. >
  68. <img v-if="ruleForm.logo" :src="ruleForm.logo" class="avatar" />
  69. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  70. <div class="el-upload__tip" slot="tip">
  71. 建议上传jpg/png/jpeg文件,且不超过500kb
  72. </div>
  73. </el-upload>
  74. </el-form-item>
  75. </el-col>
  76. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  77. <el-form-item label="首页二维码" prop="firstPageCode">
  78. <el-upload
  79. accept=".png, .jpg, .jpeg"
  80. class="avatar-uploader"
  81. name="file"
  82. :action="action"
  83. :show-file-list="false"
  84. :on-success="handleFirstPageCodeSuccess"
  85. :before-upload="beforeAvatarUpload"
  86. >
  87. <img
  88. v-if="ruleForm.firstPageCode"
  89. :src="ruleForm.firstPageCode"
  90. class="avatar"
  91. />
  92. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  93. <div class="el-upload__tip" slot="tip">
  94. 建议上传jpg/png/jpeg文件,且不超过500kb
  95. </div>
  96. </el-upload>
  97. </el-form-item>
  98. </el-col>
  99. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  100. <el-form-item label="网址" prop="webAddress">
  101. <el-input
  102. v-model="ruleForm.webAddress"
  103. class="inputCom"
  104. placeholder="请输入网址"
  105. ></el-input>
  106. </el-form-item>
  107. </el-col>
  108. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  109. <el-form-item label="邮箱" prop="mail">
  110. <el-input
  111. v-model="ruleForm.mail"
  112. class="inputCom"
  113. placeholder="请输入邮箱"
  114. ></el-input>
  115. </el-form-item>
  116. </el-col>
  117. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  118. <el-form-item label="是否展示尾页二维码" prop="isCode">
  119. <el-select v-model="ruleForm.isCode" placeholder="请选择是否展示尾页二维码">
  120. <el-option
  121. :label="item.name"
  122. :value="item.id"
  123. v-for="item in isCodeList"
  124. :key="item.id"
  125. ></el-option>
  126. </el-select>
  127. </el-form-item>
  128. </el-col>
  129. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  130. <el-form-item label="是否展示尾页公司名及地址" prop="isLastPageName">
  131. <el-select
  132. v-model="ruleForm.isLastPageName"
  133. placeholder="请选择是否展示尾页公司名及地址"
  134. >
  135. <el-option
  136. :label="item.name"
  137. :value="item.id"
  138. v-for="item in isLastPageNameList"
  139. :key="item.id"
  140. ></el-option>
  141. </el-select>
  142. </el-form-item>
  143. </el-col>
  144. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  145. <el-form-item label="尾页公司名" prop="lastPageName">
  146. <el-input
  147. v-model="ruleForm.lastPageName"
  148. class="inputCom"
  149. placeholder="请输入尾页公司名"
  150. ></el-input>
  151. </el-form-item>
  152. </el-col>
  153. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  154. <el-form-item label="尾页公司地址" prop="lastPageAddress">
  155. <el-input
  156. v-model="ruleForm.lastPageAddress"
  157. class="inputCom"
  158. placeholder="请输入尾页公司地址"
  159. ></el-input>
  160. </el-form-item>
  161. </el-col>
  162. </el-row>
  163. <el-row>
  164. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  165. <el-form-item label="尾页二维码" prop="lastPageCode">
  166. <el-upload
  167. accept=".png, .jpg, .jpeg"
  168. class="avatar-uploader"
  169. name="file"
  170. :action="action"
  171. :show-file-list="false"
  172. :on-success="handleLastPageCodeSuccess"
  173. :before-upload="beforeAvatarUpload"
  174. >
  175. <img
  176. v-if="ruleForm.lastPageCode"
  177. :src="ruleForm.lastPageCode"
  178. class="avatar"
  179. />
  180. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  181. <div class="el-upload__tip" slot="tip">
  182. 建议上传jpg/png/jpeg文件,且不超过500kb
  183. </div>
  184. </el-upload>
  185. </el-form-item>
  186. </el-col>
  187. </el-row>
  188. </el-form>
  189. <span slot="footer" class="dialog-footer">
  190. <el-button @click="cancle" round>取 消</el-button>
  191. <el-button
  192. v-show="isView"
  193. type="primary"
  194. round
  195. :disabled="disableFlag"
  196. @click="submitCom"
  197. >确 定</el-button
  198. >
  199. <el-button
  200. v-show="!isView"
  201. type="primary"
  202. round
  203. :disabled="disableFlag"
  204. @click="submitCom"
  205. >修 改</el-button
  206. >
  207. </span>
  208. </el-dialog>
  209. </div>
  210. </template>
  211. <script>
  212. // import { oSessionStorage } from "../../utils/utils";
  213. import { oSessionStorage } from "../utils/utils";
  214. import { basePath } from "../utils/http";
  215. import md5 from "md5";
  216. export default {
  217. data() {
  218. return {
  219. action: "",
  220. disableFlag: false,
  221. phoneFlag: false,
  222. flag: 3,
  223. dialogVisible: false,
  224. //渠道列表
  225. stateList: [
  226. { name: "签约", state: "1" },
  227. { name: "解约", state: "0" },
  228. ],
  229. isDetailList: [
  230. { name: "是", id: "1" },
  231. { name: "否", id: "0" },
  232. ],
  233. isCodeList: [
  234. { name: "是", id: "1" },
  235. { name: "否", id: "0" },
  236. ],
  237. isLastPageNameList: [
  238. { name: "是", id: "1" },
  239. { name: "否", id: "0" },
  240. ],
  241. ruleForm: {
  242. //渠道ID
  243. channelId: "",
  244. //报告来源
  245. reportSource: "",
  246. //公司名称
  247. companyName: "",
  248. //是否展示详细信息
  249. isDetail: "",
  250. //公司英文名称
  251. companyEname: "",
  252. //网址
  253. webAddress: "",
  254. //是否展示尾页二维码
  255. isCode: "",
  256. //是否展示尾页公司名称及地址
  257. isLastPageName: "",
  258. // //尾页公司名称
  259. lastPageName: "",
  260. //尾页公司地址
  261. lastPageAddress: "",
  262. //是否删除
  263. isDelete: "",
  264. //主键
  265. id: "",
  266. //邮箱
  267. mail: "",
  268. //尾页二维码
  269. lastPageCode: "",
  270. //公司logo
  271. logo: "",
  272. //首页二维码
  273. firstPageCode: "",
  274. },
  275. isView: true,
  276. rules: {
  277. reportSource: [{ required: true, message: "请输入报告来源", trigger: "blur" }],
  278. // phone: [
  279. // { required: true, message: "请输入手机号", trigger: "blur" },
  280. // {
  281. // pattern: /^1[3456789]\d{9}$/,
  282. // message: "请输入正确的手机号",
  283. // trigger: ["blur", "change"],
  284. // },
  285. // ],
  286. isDetail: [
  287. { required: true, message: "请选择是否展示详细信息", trigger: "change" },
  288. ],
  289. isLastPageName: [
  290. { required: true, message: "是否展示尾页公司名称及地址", trigger: "change" },
  291. ],
  292. mail: [
  293. // { required: true, message: "请输选择邮箱", trigger: "blur" },
  294. { type: "email", message: "请输入正确的邮箱地址", trigger: ["blur", "change"] },
  295. ],
  296. },
  297. };
  298. },
  299. mounted() {
  300. let userInfo = JSON.parse(oSessionStorage.getItem("userInfo"));
  301. this.ruleForm.parentCode = userInfo.invitationCode;
  302. this.action = basePath + "/file/customUpload";
  303. //获取到router 传输过来的信息
  304. this.ruleForm.channelId = this.$route.query.channelId;
  305. //获取渠道信息
  306. // this.ruleForm.type = "3";
  307. },
  308. methods: {
  309. disableFlagStatus() {
  310. setTimeout(() => {
  311. this.disableFlag = false;
  312. }, 1500);
  313. },
  314. beforeAvatarUpload(file) {
  315. const fileName = file.name;
  316. const fileType = fileName.substring(fileName.lastIndexOf("."));
  317. if (fileType !== ".jpg" && fileType !== ".jpeg" && fileType !== ".png") {
  318. // alert("请上传jpg、jpge或png的图片!");
  319. this.$message.error("请上传jpg、jpge或png的图片!");
  320. return false;
  321. }
  322. return true;
  323. },
  324. //上传成功后的回调
  325. handleLogoSuccess(data) {
  326. if (data.code == 200) {
  327. this.ruleForm.logo = basePath + "/file/show?filePath=" + data.data;
  328. } else {
  329. //失败
  330. }
  331. },
  332. handleFirstPageCodeSuccess(data) {
  333. if (data.code == 200) {
  334. this.ruleForm.firstPageCode = basePath + "/file/show?filePath=" + data.data;
  335. } else {
  336. //失败
  337. }
  338. },
  339. handleLastPageCodeSuccess(data) {
  340. if (data.code == 200) {
  341. this.ruleForm.lastPageCode = basePath + "/file/show?filePath=" + data.data;
  342. } else {
  343. //失败
  344. }
  345. },
  346. phoneCheck() {
  347. //判断是否重复
  348. this.$http.get(`v1/system/checkPhone/${this.ruleForm.phone}`, {}, (res) => {
  349. // this.$toast.success({message:'成功'});
  350. if (res && res.code == 200) {
  351. if (res.data) {
  352. this.phoneFlag = true;
  353. } else {
  354. this.phoneFlag = false;
  355. // this.$toast.success({ message: "手机号重复" });
  356. this.$message.warning("手机号重复");
  357. }
  358. } else {
  359. // this.$toast.fail({ message: res.msg });
  360. this.$message.error(res.msg);
  361. }
  362. });
  363. },
  364. timeChange(val) {
  365. if (val !== null) {
  366. //根据时间得到格式化的数据
  367. this.ruleForm.birthDate = this.formatterTime(val);
  368. }
  369. },
  370. formatterTime(val) {
  371. let date = new Date(val);
  372. let year = date.getFullYear();
  373. let month = date.getMonth() + 1;
  374. month = this.formatterMon(month);
  375. let day = date.getDate();
  376. day = this.formatterMon(day);
  377. return year + "-" + month + "-" + day;
  378. },
  379. formatterMon(val) {
  380. if (val < 10) {
  381. return "0" + val;
  382. } else {
  383. return val;
  384. }
  385. },
  386. open(val) {
  387. this.dialogVisible = true;
  388. this.isView = val;
  389. this.ruleForm.channelId = val;
  390. this.$nextTick(() => {
  391. this.$refs["ruleForm"].clearValidate();
  392. });
  393. },
  394. edit(val) {
  395. this.dialogVisible = true;
  396. this.isView = false;
  397. this.ruleForm.channelId = val.channelId;
  398. //报告来源
  399. this.ruleForm.reportSource = val.reportSource;
  400. //公司名称
  401. this.ruleForm.companyName = val.companyName;
  402. //是否展示详细信息
  403. this.ruleForm.isDetail = val.isDetail;
  404. //公司英文名称
  405. this.ruleForm.companyEname = val.companyEname;
  406. //网址
  407. this.ruleForm.webAddress = val.webAddress;
  408. //是否展示尾页二维码
  409. this.ruleForm.isCode = val.isCode;
  410. //是否展示尾页公司名称及地址
  411. this.ruleForm.isLastPageName = val.isLastPageName;
  412. // //尾页公司名称
  413. this.ruleForm.lastPageName = val.lastPageName;
  414. //尾页公司地址
  415. this.ruleForm.lastPageAddress = val.lastPageAddress;
  416. //是否删除
  417. this.ruleForm.isDelete = val.isDelete;
  418. //主键
  419. this.ruleForm.id = val.id;
  420. //邮箱
  421. this.ruleForm.mail = val.mail;
  422. //尾页二维码
  423. this.ruleForm.lastPageCode = val.lastPageCode;
  424. //公司logo
  425. this.ruleForm.logo = val.logo;
  426. //首页二维码
  427. this.ruleForm.firstPageCode = val.firstPageCode;
  428. },
  429. cancle() {
  430. //渠道ID
  431. this.ruleForm.channelId = "";
  432. //报告来源
  433. this.ruleForm.reportSource = "";
  434. //公司名称
  435. this.ruleForm.companyName = "";
  436. //是否展示详细信息
  437. this.ruleForm.isDetail = "";
  438. //公司英文名称
  439. this.ruleForm.companyEname = "";
  440. //网址
  441. this.ruleForm.webAddress = "";
  442. //是否展示尾页二维码
  443. this.ruleForm.isCode = "";
  444. //是否展示尾页公司名称及地址
  445. this.ruleForm.isLastPageName = "";
  446. // //尾页公司名称
  447. this.ruleForm.lastPageName = "";
  448. //尾页公司地址
  449. this.ruleForm.lastPageAddress = "";
  450. //是否删除
  451. this.ruleForm.isDelete = "";
  452. //主键
  453. this.ruleForm.id = "";
  454. //邮箱
  455. this.ruleForm.mail = "";
  456. //尾页二维码
  457. this.ruleForm.lastPageCode = "";
  458. //公司logo
  459. this.ruleForm.logo = "";
  460. //首页二维码
  461. this.ruleForm.firstPageCode = "";
  462. //清空表单
  463. this.$refs["ruleForm"].clearValidate();
  464. this.dialogVisible = false;
  465. },
  466. submitCom() {
  467. if (this.ruleForm.isLastPageName == "1") {
  468. if (this.ruleForm.lastPageName == "") {
  469. this.$message.error("是否展示尾页公司名称及地址选择是则尾页公司名称必填");
  470. return;
  471. }
  472. if (this.ruleForm.lastPageAddress == "") {
  473. this.$message.error("是否展示尾页公司名称及地址选择是则尾页公司地址必填");
  474. return;
  475. }
  476. }
  477. if (this.ruleForm.isCode == "1") {
  478. if (this.ruleForm.lastPageCode == "") {
  479. this.$message.error("是否展示尾页二维码选择是时尾页二维码必填");
  480. return;
  481. }
  482. }
  483. if (this.disableFlag) {
  484. return;
  485. }
  486. this.disableFlag = true;
  487. this.$refs["ruleForm"].validate((valid) => {
  488. if (valid) {
  489. //判断是编辑还是新增
  490. if (this.isView) {
  491. this.register();
  492. } else {
  493. this.editUserFun();
  494. }
  495. //都校验通过后可以触发注册接口了
  496. //调用方法进行入参
  497. } else {
  498. this.disableFlagStatus();
  499. }
  500. });
  501. },
  502. register() {
  503. let that = this;
  504. this.$http.post(
  505. `/pdf/save`,
  506. {
  507. channelId: this.ruleForm.channelId,
  508. //报告来源
  509. reportSource: this.ruleForm.reportSource,
  510. //公司名称
  511. companyName: this.ruleForm.companyName,
  512. //是否展示详细信息
  513. isDetail: this.ruleForm.isDetail,
  514. //公司英文名称
  515. companyEname: this.ruleForm.companyEname,
  516. //网址
  517. webAddress: this.ruleForm.webAddress,
  518. //是否展示尾页二维码
  519. isCode: this.ruleForm.isCode,
  520. //是否展示尾页公司名称及地址
  521. isLastPageName: this.ruleForm.isLastPageName,
  522. // //尾页公司名称
  523. lastPageName: this.ruleForm.lastPageName,
  524. //尾页公司地址
  525. lastPageAddress: this.ruleForm.lastPageAddress,
  526. //是否删除
  527. isDelete: this.ruleForm.isDelete,
  528. //邮箱
  529. mail: this.ruleForm.mail,
  530. //尾页二维码
  531. lastPageCode: this.ruleForm.lastPageCode,
  532. //公司logo
  533. logo: this.ruleForm.logo,
  534. //首页二维码
  535. firstPageCode: this.ruleForm.firstPageCode,
  536. },
  537. (res) => {
  538. this.disableFlagStatus();
  539. if (res && res.code == 200) {
  540. this.dialogVisible = false;
  541. this.$message.success(res.msg);
  542. // this.$toast.success({ message: "成功" });
  543. //调用父组件的查询方法
  544. that.$emit("search");
  545. } else {
  546. // this.$toast.fail({ message: res.msg });
  547. this.$message.error(res.msg);
  548. }
  549. //清空缓存
  550. this.cancle();
  551. }
  552. );
  553. },
  554. editUserFun() {
  555. let that = this;
  556. this.$http.post(
  557. `/pdf/save`,
  558. {
  559. ...this.ruleForm,
  560. // ...this.ruleForm, //解构对象
  561. },
  562. (res) => {
  563. this.disableFlagStatus();
  564. if (res && res.code == 200) {
  565. this.dialogVisible = false;
  566. // this.$toast.success({ message: "成功" });
  567. //调用父组件的查询方法
  568. that.$emit("search");
  569. this.$message.success("修改成功");
  570. } else {
  571. // this.$toast.fail({ message: res.msg });
  572. this.$message.error(res.msg);
  573. }
  574. //清空缓存
  575. }
  576. );
  577. },
  578. },
  579. };
  580. </script>
  581. <style scoped>
  582. .inputCom {
  583. width: 200px;
  584. }
  585. .avatar-uploader .el-upload {
  586. border: 1px dashed #d9d9d9;
  587. border-radius: 6px;
  588. cursor: pointer;
  589. position: relative;
  590. overflow: hidden;
  591. }
  592. .avatar-uploader .el-upload:hover {
  593. border-color: #409eff;
  594. }
  595. .avatar-uploader-icon {
  596. font-size: 28px;
  597. color: #8c939d;
  598. width: 178px;
  599. height: 178px;
  600. line-height: 178px;
  601. text-align: center;
  602. border: 1px solid;
  603. }
  604. .avatar {
  605. width: 178px;
  606. height: 178px;
  607. display: block;
  608. }
  609. </style>