case_add.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <template>
  2. <div>
  3. <div class="diaContentWork">
  4. <div class="taskName">
  5. <div class="name">案例名称</div>
  6. <div class="value">
  7. <el-input v-model="dataItem.title" placeholder="请输入案例名称(2-10个字符)"></el-input>
  8. </div>
  9. </div>
  10. <div class="ourLogo">
  11. <div class="name">品牌logo</div>
  12. <div class="value">
  13. <div class="uploadInfo">
  14. <div class="left">
  15. <el-upload
  16. class="avatar-uploader"
  17. action="#"
  18. :show-file-list="false"
  19. :multiple="false"
  20. accept="image/png, image/jpeg"
  21. :before-upload="(file) => handleFileChange(file, 'logo')"
  22. >
  23. <i
  24. v-if="dataItem.logo"
  25. class="el-icon-delete avatar-uploader-icon"
  26. @click.stop="() => handleDeleteFile('logo') "
  27. ></i>
  28. <img v-if="dataItem.logo" :src="dataItem.logo" class="avatar" />
  29. <div v-else class="noneImage">
  30. <i class="el-icon-plus avatar-uploader-icon"></i>
  31. </div>
  32. </el-upload>
  33. </div>
  34. <div class="right">
  35. <p>(800*800,图片最大2M,最多1张)</p>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. <div class="taskFile">
  41. <div class="name">案例附件</div>
  42. <div class="value">
  43. <el-upload
  44. class="upload-demo"
  45. action="#"
  46. :show-file-list="true"
  47. :multiple="false"
  48. accept="application/pdf"
  49. :file-list="fileList"
  50. :before-upload="handlePDFFileChange"
  51. :before-remove="handlePDFFileRemove"
  52. >
  53. <div style="margin-top: 10px">
  54. <span class="uploadFileWord">立即上传</span>
  55. <span class="uploadFileTip">仅支持PDF格式(最大2M)</span>
  56. </div>
  57. </el-upload>
  58. </div>
  59. </div>
  60. <div class="taskDesc">
  61. <div class="name">案例描述</div>
  62. <div class="value">
  63. <editor
  64. :content="dataItem.description"
  65. @change="(val) => dataItem.description = val"
  66. :haveVideo="true"
  67. placeholder="支持图文混排,请至少添加不低于100字成功案例描述"
  68. ></editor>
  69. </div>
  70. </div>
  71. </div>
  72. <div class="dialog-footer">
  73. <div class="submit" @click="addCase">
  74. <p>提交</p>
  75. </div>
  76. <div class="cancle" @click="qx">
  77. <p>取消</p>
  78. </div>
  79. </div>
  80. </div>
  81. </template>
  82. <script>
  83. import editor from "@/components/editor";
  84. import uploadFile from "@/mixins/uploadFile";
  85. import DealSeoFooter from "@/components/kaifain/dealSeoFooter";
  86. import KaifainFooter from "@/components/SeoFooter";
  87. export default {
  88. name: "userSetting",
  89. components: {
  90. editor,
  91. KaifainFooter,
  92. },
  93. props: {
  94. lastId: {
  95. type: Number,
  96. default: 0
  97. },
  98. },
  99. data() {
  100. return {
  101. data: {
  102. city: 1,
  103. industry: null, //所处行业的ID
  104. title: "", //服务名称
  105. description: "", //简单描述
  106. images: "", //封面图片,缩略图的地址URL
  107. detail: "", //具体的描述
  108. tech_type: null, //技术类型
  109. successful_case: [],
  110. status: 0,
  111. },
  112. tempData: {},
  113. industryList: [],
  114. techTypeList: [],
  115. dialogVisible: false,
  116. dataItem: {
  117. provider_id: 0, //服务商ID
  118. title: "", //成功案例1
  119. logo: "", //http://www.baidu.com,URL
  120. description: "", //描述一下啊啥的发啊的算法
  121. file: "", //https://www.baidu.com,用户上传的PDF,格式必须为PDF,URL
  122. },
  123. fileList: [],
  124. kaifainUrl: ""
  125. };
  126. },
  127. async asyncData({ ...params }) {
  128. try {
  129. params.store.commit("updateNoneCommonFooter", true);
  130. } catch (e) {
  131. console.log("updateNoneCommonFooter", e);
  132. }
  133. let dealSeoFooterObj = new DealSeoFooter(params);
  134. let footer = await dealSeoFooterObj.dealData();
  135. let domainConfig = params.store.state.domainConfig;
  136. return {
  137. ...domainConfig,
  138. ...footer,
  139. mobile: params.app.$deviceType.isMobile(),
  140. };
  141. },
  142. mixins: [uploadFile],
  143. computed: {
  144. statusObj() {
  145. let status = Number(this.data.status || 0);
  146. let nameList = ["未申请", "审核中", "已入驻", "拒绝"];
  147. let o = {
  148. isOk: status === 2,
  149. name: nameList[status],
  150. };
  151. return o;
  152. },
  153. isDis() {
  154. let status = Number(this.data.status || 0);
  155. return status === 1;
  156. },
  157. },
  158. created() {
  159. const {kaifainUrl, jishuBaseUrl, siteUrl} = this.$store.state.domainConfig;
  160. this.kaifainUrl = kaifainUrl
  161. this.siteUrl = siteUrl
  162. },
  163. async mounted() {
  164. this.needLogin();
  165. //如果存在ID,则优先获取ID
  166. if (this.lastId) {
  167. this.getLastDetail();
  168. } else {
  169. this.getDraftInfo();
  170. }
  171. this.getTypeList();
  172. },
  173. methods: {
  174. jumpTo() {
  175. location.href = this.siteUrl + "/otherpage/companyComplete";
  176. },
  177. /** 图片文件上传 **/
  178. handleFileChange(file, type) {
  179. const isJPG = file.type === "image/jpeg";
  180. const isPNG = file.type === "image/png";
  181. const isLt2M = file.size / 1024 / 1024 < 2;
  182. if (!isJPG && !isPNG) {
  183. this.$message.error("上传头像图片只能是 JPG/PNG 格式!");
  184. return;
  185. }
  186. if (!isLt2M) {
  187. this.$message.error("上传头像图片大小不能超过 2MB!");
  188. return;
  189. }
  190. const formData = new FormData();
  191. formData.append("file", file);
  192. formData.append("original_filename", file.name);
  193. this.uploading = true;
  194. this.$axios
  195. .$post(`/upload_image`, formData, {
  196. headers: { "Content-Type": "multipart/form-data" },
  197. })
  198. .then((res) => {
  199. if (type === "images") {
  200. this.data.images = res.filename;
  201. } else if (type === "logo") {
  202. this.dataItem.logo = res.filename;
  203. }
  204. console.log("type", type, this.data, this.dataItem);
  205. })
  206. .finally(() => {
  207. this.uploading = false;
  208. });
  209. },
  210. /** 删除问及爱你 **/
  211. handleDeleteFile(type) {
  212. if (type === "images") {
  213. this.data.images = "";
  214. } else if (type === "logo") {
  215. this.dataItem.logo = "";
  216. }
  217. },
  218. /** pdf上传 **/
  219. handlePDFFileChange(file, type) {
  220. console.log(file);
  221. const isPDF = file.type === "application/pdf";
  222. const isLt2M = file.size / 1024 / 1024 < 2;
  223. if (!isPDF) {
  224. this.$message.error("上传文件只能是 JPG/PNG 格式!");
  225. return;
  226. }
  227. // if (!isLt2M) {
  228. // this.$message.error('上传文件大小不能超过 2MB!');
  229. // return
  230. // }
  231. const formData = new FormData();
  232. formData.append("file", file);
  233. formData.append("original_filename", file.name);
  234. this.uploading = true;
  235. this.apiPrepareUpload(file, (res) => {
  236. if (res.data && res.data.status === 1) {
  237. let url = res.data.data.url;
  238. this.dataItem.file = url;
  239. this.fileList = [{ name: file.name, url: url }];
  240. } else {
  241. this.$message.error("上传失败");
  242. }
  243. });
  244. return false;
  245. },
  246. /** pdf删除 **/
  247. handlePDFFileRemove() {
  248. this.fileList = [];
  249. this.dataItem.file = "";
  250. },
  251. /** 弹窗逻辑 **/
  252. submitChange() {},
  253. /** 获取选择信息 **/
  254. getTypeList() {
  255. this.$axios.get("/api/kaifawu/get_options").then((res) => {
  256. if (Number(res.data.status) === 1) {
  257. this.industryList = res.data.data.industries;
  258. this.techTypeList = res.data.data.tech_types;
  259. }
  260. });
  261. },
  262. /** 点击添加生成案例 **/
  263. async addSuccessInfo() {
  264. let res = null;
  265. if (!this.data.id) {
  266. res = await this.saveDraft();
  267. }
  268. if (this.data.id || res) {
  269. this.dialogVisible = true;
  270. this.dataItem = {
  271. provider_id: "", //服务商ID
  272. title: "", //成功案例1
  273. logo: "", //http://www.baidu.com,URL
  274. description: "", //描述一下啊啥的发啊的算法
  275. file: "", //https://www.baidu.com,用户上传的PDF,格式必须为PDF,URL
  276. };
  277. }
  278. },
  279. /** 删除案例 **/
  280. deleteCase(item) {
  281. this.$confirm("此操作将直接删除该成功案例, 是否继续?", "提示", {
  282. confirmButtonText: "确定",
  283. cancelButtonText: "取消",
  284. type: "warning",
  285. })
  286. .then(() => {
  287. this.$axios
  288. .post("/api/kaifawu/delete_case", {
  289. id: item.id,
  290. })
  291. .then((res) => {
  292. if (Number(res.data.status) === 1) {
  293. this.$message({
  294. type: "success",
  295. message: "删除成功!",
  296. });
  297. }
  298. });
  299. })
  300. .catch(() => {
  301. this.$message({
  302. type: "info",
  303. message: "已取消删除",
  304. });
  305. });
  306. },
  307. /** 添加案例 **/
  308. async addCase() {
  309. let p = {};
  310. let keyList = [
  311. "id",
  312. "provider_id",
  313. "title",
  314. "logo",
  315. "description",
  316. "file",
  317. ];
  318. for (let key of keyList) {
  319. if (this.dataItem[key]) {
  320. p[key] = this.dataItem[key];
  321. }
  322. }
  323. p.provider_id = this.lastId;
  324. let isEdit = !!p.id;
  325. if (!p.title || p.title.length < 2 || p.title.length > 20) {
  326. this.$message.warning("请填写2-20字符的案例名称!");
  327. return;
  328. }
  329. if (!p.logo) {
  330. this.$message.warning("请上传品牌logo");
  331. return;
  332. }
  333. if (!p.description || p.description.length < 100) {
  334. this.$message.warning("请填写100字符的案例描述");
  335. return;
  336. }
  337. // if (!p.file) {
  338. // this.$message.warning('请上传案例附件')
  339. // return
  340. // }
  341. let url = isEdit ? "/api/kaifawu/update_case" : "/api/kaifawu/store_case";
  342. this.$axios.post(url, p).then((res) => {
  343. if (Number(res.data.status) === 1) {
  344. this.$emit('getLastDetail');
  345. this.$message.success(isEdit ? "更新成功" : "添加成功");
  346. }
  347. });
  348. },
  349. qx()
  350. {
  351. this.$emit('getLastDetail');
  352. },
  353. openEditCase(item) {
  354. this.dataItem = {
  355. ...item,
  356. };
  357. if (item.file) {
  358. this.fileList = [
  359. {
  360. name: "成功案例.pdf",
  361. url: item.file,
  362. },
  363. ];
  364. } else {
  365. this.fileList = [];
  366. }
  367. this.dialogVisible = true;
  368. console.log("openEditCase", this);
  369. },
  370. /** 获取草稿 **/
  371. getDraftInfo(isPreview) {
  372. this.$axios.get("/api/kaifawu/get_draft").then((res) => {
  373. if (Number(res.data.status) == 1 && res.data.data) {
  374. let data = res.data.data;
  375. if (!Array.isArray(data.successful_case)) {
  376. if (
  377. data.successful_case &&
  378. typeof data.successful_case === "object"
  379. ) {
  380. data.successful_case = [data.successful_case];
  381. } else {
  382. data.successful_case = [];
  383. }
  384. }
  385. data.city = Number(data.city);
  386. data.industry = Number(data.industry);
  387. data.tech_type = Number(data.tech_type);
  388. this.data = data;
  389. }
  390. });
  391. },
  392. /** 传入id后处理 **/
  393. getLastDetail() {
  394. this.$axios
  395. .post("/api/kaifawu/get_provider", {
  396. id: this.lastId,
  397. self: 1,
  398. })
  399. .then((res) => {
  400. if (Number(res.data.status) === 1) {
  401. let data = res.data.data;
  402. data.city = Number(data.city);
  403. data.industry = Number(data.industry);
  404. data.tech_type = Number(data.tech_type);
  405. if (!Array.isArray(data.successful_case)) {
  406. if (
  407. data.successful_case &&
  408. typeof data.successful_case === "object"
  409. ) {
  410. data.successful_case = [data.successful_case];
  411. } else {
  412. data.successful_case = [];
  413. }
  414. }
  415. this.data = data;
  416. }
  417. });
  418. },
  419. /** 存储草稿 **/
  420. async saveDraft(isPublish, isPreview) {
  421. let url = "/api/kaifawu/store";
  422. if (this.data.id) {
  423. url = "/api/kaifawu/publish";
  424. }
  425. let p = {
  426. ...this.data,
  427. publish: isPublish ? 1 : 0,
  428. };
  429. //服务名称
  430. if (!p.title) {
  431. this.$message.warning("请填写正确的服务名称(2-20字符)");
  432. return;
  433. }
  434. //所处行业
  435. if (!p.industry) {
  436. this.$message.warning("请选择所处行业");
  437. return;
  438. }
  439. //技术类型
  440. if (!p.tech_type) {
  441. this.$message.warning("请选择技术类型");
  442. return;
  443. }
  444. //缩略图
  445. if (!p.images) {
  446. this.$message.warning("请上传缩略图");
  447. return;
  448. }
  449. //方案简介
  450. if (
  451. !p.description ||
  452. p.description.length < 8 ||
  453. p.description.length > 255
  454. ) {
  455. this.$message.warning("请填写正确的方案简介(8-255字符)");
  456. return;
  457. }
  458. //方案简介
  459. if (!p.detail) {
  460. this.$message.warning("请填写方案介绍");
  461. return;
  462. }
  463. // 更改已有的时候发布,校验状态
  464. if (p.publish === 1 && this.lastId && Number(this.data.status) === 2) {
  465. this.$message.warning("该解决方案已发布,暂不允许修改");
  466. return;
  467. }
  468. let res = await this.$axios.post(url, p);
  469. if (Number(res.data.status) === 1) {
  470. if (!isPublish) {
  471. this.getDraftInfo(isPreview);
  472. this.$message.success("保存草稿成功");
  473. } else {
  474. this.$message.success("提交成功");
  475. this.$emit('service_provider');
  476. }
  477. return true;
  478. }
  479. },
  480. /** 确认提交 **/
  481. submitAll() {
  482. this.saveDraft(true);
  483. },
  484. /** 预览 **/
  485. preview() {
  486. try {
  487. localStorage.setItem("kaifainPreviewData", JSON.stringify(this.data));
  488. window.open(`/kaifain/preview`, "_black");
  489. } catch (e) {
  490. console.log("");
  491. }
  492. },
  493. /** 预览 **/
  494. previewCase() {
  495. try {
  496. localStorage.setItem(
  497. "kaifainPreviewCaseData",
  498. JSON.stringify(this.dataItem)
  499. );
  500. window.open(`${this.kaifainUrl}/previewCase`, '_black')
  501. } catch (e) {
  502. console.log("");
  503. }
  504. },
  505. openNewUrl(item) {
  506. window.open(item.file, "__black");
  507. },
  508. jumpToOther() {
  509. let url = "https://kaifain.proginn.com/s/10";
  510. window.open(url, "__black");
  511. },
  512. },
  513. };
  514. </script>
  515. <style lang="scss" scoped>
  516. @import "../../assets/css/kaifain/kaifainAdd.scss";
  517. </style>
  518. <style lang="scss">
  519. @import "../../assets/css/kaifain/kaifainAddNoScoped.scss";
  520. </style>