editPage.vue 11 KB

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