categoryList.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. <template>
  2. <div class="mainBox">
  3. <!--搜索功能 start------------------------------------------------------------>
  4. <div class="layerBox_search">
  5. <el-row>
  6. <el-col :span="8">
  7. <div class="searchBox">
  8. <div class="searchTitle">栏目名称:</div>
  9. <el-input v-model="getApiData.name" placeholder="请输入栏目名称" :clearable="true" @clear="onInputClear" />
  10. <!-- <el-input placeholder="请输入栏目名称" autocomplete="off" v-model="getApiData.name" /> -->
  11. </div>
  12. </el-col>
  13. </el-row>
  14. </div>
  15. <div class="layerBoxNoBg">
  16. <div>
  17. <el-button type="primary" @click="addCategoryList()">添加栏目名称</el-button>
  18. </div>
  19. <div>
  20. <el-button @click="clearSearchList">重置</el-button>
  21. <el-button type="primary" style="margin-right:20px" @click="getData('search')">搜索</el-button>
  22. </div>
  23. </div>
  24. <!--搜索功能 end------------------------------------------------------------>
  25. <!--表格内容 start------------------------------------------------------------>
  26. <div class="layerBox">
  27. <tableTitle :name="tableDivTitle" />
  28. <el-row>
  29. <template>
  30. <el-table :data="tableData" style="width: 100%" row-key="id" :default-expand-all="isExpandAll"
  31. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
  32. <el-table-column fixed prop="id" label="编号" width="150"></el-table-column>
  33. <el-table-column prop="name" label="栏目名称">
  34. <template slot-scope="scope">
  35. <span :class="{ highlight: isHighlight(scope.row, search) }" v-if="scope.row.pid == 0">{{ scope.row.name
  36. }}</span>
  37. <span :class="{ highlight: isHighlight(scope.row, search) }" v-else>____{{ scope.row.name }}</span>
  38. </template>
  39. </el-table-column>
  40. <el-table-column label="是否外链" align="center">
  41. <template slot-scope="scope">
  42. <div>
  43. {{ scope.row.is_url ? '是' : "否" }}
  44. </div>
  45. </template>
  46. </el-table-column>
  47. <el-table-column prop="created_at" label="创建时间"></el-table-column>
  48. <el-table-column prop="updated_at" label="修改时间"></el-table-column>
  49. <el-table-column fixed="right" label="操作" width="230" header-align="center">
  50. <template slot-scope="scope">
  51. <div class="listBtnBox">
  52. <div class="listDeleteBtn" @click="deleteData(scope.row.id, tableData)"><i
  53. class="el-icon-delete"></i>删除</div>
  54. <div class="listEditBtn" @click="getDataMain(scope.row.id, tableData)"><i
  55. class="el-icon-edit-outline"></i>编辑</div>
  56. <div class="listMainBtn" @click="addCategoryList(scope.row)"><i class="el-icon-document-add"></i>添加
  57. </div>
  58. </div>
  59. <!-- <el-button @click.native.prevent="deleteData(scope.row.id, tableData)" type="text" size="small">删除</el-button>
  60. <el-button @click.native.prevent="getDataMain(scope.row.id, tableData)" type="text" size="small">编辑</el-button> -->
  61. </template>
  62. </el-table-column>
  63. </el-table>
  64. </template>
  65. </el-row>
  66. </div>
  67. <!--分页 start------------------------------------------------------------>
  68. <div class="alignBox">
  69. <el-row>
  70. <el-col :span="24">
  71. <el-pagination :current-page="getApiData.page" @size-change="handleSizeChange"
  72. @current-change="handleCurrentChange" :page-size="10" layout="total, prev, pager, next, jumper"
  73. :total="allCount"></el-pagination>
  74. </el-col>
  75. </el-row>
  76. </div>
  77. <!--分页 end------------------------------------------------------------>
  78. <!--表格内容 end------------------------------------------------------------>
  79. <!--弹出框 start------------------------------------------------------------>
  80. <el-dialog :title="editId ? '编辑栏目名称' : '添加栏目名称'" :visible.sync="windowStatus" :close-on-click-modal="false"
  81. @close="clearToServe(2)">
  82. <el-form :model="form" ref="form" :rules="formRules" autocomplete="off" label-position="left">
  83. <div class="formDiv">
  84. <el-form-item label="栏目名称:" :label-width="formLabelWidth" prop="name" class="custom-align-right">
  85. <el-input v-model="form.name" autocomplete="off" placeholder="请输入栏目名称"></el-input>
  86. <el-checkbox v-model="show_url" @change="ifUrl">引用外链</el-checkbox>
  87. </el-form-item>
  88. <div v-if="show_url == 1">
  89. <el-form-item label="外链地址:" :label-width="formLabelWidth" prop="web_url" class="custom-align-right">
  90. <el-input v-model="form.web_url" autocomplete="off" placeholder="请输入外链地址"></el-input>
  91. </el-form-item>
  92. <el-form-item label="栏目标题:" :label-width="formLabelWidth" prop="seo_title" class="custom-align-right">
  93. <el-input v-model="form.seo_title" autocomplete="off" placeholder="请输入栏目标题"></el-input>
  94. </el-form-item>
  95. <el-form-item label="栏目关键词:" :label-width="formLabelWidth" prop="seo_keywords" class="custom-align-right">
  96. <!-- <el-input v-model="form.seo_keywords" autocomplete="off" placeholder="请输入栏目关键词"></el-input> -->
  97. <inputTag :initialTags="tags" @tags-updated="updateTags" />
  98. </el-form-item>
  99. <el-form-item label="栏目描述:" :label-width="formLabelWidth" prop="seo_description" class="custom-align-right">
  100. <el-input type="textarea" v-model="form.seo_description" placeholder="请输入栏目描述"></el-input>
  101. </el-form-item>
  102. <!-- <el-form-item label="排序:" :label-width="formLabelWidth" class="custom-align-right">
  103. <el-input v-model="form.sort" autocomplete="off" placeholder="请输入排序"></el-input>
  104. </el-form-item> -->
  105. </div>
  106. <div v-if="show_url == 0">
  107. <!-- <el-form-item label="关联职能部门:" :label-width="formLabelWidth" prop="department_arr_id" class="custom-align-right"> -->
  108. <!-- <el-cascader :key="departmentKey" v-model="form.department_arr_id" placeholder="选择要绑定的职能部门" :props="departmentData" filterable clearable></el-cascader> -->
  109. <!-- <el-cascader :key="departmentKey" :props="{value:'id',label:'name',children:'children'}" :options="allDepartment" v-model="form.department_arr_id" :show-all-levels="false" filterable />
  110. </el-form-item> -->
  111. <!-- <el-form-item label="关联行政区划:" :label-width="formLabelWidth" prop="city_arr_id" class="custom-align-right">
  112. <el-cascader :key="cascaderKey" v-model="form.city_arr_id" placeholder="选择要绑定行政区划" :props="cityData" filterable clearable></el-cascader>
  113. </el-form-item> -->
  114. <el-form-item label="父级栏目:" :label-width="formLabelWidth" class="custom-align-right">
  115. <el-cascader :key="parentKey" v-model="form.pid_arr" placeholder="请选择要绑定的父级栏目" :props="parentData"
  116. filterable clearable></el-cascader>
  117. </el-form-item>
  118. <el-form-item label="栏目类型:" :label-width="formLabelWidth" prop="type" class="custom-align-right">
  119. <template #label>
  120. <span class="askBox">
  121. 栏目类型:
  122. <el-tooltip class="item" effect="dark" content=" 选择类型提交后不可更改,请谨慎考虑后提交!" placement="top">
  123. <i class="el-icon-question"></i>
  124. </el-tooltip>
  125. </span>
  126. </template>
  127. <el-radio-group v-model="form.type" size="small" :disabled="editId ? true : false">
  128. <el-radio-button label="1">资讯</el-radio-button>
  129. <el-radio-button label="2">商品</el-radio-button>
  130. <el-radio-button label="3">书刊音响</el-radio-button>
  131. <el-radio-button label="4">招聘</el-radio-button>
  132. <el-radio-button label="5">求职</el-radio-button>
  133. </el-radio-group>
  134. <!-- 选择类型提交后不可更改,请谨慎考虑后提交! 提示词 -->
  135. <div style="color: brown;">
  136. 选择类型提交后不可更改,请谨慎考虑后提交!
  137. </div>
  138. </el-form-item>
  139. <el-form-item label="栏目标题:" :label-width="formLabelWidth" prop="seo_title" class="custom-align-right">
  140. <template #label>
  141. <span class="askBox">
  142. 栏目标题:
  143. <el-tooltip class="item" effect="dark" content="栏目标题,如:三农市场网_农资产品商城_网站列表_全国信息一体化网络平台_项目大全。"
  144. placement="top">
  145. <i class="el-icon-question"></i>
  146. </el-tooltip>
  147. </span>
  148. </template>
  149. <el-input v-model="form.seo_title" autocomplete="off" placeholder="请输入栏目标题"></el-input>
  150. </el-form-item>
  151. <el-form-item label="栏目关键词:" :label-width="formLabelWidth" prop="seo_keywords" class="custom-align-right">
  152. <template #label>
  153. <span class="askBox">
  154. 栏目关键词:
  155. <el-tooltip class="item" effect="dark" content="栏目关键词,如:三农市场网、农资产品商城、全国三农、信息一体化。" placement="top">
  156. <i class="el-icon-question"></i>
  157. </el-tooltip>
  158. </span>
  159. </template>
  160. <!-- <el-input v-model="form.seo_keywords" autocomplete="off" placeholder="请输入栏目关键词"></el-input> -->
  161. <inputTag :initialTags="tags" @tags-updated="updateTags" />
  162. </el-form-item>
  163. <el-form-item label="栏目描述:" :label-width="formLabelWidth" prop="seo_description" class="custom-align-right">
  164. <template #label>
  165. <span class="askBox">
  166. 栏目描述:
  167. <el-tooltip class="item" effect="dark" content="栏目描述,如:中国三农市场网,农资产品商城属市场类频道,共有5个栏目。" placement="top">
  168. <i class="el-icon-question"></i>
  169. </el-tooltip>
  170. </span>
  171. </template>
  172. <el-input type="textarea" v-model="form.seo_description" class="custom-textarea"
  173. placeholder="请输入栏目描述"></el-input>
  174. </el-form-item>
  175. <!-- <el-form-item label="排序:" :label-width="formLabelWidth" class="custom-align-right">
  176. <el-input v-model="form.sort" autocomplete="off" placeholder="请输入排序"></el-input>
  177. </el-form-item> -->
  178. </div>
  179. </div>
  180. </el-form>
  181. <div slot="footer" class="dialog-footer">
  182. <el-button @click="closeWindow">取 消</el-button>
  183. <el-button type="primary" @click="editToServe" v-if="editBtn == true">确定</el-button>
  184. <el-button type="primary" @click="addToServe" v-else>提交</el-button>
  185. </div>
  186. </el-dialog>
  187. <!--弹出框 end------------------------------------------------------------>
  188. </div>
  189. </template>
  190. <script>
  191. //表格标题
  192. import tableTitle from './components/tableTitle';
  193. import InputTag from '@/components/InputTag';
  194. //引入公用样式
  195. import '@/styles/global.less';
  196. export default {
  197. components: {
  198. tableTitle,//表格标题
  199. InputTag
  200. },
  201. data() {
  202. //0.全局操作 start ------------------------------------------------------------>
  203. //表单验证
  204. const validateEmpty = (rule, value, callback) => {
  205. if (value.length == 0) {
  206. callback(new Error('该项不能为空!'))
  207. } else {
  208. callback()
  209. }
  210. }
  211. // const validateDepartment = (rule,value,callback) => {
  212. // if (value.length === 0) {
  213. // callback(new Error('请选择职能部门!'))
  214. // } else {
  215. // callback()
  216. // }
  217. // }
  218. // const validateCity = (rule,value,callback) => {
  219. // if (value.length === 0) {
  220. // callback(new Error('请选择行政区划!'))
  221. // } else {
  222. // callback()
  223. // }
  224. // }
  225. const validatePid = (rule, value, callback) => {
  226. if (value.length === 0) {
  227. callback(new Error('请选择父级栏目!'))
  228. } else {
  229. callback()
  230. }
  231. }
  232. let self = this;
  233. //0.全局操作 end ------------------------------------------------------------>
  234. return {
  235. isExpandAll: false,
  236. search: '',
  237. tags: [],
  238. //1.列表和分页相关 start ------------------------------------------------------------>
  239. tableDivTitle: "栏目名称列表",
  240. tableData: [],//内容
  241. allCount: 0,//总条数
  242. editId: 0,//要修改的网站id
  243. getApiData: {
  244. name: "",//栏目池名称查询
  245. // department_id:[],//行政职能部门id
  246. // city_id:[],//行政区划
  247. page: 1,//当前是第几页
  248. pageSize: 10,//一共多少条
  249. },
  250. allDepartment: [],//所有职能
  251. //列表和分页相关 end ------------------------------------------------------------>
  252. //2.搜索相关 start ------------------------------------------------------------>
  253. //行政职能部门
  254. searchDepartmentKey: 0, //列表缓存key
  255. // searchDepartmentData: {
  256. // checkStrictly: true,
  257. // lazy: true,
  258. // async lazyLoad (node, resolve) {
  259. // const { level, data } = node;
  260. // if (data && data.children && data.children.length !== 0) {
  261. // return resolve(node)
  262. // }
  263. // console.log(level)
  264. // let parentId = level == 0 ? 0 : data.value
  265. // let parames = {
  266. // 'pid':parentId
  267. // }
  268. // self.$store.dispatch('pool/getDepartment',parames).then(res=> {
  269. // if (res.data) {
  270. // const nodes = res.data.map(item => ({
  271. // value: item.id,
  272. // label: item.name,
  273. // leaf: level >= 3,
  274. // children: []
  275. // }))
  276. // resolve(nodes)
  277. // }
  278. // })
  279. // }
  280. // },
  281. //获取城市列表
  282. searchCascaderKey: 0, //列表缓存key
  283. searchCityData: {
  284. checkStrictly: true,
  285. lazy: true,
  286. async lazyLoad(node, resolve) {
  287. const { level, data } = node;
  288. if (data && data.children && data.children.length !== 0) {
  289. return resolve(node)
  290. }
  291. console.log(level)
  292. let parentId = level == 0 ? 0 : data.value
  293. let parames = {
  294. 'pid': parentId
  295. }
  296. self.$store.dispatch('pool/getcityList', parames).then(res => {
  297. if (res.data) {
  298. const nodes = res.data.map(item => ({
  299. value: item.id,
  300. label: item.name,
  301. leaf: level >= 3,
  302. children: []
  303. }))
  304. resolve(nodes)
  305. }
  306. })
  307. }
  308. },
  309. //搜索相关 end ------------------------------------------------------------>
  310. //3.弹出框设置 start ------------------------------------------------------------>
  311. windowStatus: false, //显示弹出框
  312. formLabelWidth: '140px',
  313. show_url: false, //是否显示外链输入框
  314. editBtn: false,//当显示编辑按钮的时候,就不显示提交
  315. //弹出框设置 end ------------------------------------------------------------>
  316. //4.弹出框中的表单设置 start ------------------------------------------------------------>
  317. //4.1表单收集的数据
  318. form: {
  319. name: '',//栏目池名称
  320. is_url: 0,//是否为外链,0=否 1=是
  321. web_url: "",//外链地址
  322. // department_arr_id:[],//职能部门
  323. // city_arr_id:[],//行政区划
  324. sort: 0,//排序
  325. //pid:2,
  326. seo_title: "",//标题
  327. seo_keywords: "",//关键词
  328. seo_description: "",//描述
  329. type: 1,//栏目类型
  330. pid_arr: []//父级栏目
  331. },
  332. //4.2表单验证规则
  333. formRules: {
  334. //网站名称不能为空
  335. name: [{ required: true, trigger: 'blur', validator: validateEmpty }],//栏目池名称不能为空
  336. web_url: [{ required: true, trigger: 'blur', validator: validateEmpty }],//外链地址不能为空
  337. // department_arr_id: [{type:'array',required:true,trigger:'change',message:'请选择职能部门!',validator:validateDepartment}],
  338. // city_arr_id: [{type:'array',required:true,trigger:'change',message:'请选择行政区划!',validator:validateCity}],
  339. // pid_arr: [{type:'array',required:true,trigger:'change',message:'请选择父级栏目!',validator:validatePid}],
  340. seo_title: [{ required: true, trigger: 'blur', validator: validateEmpty }],//标题不能为空
  341. seo_keywords: [{ required: true, trigger: 'blur', validator: validateEmpty }],//关键词不能为空
  342. seo_description: [{ required: true, trigger: 'blur', validator: validateEmpty }],//描述不能为空
  343. },
  344. //获取城市列表
  345. cascaderKey: 0,//弹窗用的key
  346. cityData: {
  347. checkStrictly: true,
  348. lazy: true,
  349. async lazyLoad(node, resolve) {
  350. const { level, data } = node;
  351. if (data && data.children && data.children.length !== 0) {
  352. return resolve(node)
  353. }
  354. console.log(level)
  355. let parentId = level == 0 ? 0 : data.value
  356. let parames = {
  357. 'pid': parentId
  358. }
  359. self.$store.dispatch('pool/getcityList', parames).then(res => {
  360. if (res.data) {
  361. const nodes = res.data.map(item => ({
  362. value: item.id,
  363. label: item.name,
  364. leaf: level >= 3,
  365. children: []
  366. }))
  367. resolve(nodes)
  368. }
  369. })
  370. }
  371. },
  372. //获取职能部门
  373. departmentKey: 0,//弹窗用的key
  374. // departmentData: {
  375. // checkStrictly: true,//父级不可选
  376. // lazy: true,
  377. // async lazyLoad (node, resolve) {
  378. // const { level, data } = node;
  379. // if (data && data.children && data.children.length !== 0) {
  380. // return resolve(node)
  381. // }
  382. // console.log(level)
  383. // let parentId = level == 0 ? 0 : data.value
  384. // let parames = {
  385. // 'pid':parentId
  386. // }
  387. // self.$store.dispatch('pool/getDepartment',parames).then(res=> {
  388. // if (res.data) {
  389. // const nodes = res.data.map(item => ({
  390. // value: item.id,
  391. // label: item.name,
  392. // leaf: level >= 3,
  393. // children: []
  394. // }))
  395. // resolve(nodes)
  396. // }
  397. // })
  398. // }
  399. // },
  400. parentKey: 0,//获取父级栏目
  401. parentData: {
  402. checkStrictly: true,
  403. lazy: true,
  404. async lazyLoad(node, resolve) {
  405. const { level, data } = node;
  406. if (data && data.children && data.children.length !== 0) {
  407. return resolve(node)
  408. }
  409. console.log(level)
  410. let parentId = level == 0 ? 0 : data.value
  411. let parames = {
  412. 'pid': parentId
  413. }
  414. self.$store.dispatch('pool/categoryList', parames).then(res => {
  415. if (res.data) {
  416. const nodes = res.data.map(item => ({
  417. value: item.id,
  418. label: item.name,
  419. leaf: level >= 3,
  420. children: []
  421. }))
  422. resolve(nodes)
  423. }
  424. })
  425. }
  426. },
  427. //弹出框中的表单设置 end ------------------------------------------------------------>
  428. }
  429. },
  430. methods: {
  431. onInputClear() {
  432. this.isExpandAll = false;
  433. this.getData();
  434. },
  435. //1.列表和分页相关 start ------------------------------------------------------------>
  436. //1.1 开始请求列表信息方法
  437. getData(type) {
  438. if (type == 'search') {
  439. this.getApiData.page = 1
  440. this.isExpandAll = true;
  441. } else {
  442. this.isExpandAll = false;
  443. }
  444. //搜索条件
  445. // if(this.getApiData.department_id.length>0){
  446. // //网系只提交最后一个
  447. // this.getApiData.department_id = this.getApiData.department_id[this.getApiData.department_id.length - 1];
  448. // }
  449. // if(this.getApiData.city_id.length>0){
  450. // //城市id只提交最后一个
  451. // this.getApiData.city_id = this.getApiData.city_id[this.getApiData.city_id.length - 1];
  452. // }
  453. //如果是搜索,重新加载第一页
  454. this.$store.dispatch('pool/getCategoryList', this.getApiData).then(res => {
  455. // console.log("=============:",res.data)
  456. this.tableData = res.data.rows; //��与内容
  457. this.allCount = res.data.total
  458. }).catch(() => {
  459. this.$message({
  460. type: 'warning',
  461. message: '网络错误,请重试!'
  462. });
  463. })
  464. },
  465. //1.2 删除内容
  466. deleteData(id) {
  467. this.$confirm('删除后,该条信息及其绑定关系全部删除,确定吗', '提示', {
  468. confirmButtonText: '确定',
  469. cancelButtonText: '取消',
  470. type: 'warning'
  471. }).then(() => {
  472. console.log("当前删除:" + id)
  473. this.$store.dispatch('pool/delCategory', { id: id }).then(res => {
  474. if (res.code == 200) {
  475. this.$message({
  476. type: 'success',
  477. message: '删除成功!'
  478. });
  479. } else if (res.code == 0) {
  480. this.$message({
  481. type: 'warning',
  482. message: res.message
  483. });
  484. }
  485. this.getData();
  486. }).catch(() => {
  487. this.$message({
  488. type: 'warning',
  489. message: '网络错误,请重试!'
  490. });
  491. })
  492. }).catch(() => {
  493. this.$message({
  494. type: 'warning',
  495. message: '已取消删除'
  496. });
  497. });
  498. },
  499. //1.3 直接跳转
  500. handleSizeChange(val) {
  501. this.getApiData.page = val;
  502. this.getData();
  503. },
  504. //1.4 点击分页
  505. handleCurrentChange(val) {
  506. this.getApiData.page = val;
  507. this.getData();
  508. },
  509. //1.5 重置按钮
  510. clearSearchList() {
  511. this.isExpandAll = false;
  512. this.tableData = [];
  513. this.getApiData.name = "";
  514. // this.getApiData.department_id = [];
  515. // this.getApiData.city_id = [];
  516. this.getApiData.page = 1;
  517. this.getApiData.pageSize = 10;
  518. this.getData();
  519. },
  520. //1.6 获取所有职能
  521. getAllDepartment() {
  522. this.$store.dispatch('cms/getAllDepartment').then(res => {
  523. // console.log(res)
  524. this.allDepartment = res.data;
  525. })
  526. },
  527. //列表和分页相关 end ------------------------------------------------------------>
  528. //2.弹出框设置 start ------------------------------------------------------------>
  529. //2.1 打开弹出框
  530. openWindow() {
  531. //this.clearToServe();
  532. this.windowStatus = true;
  533. },
  534. //2.1.1 添加栏目池
  535. addCategoryList(row) {
  536. this.form.pid_arr = [];
  537. this.show_url = false;
  538. // this.form.is_url = 0;
  539. this.editId = 0;
  540. this.editBtn = false;
  541. this.tags = []
  542. if (row) {
  543. if (row.pid == 0) {
  544. this.form.pid_arr.push(row.id)
  545. } else {
  546. let pidArr = [];
  547. // console.log("fuck:",row.pid_arr);
  548. pidArr = JSON.parse(row.pid_arr)
  549. pidArr.push(row.id)
  550. this.form.pid_arr = pidArr
  551. // console.log('追加id:',this.form.pid_arr)
  552. }
  553. }
  554. // console.log("=========:", this.form.pid_arr)
  555. this.openWindow();
  556. },
  557. //2.2 关闭弹出框
  558. closeWindow() {
  559. this.windowStatus = false;
  560. this.clearToServe(2);
  561. },
  562. //2.3 清理弹出框
  563. clearToServe(type) {
  564. if (type == 1) { //type1 使用了外部链接
  565. // this.form.department_arr_id = [];
  566. // this.form.city_arr_id = [];
  567. this.form.pid_arr = [];
  568. }
  569. if (type == 2) { //type2 全部清理
  570. this.form.name = "";
  571. this.form.is_url = 0;
  572. this.form.web_url = "";
  573. // this.form.department_arr_id = [];
  574. // this.form.city_arr_id = [];
  575. this.form.sort = 0;
  576. this.form.seo_title = "";
  577. this.form.seo_keywords = "";
  578. this.form.seo_description = "";
  579. this.form.pid_arr = [];
  580. //存在验证的时候再清理
  581. if (this.$refs.form && this.$refs.form.fields.some(field => field.validateState === 'error')) {
  582. this.$refs.form.clearValidate();
  583. }
  584. }
  585. },
  586. //弹出框设置 end ------------------------------------------------------------>
  587. //3.添加栏目池 start ------------------------------------------------------------>
  588. ifUrl(value) {
  589. console.log(value)
  590. if (value == true) {
  591. this.form.is_url = 1
  592. } else {
  593. this.form.is_url = 0
  594. }
  595. this.$refs.form.clearValidate();
  596. },
  597. addToServe() {
  598. //先判断是否使用了外链
  599. if (this.show_url == true) {
  600. this.clearToServe(1)
  601. }
  602. //判断有没有添加父级栏目
  603. if (this.form.pid_arr.length == 0) {
  604. this.form.pid_arr = [0];
  605. }
  606. this.$refs.form.validate(valid => {
  607. if (valid) {
  608. this.$store.dispatch('pool/addCategory', this.form).then(res => {
  609. //汇报结果
  610. this.$message({
  611. type: 'success',
  612. message: '已成功添加栏目池!'
  613. });
  614. //清空并退出
  615. this.closeWindow();
  616. this.getData();
  617. }).catch(() => {
  618. this.$message({
  619. type: 'warning',
  620. message: '网络错误,请重试!'
  621. });
  622. })
  623. }
  624. })
  625. },
  626. //添加栏目池 end ------------------------------------------------------------>
  627. //编辑栏目池 start ------------------------------------------------------------>
  628. getDataMain(id) {
  629. //先清空窗口
  630. this.clearToServe(2)
  631. //打开输入窗口
  632. this.openWindow();
  633. //添加修改id
  634. this.editId = id;
  635. //获取网站详情
  636. this.$store.dispatch('pool/getCategoryInfo', { id: id }).then(res => {
  637. //清除错误状态
  638. //this.$refs.form.clearValidate();
  639. // console.log(res)
  640. //回显栏目池名称
  641. this.form.name = res.data.name;
  642. //回显示是否使用外链
  643. if (res.data.is_url == 1) {
  644. this.show_url = true;
  645. } else if (res.data.is_url == 0 || res.data.is_url == null) {
  646. this.show_url = false;
  647. }
  648. // console.log(res.data.is_url)
  649. this.form.is_url = res.data.is_url;
  650. //回显外链
  651. this.form.web_url = res.data.web_url;
  652. //回显行政区划
  653. // this.form.city_arr_id = JSON.parse(res.data.city_arr_id);
  654. // //当cascaderKey的值改变的时候 级联选择器会重置里面的内容
  655. // this.cascaderKey += 1;
  656. // this.loadCascaderPath(this.form.city_arr_id,"xzqh");
  657. //回显父级栏目
  658. this.form.pid_arr = JSON.parse(res.data.pid_arr);
  659. this.parentKey += 1;
  660. // this.loadCascaderPath(this.form.pid_arr,"fjdh");
  661. //回显职能部门
  662. // this.form.department_arr_id = JSON.parse(res.data.department_arr_id);
  663. // this.departmentKey += 1;
  664. // this.loadCascaderPath(this.form.department_arr_id,"znbm");
  665. //回显栏目池标题,描述,关键词
  666. this.form.seo_title = res.data.seo_title;
  667. this.form.seo_keywords = res.data.seo_keywords;
  668. this.tags = res.data.seo_keywords ? res.data.seo_keywords.split(',') : [];
  669. this.form.seo_description = res.data.seo_description;
  670. this.form.type = res.data.type;
  671. //回显排序
  672. this.form.sort = res.data.sort;
  673. })
  674. this.editBtn = true;//显示编辑按钮
  675. },
  676. //回显行政区划
  677. // async loadCascaderPath(path,type) {
  678. // for (let i = 0; i < path.length; i++) {
  679. // const parentId = path[i - 1] || 0; // 获取当前层级的父级ID
  680. // const level = i; // 当前层级的索引
  681. // await this.$store.dispatch('pool/getcityList', { pid: parentId })
  682. // .then((res) => {
  683. // const nodes = res.data.map(item => ({
  684. // value: item.id,
  685. // label: item.name,
  686. // leaf: level >= 3, // 这里假设4层结构,设置叶子节点标记
  687. // }));
  688. // // 将数据传递到 resolve,通知 cascader 这一层的数据加载完毕
  689. // if (level === path.length - 1) {
  690. // if(type=="xzqh"){this.form.city_arr_id = path;}
  691. // if(type=="fjdh"){this.form.pid_arr = path;}
  692. // if(type=="znbm"){this.form.department_arr_id = path;}
  693. // }
  694. // });
  695. // }
  696. // },
  697. //修改表单
  698. editToServe() {
  699. //防止提交[1,1]这种重复的数据
  700. // if (this.form.department_arr_id.length > 1) {
  701. // const lastIndex = this.form.department_arr_id.length - 1;
  702. // if (this.form.department_arr_id[lastIndex] === this.form.department_arr_id[lastIndex - 1]) {
  703. // this.form.department_arr_id.pop(); // Remove the last element if it's the same as the previous one
  704. // }
  705. // }
  706. this.form.id = this.editId;
  707. this.$refs.form.validate(valid => {
  708. if (valid) {
  709. //提交表单
  710. this.$store.dispatch('pool/updateCategory', this.form).then(res => {
  711. //汇报结果
  712. this.$message({
  713. type: 'success',
  714. message: '已成功修改栏目池信息!'
  715. });
  716. //清空并退出
  717. this.closeWindow();
  718. this.getData();
  719. }).catch(() => {
  720. this.$message({
  721. type: 'warning',
  722. message: '网络错误,请重试!'
  723. });
  724. })
  725. }
  726. })
  727. },
  728. //关键词
  729. updateTags(newTags) {
  730. // this.foem.seo_keywords = newTags;
  731. this.tags = newTags;
  732. this.form.seo_keywords = newTags.join(',');
  733. },
  734. isHighlight(row, search) {
  735. if (!search) return false;
  736. const lowerSearch = search.toLowerCase();
  737. return row.name.toLowerCase().includes(lowerSearch);
  738. },
  739. //编辑栏目池 end ------------------------------------------------------------>
  740. },
  741. mounted() {
  742. //1.获得初始数据
  743. this.getData();
  744. //2.获取所有网系
  745. //this.getwebsiteColumn();
  746. //本地转换id为文字
  747. //console.log(getLocationNameById("110000"))
  748. this.getAllDepartment();
  749. }
  750. }
  751. </script>
  752. <style scoped lang="less">
  753. ::v-deep .highlight {
  754. background-color: yellow;
  755. }
  756. //表单微调 start------------------------------------------------------------>*/
  757. ::v-deep .custom-form-item>.el-form-item__label {
  758. line-height: 140px !important;
  759. }
  760. ::v-deep .custom-textarea .el-textarea__inner {
  761. resize: none;
  762. /* 禁止用���拖拽调整大小 */
  763. }
  764. ::v-deep .custom-align-right .el-form-item__label {
  765. text-align: right;
  766. /* 设置标签文字右对齐 */
  767. }
  768. .collector {
  769. margin-left: 0px;
  770. padding-left: 0px;
  771. margin-right: 20px;
  772. width: 76px;
  773. height: 36px;
  774. line-height: 36px;
  775. position: relative;
  776. .collectorIcon {
  777. display: inline-block;
  778. width: 20px;
  779. height: 20px;
  780. background: url("../../assets/advertise/Graph.png");
  781. vertical-align: middle;
  782. margin-right: 6px;
  783. }
  784. .collectorIcon1 {
  785. position: absolute;
  786. top: 12px;
  787. left: 8px;
  788. }
  789. }
  790. .collector {
  791. text-align: center;
  792. border-radius: 8px;
  793. cursor: pointer;
  794. color: #519C66;
  795. background-color: rgba(81, 156, 102, 0.16);
  796. >i {
  797. padding-right: 8px;
  798. }
  799. }
  800. //表单微调 end------------------------------------------------------------>*/</style>