<template>
	<template-page ref="pageRef" :get-list="getList" :table-attributes="tableAttributes" :table-events="tableEvents" :operationColumnWidth="50"
	  :options-evens-group="optionsEvensGroup" :moreParameters="moreParameters" :column-parsing="columnParsing"
	  :operation="operation">
	   <!-- :exportList="exportList" -->
	</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 { downloadFiles } from '@/utils/util'
import { required, mobileRequired, mobile, httpUrl, email } from '@/components/template/rules_verify.js'
import { listPageV2,pageExport, del, listImport } from "@/api/workerProfileInit";
import { commonTemplateDownload } from '@/api/common.js'
export default {
  components: { TemplatePage, ImageUpload },
  mixins: [import_mixin],
  data() {
    return {
      // 事件组合
      optionsEvensGroup: [
		[
		  [
		    {
		      name: '导入模板',
		      click: this.handleDownload
		    }
		  ],
		  [
		    {
		      name: '导入师傅资料',
		      render: () => {
		        return this.importButton(listImport, '导入师傅资料')
		      }
		    }
		  ],
		]
	  ],
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: true
      },
      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      // 勾选选中行
      recordSelected: [],
      /** 表单变量 */
      formDialogType: 0,
      formDialogTitles: ["新增","编辑", "详情"],
      formDialog: false,
      formData: {},
    }
  },
  computed: {
    // 更多参数
    moreParameters() {
      return []
    },
    formItems() {}
  },
  methods: {
    // 列表请求函数
	getList(p,cb) {
	  try {
	    var pam = JSON.parse(JSON.stringify(p))
	    // if (this.examineStatus) {
	    //   pam.params.push({ "param": "b.examine_status", "compare": "=", "value": this.examineStatus })
	    // }
		cb && cb(pam)
	    return listPageV2(pam)
	  } catch (error) {
	    console.log(error)
	  }
	},
    // 列表导出函数
    exportList: pageExport,
    // 表格列解析渲染数据更改
    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={() => {
		    this.$confirm(`请确认是否删除该数据, 是否继续?`, '提示', {
		    	confirmButtonText: '确定',
		    	cancelButtonText: '取消',
		    	type: 'warning'
		    }).then(() => {
		    	del({
		    		id: row.id
		    	}).then(res => {
		    		if (res.code == 200) {
		    			this.$message({ type: 'success', message: `删除成功!` })
		    			this.$refs.pageRef.refreshList()
		    		} else {
		    			this.$message.error(res.msg);
		    		}
		    	})
		    });
		  }}>删除</el-button>
        </div>
      )
    },
    addData() {
      this.formDialogType = 0
      this.openForm()
    },
    openForm() {
      this.formDialog = true;
    },
    formCancel() {
      this.$refs.formRef.$refs.inlineForm.clearValidate()
      this.$data.formData = this.$options.data().formData
      this.formDialog = false
    },
    formConfirm() {
      this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
        if (valid) {
          ([add, edit][this.formDialogType])(this.formData).then(res => {
            this.$message({ type: 'success', message: `${this.formDialogTitles[this.formDialogType]}成功!` })
            this.formCancel()
            this.$refs.pageRef.refreshList()
          })
        }
      })
    },
	handleDownload() {
		commonTemplateDownload({ name: '师傅分销员资料初始化.xlsx' }, `${this.$route.meta.title}`).then(res => {
		    this.$message({
		        message: '下载成功',
		        type: 'success'
		    })
		}).catch(err => {
		    this.$message.error('下载失败')
		})
	},
  }
}
</script>

<style lang="scss" scoped>
	.tab{
		padding: 20px 20px 0 20px;
	}
</style>
