editPage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <div class="notice_changShang_edit">
  3. <form>
  4. <div class="Line Line1">
  5. <span>标题:</span>
  6. <input
  7. type="text"
  8. v-model="contentParam.title"
  9. />
  10. <p v-show="tipFlag" style="margin-left: 88px; color: red">
  11. {{ tipText }}
  12. </p>
  13. </div>
  14. <div class="Line Line2">
  15. <span>类型:</span>
  16. <select>
  17. <option>重要通知</option>
  18. </select>
  19. </div>
  20. <div class="Line Line3">
  21. <span>区域:</span>
  22. <div class="areaBox">
  23. <div v-for="(item, index) in areaList" :key="index">
  24. <input
  25. type="checkbox"
  26. :value="item"
  27. v-model="contentParam.area"
  28. @click="clickCheckbox(index)"
  29. /><span>{{ item }}</span>
  30. </div>
  31. </div>
  32. </div>
  33. <div class="Line Line4">
  34. <span>信息配置:</span>
  35. <div class="fuWenBen">
  36. <editor-bar v-model="contentParam.content" :content="this.contentParam.content"></editor-bar>
  37. </div>
  38. <div style="clear: both; display: block"></div>
  39. </div>
  40. <div class="uploadFile">
  41. <p class="title">附件:</p>
  42. <label for="fileInput" @change="getFileInfo($event)"
  43. >添加附件
  44. <input type="file" ref="referenceUpload" name="fileName" id="fileInput" multiple />
  45. </label>
  46. <div class="fileDes">
  47. <p v-for="(item, index) in contentParam.files" :key="index">
  48. {{ item.file_name || item.name }}
  49. <span class="deleteFile" @click="deleteFile(index, item)">×</span>
  50. </p>
  51. </div>
  52. </div>
  53. </form>
  54. <div class="operationStyle">
  55. <button @click="addNotice(contentParam.id)">保存</button>
  56. <button @click="backToPre()">返回</button>
  57. </div>
  58. <TipModal
  59. :tipFlag="tipModalFlag"
  60. :tipText="tipModalText"
  61. @close_tip_modal="closeTipModal"
  62. />
  63. <Loading v-if="uploading"></Loading>
  64. </div>
  65. </template>
  66. <script>
  67. import TipModal from "../../../components/TipModal";
  68. import Loading from "../../data/components/UploadLoading";
  69. import EditorBar from '../../../components/wangEditor'
  70. // import helpButton from "../custom_extensions/helpButton/index";
  71. import { php_url } from "../../../config/env";
  72. import axiosPhp from "axios";
  73. export default {
  74. components: { TipModal, Loading ,EditorBar},
  75. name: 'tinymce',
  76. data() {
  77. return {
  78. tipFlag: false,
  79. isClear: false,
  80. tipText: "",
  81. noticeTitle: "",
  82. InfoType: "",
  83. title: this.$route.query.title,
  84. areaList: ["全区", "华东", "华南","华北"],
  85. content: "",
  86. unifiedUrl: "/lexus_php/api/",
  87. fileDes: [], // 上传的文件名,
  88. file: [],
  89. tipModalFlag: false,
  90. tipModalText: "",
  91. uploading: false,
  92. contentParam: {},
  93. noticeId: "",
  94. delFileIds: [],
  95. editFileLength: "",
  96. allDataNameList: [],
  97. };
  98. },
  99. computed: {},
  100. methods: {
  101. addNotice(id) {
  102. let requestURL, paramData;
  103. this.checkName();
  104. if(this.contentParam.area.length === 0){
  105. alert('请选择地区')
  106. return;
  107. }
  108. if (!this.tipFlag) {
  109. if (id) {
  110. //编辑
  111. requestURL = "notice_update.php";
  112. paramData = new FormData();
  113. paramData.append("title", this.contentParam.title);
  114. paramData.append("area", this.contentParam.area);
  115. paramData.append("content", this.contentParam.content);
  116. paramData.append("id", id);
  117. console.log(this.delFileIds);
  118. console.log(this.delFileIds.length);
  119. if (this.delFileIds.length) {
  120. let delFileStr = this.delFileIds.join(",");
  121. paramData.append("del_file_ids", delFileStr);
  122. }
  123. if (this.contentParam.files && this.contentParam.files.length === 0) {
  124. paramData.append("file_num", "0");
  125. } else {
  126. let count = 0;
  127. let len = this.file.length;
  128. this.file.forEach((item) => {
  129. count++;
  130. paramData.append("file" + count, item);
  131. });
  132. paramData.append("file_num", len);
  133. }
  134. } else {
  135. //新增
  136. requestURL = "notice_add.php";
  137. paramData = new FormData();
  138. paramData.append("title", this.contentParam.title);
  139. paramData.append("area", this.contentParam.area);
  140. paramData.append("content", this.contentParam.content);
  141. if (this.file.length === 0) {
  142. paramData.append("file_num", "0");
  143. } else {
  144. let count = 0;
  145. let len = this.file.length;
  146. this.file.forEach((item) => {
  147. count++;
  148. paramData.append("file" + count, item);
  149. });
  150. paramData.append("file_num", len);
  151. }
  152. }
  153. this.uploading = true;
  154. axiosPhp({
  155. url: php_url + this.unifiedUrl + requestURL,
  156. method: "post",
  157. data: paramData,
  158. dataType: "json", //声明成功使用json数据类型回调
  159. cache: false,
  160. processData: false,
  161. contentType: false,
  162. })
  163. .then((res) => {
  164. this.uploading = false;
  165. if (res.data.code === 200) {
  166. this.tipModalFlag = true;
  167. if (id) {
  168. this.tipModalText = "更新成功!";
  169. } else {
  170. this.tipModalText = "新增成功!";
  171. }
  172. } else {
  173. alert(res.data.message);
  174. }
  175. })
  176. .catch((err) => {
  177. alert(err);
  178. });
  179. }
  180. },
  181. // 关闭提示框
  182. closeTipModal: function () {
  183. this.tipModalFlag = false;
  184. this.$router.push({ path: "/changShang" });
  185. },
  186. // 获取文件,文件名
  187. getFileInfo: function (event) {
  188. let file = event.target.files;
  189. Array.from(file).forEach((item) => {
  190. this.file.push(item);
  191. this.contentParam.files.push(item);
  192. });
  193. this.$refs.referenceUpload.value = null;
  194. },
  195. // 删除文件
  196. deleteFile: function (i, item) {
  197. if (this.noticeId && this.editFileLength > this.delFileIds.length) {
  198. this.delFileIds.push(item.file_id);
  199. }
  200. this.file.splice(i, 1);
  201. this.contentParam.files.splice(i, 1);
  202. },
  203. // 保证多选框东区和其他的多选框互斥
  204. clickCheckbox(i) {
  205. let list = this.contentParam.area;
  206. let include = list.indexOf("全区");
  207. if (i === 0) {
  208. this.contentParam.area = [];
  209. return;
  210. }
  211. if (include >= 0) {
  212. this.contentParam.area.splice(0, 1);
  213. }
  214. },
  215. backToPre() {
  216. this.$router.push({
  217. path: "/changShang",
  218. query: {},
  219. });
  220. },
  221. // 转地区的格式
  222. // areaToList() {
  223. // this.contentParam = this.$route.query
  224. // },
  225. getDataList: function (data = {}) {
  226. axiosPhp({
  227. method: "post",
  228. url: php_url + this.unifiedUrl + "notice_list.php",
  229. data,
  230. })
  231. .then((res) => {
  232. if (res.data.code === 200) {
  233. res.data.data.forEach((element) => {
  234. if(element.title !==this.title){
  235. this.allDataNameList.push(element.title);
  236. }
  237. });
  238. }
  239. })
  240. .catch((err) => {
  241. console.log(err);
  242. });
  243. },
  244. // // 名字不重复,隐藏提示
  245. // hideTip: function () {
  246. // this.tipText = "资料名称不能重复,请重新输入";
  247. // this.tipFlag = false;
  248. // },
  249. checkName: function () {
  250. // console.log(this.contentParam.area)
  251. // 去前后空格
  252. // this.contentParam.title = this.contentParam.title.replace(
  253. // /(^\s*)|(\s*$)/g,
  254. // ""
  255. // );
  256. this.tipFlag = false;
  257. // let include = this.allDataNameList.indexOf(this.contentParam.title);
  258. if (!this.contentParam.title) {
  259. this.tipText = "标题不能为空";
  260. this.tipFlag = true;
  261. return;
  262. }
  263. // else if (include >= 0 && !this.noticeId) {
  264. // this.tipText = "资料名称不能重复,请重新输入";
  265. // this.tipFlag = true;
  266. // return;
  267. // }
  268. },
  269. },
  270. mounted() {
  271. // this.getDataList();
  272. this.contentParam = JSON.parse(localStorage.getItem('nowPageEdit'));
  273. this.noticeId = this.contentParam.id;
  274. if (this.contentParam.files) {
  275. this.editFileLength = this.contentParam.files.length;
  276. }
  277. },
  278. created() {},
  279. };
  280. </script>
  281. <style scoped lang="less">
  282. .fuWenBen {
  283. position: relative;
  284. left: 85px;
  285. top: -40px;
  286. width: 950px;
  287. }
  288. .operationStyle {
  289. display: flex;
  290. justify-content: center;
  291. }
  292. .operationStyle button:nth-child(1) {
  293. margin-right: 36px;
  294. }
  295. .operationStyle button {
  296. border-radius: 5px;
  297. width: 100px;
  298. height: 36px;
  299. }
  300. .Line5 button {
  301. border-radius: 5px;
  302. width: 100px;
  303. height: 23px;
  304. vertical-align: middle;
  305. }
  306. /* .operationStyle button:nth-child(2){
  307. display: flex;
  308. justify-content: center;
  309. } */
  310. .focusStyle {
  311. border: 1px solid #ccc;
  312. line-height: 20px;
  313. color: #555555;
  314. outline: none;
  315. position: absolute;
  316. }
  317. .focusStyle:focus {
  318. animation: shadowAni 200ms linear forwards;
  319. }
  320. .Line {
  321. height: 50px;
  322. }
  323. .Line span {
  324. width: 80px;
  325. height: 36px;
  326. display: inline-flex;
  327. vertical-align: middle;
  328. line-height: 36px;
  329. justify-content: flex-end;
  330. margin-right: 8px;
  331. }
  332. .areaBox {
  333. display: flex;
  334. }
  335. .areaBox span {
  336. width: 30px;
  337. }
  338. .areaBox input {
  339. vertical-align: middle;
  340. }
  341. .Line3 {
  342. display: flex;
  343. }
  344. .Line4 span {
  345. line-height: 10px;
  346. }
  347. .Line4 {
  348. margin-top: 9px;
  349. height: auto;
  350. }
  351. .Line5 span {
  352. position: relative;
  353. }
  354. .Line5 button {
  355. margin-left: 64px;
  356. }
  357. .Line1 input {
  358. height: 24px;
  359. }
  360. .Line2 select {
  361. vertical-align: middle;
  362. width: 120px;
  363. }
  364. .uploadFile {
  365. display: flex;
  366. margin-top: 35px;
  367. min-height: 100px;
  368. .title {
  369. margin-right: 8px;
  370. height: 20px;
  371. line-height: 20px;
  372. margin-left: 5%;
  373. }
  374. .fileDes {
  375. margin-left: 20px;
  376. width: 500px;
  377. overflow: hidden; /* 超出一行文字自动隐藏 */
  378. text-overflow: ellipsis; /* 文字隐藏后添加省略号 */
  379. white-space: nowrap; /* 强制不换行 */
  380. p {
  381. height: 30px;
  382. line-height: 30px;
  383. .deleteFile {
  384. font-size: 20px;
  385. margin-left: 20px;
  386. height: 30px;
  387. line-height: 30px;
  388. // color: #0056a0;
  389. &:hover {
  390. cursor: pointer;
  391. }
  392. }
  393. }
  394. }
  395. label {
  396. height: 30px;
  397. line-height: 30px;
  398. width: 72px;
  399. background-color: #0056a0;
  400. color: #fff;
  401. text-align: center;
  402. font-size: 14px;
  403. border-radius: 5px;
  404. input {
  405. display: none;
  406. }
  407. }
  408. }
  409. </style>