|
@@ -35,13 +35,13 @@
|
|
|
]"
|
|
|
/>
|
|
|
</a-form-item>
|
|
|
- <a-form-item label="文章分类">
|
|
|
+ <a-form-item label="文章分类" v-if="optionType == 'create'">
|
|
|
<!-- 文章分类父类 -->
|
|
|
<a-select
|
|
|
v-decorator="[
|
|
|
'articleParentClass',
|
|
|
{
|
|
|
- rules: [{ required: true, message: '请选择文章分类父类' }],
|
|
|
+ rules: [{ required: optionType == 'create', message: '请选择文章分类父类' }],
|
|
|
},
|
|
|
]"
|
|
|
@change="articleClassParentChange"
|
|
@@ -53,13 +53,13 @@
|
|
|
>
|
|
|
</a-select>
|
|
|
</a-form-item>
|
|
|
- <a-form-item label="文章子类">
|
|
|
+ <a-form-item label="文章子类" v-if="optionType == 'create'">
|
|
|
<!-- 文章分类子类 -->
|
|
|
<a-select
|
|
|
v-decorator="[
|
|
|
'articleChildClass',
|
|
|
{
|
|
|
- rules: [{ required: true, message: '请选择文章分类子类' }],
|
|
|
+ rules: [{ required: optionType == 'create', message: '请选择文章分类子类' }],
|
|
|
},
|
|
|
]"
|
|
|
:disabled="!articleParentClass || !articleParentClass.id"
|
|
@@ -152,6 +152,7 @@ export default {
|
|
|
articleChildClass: {},
|
|
|
engineerType: '',
|
|
|
learnDate: '',
|
|
|
+ optionType:''
|
|
|
};
|
|
|
},
|
|
|
created() {
|
|
@@ -163,9 +164,18 @@ export default {
|
|
|
computed: {},
|
|
|
methods: {
|
|
|
//初始化数据
|
|
|
- initDataFun() {
|
|
|
- this.getArticleParentClass();
|
|
|
- this.getEngineersWork();
|
|
|
+ async initDataFun() {
|
|
|
+ await this.getArticleParentClass();
|
|
|
+ await this.getEngineersWork();
|
|
|
+ let type = this.$route.query.type;
|
|
|
+ this.optionType = type;
|
|
|
+ // 判断是新增文章还是编辑文章
|
|
|
+ if('edit' === type) {
|
|
|
+ console.log("---edit---");
|
|
|
+ await this.getArticleContent();
|
|
|
+ }else if('create'===type) {
|
|
|
+ console.log("---create---");
|
|
|
+ }
|
|
|
},
|
|
|
// 查询文章分类父级
|
|
|
getArticleParentClass() {
|
|
@@ -204,8 +214,8 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
// 查询工作类别
|
|
|
- getEngineersWork() {
|
|
|
- this.$_http
|
|
|
+ async getEngineersWork() {
|
|
|
+ await this.$_http
|
|
|
.get(this.$_API.INTERFACE_GET_ENGINEERINGWORK_LIST)
|
|
|
.then((res) => {
|
|
|
this.engineerTypeArray = [{ name: '不限', id: '' }, ...res.data];
|
|
@@ -229,8 +239,8 @@ export default {
|
|
|
this.articleChildClass = this.articleChildClassArr[value];
|
|
|
},
|
|
|
// 工种变化
|
|
|
- engineerTypeChange(value) {
|
|
|
- this.engineerType = this.engineerTypeArray[value];
|
|
|
+ engineerTypeChange(index) {
|
|
|
+ this.engineerType = this.engineerTypeArray[index];
|
|
|
},
|
|
|
// 必学日期选择
|
|
|
learnDateChoose(date, dateString) {
|
|
@@ -239,10 +249,64 @@ export default {
|
|
|
handleSubmitBtnFun() {
|
|
|
document.getElementById('articleCreateSubmit').click();
|
|
|
},
|
|
|
+ // 查询文章内容
|
|
|
+ getArticleContent() {
|
|
|
+ let pathParamsData = { materialId: this.$route.query.id };
|
|
|
+ this.$_http
|
|
|
+ .get(
|
|
|
+ formatePathParams(
|
|
|
+ this.$_API.INTERFACE_GET_MATERIALS,
|
|
|
+ pathParamsData
|
|
|
+ )
|
|
|
+ )
|
|
|
+ .then((res) => {
|
|
|
+ console.log("----" + JSON.stringify(res));
|
|
|
+ this.initEditArticleForm(res.data);
|
|
|
+ this.loading = false;
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ this.loading = false;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ initEditArticleForm(item){
|
|
|
+ console.log('--------'+JSON.stringify(item));
|
|
|
+ // 文章标题
|
|
|
+ this.form.setFieldsValue({
|
|
|
+ name: item.name,
|
|
|
+ });
|
|
|
+ // 文章描述
|
|
|
+ let description = item.description==null?"":item.description
|
|
|
+ this.form.setFieldsValue({
|
|
|
+ description: description,
|
|
|
+ });
|
|
|
+ // 选中工种
|
|
|
+ if(item.engineerTypes.length !== 0){
|
|
|
+ let engineerId = item.engineerTypes[0];
|
|
|
+ for(let i = 0;i<this.engineerTypeArray.length;i++){
|
|
|
+ let element = this.engineerTypeArray[i];
|
|
|
+ if(element.id === engineerId){
|
|
|
+ this.engineerTypeChange(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let learnDate = item.tags.length===0?"":item.tags[0];
|
|
|
+ // 必学日期
|
|
|
+ this.learnDateChoose(null,learnDate );
|
|
|
+ // 文章内容
|
|
|
+ this.content = item.contents;
|
|
|
+ },
|
|
|
// 提交表单
|
|
|
handleSubmit(e) {
|
|
|
e.preventDefault();
|
|
|
-
|
|
|
+ if('create'===this.optionType){
|
|
|
+ console.log("创建文章");
|
|
|
+ this.createArtical();
|
|
|
+ }else if('edit'===this.optionType){
|
|
|
+ console.log("更新文章");
|
|
|
+ this.updateArtical();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ createArtical(){
|
|
|
this.form.setFieldsValue({
|
|
|
articleParentClass: this.articleParentClass.name,
|
|
|
});
|
|
@@ -252,7 +316,6 @@ export default {
|
|
|
this.form.setFieldsValue({
|
|
|
engineerType: this.engineerType.name,
|
|
|
});
|
|
|
-
|
|
|
this.form.validateFields((err, values) => {
|
|
|
if (!err) {
|
|
|
// 新建文章
|
|
@@ -287,6 +350,43 @@ export default {
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
+ updateArtical(){
|
|
|
+ let pathParamsData = { materialId: this.$route.query.id };
|
|
|
+ this.form.validateFields((err, values) => {
|
|
|
+ if (!err) {
|
|
|
+ // 更新文章
|
|
|
+ let that = this;
|
|
|
+ that.$confirm({
|
|
|
+ title: '更新文章',
|
|
|
+ content: `确认更新文章吗?`,
|
|
|
+ okText: '确认',
|
|
|
+ cancelText: '取消',
|
|
|
+ onOk() {
|
|
|
+ that.loading = true;
|
|
|
+ let params = { categoryid: that.articleChildClass.id };
|
|
|
+ let bodyParams = {
|
|
|
+ id: that.$route.query.id,
|
|
|
+ name: values.name,
|
|
|
+ description: values.description,
|
|
|
+ type: 'ARTICLE',
|
|
|
+ contents: that.content,
|
|
|
+ tages: [that.learnDate],
|
|
|
+ engineerTypes: [that.engineerType.id],
|
|
|
+ links: [],
|
|
|
+ };
|
|
|
+ that.$_http
|
|
|
+ .put(formatePathParams(that.$_API.INTERFACE_PUT_ADMIN_MATERIALS,pathParamsData), bodyParams, {
|
|
|
+ params,
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ that.$message.success('更新文章成功');
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onCancel() {},
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
// 预览
|
|
|
preview() {
|
|
|
this.previewVisible = true;
|