| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- <template>
- <div class="container-fluid">
- <div class="row">
- <div class="btn-group" role="group">
- <button type="button" class="btn btn-default" @click="back">返回</button>
- <button type="button" class="btn btn-success" @click="refresh">刷新</button>
- <button type="button" class="btn btn-primary" @click="saveAttribute">保存</button>
- <button type="button" class="btn btn-info" @click="addAttribute">添加属性</button>
- </div>
- </div>
- <div v-for="attribute in attributes" :key="attribute.name" class="row">
- <div class="form-inline">
- <div class="form-group">
- <label>属性名称</label>
- <input v-model="attribute.name" autocomplete="off" type="text" class="form-control" />
- </div>
- <div class="checkbox">
- <label>
- <input v-model="attribute.isRequired" autocomplete="off" type="checkbox" /> 必填项
- </label>
- </div>
- <div class="checkbox">
- <label>
- <input v-model="attribute.isInput" autocomplete="off" type="checkbox" /> 输入项
- </label>
- </div>
- <div class="checkbox">
- <label>
- <input v-model="attribute.isMutipleSelect" autocomplete="off" type="checkbox" /> 多选
- </label>
- </div>
- <div class="checkbox">
- <label>
- <input v-model="attribute.isNumber" autocomplete="off" type="checkbox" /> 数字
- </label>
- </div>
- <button type="button" class="btn btn-danger" @click="deleteAttribute(attribute)">删除</button>
- <button type="button" class="btn btn-info" @click="addAttributeName(attribute)">添加属性值</button>
- </div>
- <div v-for="attributeName in attribute.attributeNameDtoList" :key="attributeName.id" class="form-inline form-attributeName">
- <div class="form-group">
- <label>属性值</label>
- <input v-if="attribute.isNumber" v-model="attributeName.nameDec" autocomplete="off" type="number" class="form-control" />
- <input v-else v-model="attributeName.nameStr" autocomplete="off" type="text" class="form-control" />
- </div>
- <button type="button" class="btn btn-danger" @click="deleteAttributeName(attribute, attributeName)">删除</button>
- </div>
- </div>
- </div>
- </template>
- <script>
- import Common from '../../common/Common.js';
- import { Notify, Uuid } from 'pc-component-v3';
- export default {
- components: {
-
- },
- props: [],
- data: function() {
- return {
- modelData: {},
- attributeKey: null,
- attributes: [],
- };
- },
- mounted: function() {
- var _self = this;
- var uuid = this.$route.params.uuid;
- var cacheData = localStorage.getItem(uuid);
- if (cacheData != undefined && cacheData.length > 0) {
- cacheData = JSON.parse(cacheData);
- _self.modelData = cacheData.modelData;
- }
- console.log(_self.modelData);
- _self.initData();
- },
- methods: {
- /**
- * 初始化数据
- * @return {void}
- */
- initData: function() {
- var _self = this;
- if (
- _self.modelData.data.attributeKey != undefined &&
- _self.modelData.data.attributeKey.displayValue != undefined
- ) {
- var displayValue =
- _self.modelData.data.attributeKey.displayValue;
- if (displayValue.length > 0) {
- _self.attributeKey = displayValue[0];
- _self.getAttribute();
- }
- }
- },
- /**
- * 获取属性
- * @return {void}
- */
- getAttribute: function() {
- var _self = this;
- $.ajax({
- url: Common.getApiURL('attributeResource/getAttribute'),
- type: 'get',
- dataType: 'json',
- beforeSend: function(request) {
- Common.addTokenToRequest(request);
- },
- // contentType : "application/json",
- data: {
- classKey: _self.attributeKey,
- },
- success: function(data) {
- console.log('=========>');
- console.log(data);
- _self.attributes = data;
- },
- error: function(XMLHttpRequest, textStatus, errorThrown) {
- Common.processException(
- XMLHttpRequest,
- textStatus,
- errorThrown,
- );
- },
- });
- },
- /**
- * 添加属性
- */
- addAttribute: function() {
- var _self = this;
- var newAttribute = _self.generateAttribute();
- _self.attributes.push(newAttribute);
- },
- /**
- * 保存属性
- * @return {void}
- */
- saveAttribute: function() {
- var _self = this;
- console.log(_self.attributes);
- $.ajax({
- url: Common.getApiURL('attributeResource/saveAttribute'),
- type: 'post',
- beforeSend: function(request) {
- Common.addTokenToRequest(request);
- },
- contentType: 'application/json',
- data: JSON.stringify(_self.attributes),
- success: function(data) {
- Notify.success('成功', '保存成功', true);
- },
- error: function(XMLHttpRequest, textStatus, errorThrown) {
- Common.processException(
- XMLHttpRequest,
- textStatus,
- errorThrown,
- );
- },
- });
- },
- /**
- * 刷新
- * @return {void}
- */
- refresh: function() {
- var _self = this;
- _self.attributes = [];
- _self.getAttribute();
- },
- /**
- * 删除属性
- * @param {Object} attribute 属性
- * @return {void}
- */
- deleteAttribute: function(attribute) {
- var _self = this;
- if (attribute.id != undefined && attribute.id > 0) {
- Notify.show({
- title: _self.$t('lang.AttributeEditPane.deleteConfirmation'),
- message:
- _self.$t('lang.AttributeEditPane.someWhatThree') +
- attribute.name +
- _self.$t('lang.AttributeEditPane.someWhatFour'),
- buttons: [
- {
- label: _self.$t('lang.AttributeEditPane.determine'),
- cssClass: 'btn-primary',
- action: function(dialogItself) {
- dialogItself.close();
- $.ajax({
- url: Common.getApiURL(
- 'attributeResource/deleteAttribute',
- ),
- type: 'get',
- dataType: 'json',
- beforeSend: function(request) {
- Common.addTokenToRequest(request);
- },
- data: {
- attributeId: attribute.id,
- },
- success: function(data) {
- var index = _self.attributes.indexOf(
- attribute,
- );
- if (index >= 0) {
- _self.attributes.splice(index, 1);
- }
- },
- error: function(
- XMLHttpRequest,
- textStatus,
- errorThrown,
- ) {
- Common.processException(
- XMLHttpRequest,
- textStatus,
- errorThrown,
- );
- },
- });
- },
- },
- {
- label: _self.$t('lang.AttributeEditPane.cancel'),
- action: function(dialogItself) {
- dialogItself.close();
- },
- },
- ],
- });
- } else {
- var index = _self.attributes.indexOf(attribute);
- if (index >= 0) {
- _self.attributes.splice(index, 1);
- }
- }
- },
- /**
- * 添加属性名称
- * @param {void} attribute
- */
- addAttributeName: function(attribute) {
- var _self = this;
- var newAttributeName = _self.generateAttributeName();
- if (attribute.id != undefined && attribute.id > 0) {
- newAttributeName.attributeId = attribute.id;
- }
- attribute.attributeNameDtoList.push(newAttributeName);
- },
- /**
- * 删除属性名称
- * @param {Object} attribute 属性
- * @param {Object} attributeName 属性名称
- * @return {void}
- */
- deleteAttributeName: function(attribute, attributeName) {
- var _self = this;
- if (attributeName.id != undefined && attributeName.id > 0) {
- Notify.show({
- title:_self.$t('lang.AttributeEditPane.deleteConfirmation'),
- message:
- _self.$t('lang.AttributeEditPane.someWhatOne') +
- attributeName.name +
- _self.$t('lang.AttributeEditPane.someWhatTwo'),
- buttons: [
- {
- label: _self.$t('lang.AttributeEditPane.determine'),
- cssClass: 'btn-primary',
- action: function(dialogItself) {
- dialogItself.close();
- $.ajax({
- url: Common.getApiURL(
- 'attributeResource/deleteAttributeName',
- ),
- type: 'get',
- dataType: 'json',
- beforeSend: function(request) {
- Common.addTokenToRequest(request);
- },
- data: {
- attributeNameId: attributeName.id,
- },
- success: function(data) {
- var index = attribute.attributeNameDtoList.indexOf(
- attributeName,
- );
- if (index >= 0) {
- attribute.attributeNameDtoList.splice(
- index,
- 1,
- );
- }
- },
- error: function(
- XMLHttpRequest,
- textStatus,
- errorThrown,
- ) {
- Common.processException(
- XMLHttpRequest,
- textStatus,
- errorThrown,
- );
- },
- });
- },
- },
- {
- label: _self.$t('lang.AttributeEditPane.cancel'),
- action: function(dialogItself) {
- dialogItself.close();
- },
- },
- ],
- });
- } else {
- var index = attribute.attributeNameDtoList.indexOf(
- attributeName,
- );
- if (index >= 0) {
- attribute.attributeNameDtoList.splice(index, 1);
- }
- }
- },
- /**
- * 生成Attribute
- * @return {Object} 属性
- */
- generateAttribute: function() {
- var _self = this;
- var newAttribute = {
- id: -1,
- name: '',
- help: '',
- classKey: _self.attributeKey,
- isRequired: false,
- isInput: false,
- isSearchable: false,
- isMutipleSelect: false,
- isNumber: false,
- attributeNameDtoList: [],
- };
- return newAttribute;
- },
- /**
- * 生成AttributeName
- * @return {Object} 属性值
- */
- generateAttributeName: function() {
- var _self = this;
- var newAttributeName = {
- id: -1,
- attributeId: null,
- nameStr: '',
- nameDec: null,
- };
- return newAttributeName;
- },
- /**
- * 返回
- * @return {void}
- */
- back: function() {
- window.history.back();
- },
- },
- };
- </script>
- <style scoped>
- .checkbox {
- margin-left: 10px;
- }
- .form-attributeName {
- margin-left: 100px;
- }
- </style>
|