creatProject.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. <template>
  2. <div class="mainBox">
  3. <div class="layerBox">
  4. <tableTitle :name="tableDivTitle" />
  5. <el-form :model="form" ref="form" :rules="formRules" label-position="left" label-width="140px">
  6. <div class="formDiv">
  7. <div v-if="creatNews_user_type == 10000">
  8. <el-form-item label="站点名称:" prop="website_id" class="custom-align-right">
  9. <el-cascader :key="parentKey" v-model="form.website_id" placeholder="请选择站点名称"
  10. popper-class="my_cascader" :options="creatNews_nav_pool_arr"
  11. @change="creatNews_nav_pool_change_fun(form.website_id)" filterable clearable></el-cascader>
  12. </el-form-item>
  13. <el-form-item label="栏目名称:" prop="cat_arr_id" class="custom-align-right">
  14. <el-cascader :key="parentKey_2" v-model="form.cat_arr_id" placeholder="请选择要绑定的展示名称"
  15. popper-class="my_cascader" style="height: 100%;" :props="parentData_2" filterable clearable>
  16. </el-cascader>
  17. </el-form-item>
  18. </div>
  19. <div v-if="creatNews_user_type != 10000">
  20. <el-form-item label="栏目名称:" prop="cat_arr_id" class="custom-align-right">
  21. <el-cascader :key="parentKey" v-model="form.cat_arr_id" placeholder="请选择要绑定的展示名称" :props="parentData"
  22. popper-class="my_cascader" style="height: 100%;" filterable clearable>
  23. </el-cascader>
  24. </el-form-item>
  25. </div>
  26. <div>
  27. <el-form-item label="标题名称:" prop="title" class="custom-align-right">
  28. <el-input v-model="form.title" autocomplete="off" placeholder="请输入标题名称"></el-input>
  29. <!-- <el-checkbox v-model="form.islink">是否使用外链</el-checkbox> -->
  30. </el-form-item>
  31. <el-form-item label="推荐等级:" prop="level" class="custom-align-right">
  32. <el-select v-model="form.level" clearable placeholder="请选择公司的推荐等级">
  33. <el-option label="推荐项目" :value="1"></el-option>
  34. </el-select>
  35. </el-form-item>
  36. <div>
  37. <el-form-item label="缩略图:" class="custom-align-right" prop="imgurl">
  38. <div class="uploaderBox">
  39. <span v-if="imgurl.length > 0" class="uploaded-images">
  40. <div v-for="(url, index) in imgurl" :key="index"
  41. style="display: inline;float: left; width: 150px; height:140px;">
  42. <img :src="url" class="avatar" style="float: left; margin-right: 10px;">
  43. <div style="position: relative;
  44. transform: translate(-50%, -50%);
  45. right: -120px;
  46. top: -20px;
  47. background-color: rgba(0, 0, 0, 0.5);
  48. color: white;
  49. border-radius: 50%;
  50. width: 24px;
  51. height: 24px;
  52. display: flex;
  53. align-items: center;
  54. justify-content: center;
  55. cursor: pointer;
  56. z-index: 10;" @click="deleteImage(index)">
  57. <i class="el-icon-delete"></i>
  58. </div>
  59. </div>
  60. </span>
  61. <el-upload v-if="imgurl.length < 5" class="avatar-uploader" action="#" :show-file-list="true"
  62. :before-upload="beforeAvatarUpload" >
  63. <!-- 预览图片 -->
  64. <img v-if="imgurl.length > 5" :src="imgUrl" class="avatar">
  65. <div v-else class="chooseImgDiv">
  66. <div>
  67. <img src="@/assets/public/upload/noImage.png">
  68. <div>选择图片</div>
  69. </div>
  70. </div>
  71. </el-upload>
  72. <div v-if="hovering && imgUrl" class="delete-button" @click="handleDelete">
  73. <i class="el-icon-delete"></i>
  74. </div>
  75. </div>
  76. </el-form-item>
  77. <p class="photo_tips" style="margin-left: 140px;"> 最多可上传5张,每张图片大小不能超过500K,推荐上传图片尺寸
  78. 宽1000像素 高1000像素。(首张显示为项目头图)
  79. </p>
  80. <el-form-item label="项目关键词:" prop="" class="custom-align-right">
  81. <template #label>
  82. <span class="askBox">
  83. 项目关键词:
  84. <el-tooltip class="item" effect="dark" content="项目关键词,如:三农市场网、全国三农、信息一体化。" placement="top">
  85. <i class="el-icon-question"></i>
  86. </el-tooltip>
  87. </span>
  88. </template>
  89. <tagInput :initialTags="tags" @tags-updated="updateTags"></tagInput>
  90. </el-form-item>
  91. <el-form-item label="项目描述:" prop="" class="custom-align-right">
  92. <template #label>
  93. <span class="askBox">
  94. 项目描述:
  95. <el-tooltip class="item" effect="dark" content="项目描述,如:中国三农市场网创建以来,社会效益和会员经济效益贡献。" placement="top">
  96. <i class="el-icon-question"></i>
  97. </el-tooltip>
  98. </span>
  99. </template>
  100. <el-input type="textarea" v-model="form.description" class="custom-textarea"
  101. placeholder="请输入项目描述"></el-input>
  102. </el-form-item>
  103. <el-form-item label="企业名称:" prop="business_name" class="custom-align-right">
  104. <el-input v-model="form.business_name" autocomplete="off" placeholder="请输入企业名称"></el-input>
  105. </el-form-item>
  106. <el-form-item label="联系人:" prop="content_person" class="custom-align-right">
  107. <el-input v-model="form.content_person" autocomplete="off" placeholder="请输入联系人"></el-input>
  108. </el-form-item>
  109. <el-form-item label="联系电话:" prop="telephone" class="custom-align-right">
  110. <el-input v-model="form.telephone" autocomplete="off" placeholder="请输入联系电话"></el-input>
  111. </el-form-item>
  112. <el-form-item label="手机:" prop="mobile" class="custom-align-right">
  113. <el-input v-model="form.mobile" autocomplete="off" placeholder="请输入手机"></el-input>
  114. </el-form-item>
  115. <el-form-item label="邮编:" prop="post_code" class="custom-align-right">
  116. <el-input v-model="form.post_code" autocomplete="off" placeholder="请输入邮编"></el-input>
  117. </el-form-item>
  118. <el-form-item label="传真:" prop="fax" class="custom-align-right">
  119. <el-input v-model="form.fax" autocomplete="off" placeholder="请输入传真"></el-input>
  120. </el-form-item>
  121. <el-form-item label="电子邮件:" prop="email" class="custom-align-right">
  122. <el-input v-model="form.email" autocomplete="off" placeholder="请输入电子邮件"></el-input>
  123. </el-form-item>
  124. <el-form-item label="行政区划:" class="custom-align-right" prop="city_arr_id">
  125. <CityCascader v-model="form.city_arr_id" @update-city-id="update_city_arr_id"></CityCascader>
  126. </el-form-item>
  127. <el-form-item label="详细地址:" prop="address" class="custom-align-right">
  128. <el-input v-model="form.address" autocomplete="off" placeholder="请输入详细地址"></el-input>
  129. </el-form-item>
  130. <el-form-item label="项目介绍:" prop="introduce" class="custom-align-right">
  131. <myEditor ref="myEditor" v-model="form.introduce"></myEditor>
  132. </el-form-item>
  133. <el-form-item label="加盟详情:" prop="franchise_details" class="custom-align-right">
  134. <el-input type="textarea" v-model="form.franchise_details" :autosize="{ minRows: 10, maxRows: 50 }"></el-input>
  135. </el-form-item>
  136. </div>
  137. </div>
  138. </div>
  139. </el-form>
  140. </div>
  141. <div class="bottomBtnBox">
  142. <el-button type="info" @click="returnPage">返回</el-button>
  143. <el-button type="primary" @click="editToServe" v-if="editStatus == true">确定</el-button>
  144. <el-button type="primary" @click="addToServe" v-else>确定</el-button>
  145. </div>
  146. </div>
  147. </template>
  148. <script>
  149. import { getWebSiteId, getUseType } from '@/utils/auth'
  150. //表格标题
  151. import tableTitle from './components/tableTitle.vue';
  152. //引入tag标签组件
  153. import tagInput from '../../components/InputTag/index.vue';
  154. //引入公用样式
  155. import '@/styles/global.less';
  156. //城市级联选择器
  157. import CityCascader from './components/CityCascader';
  158. //引入富文本编辑器
  159. import myEditor from '../../components/edit/myEditor.vue';
  160. //引入拖拽组件
  161. import draggable from 'vuedraggable';
  162. export default {
  163. components: {
  164. tableTitle,
  165. CityCascader,
  166. tagInput,
  167. myEditor,
  168. draggable
  169. },
  170. data() {
  171. //0.全局操作 start ------------------------------------------------------------>
  172. //表单验证
  173. const validateEmpty = (rule, value, callback) => {
  174. if (value == '') {
  175. callback(new Error('该项不能为空!'))
  176. } else {
  177. callback()
  178. }
  179. }
  180. const validateArray = (rule, value, callback) => {
  181. if (value.length == 0) {
  182. callback(new Error('该项不能为空!'))
  183. } else {
  184. callback()
  185. }
  186. }
  187. const validateRadio = (rule, value, callback) => {
  188. if (value != '1' || value != '0') {
  189. callback()
  190. } else {
  191. callback()
  192. }
  193. }
  194. const validateZero = (rule, value, callback) => {
  195. if (value == 0 || value == '' || value == "0") {
  196. callback(new Error('该项不能为空!'))
  197. } else {
  198. callback()
  199. }
  200. }
  201. let self = this;
  202. //0.全局操作 end ------------------------------------------------------------>
  203. return {
  204. loading: false,
  205. logoUrl: '',
  206. hovering: false, // 鼠标悬浮状态 悬浮时显示删除
  207. tags: [],//标签数组
  208. websiteid: 0,
  209. creatNews_pid_num: "0",//请求子导航用的pid
  210. creatNews_nav_pool_arr: [],//
  211. creatNews_add_nav_pool_arr: [],//
  212. creatNews_son_website_id_num: "",
  213. checked: false,
  214. formLabelWidth: '80px',//表单的长度
  215. //1.表单项 start ------------------------------------------------------------>
  216. editStatus: false,
  217. tableDivTitle:"添加项目",
  218. disclaimer: true,//免责声明
  219. //提交表单
  220. creatNews_user_type: 0,//判断用户类型'
  221. created_at: "",//创建时间
  222. imgurl: [],//缩略图
  223. imgUrl:[],//显示缩略图
  224. form: {
  225. website_id: 0,//站点id
  226. cat_arr_id: [],//导航池名称
  227. category_id: 0,//栏目id
  228. nav_add_pool_id: [],//导航池子级
  229. title: '',//项目标题
  230. level: null,//推荐等级
  231. imgurl: [],//缩略图
  232. description: "",//描述
  233. keyword: "",//关键词
  234. content_person: "",//联系人
  235. telephone: "",//联系电话
  236. mobile: "",//手机
  237. post_code: "",//邮编
  238. fax: "",//传真
  239. email: "",//电子邮件
  240. address: "",//详细地址
  241. introduce: "",//项目简介
  242. user_type: "??",//判断用户类型'
  243. city_arr_id: [],//行政区划
  244. city_id: "",//区划最后一个数字
  245. franchise_details: "",//加盟详情
  246. status: 0,//状态状态:0:未审核;1:已审核;2:已拒绝;
  247. },
  248. //1.2 表单验证规则
  249. formRules: {
  250. //导航池名称不能为空
  251. website_id: [{ required: true, trigger: 'blur', validator: validateZero }],
  252. //项目名称不能为空
  253. title: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  254. //如果使用了外链,外链地址不能为空
  255. imgurl: [{ required: true, trigger: 'blur', validator: validateArray }],
  256. //导航池名称不能为空
  257. cat_arr_id: [{ required: true, trigger: 'blur', validator: validateArray }],
  258. //行政区划
  259. city_arr_id: [{ required: true, trigger: 'blur', validator: validateArray }],
  260. //企业名称不能为空
  261. business_name: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  262. //联系人不能为空
  263. content_person: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  264. //联系电话不能为空
  265. telephone: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  266. //项目简介不能为空
  267. introduce: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  268. //加盟详情不能为空
  269. franchise_details: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  270. },
  271. //1.4图片上传
  272. imgUrl: "",//在页面上显示缩略图
  273. //获取父级导航池
  274. parentKey: 0,//获取父级导航
  275. parentData: {
  276. checkStrictly: true,
  277. lazy: true,
  278. async lazyLoad(node, resolve) {
  279. const { level, data } = node;
  280. if (data && data.children && data.children.length !== 0) {
  281. return resolve(node)
  282. }
  283. let parentId;
  284. parentId = level == 0 ? 0 : data.value;
  285. let parames = {
  286. 'type': 7,
  287. 'website_id': getWebSiteId(),
  288. 'pid': parentId
  289. }
  290. self.$store.dispatch('pool/get_creatNews_nav_son_actions', parames).then(res => {
  291. if (res.data) {
  292. const nodes = res.data.map(item => ({
  293. value: item.category_id,
  294. label: item.name,
  295. leaf: level >= 3,
  296. children: [],
  297. disabled: item.type != 7
  298. }))
  299. resolve(nodes)
  300. }
  301. })
  302. }
  303. },
  304. parentKey_2: 0,//获取父级导航
  305. parentData_2: {
  306. checkStrictly: true,
  307. lazy: true,
  308. async lazyLoad(node, resolve) {
  309. const { level, data } = node;
  310. if (data && data.children && data.children.length !== 0) {
  311. return resolve(node)
  312. }
  313. let parentId;
  314. if (self.ifwebsitId == true) {
  315. parentId = 0;
  316. self.ifwebsitId = false;
  317. self.cat_arr_id = [];
  318. } else {
  319. parentId = level == 0 ? 0 : data.value;
  320. self.ifwebsitId = false;
  321. }
  322. let parames = {
  323. 'type': 7,
  324. 'website_id': self.form.website_id,
  325. 'pid': parentId
  326. }
  327. self.$store.dispatch('pool/get_creatNews_nav_son_actions', parames).then(res => {
  328. if (res.data) {
  329. const nodes = res.data.map(item => ({
  330. value: item.category_id,
  331. label: item.alias,
  332. leaf: level >= 3,
  333. children: [],
  334. disabled: item.type != 7
  335. }))
  336. resolve(nodes)
  337. }
  338. })
  339. }
  340. },
  341. inputList: [
  342. { value: '' }
  343. ]
  344. //表单项 end ------------------------------------------------------------>
  345. };
  346. }, watch: {
  347. '$route'(to, from) {
  348. // 监听路由参数中的 id 变化,若变化则更新页面状态并获取数据
  349. if (to.query.id) {
  350. this.getMainData();
  351. }
  352. },
  353. },
  354. methods: {
  355. //1.提交表单 start ------------------------------------------------------------>
  356. //1.1 直接上传图片
  357. beforeAvatarUpload(file) {
  358. const isJPG = file.type === 'image/jpeg';
  359. const isPNG = file.type === 'image/png';
  360. const isLt2M = file.size / 1024 / 1024 < 2;
  361. if (!isJPG && !isPNG) {
  362. this.$message.error('上传缩略图只能是 JPG 或 PNG 格式!');
  363. return false;
  364. }
  365. if (!isLt2M) {
  366. this.$message.error('上传缩略图大小不能超过 2MB!');
  367. return false;
  368. }
  369. // ---------------多图上传---处理
  370. if (this.imgurl.length > 4) {
  371. this.$message.warning('只能上传5张图片');
  372. return false;
  373. }
  374. // ---------------多图上传---处理
  375. const formData = new FormData();
  376. formData.append('file', file);
  377. this.$store.dispatch('pool/uploadFile', formData).then(res => {
  378. // ---------------多图上传---处理
  379. this.imgurl.push(res.data.imgUrl);//显示缩略图
  380. this.form.imgurl.push(res.data.imgUrl);//提供表单地址
  381. // ---------------多图上传---处理
  382. })
  383. // 阻止默认的上传行为
  384. return false;
  385. },
  386. deleteImage(index) { // 删除图片
  387. this.imgurl.splice(index, 1);
  388. this.form.imgurl.splice(index, 1);
  389. },
  390. //1.2 提交表单
  391. addToServe() {
  392. //取出行政职能和行政区划数组的最后一个数字
  393. if (this.form.city_arr_id == "[]" || this.form.city_arr_id == null) {
  394. this.form.city_arr_id = '[]'
  395. this.form.city_id = 0;
  396. } else {
  397. if (JSON.parse(this.form.city_arr_id.length == 0)) {
  398. this.form.city_id = 0;
  399. } else {
  400. this.form.city_id = this.form.city_arr_id[this.form.city_arr_id.length - 1];
  401. }
  402. }
  403. // this.form.keyword = JSON.stringify(this.form.keyword);
  404. //判断用户身份
  405. if (this.creatNews_user_type == 10000) {
  406. console.log("用户身份为管理员,无需审核直接发布!")
  407. this.form.status = 1;
  408. } else {
  409. console.log("用户身份为其他用户,提交到审核!")
  410. this.form.status = 0;
  411. this.form.website_id = this.websiteid;
  412. }
  413. this.$refs.form.validate(valid => {
  414. if (valid) {
  415. // delete formData.cat_arr_id;
  416. const formData = { ...this.form };
  417. formData.city_arr_id = Array.isArray(this.form.city_arr_id) ? JSON.stringify(this.form.city_arr_id): this.form.city_arr_id ;
  418. formData.imgurl = Array.isArray(this.form.imgurl) ? JSON.stringify(this.form.imgurl): this.form.imgurl ;
  419. if (this.form.cat_arr_id == "[]" || this.form.cat_arr_id == null) {
  420. this.form.cat_arr_id = '[]'
  421. this.form.category_id = 0;
  422. } else {
  423. if (JSON.parse(this.form.cat_arr_id.length == 0)) {
  424. this.form.category_id = 0;
  425. } else {
  426. this.form.category_id = this.form.cat_arr_id[this.form.cat_arr_id.length - 1];
  427. }
  428. }
  429. formData.category_id = this.form.category_id;
  430. formData.cat_arr_id = Array.isArray(this.form.cat_arr_id) ? JSON.stringify(this.form.cat_arr_id): this.form.cat_arr_id ;
  431. formData.level = this.form.level;
  432. delete formData.commend_id;
  433. delete formData.nav_add_pool_id;
  434. delete formData.user_type;
  435. this.$store.dispatch('project/addProject', formData).then(res => {
  436. if (res.code == 200) {
  437. //汇报结果
  438. if (this.creatNews_user_type == 10000) {
  439. this.$message({
  440. type: 'success',
  441. message: '已成功添加项目!'
  442. });
  443. this.cleatForm(2);
  444. //返回列表页
  445. this.returnPage()
  446. } else {
  447. this.$message({
  448. type: 'success',
  449. message: '待管理员审核!'
  450. });
  451. this.cleatForm(2);
  452. //返回列表页
  453. this.returnPage()
  454. }
  455. } else {
  456. this.$message({
  457. type: 'error',
  458. message: res.message
  459. });
  460. }
  461. }).catch(() => {
  462. this.$message({
  463. type: 'info',
  464. message: '网络错误,请重试!'
  465. });
  466. })
  467. }
  468. })
  469. },
  470. //1.3 清理表单
  471. cleatForm() {
  472. this.form.website_id = 0;
  473. this.form.cat_arr_id = [];
  474. this.form.nav_add_pool_id = [],//导航池子级
  475. this.form.category_id = 0;
  476. this.form.title = "";
  477. this.form.level = null;
  478. this.form.imgurl = "";
  479. this.form.description = "";
  480. this.form.keyword = "";
  481. this.form.business_name = "";
  482. this.form.content_person = "";
  483. this.form.telephone = "";
  484. this.form.mobile = "";
  485. this.form.post_code = "";
  486. this.form.fax = "";
  487. this.form.email = "";
  488. this.form.business_name = "";
  489. this.form.address = "";
  490. this.form.introduce = "";
  491. this.form.city_arr_id = [];
  492. this.form.city_id = "";
  493. this.form.status = 0;
  494. this.form.franchise_details = "";
  495. },
  496. //1.4更新详细地址
  497. update_city_arr_id(value) {
  498. this.form.city_arr_id = value;
  499. },
  500. //1.5 删除图片
  501. handleDelete() {
  502. // 删除图片
  503. this.imgUrl = ''; // 清空图片 URL
  504. this.imgurl = '';
  505. this.form.imgurl = ''; // 清空表单中的图片 URL
  506. },
  507. //提交表单 end ------------------------------------------------------------>
  508. //2.跳转操作 start ------------------------------------------------------------>
  509. returnPage() {
  510. if (this.$route.query.to == "checkProject") {
  511. this.$router.push({
  512. path: '/checkprojectList',
  513. });
  514. } else {
  515. this.$router.push({
  516. path: '/projectList',
  517. });
  518. }
  519. },
  520. //跳转操作 end ------------------------------------------------------------>
  521. //3.回显操作 ------------------------------------------------------------>
  522. //3.1回显数据
  523. getMainData() {
  524. let data = {
  525. id: this.$route.query.id
  526. };
  527. this.$store.dispatch('project/getProjectInfo', data).then(res => {
  528. this.form.title = res.data.title;
  529. this.form.level = res.data.level;
  530. console.log(res.data.level)
  531. if (typeof res.data.website_id === 'string') {
  532. this.form.website_id = Number(res.data.website_id);
  533. } else {
  534. this.form.website_id = res.data.website_id//站点名称
  535. }
  536. this.form.cat_arr_id = Array.isArray(res.data.cat_arr_id) ? res.data.cat_arr_id : JSON.parse(res.data.cat_arr_id);
  537. //回显导航池 连同非管理员得一起刷新
  538. this.parentKey += 1; // 触发级联选择器重新加载
  539. this.loadCascaderPath(this.form.cat_arr_id); // 加载路径数据
  540. this.parentKey_2 += 1; // 触发级联选择器重新加载
  541. this.loadCascaderPath(this.form.cat_arr_id); // 加载路径数据
  542. //回显行政区划
  543. this.form.city_arr_id = JSON.parse(res.data.city_arr_id);
  544. //回显其他数据
  545. this.form.imgurl = Array.isArray(res.data.imgurl) ? res.data.imgurl : JSON.parse(res.data.imgurl);
  546. this.imgurl = Array.isArray(res.data.imgurl) ? res.data.imgurl : JSON.parse(res.data.imgurl);
  547. this.form.keyword = res.data.keyword;
  548. this.tags = res.data.keyword ? res.data.keyword.split(",") : '';
  549. this.form.description = res.data.description;
  550. //回显编辑器内容
  551. this.$nextTick(() => {
  552. this.form.introduce = res.data.introduce;
  553. });
  554. //回显编辑器内容
  555. // this.$nextTick(() => {
  556. this.form.franchise_details = res.data.franchise_details;
  557. // });
  558. this.form.status = res.data.status;
  559. this.form.business_name = res.data.business_name;
  560. this.form.content_person = res.data.content_person;
  561. this.form.telephone = res.data.telephone;
  562. this.form.mobile = res.data.mobile;
  563. this.form.post_code = res.data.post_code;
  564. this.form.fax = res.data.fax;
  565. this.form.email = res.data.email;
  566. this.form.address = res.data.address;
  567. })
  568. },
  569. async loadCascaderPath(path) {
  570. for (let i = 0; i < path.length; i++) {
  571. const parentId = path[i - 1] || 0; // 获取当前层级的父级ID
  572. const level = i; // 当前层级的索引
  573. await this.$store.dispatch('pool/categoryList', { pid: parentId })
  574. .then((res) => {
  575. const nodes = res.data.map(item => ({
  576. value: item.id,
  577. label: item.name,
  578. leaf: level >= 3, // 假设4层结构,设置叶子节点标记
  579. }));
  580. // 级联选择器加载数据
  581. if (level === path.length - 1) {
  582. this.form.cat_arr_id = path; // 确保最后一级路径正确设置
  583. this.parentKey += 1; // 强制刷新 cascader
  584. }
  585. });
  586. }
  587. },
  588. //1.3提交修改
  589. editToServe() {
  590. //不使用外联 验证投票逻辑
  591. this.form.id = this.editId;
  592. //先进行验证
  593. this.$refs.form.validate(valid => {
  594. if (valid) {
  595. // 如果没有,可以根据实际情况修改
  596. // ===== 日期处理逻辑结束 =====
  597. //取出行政职能和行政区划数组的最后一个数字
  598. if (this.form.city_arr_id == "[]" || this.form.city_arr_id == null) {
  599. this.form.city_arr_id = '[]';
  600. this.form.city_id = 0;
  601. } else {
  602. if (JSON.parse(this.form.city_arr_id.length == 0)) {
  603. this.form.city_id = 0;
  604. } else {
  605. this.form.city_id = this.form.city_arr_id[this.form.city_arr_id.length - 1];
  606. }
  607. }
  608. if (this.form.cat_arr_id == "[]" || this.form.cat_arr_id == null) {
  609. this.form.cat_arr_id = '[]';
  610. this.form.category_id = 0;
  611. } else {
  612. if (JSON.parse(this.form.cat_arr_id.length == 0)) {
  613. this.form.category_id = 0;
  614. } else {
  615. this.form.category_id = this.form.cat_arr_id[this.form.cat_arr_id.length - 1];
  616. }
  617. }
  618. if (this.creatNews_user_type == 10000) {
  619. this.form.status = 1;
  620. } else {
  621. this.form.status = 0;
  622. this.form.website_id = this.websiteid;
  623. }
  624. if(this.form.level == 0 || this.form.level == ''){
  625. this.form.level = null;
  626. }
  627. const formData = { ...this.form };
  628. formData.city_arr_id = Array.isArray(this.form.city_arr_id) ? JSON.stringify(this.form.city_arr_id): this.form.city_arr_id ;
  629. formData.cat_arr_id = Array.isArray(this.form.cat_arr_id) ? JSON.stringify(this.form.cat_arr_id): this.form.cat_arr_id ;
  630. formData.imgurl = Array.isArray(this.form.imgurl) ? JSON.stringify(this.form.imgurl): this.form.imgurl ;
  631. delete formData.user_type;
  632. delete formData.nav_add_pool_id;
  633. this.$store.dispatch('project/upProject', formData).then(res => {
  634. if (res.code != 200) {
  635. this.$message({
  636. type: 'error',
  637. message: res.message
  638. });
  639. } else {
  640. //汇报结果
  641. if (this.creatNews_user_type == 10000) {
  642. this.$message({
  643. type: 'success',
  644. message: '已成功编辑项目!'
  645. });
  646. this.cleatForm(2);
  647. //返回列表页
  648. this.returnPage()
  649. } else {
  650. this.$message({
  651. type: 'success',
  652. message: '待管理员审核!'
  653. });
  654. this.cleatForm(2);
  655. //返回列表页
  656. this.returnPage()
  657. }
  658. }
  659. }).catch(() => {
  660. this.$message({
  661. type: 'info',
  662. message: '网络错误,请重试!'
  663. });
  664. })
  665. }
  666. })
  667. },
  668. //跳转操作 end ------------------------------------------------------------>
  669. //5.站点选择 曹国庆 start ------------------------------------------------------------>
  670. get_creatNews_form_id_fun() {
  671. //判断用户类型ajax
  672. this.$store.dispatch('public/getInfo').then(res => {
  673. this.form.user_type = res.data.type_id;
  674. }).catch(() => {
  675. this.$message({
  676. type: 'info',
  677. message: '网络错误,请重试!'
  678. });
  679. })
  680. },
  681. get_creatNews_nav_pool_arr_fun() {//
  682. this.$store.dispatch('pool/get_creatNews_nav_actions', { page: 1, pageSize: 666666 }).then(res => {
  683. res.data.rows.forEach((per_obj) => {
  684. let new_per = {
  685. label: per_obj.website_name,
  686. value: per_obj.id,
  687. }
  688. this.creatNews_nav_pool_arr.push(new_per)
  689. })
  690. }).catch(() => {
  691. this.$message({
  692. type: 'info',
  693. message: '网络错误,请重试!'
  694. });
  695. })
  696. },
  697. creatNews_nav_pool_change_fun() {
  698. //开启导航池级联选择器
  699. this.ifwebsitId = true;
  700. // 导航池级
  701. let that = this;
  702. this.form.website_id = this.form.website_id[0];
  703. that.parentKey_2 += 1;
  704. this.$store.dispatch('pool/get_creatNews_nav_son_actions', { type: 7, pid: String(this.creatNews_pid_num), website_id: String(this.form.website_id) }).then(res => {
  705. if (res.data.length == 0) {//没有导航池子级
  706. // alert("没有导航池子级");
  707. return
  708. }
  709. this.creatNews_add_nav_pool_arr = res.data;
  710. this.creatNews_add_nav_pool_arr.forEach((per_obj) => {
  711. per_obj.label = per_obj.name,
  712. per_obj.value = per_obj.id,
  713. this.creatNews_pid_num = per_obj.category_id
  714. })
  715. }).catch(() => {
  716. this.$message({
  717. type: 'info',
  718. message: '网络错误,请重试!'
  719. });
  720. })
  721. },
  722. updateTags(newTags) {
  723. this.tags = newTags;
  724. if(this.tags.length == 0){
  725. this.form.keyword = '';
  726. }else{
  727. this.form.keyword = JSON.stringify(newTags);
  728. }
  729. },
  730. //推荐等级多选获取到的数据
  731. levelChange(value) {
  732. this.form.level = value;
  733. },
  734. // 远程搜索方法
  735. remoteMethod(query) {
  736. const artical_params = { page: 1, pageSize: 20, id: query }
  737. if (query !== '') {
  738. this.loading = true;
  739. //如果全是数字,就id,其他就是搜title
  740. let reg = /^[0-9]+$/;
  741. let isNum = reg.test(query);
  742. if (isNum) {
  743. delete artical_params.title;
  744. artical_params.id = query;
  745. } else {
  746. delete artical_params.id;
  747. artical_params.title = query;
  748. }
  749. this.$store.dispatch('project/getProjectList', artical_params).then(res => {
  750. this.loading = false;
  751. let data = [];
  752. for (let item of res.data.rows) {
  753. data.push(item);
  754. }
  755. this.commend_article = data;
  756. }).catch(() => {
  757. this.loading = false;
  758. this.$message({
  759. type: 'info',
  760. message: '网络错误,请重试!'
  761. });
  762. });
  763. } else {
  764. this.commend_article = [];
  765. }
  766. },
  767. //5.站点选择 曹国庆 end ------------------------------------------------------------>
  768. },
  769. mounted() {
  770. // this.getNews()
  771. this.creatNews_user_type = getUseType()
  772. this.websiteid = getWebSiteId()
  773. //1.获得站点标识
  774. this.get_creatNews_form_id_fun()
  775. this.get_creatNews_nav_pool_arr_fun()
  776. //2.判断是新建还是回显
  777. if (this.$route.query.id != undefined) {
  778. this.editId = this.$route.query.id;
  779. this.editStatus = true;
  780. // this.tableDivTitle = "编辑项目";
  781. this.getMainData();
  782. } else {
  783. this.editStatus = false;
  784. // this.tableDivTitle = "添加项目";
  785. }
  786. },
  787. };
  788. </script>
  789. <style scoped lang="less">
  790. //执行v-deep穿透scope选择器 start------------------------------------------------------------>*/
  791. ::v-deep .custom-form-item>.el-form-item__label {
  792. line-height: 140px !important;
  793. }
  794. ::v-deep .custom-textarea .el-textarea__inner {
  795. resize: none;
  796. /* 禁止用户拖拽调整大小 */
  797. }
  798. ::v-deep .custom-align-right .el-form-item__label {
  799. text-align: right;
  800. /* 设置标签文字右对齐 */
  801. }
  802. ::v-deep .el-popper {
  803. height: 500px;
  804. }
  805. ::v-deep .el-select {
  806. width: 100%;
  807. /* 禁止用户拖拽调整大小 */
  808. }
  809. ::v-deep .el-input-group__prepend {
  810. color: black !important;
  811. }
  812. .formLabelFloatBox {
  813. margin-bottom: 10px;
  814. position: relative;
  815. .formLabeladdIcon {
  816. position: absolute;
  817. right: 45px;
  818. top: 5px;
  819. width: 38px;
  820. height: 24px;
  821. }
  822. .formLabelDelIcon {
  823. position: absolute;
  824. right: 5px;
  825. top: 5px;
  826. width: 38px;
  827. height: 24px;
  828. }
  829. }
  830. //该项不能为空几个字的位置
  831. ::v-deep .el-form-item__error {
  832. color: #ff4949;
  833. font-size: 12px;
  834. line-height: 1;
  835. padding-top: 4px;
  836. position: relative;
  837. // top: 22%;
  838. // left: 93%;
  839. }
  840. //输入框距离底部的距离
  841. ::v-deep .el-form-item {
  842. margin-bottom: 5px;
  843. }
  844. //图片提示文字样式
  845. .photo_tips {
  846. font-size: 12px;
  847. color: #999;
  848. }
  849. // 执行v-deep穿透scope选择器 end------------------------------------------------------------></style>