messageCreat.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <div class="mainBox">
  3. <div class="layerBox">
  4. <tableTitle :name="'添加留言'" v-if="pageMode == 'add'"/>
  5. <tableTitle :name="'编辑留言'" v-if="pageMode == 'edit'"/>
  6. <tableTitle :name="'留言详情'" v-if="pageMode == 'view'"/>
  7. <el-form :model="form" ref="form" :rules="formRules" label-position="left" label-width="120px">
  8. <div class="formDiv">
  9. <div>
  10. <!--1.添加留言标题-->
  11. <el-form-item label="留言标题:" :label-width="formLabelWidth" prop="title" class="custom-align-right" v-if="pageMode == 'add'">
  12. <el-input v-model="form.title" autocomplete="off" placeholder="请输入留言标题"></el-input>
  13. </el-form-item>
  14. <!--1.编辑留言标题-->
  15. <el-form-item label="留言标题:" :label-width="formLabelWidth" prop="title" class="custom-align-right" v-else>
  16. <el-input v-model="form.title" autocomplete="off" placeholder="请输入留言标题" :disabled="pageMode == 'view' || isme == false"></el-input>
  17. </el-form-item>
  18. <!--2.添加网站属性-->
  19. <el-form-item label="网站属性:" :label-width="formLabelWidth" prop="column_id" class="custom-align-right" v-if="pageMode == 'add'">
  20. <el-cascader v-model="form.column_id" :props="{ checkStrictly: true }" :options="website_column_arr"></el-cascader>
  21. </el-form-item>
  22. <!--2.编辑网站属性-->
  23. <el-form-item label="网站属性:" :label-width="formLabelWidth" prop="column_id" class="custom-align-right" v-else>
  24. <el-cascader v-model="form.column_id" :props="{ checkStrictly: true }" :options="website_column_arr" :disabled="pageMode == 'view' || isme == false"></el-cascader>
  25. </el-form-item>
  26. <div v-if="pageMode == 'add'">
  27. <!--3.添加留言关键词-->
  28. <el-form-item label="留言关键词:" class="custom-align-right">
  29. <template #label>
  30. <span class="askBox">
  31. 留言关键词:
  32. <el-tooltip class="item" effect="dark" content="留言关键词,如:三农市场网、全国三农、信息一体化。" placement="top">
  33. <i class="el-icon-question"></i>
  34. </el-tooltip>
  35. </span>
  36. </template>
  37. <tagInput :initialTags="tags" @tags-updated="updateTags"></tagInput>
  38. </el-form-item>
  39. </div>
  40. <div v-else>
  41. <!--3.编辑留言关键词-->
  42. <el-form-item label="留言关键词:" class="custom-align-right" v-if="pageMode != 'view' && isme == true">
  43. <template #label>
  44. <span class="askBox">
  45. 留言关键词:
  46. <el-tooltip class="item" effect="dark" content="留言关键词,如:三农市场网、全国三农、信息一体化。" placement="top">
  47. <i class="el-icon-question"></i>
  48. </el-tooltip>
  49. </span>
  50. </template>
  51. <tagInput :initialTags="tags" @tags-updated="updateTags"></tagInput>
  52. </el-form-item>
  53. <el-form-item label="留言关键词:" class="custom-align-right" v-else>
  54. <el-input v-model="this.form.keyword" autocomplete="off" placeholder="请输入留言标题" disabled="disabled"></el-input>
  55. </el-form-item>
  56. </div>
  57. <!--4.添加留言描述-->
  58. <el-form-item label="留言描述:" class="custom-align-right" v-if="pageMode == 'add'">
  59. <template #label>
  60. <span class="askBox">
  61. 留言描述:
  62. <el-tooltip class="item" effect="dark" content="留言描述,如:中国三农市场网创建以来,社会效益和会员经济效益贡献。" placement="top">
  63. <i class="el-icon-question"></i>
  64. </el-tooltip>
  65. </span>
  66. </template>
  67. <el-input type="textarea" v-model="form.description" class="custom-textarea" placeholder="请输入留言描述"></el-input>
  68. </el-form-item>
  69. <!--4.编辑留言描述-->
  70. <el-form-item label="留言描述:" class="custom-align-right" v-else>
  71. <template #label>
  72. <span class="askBox">
  73. 留言描述:
  74. <el-tooltip class="item" effect="dark" content="留言描述,如:中国三农市场网创建以来,社会效益和会员经济效益贡献。" placement="top">
  75. <i class="el-icon-question"></i>
  76. </el-tooltip>
  77. </span>
  78. </template>
  79. <el-input type="textarea" v-model="form.description" class="custom-textarea" placeholder="请输入留言描述" :disabled="pageMode == 'view' || isme == false"></el-input>
  80. </el-form-item>
  81. <!--5.添加留言内容-->
  82. <div v-if="pageMode == 'add'">
  83. <el-form-item label="留言内容:" prop="content" class="custom-align-right">
  84. <el-input type="textarea" v-model="form.content" class="custom-textarea custom-textarea-height" placeholder="请输入留言内容"></el-input>
  85. </el-form-item>
  86. </div>
  87. <!--5.编辑留言内容-->
  88. <div v-else>
  89. <el-form-item label="留言内容:" prop="content" class="custom-align-right" v-if="pageMode == 'add' || pageMode == 'edit' && isme == true">
  90. <!-- <myEditor ref="myEditor" v-model="form.content"></myEditor> -->
  91. <el-input type="textarea" v-model="form.content" class="custom-textarea custom-textarea-height" placeholder="请输入留言内容"></el-input>
  92. </el-form-item>
  93. <el-form-item label="留言内容:" prop="content" class="custom-align-right" v-else>
  94. <div v-html="form.content" class="contentBox "></div>
  95. </el-form-item>
  96. </div>
  97. <!--6.查看回复内容-->
  98. <div v-if="pageMode == 'view'">
  99. <el-form-item label="回复:" :label-width="formLabelWidth" class="custom-align-right">
  100. <el-input type="textarea" v-model="form.reply" class="custom-textarea custom-textarea-height" placeholder="暂无回复" :disabled="creatNews_user_type!=10000"></el-input>
  101. </el-form-item>
  102. </div>
  103. <div v-if="pageMode != 'view' && pageName == 'messageList' && pageMode != 'add'">
  104. <el-form-item label="回复:" :label-width="formLabelWidth" class="custom-align-right">
  105. <el-input type="textarea" v-model="form.reply" class="custom-textarea custom-textarea-height" placeholder="请输入回复" :disabled="creatNews_user_type!=10000"></el-input>
  106. </el-form-item>
  107. </div>
  108. </div>
  109. </div>
  110. </el-form>
  111. </div>
  112. <div class="bottomBtnBox">
  113. <el-button type="info" @click="returnPage">返回</el-button>
  114. <el-button type="primary" @click="addToServe" v-if="pageMode == 'add'">确定</el-button>
  115. <!--管理员编辑-->
  116. <el-button type="primary" @click="editToServe" v-else>编辑</el-button>
  117. </div>
  118. </div>
  119. </template>
  120. <script>
  121. import { getWebSiteId, getUseType } from '@/utils/auth'
  122. //表格标题
  123. import tableTitle from './components/tableTitle.vue';
  124. //引入tag标签组件
  125. import tagInput from '../../components/InputTag/index.vue';
  126. //引入公用样式
  127. import '@/styles/global.less';
  128. //引入富文本编辑器
  129. import myEditor from '../../components/edit/myEditor.vue';
  130. export default {
  131. components: {
  132. tableTitle,
  133. tagInput,
  134. myEditor,
  135. },
  136. data() {
  137. const validateEmpty = (rule, value, callback) => {
  138. if (value == '') {
  139. callback(new Error('该项不能为空!'))
  140. } else {
  141. callback()
  142. }
  143. }
  144. const validateArray = (rule, value, callback) => {
  145. if (value.length == 0) {
  146. callback(new Error('该项不能为空!'))
  147. } else {
  148. callback()
  149. }
  150. }
  151. let self = this;
  152. return {
  153. isme:false,//是否是自己发布的
  154. pageMode: 'add',//页面模式 add=新建 edit=编辑 view=查看
  155. pageName: 'messageReviewList',//页面名称
  156. formLabelWidth: '120px',
  157. creatNews_user_type: 0,//用户身份
  158. tableDivTitle:"添加留言",
  159. tags: [],//标签数组
  160. website_column_arr: [],//网系列表
  161. column_id: [],//选择的网系
  162. form: {
  163. column_id:0,//网站属性id
  164. title:"",//留言标题
  165. keyword: "",//留言关键词
  166. description: "",//留言描述
  167. content: "",//留言内容
  168. reply:"",//回复内容
  169. },
  170. formRules: {
  171. title: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  172. content: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  173. column_id: [{ type: 'array', required: true, trigger: 'change', message: '必须选择一个网系!' }],
  174. },
  175. };
  176. },
  177. methods: {
  178. //拆解标签
  179. updateTags(newTags) {
  180. this.tags = newTags;
  181. this.form.keyword = newTags.join(',');
  182. },
  183. //获得所有网系
  184. getwebsiteColumn() {
  185. let that = this;
  186. this.$store.dispatch('pool/getwebsiteColumn').then(res => {
  187. let arrData = this.transformData(res.data)
  188. this.website_column_arr = arrData;
  189. })
  190. },
  191. transformData(arrData) {
  192. let that = this;
  193. return arrData.map(item => {
  194. let newItem = {
  195. label: item.column_name,
  196. value: item.id
  197. };
  198. if (item.children && item.children.length > 0) {
  199. newItem.children = that.transformData(item.children);
  200. }
  201. return newItem;
  202. });
  203. },
  204. //提交表单
  205. addToServe() {
  206. console.log(this.form)
  207. //表单验证
  208. this.$refs.form.validate(valid => {
  209. if (valid) {
  210. //获得最后一位
  211. if (Array.isArray(this.form.column_id) && this.form.column_id.length > 0) {
  212. this.form.column_id = this.form.column_id[this.form.column_id.length - 1];
  213. }
  214. this.$store.dispatch('news/addMessage',this.form).then(res => {
  215. if(res.code == 200) {
  216. console.log(res)
  217. this.$router.push({
  218. path: '/' + this.$route.query.page,
  219. })
  220. this.$message.success("留言添加成功!");
  221. } else {
  222. this.$message.error(res.message);
  223. }
  224. })
  225. }
  226. })
  227. },
  228. //管理员编辑表单
  229. editToServe() {
  230. console.log(this.form)
  231. //表单验证
  232. this.$refs.form.validate(valid => {
  233. if (valid) {
  234. //添加留言id
  235. this.form.id = this.$route.query.id;
  236. //获得最后一位
  237. if (Array.isArray(this.form.column_id) && this.form.column_id.length > 0) {
  238. this.form.column_id = this.form.column_id[this.form.column_id.length - 1];
  239. }
  240. this.$store.dispatch('news/upMessage',this.form).then(res => {
  241. if(res.code == 200) {
  242. console.log(res)
  243. this.$router.push({
  244. path: '/' + this.$route.query.page,
  245. })
  246. this.$message.success("留言编辑成功!");
  247. } else {
  248. this.$message.error(res.message);
  249. }
  250. })
  251. }
  252. })
  253. },
  254. //清理表单
  255. cleatForm() {
  256. this.tags = [];
  257. this.website_column_arr = [];
  258. this.column_id = [];
  259. this.form.column_id = 0;
  260. this.form.title = "";
  261. this.form.keyword = "";
  262. this.form.description = "";
  263. this.form.content = "";
  264. this.form.reply = "";
  265. this.pageMode = "add"
  266. delete this.form.id;
  267. },
  268. //回显数据
  269. getMainData(id) {
  270. this.$store.dispatch('news/getMessageInfo',{id:id}).then(res => {
  271. if(res.code == 200) {
  272. this.form.column_id = res.data.column_arr_id;
  273. this.form.title = res.data.title;
  274. this.form.keyword = res.data.keyword;
  275. this.form.description = res.data.description;
  276. setTimeout(() => {
  277. this.form.content = res.data.content;
  278. }, 100);
  279. this.form.reply = res.data.reply;
  280. this.tags = res.data.keyword.split(',');
  281. //判断当前的留言是否是自己发布的
  282. if(res.data.user_id == this.$store.state.user.userid) {
  283. this.isme = true;
  284. } else {
  285. this.isme = false;
  286. }
  287. } else {
  288. this.$message.error(res.message);
  289. }
  290. })
  291. },
  292. returnPage(){
  293. let pagename = this.$route.query.page
  294. console.log(this.$route.query.page)
  295. this.$router.push({
  296. path: "/" + pagename,
  297. })
  298. }
  299. },
  300. mounted() {
  301. //1.清理表单
  302. this.cleatForm();
  303. //2.获得用户身份
  304. this.creatNews_user_type = getUseType()
  305. //3.获得站点id
  306. this.websiteid = getWebSiteId()
  307. //4.获得所有网系
  308. this.getwebsiteColumn();
  309. //5.判断是新建还是回显
  310. //5.1 新建留言
  311. if (this.$route.query.id == undefined && this.$route.query.type == 'add') {
  312. this.pageMode = "add"
  313. this.pageName = this.$route.query.page;
  314. }
  315. //5.2 编辑留言
  316. if(this.$route.query.id != undefined && this.$route.query.type == 'edit') {
  317. this.pageMode = "edit";
  318. this.pageName = this.$route.query.page;
  319. this.getMainData(this.$route.query.id)
  320. }
  321. //5.3 查看留言
  322. if(this.$route.query.id != undefined && this.$route.query.type == 'view') {
  323. this.pageMode = "view";
  324. this.pageName = this.$route.query.page;
  325. this.getMainData(this.$route.query.id)
  326. }
  327. }
  328. };
  329. </script>
  330. <style scoped lang="less">
  331. .contentBox {
  332. padding: 5px 15px;
  333. border: 1px solid #DCDFE6;
  334. border-radius: 4px;
  335. background: #F5F7FA;
  336. color: #C0C4CC;
  337. ::v-deep * {
  338. color: #C0C4CC;
  339. }
  340. }
  341. .custom-textarea-height {
  342. ::v-deep .el-textarea__inner {
  343. height: 100px;
  344. resize: none;
  345. /* 禁止用户拖拽调整大小 */
  346. }
  347. }
  348. //执行v-deep穿透scope选择器 start------------------------------------------------------------>*/
  349. ::v-deep .custom-form-item>.el-form-item__label {
  350. line-height: 140px !important;
  351. }
  352. ::v-deep .custom-textarea .el-textarea__inner {
  353. resize: none;
  354. /* 禁止用户拖拽调整大小 */
  355. }
  356. ::v-deep .custom-align-right .el-form-item__label {
  357. text-align: right;
  358. /* 设置标签文字右对齐 */
  359. }
  360. ::v-deep .el-popper {
  361. height: 500px;
  362. }
  363. ::v-deep .el-select {
  364. width: 100%;
  365. /* 禁止用户拖拽调整大小 */
  366. }
  367. ::v-deep .el-input-group__prepend {
  368. color: black !important;
  369. }
  370. .formLabelFloatBox {
  371. margin-bottom: 10px;
  372. position: relative;
  373. .formLabeladdIcon {
  374. position: absolute;
  375. right: 45px;
  376. top: 5px;
  377. width: 38px;
  378. height: 24px;
  379. }
  380. .formLabelDelIcon {
  381. position: absolute;
  382. right: 5px;
  383. top: 5px;
  384. width: 38px;
  385. height: 24px;
  386. }
  387. }
  388. //该项不能为空几个字的位置
  389. ::v-deep .el-form-item__error {
  390. color: #ff4949;
  391. font-size: 12px;
  392. line-height: 1;
  393. padding-top: 4px;
  394. position: relative;
  395. // top: 22%;
  396. // left: 93%;
  397. }
  398. //输入框距离底部的距离
  399. ::v-deep .el-form-item {
  400. margin-bottom: 5px;
  401. }
  402. //图片提示文字样式
  403. .photo_tips {
  404. font-size: 12px;
  405. color: #999;
  406. }
  407. .notchooseImgDiv img {
  408. width: 120px;
  409. height: 120px;
  410. margin-left: 11px;
  411. }
  412. .notchooseImgDiv .notchooseImgDivText {
  413. font-size: 14px;
  414. margin-top: -25px;
  415. }
  416. // 执行v-deep穿透scope选择器 end------------------------------------------------------------>
  417. </style>