messageCreat.vue 14 KB

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