<template>
  <div style="padding:10px">
    <q-card inline class="fit shadow-6">
      <q-card-main style="height:80%">
        <div class="layout-padding">
          <q-field class="liststype"><q-input v-model="tempAdv.title" float-label="标题" /></q-field>
          <q-field class="liststype"><q-select v-model="tempAdv.type" :options="kindlist" float-label="分类" /></q-field>
          <q-field class="liststype"><q-select v-model="tempAdv.status" :options="yesnokindlist" float-label="启用" /></q-field>
          <q-field class="liststype">
            <!-- <q-input v-model="tempAdv.content" float-label="描述" /> --> <tinymce  :value="tempAdv.content" ref="editFormContent" v-model="tempAdv.content"
                           class="mytextarea my-tinymce5002"></tinymce>
          </q-field>
        </div>

        <div style="float: right;margin: 15px 0;">
          <!--  <q-btn push dense color="primary" icon="add" @click="saveRecipes">提交</q-btn>
          <q-btn push dense color="" @click="cancelFunction">{{ $t('Cancel') }}</q-btn>
 -->
          <q-btn round color="red" round @click="addFunction">{{ $t('Save') }}</q-btn>
          <q-btn  @click="cancelFunction">{{ $t('Cancel') }}</q-btn>
        </div>
      </q-card-main>
    </q-card>
  </div>
</template>

<script>
import { getAdvPagedList, delAdv, updateAdvStatus, saveAdv, editAdv, loadAdv, updateAdvsStatus, getSysAdvListByTypeAndNum, uploadfile } from '@/service/library/syslibrary';
import { getSysCodelistByKindcode } from '@/service/syscodelist/syscodelist';
import tinymce from '../../components/tinymceEditor'
const host= window.location.protocol;
const protocol=window.location.host;
const uploadpath =  host+"//"+protocol+"/uploadfileadmin/manager";
export default {
  components: { tinymce },
  data() {
    return {
      uploadurl: uploadpath + '/znzl/file/upload/videoandimgurl?uploadPar=library&',
      serverData: [],
      menuModal: false,
      tempFunction: {
        id: 0,
        name: '',
        moduleId: 0,
        module: '',
        code: '',
        description: ''
      },
      serverPagination: {
        page: 1,
        rowsNumber: 0, // specifying this determines pagination is server-side
        rowsPerPage: 10 // current rows per page being displayed
      },
      nextserverPagination: {
        page: 1,
        rowsNumber: 0, // specifying this determines pagination is server-side
        rowsPerPage: 100 // current rows per page being displayed
      },
      yesnokindlist: [],
      columns: [
        {
          name: 'title',
          required: true,
          label: '标题',
          align: 'left',
          field: 'title',
          sortable: false
        },
        {
          name: 'statusname',
          label: '启用状态',
          field: 'statusname',
          sortable: false,
          align: 'center'
        },
        {
          name: 'typename',
          label: '分类',
          field: 'typename',
          sortable: false,
          align: 'center'
        },
        {
          name: 'id',
          required: true,
          label: this.$t('ID'),
          align: 'center',
          field: 'id'
        }
      ],
      filter: {
        name: '',
        pid: '',
        type: '',
        status: '',
        content: ''
      },
      selected: [],
      kindlist: [],
      loading: false,
      editModal: false,
      subtype: 'add',
      fileCount: 0,
      tempAdv: {
        id: '',
        title: '',
        status: '',
        statusname: '',
        ctime: '',
        type: '',
        typename: '',
        content: ''
      }
    };
  },
  // validations: {
  //   addForm: {
  //     title: { required },
  //     content: { required },
  //     itemid: { required }
  //   }
  // },
  mounted() {
    this.getCodelistByKindcode();
    this.getYesNoCodelistByKindcode();
    // this.getYesNoCodelistByKindcode();
  },
  methods: {
    async addFunction() {
     if (
       this.tempAdv.title == null ||
       this.tempAdv.type == null ||
       this.tempAdv.title == "" ||
       this.tempAdv.type == ""
     ) {
       this.$q.notify({
         message: "请完善信息，标题和分类不能为空",
         type: "negative",
         icon: "error_outline",
         timeout: 3000,
         position: "center"
       });
       return false;
     }
     let dataRes = await saveAdv(this.tempAdv);
      ;
      if(dataRes.data.code=='200'){
          this.$q.notify({
              type: "positive",
              message: '提交成功',
              position: "bottom-right"
          });
          this.cancelFunction();
      }
    },
    async getCodelistByKindcode() {
      this.kindlist = [];
      let kindlist_code = await getSysCodelistByKindcode('LIBRARY_TYPE');
      if (kindlist_code.data.data.length > 0) {
        for (var item of kindlist_code.data.data) {
          let obj = {
            label: item.codename,
            value: item.codevalue
          };
          this.kindlist.push(obj);
        }
      }
    },
    async getYesNoCodelistByKindcode() {
      this.yesnokindlist = [];
      //  this.yeornoOptions=[];
      let kindlist_code = await getSysCodelistByKindcode('YES_NO');
      if (kindlist_code.data.data.length > 0) {
        for (var item of kindlist_code.data.data) {
          let obj = {
            label: item.codename,
            value: item.codevalue
          };
          this.yesnokindlist.push(obj);
          // this.yeornoOptions.push(obj);
        }
      }
    },
    cancelFunction() {
      this.$router.push('/system/syslibrary');
    }
  },

};
</script>

<style scoped>
/* .q-input {
        width: 230px;
    }
    .q-select{
        width: 230px;
    } */
</style>
