index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. <template>
  2. <zj-tab-page ref="tabPage" :defaultActives="[{ key: 'list', label: $route.meta.title+'-列表', essential: true }]">
  3. <template slot-scope="{activeKey, data}">
  4. <div :style="{
  5. width: '100%',
  6. height: activeKey == 'list' ? '100%' : '0px',
  7. overflow: 'hidden'
  8. }">
  9. <template-page ref="pageRef" :get-list="getList" :table-attributes="tableAttributes" :table-events="tableEvents"
  10. :operationColumnWidth="200" :options-evens-group="optionsEvensGroup" :moreParameters="moreParameters"
  11. :column-parsing="columnParsing" :operation="operation" :exportList="exportList">
  12. <div slot="moreSearch">
  13. <el-radio-group v-model="status" size="mini" @change="changeType">
  14. <el-radio-button label="">全部</el-radio-button>
  15. <el-radio-button label="NO">未发布</el-radio-button>
  16. <el-radio-button label="YES">已发布</el-radio-button>
  17. </el-radio-group>
  18. <br><br>
  19. </div>
  20. </template-page>
  21. </div>
  22. <div v-if="~['add', 'edit'].indexOf(activeKey)" style="box-sizing: border-box;padding: 16px;">
  23. <zj-form-container ref="formRef" :form-data="formData" :styleSwitch="false">
  24. <zj-form-module :title="data.label" label-width="100px" :showPackUp="false" :form-data="formData"
  25. :form-items="formItems">
  26. </zj-form-module>
  27. </zj-form-container>
  28. <div slot="footer" class="dialog-footer">
  29. <el-button size="mini" @click="data.removeTab()">取 消</el-button>
  30. <el-button v-if="formDialogType < 2" size="mini" type="primary"
  31. @click="formConfirm('NO', data.removeTab)">保存</el-button>
  32. <el-button v-if="formDialogType < 2" size="mini" type="primary"
  33. @click="formConfirm('YES', data.removeTab)">发布</el-button>
  34. </div>
  35. </div>
  36. <div v-if="~['detail'].indexOf(activeKey)" style="box-sizing: border-box;padding: 16px;">
  37. <zj-form-container ref="formRef" :form-data="formData" :styleSwitch="false">
  38. <zj-form-module :title="data.label" label-width="100px" :showPackUp="false" :form-data="formData"
  39. :form-items="formItems2">
  40. </zj-form-module>
  41. </zj-form-container>
  42. <div slot="footer" class="dialog-footer">
  43. <el-button size="mini" @click="data.removeTab()">取 消</el-button>
  44. </div>
  45. </div>
  46. </template>
  47. </zj-tab-page>
  48. </template>
  49. <script>
  50. import TemplatePage from '@/components/template/template-page-1.vue'
  51. import import_mixin from '@/components/template/import_mixin.js'
  52. import ImageUpload from '@/components/file-upload'
  53. import { required, mobileRequired, mobile } from '@/components/template/rules_verify.js'
  54. import { noticeListPageV2, noticePageExport, getNoticeDetail, noticeAdd, noticeUpdate, noticeDel } from "@/api/announcement";
  55. import { memberListPageV2 } from "@/api/masterManagement";
  56. import { getMemberList } from "@/api/member";
  57. import { getList as getListaa } from "@/api/merchant";
  58. export default {
  59. components: { TemplatePage, ImageUpload },
  60. mixins: [import_mixin],
  61. data() {
  62. return {
  63. // 事件组合
  64. optionsEvensGroup: [
  65. [
  66. [
  67. {
  68. name: '新建',
  69. click: this.addData
  70. }
  71. ],
  72. ],
  73. ],
  74. // 表格属性
  75. tableAttributes: {
  76. // 启用勾选列
  77. selectColumn: false
  78. },
  79. // 表格事件
  80. tableEvents: {
  81. 'selection-change': this.selectionChange
  82. },
  83. // 勾选选中行
  84. recordSelected: [],
  85. /** 表单变量 */
  86. formDialogType: 0,
  87. formData: {
  88. type: "A",
  89. title: "",
  90. files: [],
  91. adminWebsitIds: [],
  92. adminNickName: "",
  93. workerIds: [],
  94. content: "",
  95. },
  96. status: '',
  97. websitList: [],
  98. workerList: []
  99. }
  100. },
  101. computed: {
  102. // 更多参数
  103. moreParameters() {
  104. return []
  105. },
  106. formItems() {
  107. return [{
  108. md: 24,
  109. isShow: true,
  110. name: 'el-radio',
  111. options: [
  112. {
  113. label: `活动`,
  114. value: "A"
  115. },
  116. {
  117. label: `公告`,
  118. value: "B"
  119. }],
  120. attributes: { filterable: true, placeholder: '请选择', disabled: this.formDialogType == 2 },
  121. formItemAttributes: {
  122. label: '类型',
  123. prop: 'type',
  124. rules: [...required]
  125. },
  126. },
  127. {
  128. md: 24,
  129. isShow: true,
  130. name: 'el-input',
  131. attributes: { placeholder: '请输入', disabled: this.formDialogType == 2 },
  132. formItemAttributes: {
  133. label: '标题',
  134. prop: 'title',
  135. rules: [...required]
  136. }
  137. },
  138. {
  139. md: 24,
  140. isShow: this.formDialogType < 2 && JSON.parse(localStorage.getItem("greemall_user")).type == 2,
  141. name: 'zj-paging-pull-down',
  142. options: this.websitList,
  143. attributes: {
  144. valueKey: "adminUserId",
  145. labelKey: "companyName",
  146. size: 'mini',
  147. placeholder: '请选择',
  148. multiple: true
  149. },
  150. formItemAttributes: {
  151. label: '选择商户',
  152. prop: 'adminWebsitIds',
  153. rules: [...required]
  154. }
  155. },
  156. {
  157. md: 24,
  158. isShow: this.formDialogType < 2 && JSON.parse(localStorage.getItem("greemall_user")).type != 2,
  159. name: 'zj-paging-pull-down',
  160. options: this.workerList,
  161. attributes: {
  162. valueKey: "userId",
  163. labelKey: "nickName",
  164. size: 'mini',
  165. placeholder: '请选择',
  166. multiple: true
  167. },
  168. formItemAttributes: {
  169. label: '选择师傅',
  170. prop: 'workerIds',
  171. rules: [...required]
  172. }
  173. },
  174. {
  175. md: 24,
  176. isShow: true,
  177. name: 'slot-component',
  178. formItemAttributes: {
  179. label: '附件',
  180. prop: 'files',
  181. rules: this.formData.type == "A" ? [...required] : []
  182. },
  183. render: (h, { props, onInput }) => {
  184. var { value } = props
  185. return (
  186. <ImageUpload fileList={this.formData.files} uid="idcardUpUrl_drawing_aiuh" limit={100} isEdit={this.formDialogType !== 2} />
  187. )
  188. }
  189. },
  190. {
  191. md: 24,
  192. isShow: true,
  193. name: 'slot-component',
  194. formItemAttributes: {
  195. label: '内容',
  196. prop: 'content',
  197. rules: [...required]
  198. },
  199. render: (h, { props, onInput }) => {
  200. var { value } = props
  201. return (
  202. <v-quill-editor value={value} onInput={onInput} disabled={this.formDialogType == 2} />
  203. )
  204. }
  205. }]
  206. },
  207. formItems2() {
  208. return [{
  209. md: 24,
  210. isShow: true,
  211. name: 'slot-component',
  212. formItemAttributes: {
  213. prop: 'type',
  214. label: '',
  215. 'label-width': "0px"
  216. },
  217. render: (h, { props, onInput }) => {
  218. var { value } = props
  219. return <div>类型:{({ A: "活动", B: "公告" })[value]}</div>
  220. }
  221. },
  222. {
  223. md: 24,
  224. isShow: true,
  225. name: 'slot-component',
  226. attributes: { placeholder: '请输入', disabled: true },
  227. formItemAttributes: {
  228. prop: 'title',
  229. label: '',
  230. 'label-width': "0px"
  231. },
  232. render: (h, { props, onInput }) => {
  233. var { value } = props
  234. return <div>标题:{value}</div>
  235. }
  236. },
  237. {
  238. md: 24,
  239. isShow: true,
  240. name: 'slot-component',
  241. formItemAttributes: {
  242. prop: 'content',
  243. label: '',
  244. 'label-width': "0px"
  245. },
  246. render: (h, { props, onInput }) => {
  247. var { value } = props
  248. return <div domPropsInnerHTML={value}></div>
  249. }
  250. },
  251. {
  252. md: 24,
  253. isShow: true,
  254. name: 'slot-component',
  255. formItemAttributes: {
  256. prop: 'files',
  257. label: '',
  258. 'label-width': "0px"
  259. },
  260. render: (h, { props, onInput }) => {
  261. var { value } = props
  262. return (
  263. <ImageUpload fileList={this.formData.files} uid="idcardUpUrl_drawing_aiuh888" limit={100} isEdit={false} />
  264. )
  265. }
  266. },
  267. {
  268. md: 24,
  269. isShow: JSON.parse(localStorage.getItem("greemall_user")).type == 2,
  270. name: 'slot-component',
  271. formItemAttributes: {
  272. prop: 'adminWebsitIds',
  273. label: '',
  274. 'label-width': "0px"
  275. },
  276. render: (h, { props, onInput }) => {
  277. var { value } = props
  278. return <div>{this.websitList.filter(item => !!~value.indexOf(item.adminUserId)).map(item => <el-tag style="margin-right:5px">{item.companyName}</el-tag>)}</div>
  279. },
  280. },
  281. {
  282. md: 24,
  283. isShow: JSON.parse(localStorage.getItem("greemall_user")).type != 2,
  284. name: 'slot-component',
  285. options: this.workerList,
  286. formItemAttributes: {
  287. prop: 'workerIds',
  288. label: '',
  289. 'label-width': "0px"
  290. },
  291. render: (h, { props, onInput }) => {
  292. var { value } = props
  293. return <div>{this.workerList.filter(item => !!~value.indexOf(item.userId)).map(item => <el-tag style="margin-right:5px">{item.nickName}</el-tag>)}</div>
  294. },
  295. }]
  296. }
  297. },
  298. created() {
  299. if (this.$route.query.id) {
  300. this.getNoticeDetail(this.$route.query.id, 2, 'formDialog2')
  301. }
  302. },
  303. methods: {
  304. // 切换状态
  305. changeType(val) {
  306. this.$refs.pageRef.refreshList()
  307. },
  308. // 列表请求函数
  309. getList(p) {
  310. try {
  311. var pam = JSON.parse(JSON.stringify(p))
  312. if (this.status) {
  313. pam.params.push({ "param": "nr.status", "compare": "=", "value": this.status })
  314. }
  315. return noticeListPageV2(pam)
  316. } catch (error) {
  317. console.log(error)
  318. }
  319. },
  320. // 列表导出函数
  321. exportList: noticePageExport,
  322. // 表格列解析渲染数据更改
  323. columnParsing(item, defaultData) {
  324. return defaultData
  325. },
  326. // 监听勾选变化
  327. selectionChange(data) {
  328. this.recordSelected = data
  329. },
  330. getNoticeDetail(noticeId, type, name) {
  331. getNoticeDetail({
  332. noticeId
  333. }).then(res => {
  334. Object.assign(this.formData, res.data, {
  335. files: res.data.files ? res.data.files.map(item => ({
  336. ...item,
  337. size: item.fileSize,
  338. type: item.fileType,
  339. })) : []
  340. })
  341. this.formDialogType = type
  342. this.openForm(name)
  343. })
  344. },
  345. // 表格操作列
  346. operation(h, { row, index, column }) {
  347. return (<div class='operation-btns'>
  348. {row.status == "NO" ? <el-button type="text" onClick={() => {
  349. this.$refs.tabPage.addTab({
  350. activeKey: "edit",
  351. key: "edit",
  352. label: "编辑",
  353. triggerEvent: () => {
  354. this.formCancel()
  355. this.$nextTick(() => {
  356. getNoticeDetail({
  357. noticeId: row.noticeId
  358. }).then(res => {
  359. Object.assign(this.formData, res.data, {
  360. files: res.data.files ? res.data.files.map(item => ({
  361. ...item,
  362. size: item.fileSize,
  363. type: item.fileType,
  364. })) : []
  365. })
  366. this.formDialogType = 1
  367. this.openForm()
  368. })
  369. })
  370. },
  371. closeEvent: () => {
  372. }
  373. })
  374. }}>编辑</el-button> : null}
  375. <el-button type="text" onClick={() => {
  376. this.$refs.tabPage.addTab({
  377. activeKey: "detail",
  378. key: "detail",
  379. label: "查看",
  380. triggerEvent: () => {
  381. this.formCancel()
  382. this.$nextTick(() => {
  383. getNoticeDetail({
  384. noticeId: row.noticeId
  385. }).then(res => {
  386. Object.assign(this.formData, res.data, {
  387. files: res.data.files ? res.data.files.map(item => ({
  388. ...item,
  389. size: item.fileSize,
  390. type: item.fileType,
  391. })) : []
  392. })
  393. this.formDialogType = 2
  394. this.openForm()
  395. })
  396. })
  397. },
  398. closeEvent: () => {
  399. }
  400. })
  401. }}>查看</el-button>
  402. {row.status == "NO" ? <el-popconfirm
  403. title={`是否确定删除?`}
  404. onConfirm={() => {
  405. noticeDel({
  406. noticeIds: row.noticeId
  407. }).then(res => {
  408. this.$message({
  409. type: 'success',
  410. message: '删除成功!'
  411. })
  412. this.$refs.pageRef.refreshList()
  413. })
  414. }}
  415. >
  416. <el-button type="text" style="color: #ff0000" slot="reference">删除</el-button>
  417. </el-popconfirm> : null}
  418. {row.status == "YES" ? <el-button style="color: #f5680e" type="text" onClick={() => {
  419. this.$router.push({
  420. name: 'readRecords',
  421. query: {
  422. id: row.noticeId
  423. }
  424. })
  425. }}>已读记录</el-button> : null}
  426. </div>)
  427. },
  428. addData() {
  429. this.$refs.tabPage.addTab({
  430. activeKey: "add",
  431. key: "add",
  432. label: "新增",
  433. triggerEvent: () => {
  434. this.formCancel()
  435. this.$nextTick(() => {
  436. this.formDialogType = 0
  437. this.openForm()
  438. })
  439. },
  440. closeEvent: () => {
  441. }
  442. })
  443. },
  444. openForm() {
  445. if (JSON.parse(localStorage.getItem("greemall_user")).type == 2) {
  446. getListaa({ pageNum: 1, pageSize: -1, type: 1 }).then((res) => {
  447. this.websitList = res.data.records
  448. })
  449. } else {
  450. getMemberList({ "pageNum": 1, "pageSize": -1, type: "WORKER" }).then(res => {
  451. this.workerList = res.data.records
  452. })
  453. }
  454. },
  455. formCancel() {
  456. this.$refs?.formRef?.$refs?.inlineForm?.clearValidate()
  457. this.$data.formData = this.$options.data().formData
  458. this.websitList = []
  459. },
  460. formConfirm(status, removeTab) {
  461. this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
  462. if (valid) {
  463. [noticeAdd, noticeUpdate][this.formDialogType]({
  464. ...this.formData,
  465. files: this.formData.files.map(item => ({
  466. ...item,
  467. fileSize: item.size,
  468. fileType: item.type,
  469. })),
  470. status
  471. }).then(res => {
  472. this.$message({
  473. type: 'success',
  474. message: status == "YES" ? '发送成功!' : '保存成功!'
  475. })
  476. removeTab('list')
  477. this.$refs.pageRef.refreshList()
  478. })
  479. }
  480. })
  481. },
  482. }
  483. }
  484. </script>
  485. <style lang="scss" scoped></style>