| ¶Ô±ÈÐÂÎļþ | 
|  |  |  | 
|---|
|  |  |  | <script> | 
|---|
|  |  |  | import { memberSync } from '@/api/business/member' | 
|---|
|  |  |  |  | 
|---|
|  |  |  | export default { | 
|---|
|  |  |  | name: 'BaseOpera', | 
|---|
|  |  |  | data () { | 
|---|
|  |  |  | return { | 
|---|
|  |  |  | title: '', | 
|---|
|  |  |  | visible: false, | 
|---|
|  |  |  | isWorking: false, | 
|---|
|  |  |  | // æ¥å£ | 
|---|
|  |  |  | api: null, | 
|---|
|  |  |  | // é
ç½®æ°æ® | 
|---|
|  |  |  | configData: { | 
|---|
|  |  |  | 'field.id': 'id' | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | methods: { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * é
ç½® | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param extParams é
ç½®åæ° | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | config (extParams = {}) { | 
|---|
|  |  |  | if (extParams == null) { | 
|---|
|  |  |  | throw new Error('Parameter can not be null of method \'config\' .') | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (extParams.api == null) { | 
|---|
|  |  |  | throw new Error('Missing config option \'api\'.') | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.api = require('@/api' + extParams.api) | 
|---|
|  |  |  | extParams['field.id'] && (this.configData['field.id'] = extParams['field.id']) | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * æå¼çªå£ | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param title çªå£æ é¢ | 
|---|
|  |  |  | * @param target è¡å¯¹è±¡ï¼ä»
ç¼è¾éè¯¥åæ°ï¼ | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | open (title, target) { | 
|---|
|  |  |  | this.title = title | 
|---|
|  |  |  | this.visible = true | 
|---|
|  |  |  | // æ°å»º | 
|---|
|  |  |  | if (target == null) { | 
|---|
|  |  |  | this.$nextTick(() => { | 
|---|
|  |  |  | this.$refs.form.resetFields() | 
|---|
|  |  |  | this.form[this.configData['field.id']] = null | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // ç¼è¾ | 
|---|
|  |  |  | this.$nextTick(() => { | 
|---|
|  |  |  | for (const key in this.form) { | 
|---|
|  |  |  | this.form[key] = target[key] | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * ç¡®è®¤ï¼ç¹å»ç¡®è®¤æé®å触åï¼ | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | confirm () { | 
|---|
|  |  |  | if (this.form[this.configData['field.id']] == null || this.form[this.configData['field.id']] === '') { | 
|---|
|  |  |  | this.__confirmCreate() | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.__confirmEdit() | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * ç¡®è®¤æ°å»º | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @private | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | __confirmCreate () { | 
|---|
|  |  |  | this.$refs.form.validate((valid) => { | 
|---|
|  |  |  | if (!valid) { | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // è°ç¨æ°å»ºæ¥å£ | 
|---|
|  |  |  | this.isWorking = true | 
|---|
|  |  |  | var that = this | 
|---|
|  |  |  | this.api.create(this.form) | 
|---|
|  |  |  | .then(() => { | 
|---|
|  |  |  | // that.$tip.apiSuccess('æ°å»ºæå') | 
|---|
|  |  |  | that.$dialog.actionConfirmButton('æ¯å¦åç该页é¢ç»§ç»æ°å»ºæ°æ®ï¼', 'æ°å»ºæå','ç»§ç»æ·»å ','å
³éè¿å') | 
|---|
|  |  |  | .then(() => { | 
|---|
|  |  |  | that.$refs.form.resetFields() | 
|---|
|  |  |  | that.form[this.configData['field.id']] = null | 
|---|
|  |  |  | that.$emit('success') | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | .catch(() => { | 
|---|
|  |  |  | that.visible = false | 
|---|
|  |  |  | that.$emit('success') | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | .catch(e => { | 
|---|
|  |  |  | this.$tip.apiFailed(e) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | .finally(() => { | 
|---|
|  |  |  | this.isWorking = false | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * ç¡®è®¤ä¿®æ¹ | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @private | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | __confirmEdit () { | 
|---|
|  |  |  | this.$refs.form.validate((valid) => { | 
|---|
|  |  |  | if (!valid) { | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // è°ç¨æ´æ°æ¥å£ | 
|---|
|  |  |  | this.isWorking = true | 
|---|
|  |  |  | this.api.updateById(this.form) | 
|---|
|  |  |  | .then(() => { | 
|---|
|  |  |  | this.visible = false | 
|---|
|  |  |  | this.$tip.apiSuccess('ä¿®æ¹æå') | 
|---|
|  |  |  | this.$emit('success') | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | .catch(e => { | 
|---|
|  |  |  | this.$tip.apiFailed(e) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | .finally(() => { | 
|---|
|  |  |  | this.isWorking = false | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | </script> | 
|---|