|
@@ -1,13 +1,201 @@
|
|
|
<template>
|
|
|
- <div class="">这里是新建第三方文章</div>
|
|
|
+ <div class="app-container">
|
|
|
+ <div class="common-card basic-information-box">
|
|
|
+ <div class="basic-information-title">基本信息</div>
|
|
|
+ <div class="basic-information-form">
|
|
|
+ <a-form
|
|
|
+ :form="form"
|
|
|
+ :label-col="{ span: 6 }"
|
|
|
+ :wrapper-col="{ span: 18 }"
|
|
|
+ style="width: 515px"
|
|
|
+ @submit="handleSubmit"
|
|
|
+ >
|
|
|
+ <a-form-item label="文章标题">
|
|
|
+ <a-input
|
|
|
+ placeholder="请输入文章标题"
|
|
|
+ :maxLength="100"
|
|
|
+ v-decorator="[
|
|
|
+ 'name',
|
|
|
+ {
|
|
|
+ rules: [{ required: true, message: '请输入文章标题' }],
|
|
|
+ },
|
|
|
+ ]"
|
|
|
+ />
|
|
|
+ </a-form-item>
|
|
|
+ <!-- <a-form-item label="文章描述">
|
|
|
+ <a-textarea
|
|
|
+ placeholder="请输入文章描述"
|
|
|
+ :auto-size="{ minRows: 3, maxRows: 5 }"
|
|
|
+ :maxLength="100"
|
|
|
+ v-decorator="[
|
|
|
+ 'description',
|
|
|
+ {
|
|
|
+ rules: [{ message: '请输入文章描述' }],
|
|
|
+ initialValue: description,
|
|
|
+ },
|
|
|
+ ]"
|
|
|
+ />
|
|
|
+ </a-form-item> -->
|
|
|
+ <a-form-item label="文章分类">
|
|
|
+ <!-- 文章分类父类 -->
|
|
|
+ <a-select
|
|
|
+ v-decorator="[
|
|
|
+ 'articleParentClass',
|
|
|
+ {
|
|
|
+ rules: [
|
|
|
+ {
|
|
|
+ required: optionType == 'create',
|
|
|
+ message: '请选择文章分类父类',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ initialValue: articleParentClass.name,
|
|
|
+ },
|
|
|
+ ]"
|
|
|
+ @change="articleClassParentChange"
|
|
|
+ >
|
|
|
+ <a-select-option
|
|
|
+ v-for="(item, index) in articleParentClassArr"
|
|
|
+ :key="index"
|
|
|
+ >{{ articleParentClassArr[index].name }}</a-select-option
|
|
|
+ >
|
|
|
+ </a-select>
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item label="文章子类">
|
|
|
+ <!-- 文章分类子类 -->
|
|
|
+ <a-select
|
|
|
+ v-decorator="[
|
|
|
+ 'articleChildClass',
|
|
|
+ {
|
|
|
+ rules: [
|
|
|
+ {
|
|
|
+ required: optionType == 'create',
|
|
|
+ message: '请选择文章分类子类',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ initialValue: articleChildClass.name,
|
|
|
+ },
|
|
|
+ ]"
|
|
|
+ :disabled="!articleChildClass || !articleChildClass.id"
|
|
|
+ @change="articleClassChildChange"
|
|
|
+ >
|
|
|
+ <a-select-option
|
|
|
+ v-for="(item, index) in articleChildClassArr"
|
|
|
+ :key="index"
|
|
|
+ >{{ articleChildClassArr[index].name }}</a-select-option
|
|
|
+ >
|
|
|
+ </a-select>
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item label="工种类别">
|
|
|
+ <a-select
|
|
|
+ v-decorator="[
|
|
|
+ 'engineerType',
|
|
|
+ {
|
|
|
+ rules: [{ required: true, message: '请选择工种' }],
|
|
|
+ initialValue: engineerType.name,
|
|
|
+ },
|
|
|
+ ]"
|
|
|
+ @change="engineerTypeChange"
|
|
|
+ >
|
|
|
+ <a-select-option
|
|
|
+ v-for="(item, index) in engineerTypeArray"
|
|
|
+ :key="index"
|
|
|
+ >{{ engineerTypeArray[index].name }}</a-select-option
|
|
|
+ >
|
|
|
+ </a-select>
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item label="必学日期:">
|
|
|
+ <a-date-picker
|
|
|
+ placeholder="请选择日期"
|
|
|
+ @change="learnDateChoose"
|
|
|
+ v-decorator="[
|
|
|
+ 'learnDate',
|
|
|
+ {
|
|
|
+ initialValue: learnDate,
|
|
|
+ },
|
|
|
+ ]"
|
|
|
+ style="width: 100%"
|
|
|
+ />
|
|
|
+ </a-form-item>
|
|
|
+
|
|
|
+ <a-form-item label="文章链接">
|
|
|
+ <a-textarea
|
|
|
+ placeholder="请输入文章链接"
|
|
|
+ :auto-size="{ minRows: 3, maxRows: 5 }"
|
|
|
+ :maxLength="1000"
|
|
|
+ v-decorator="[
|
|
|
+ 'articleLink',
|
|
|
+ {
|
|
|
+ rules: [{ required: true, message: '请输入文章链接' }],
|
|
|
+ initialValue: articleLink,
|
|
|
+ },
|
|
|
+ ]"
|
|
|
+ />
|
|
|
+ <!-- <a-input
|
|
|
+ placeholder="请输入文章链接"
|
|
|
+ :maxLength="1000"
|
|
|
+ v-decorator="[
|
|
|
+ 'articleLink',
|
|
|
+ {
|
|
|
+ rules: [{ required: true, message: '请输入文章链接' }],
|
|
|
+ initialValue: articleLink,
|
|
|
+ },
|
|
|
+ ]"
|
|
|
+ /> -->
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item label="推荐:">
|
|
|
+ <a-radio-group
|
|
|
+ @change="recommendChange"
|
|
|
+ v-decorator="[
|
|
|
+ 'recommand',
|
|
|
+ {
|
|
|
+ initialValue: recommand,
|
|
|
+ },
|
|
|
+ ]"
|
|
|
+ >
|
|
|
+ <a-radio value="true"> 是 </a-radio>
|
|
|
+ <a-radio value="false"> 否 </a-radio>
|
|
|
+ </a-radio-group>
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item :wrapper-col="{ span: 20, offset: 10 }">
|
|
|
+ <a-button
|
|
|
+ id="articleCreateThirdSubmit"
|
|
|
+ type="primary"
|
|
|
+ html-type="submit"
|
|
|
+ >提交</a-button
|
|
|
+ >
|
|
|
+ </a-form-item>
|
|
|
+ </a-form>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import {
|
|
|
+ formatePathParams,
|
|
|
+ formateStringDate,
|
|
|
+ formateDateToString,
|
|
|
+} from '@/filters';
|
|
|
export default {
|
|
|
+ name: 'articleCreateThird',
|
|
|
props: {},
|
|
|
components: {},
|
|
|
data() {
|
|
|
- return {};
|
|
|
+ return {
|
|
|
+ form: this.$form.createForm(this, { name: 'articleCreateThird' }),
|
|
|
+ articleParentClassArr: [],
|
|
|
+ articleChildClassArr: [],
|
|
|
+ engineerTypeArray: [],
|
|
|
+ articleParentClass: {},
|
|
|
+ articleChildClass: {},
|
|
|
+ engineerType: '',
|
|
|
+ learnDate: '',
|
|
|
+ recommand: 'false',
|
|
|
+ optionType: '',
|
|
|
+ description: '',
|
|
|
+ defaultFileList: [],
|
|
|
+ articleLink: '',
|
|
|
+ };
|
|
|
},
|
|
|
created() {
|
|
|
this.initDataFun(); // 初始化数据
|
|
@@ -18,11 +206,276 @@ export default {
|
|
|
watch: {},
|
|
|
methods: {
|
|
|
// 初始化数据
|
|
|
- initDataFun() {},
|
|
|
+ async initDataFun() {
|
|
|
+ await this.getArticleParentClass();
|
|
|
+ await this.getEngineersWork();
|
|
|
+ let type = this.$route.query.type;
|
|
|
+ this.optionType = type ? type : 'create';
|
|
|
+ // 判断是新增文章还是编辑文章
|
|
|
+ if ('edit' === type) {
|
|
|
+ console.log('---edit---');
|
|
|
+ await this.getArticleContent();
|
|
|
+ } else if ('create' === type) {
|
|
|
+ console.log('---create---');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 查询文章分类父级
|
|
|
+ getArticleParentClass() {
|
|
|
+ this.$_http
|
|
|
+ .get(this.$_API.INTERFACE_GET_CATEGORIES)
|
|
|
+ .then((res) => {
|
|
|
+ this.articleParentClassArr = res.data;
|
|
|
+ this.loading = false;
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ this.loading = false;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 查询文章分类子集
|
|
|
+ getArticleChildClass() {
|
|
|
+ if (!this.articleParentClass.id) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let pathParamsData = { categoryId: this.articleParentClass.id };
|
|
|
+ this.$_http
|
|
|
+ .get(
|
|
|
+ formatePathParams(
|
|
|
+ this.$_API.INTERFACE_GET_CATEGORIES_CATEGROYID,
|
|
|
+ pathParamsData
|
|
|
+ )
|
|
|
+ )
|
|
|
+ .then((res) => {
|
|
|
+ if (res && res.data.length !== 0) {
|
|
|
+ this.articleChildClassArr = res.data;
|
|
|
+ this.articleChildClass = this.articleChildClassArr[0];
|
|
|
+ this.form.setFieldsValue({
|
|
|
+ articleChildClass: this.articleChildClass.name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ this.loading = false;
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ this.loading = false;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 查询工作类别
|
|
|
+ async getEngineersWork() {
|
|
|
+ await this.$_http
|
|
|
+ .get(this.$_API.INTERFACE_GET_ENGINEERINGWORK_LIST)
|
|
|
+ .then((res) => {
|
|
|
+ this.engineerTypeArray = [...res.data];
|
|
|
+ this.engineerType = this.engineerTypeArray[0];
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 文章分类父类变化
|
|
|
+ articleClassParentChange(value) {
|
|
|
+ this.articleParentClass = this.articleParentClassArr[value];
|
|
|
+ // 子类选项清空
|
|
|
+ this.articleChildClassArr = [];
|
|
|
+ this.form.setFieldsValue({
|
|
|
+ articleChildClass: '',
|
|
|
+ });
|
|
|
+ // 获取子类的值
|
|
|
+ this.getArticleChildClass();
|
|
|
+ },
|
|
|
+ // 文章分类子类变化
|
|
|
+ articleClassChildChange(value) {
|
|
|
+ this.articleChildClass = this.articleChildClassArr[value];
|
|
|
+ },
|
|
|
+ // 工种变化
|
|
|
+ engineerTypeChange(index) {
|
|
|
+ this.engineerType = this.engineerTypeArray[index];
|
|
|
+ },
|
|
|
+ // 必学日期选择
|
|
|
+ learnDateChoose(date, dateString) {
|
|
|
+ this.learnDate = dateString;
|
|
|
+ },
|
|
|
+ // 推荐选择
|
|
|
+ recommendChange(date) {
|
|
|
+ this.recommand = date.target.value;
|
|
|
+ console.log('------' + this.recommand);
|
|
|
+ },
|
|
|
+ // 查询文章内容
|
|
|
+ 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,
|
|
|
+ });
|
|
|
+ // 文章描述
|
|
|
+ this.description = item.description ? item.description : '';
|
|
|
+ // 文章分类-父类:
|
|
|
+ this.articleParentClass = item.rootMaterialCategory;
|
|
|
+ this.getArticleChildClass(); // 获取子类列表的值
|
|
|
+ // 文章分类-子类
|
|
|
+ this.articleChildClass = item.materialCategory;
|
|
|
+ // 选中工种
|
|
|
+ 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] : null;
|
|
|
+ // 必学日期
|
|
|
+ this.learnDate = learnDate ? formateStringDate(learnDate) : null;
|
|
|
+ // 第三方链接
|
|
|
+ this.articleLink = item.contents;
|
|
|
+ console.log('编辑初始化时间为YYYY-MM-DD', this.learnDate, learnDate);
|
|
|
+ this.recommand = item.recommand + '';
|
|
|
+ console.log('--推荐--' + item.recommand);
|
|
|
+ // 附件内容
|
|
|
+ item.links.forEach((element) => {
|
|
|
+ let upFile = {
|
|
|
+ uid: this.getUid(),
|
|
|
+ name: this.getUrlName(element),
|
|
|
+ status: 'done',
|
|
|
+ url: element,
|
|
|
+ };
|
|
|
+ this.defaultFileList.push(upFile);
|
|
|
+ });
|
|
|
+ console.log(this.defaultFileList);
|
|
|
+ },
|
|
|
+ // 提交表单
|
|
|
+ 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,
|
|
|
+ });
|
|
|
+ this.form.setFieldsValue({
|
|
|
+ articleChildClass: this.articleChildClass.name,
|
|
|
+ });
|
|
|
+ this.form.setFieldsValue({
|
|
|
+ engineerType: this.engineerType.name,
|
|
|
+ });
|
|
|
+ this.form.setFieldsValue({
|
|
|
+ recommand: this.recommand,
|
|
|
+ });
|
|
|
+ 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,
|
|
|
+ engineertypeid: that.engineerType.id,
|
|
|
+ };
|
|
|
+ let tag = formateDateToString(that.learnDate);
|
|
|
+ let bodyParams = {
|
|
|
+ name: values.name,
|
|
|
+ description: values.description,
|
|
|
+ type: 'THIRD_PARTY',
|
|
|
+ tags: tag ? [tag] : [],
|
|
|
+ engineerTypes: [that.engineerType.id],
|
|
|
+ contents: values.articleLink,
|
|
|
+ recommand: eval(that.recommand.toLowerCase()),
|
|
|
+ };
|
|
|
+ that.$_http
|
|
|
+ .post(that.$_API.INTERFACE_POST_ADMIN_MATERIALS, bodyParams, {
|
|
|
+ params,
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ that.$message.success('新建第三方文章成功');
|
|
|
+ that.$router.push({ path: 'list' });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onCancel() {},
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ 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,
|
|
|
+ engineertypeid: that.engineerType.id,
|
|
|
+ };
|
|
|
+ let tag = formateDateToString(that.learnDate);
|
|
|
+ let bodyParams = {
|
|
|
+ id: that.$route.query.id,
|
|
|
+ name: values.name,
|
|
|
+ description: values.description,
|
|
|
+ type: 'THIRD_PARTY',
|
|
|
+ tags: tag ? [tag] : [],
|
|
|
+ engineerTypes: [that.engineerType.id],
|
|
|
+ contents: values.articleLink,
|
|
|
+ recommand: eval(that.recommand.toLowerCase()),
|
|
|
+ };
|
|
|
+ console.log(
|
|
|
+ '保存修改日期格式为YYYYMMDD',
|
|
|
+ bodyParams.tags,
|
|
|
+ that.learnDate
|
|
|
+ );
|
|
|
+ that.$_http
|
|
|
+ .put(
|
|
|
+ formatePathParams(
|
|
|
+ that.$_API.INTERFACE_PUT_ADMIN_MATERIALS,
|
|
|
+ pathParamsData
|
|
|
+ ),
|
|
|
+ bodyParams,
|
|
|
+ {
|
|
|
+ params,
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .then(() => {
|
|
|
+ that.$message.success('更新第三方文章成功');
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onCancel() {},
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
},
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<style lang="less"></style>
|
|
|
|
|
|
-<style lang="less" scoped></style>
|
|
|
+<style lang="less" scoped>
|
|
|
+@import '~@/styles/common/variable.less';
|
|
|
+</style>
|