<template>
	<template-page ref="pageRef" :get-list="getList" :table-attributes="tableAttributes" :table-events="tableEvents"
		:operationColumnWidth="200" :options-evens-group="optionsEvensGroup" :moreParameters="moreParameters"
		:column-parsing="columnParsing" :operation="operation" :exportList="exportList">
		<el-dialog title="" width="500px" custom-class="diy-dialog" append-to-body :modal="true" :visible.sync="formDialog2"
			:show-close="true" :close-on-click-modal="false" :modal-append-to-body="false" :before-close="formCancel">
			<zj-form-container ref="formRef" :form-data="formData" :styleSwitch="false">
				<zj-form-module :title="formDialogTitles[formDialogType]" label-width="100px" :showPackUp="false"
					:form-data="formData" :form-items="formItems2">
				</zj-form-module>
			</zj-form-container>
			<div slot="footer" class="dialog-footer">
				<el-button size="mini" @click="formCancel">取 消</el-button>
			</div>
		</el-dialog>
	</template-page>
</template>

<script>
import TemplatePage from '@/components/template/template-page-1.vue'
import import_mixin from '@/components/template/import_mixin.js'
import ImageUpload from '@/components/file-upload'
import { required, mobileRequired, mobile } from '@/components/template/rules_verify.js'
import { noticeListPageV2, noticePageExport, getNoticeDetail, noticeAdd, noticeUpdate, noticeDel } from "@/api/announcement";
import { memberListPageV2 } from "@/api/masterManagement";
import { getList as getListaa } from "@/api/merchant";
export default {
	components: { TemplatePage, ImageUpload },
	mixins: [import_mixin],
	data() {
		return {
			// 事件组合
			optionsEvensGroup: [],
			// 表格属性
			tableAttributes: {
				// 启用勾选列
				selectColumn: false
			},
			// 表格事件
			tableEvents: {
				'selection-change': this.selectionChange
			},
			// 勾选选中行
			recordSelected: [],
			/** 表单变量 */
			formDialogType: 0,
			formDialogTitles: ["新增", "编辑", "详情"],
			formDialog: false,
			formDialog2: false,
			formData: {
				type: "A",
				title: "",
				files: [],
				adminWebsitIds: [],
				workerIds: [],
				content: "",
			},
			status: '',
			websitList: [],
			workerList: []
		}
	},
	computed: {
		// 更多参数
		moreParameters() {
			return []
		},
		formItems2() {
			return [{
				md: 24,
				isShow: true,
				name: 'slot-component',
				formItemAttributes: {
					prop: 'type',
					label: '',
					'label-width': "0px"
				},
				render: (h, { props, onInput }) => {
					var { value } = props
					return <div>类型：{({ A: "活动", B: "公告" })[value]}</div>
				}
			},
			{
				md: 24,
				isShow: true,
				name: 'slot-component',
				attributes: { placeholder: '请输入', disabled: true },
				formItemAttributes: {
					prop: 'title',
					label: '',
					'label-width': "0px"
				},
				render: (h, { props, onInput }) => {
					var { value } = props
					return <div>标题：{value}</div>
				}
			},
			{
				md: 24,
				isShow: true,
				name: 'slot-component',
				formItemAttributes: {
					prop: 'content',
					label: '',
					'label-width': "0px"
				},
				render: (h, { props, onInput }) => {
					var { value } = props
					return <div domPropsInnerHTML={value}></div>
				}
			},
			{
				md: 24,
				isShow: true,
				name: 'slot-component',
				formItemAttributes: {
					prop: 'files',
					label: '',
					'label-width': "0px"
				},
				render: (h, { props, onInput }) => {
					var { value } = props
					return (
						<ImageUpload fileList={this.formData.files} uid="idcardUpUrl_drawing_aiuh888" limit={100} isEdit={false} />
					)
				}
			}]
		}
	},
	methods: {
		// 列表请求函数
		getList:noticeListPageV2,
		// 列表导出函数
		exportList: noticePageExport,
		// 表格列解析渲染数据更改
		columnParsing(item, defaultData) {
			return defaultData
		},
		// 监听勾选变化
		selectionChange(data) {
			this.recordSelected = data
		},
		// 表格操作列
		operation(h, { row, index, column }) {
			return (<div class='operation-btns'>
				<el-button type="text" onClick={() => {
					getNoticeDetail({
						noticeId: row.noticeId
					}).then(res => {
						Object.assign(this.formData, res.data, {
							files: res.data.files ? res.data.files.map(item => ({
								...item,
								size: item.fileSize,
								type: item.fileType,
							})) : []
						})
						this.formDialogType = 2
						this.openForm('formDialog2')
					})
				}}>查看</el-button>
			</div>)
		},
		openForm(key = 'formDialog') {
			if (JSON.parse(localStorage.getItem("greemall_user")).type == 2) {
				getListaa({ pageNum: 1, pageSize: -1, type: 1 }).then((res) => {
					this.websitList = res.data.records
					this[key] = true;
				})
			} else {
				memberListPageV2({ "pageNum": 1, "pageSize": -1, "params": [] }).then(res => {
					this.workerList = res.data.records
					this[key] = true;
				})
			}
		},
		formCancel() {
			this.$refs.formRef.$refs.inlineForm.clearValidate()
			this.$data.formData = this.$options.data().formData
			this.formDialog = false
			this.formDialog2 = false
			this.websitList = []
		},
	}
}
</script>

<style lang="scss" scoped></style>