CustomPrintAssetInstance.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <div class="container-fluid">
  3. <div class="row">
  4. <Navbar :title="$t('lang.CustomPrintAssetInstance.selectTemplateToPrintAssetCard')" is-go-back="true" />
  5. </div>
  6. <div v-for="modelData in modelDatas" :key="modelData.id" class="row box">
  7. <div class="form-inline">
  8. <div class="col-md-4 col-sm-6 col-sm-12 div-form">
  9. <p><strong>{{ $t('lang.CustomPrintAssetInstance.assetName') }}:</strong>{{ modelData.data['ai.name'].displayValue[0] }}</p>
  10. </div>
  11. <div class="col-md-4 col-sm-6 col-sm-12 div-form">
  12. <p><strong>{{ $t('lang.CustomPrintAssetInstance.assetNumber') }}:</strong>{{ modelData.data['ai.assetNo'].displayValue[0] }}</p>
  13. </div>
  14. <div class="col-md-4 col-sm-6 col-sm-12 div-form">
  15. <p><strong>{{ $t('lang.CustomPrintAssetInstance.type') }}:</strong>{{ modelData.data['ai.type'].displayValue[0] }}</p>
  16. </div>
  17. <div class="col-md-4 col-sm-6 col-sm-12 div-form">
  18. <p><strong>{{ $t('lang.CustomPrintAssetInstance.categoryName') }}:</strong>{{ modelData.data['c.name'].displayValue[0] }}</p>
  19. </div>
  20. <div class="col-md-12 col-sm-12 col-sm-12 div-form">
  21. <strong>{{ $t('lang.CustomPrintAssetInstance.printTemplate') }}:</strong>
  22. <!-- <v-select :onChange="templateChange(this.value, modelData)" v-model="modelData.data['cpt.name'].displayValue[0]" :options="templates"></v-select> -->
  23. <select v-model="modelData.data['cpt.id'].displayValue[0]" class="form-control" @input="templateChange($event, modelData)">
  24. <option v-for="item in templates" :key="item.id" :value="item.id">{{ item.name }}</option>
  25. </select>
  26. </div>
  27. </div>
  28. </div>
  29. <div class="row">
  30. <button type="button" class="btn btn-primary btn-block" @click="print()">{{ $t('lang.CustomPrintAssetInstance.printing') }}</button>
  31. </div>
  32. <Loading v-if="loading" />
  33. </div>
  34. </template>
  35. <script>
  36. import Common from '../../common/Common.js';
  37. import { Notify } from 'pc-component-v3';
  38. export default {
  39. components: {
  40. },
  41. data : function(){
  42. return{
  43. modelDatas: [],
  44. infoWindowNo: 12629,
  45. fieldValue: {},
  46. displayName: 'name',
  47. templates: [],
  48. loading: false,
  49. };
  50. },
  51. mounted: function() {
  52. this.initData();
  53. this.loadTemplateData();
  54. },
  55. methods: {
  56. // 打印模板change
  57. templateChange: function(event, modelData){
  58. var element = event.currentTarget;
  59. var templateId = element.value;
  60. this.setTemplate(modelData.id, templateId);
  61. },
  62. // 设置模板
  63. setTemplate: function(assetInstanceId, templateId){
  64. var _self = this;
  65. _self.loading=true;
  66. $.ajax({
  67. url : Common.getApiURL('AssetInstanceResource/setPrintTemplate'),
  68. type : 'get',
  69. beforeSend:function(request){
  70. Common.addTokenToRequest(request);
  71. },
  72. data: {
  73. assetInstanceId: assetInstanceId,
  74. templateId: templateId,
  75. },
  76. success : function(data){
  77. if(data.errorCode == 0) {
  78. _self.loading=false;
  79. } else {
  80. Notify.error('提示', data.errorMessage, false);
  81. }
  82. },
  83. error: function (XMLHttpRequest, textStatus, errorThrown){
  84. _self.loading=false;
  85. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  86. },
  87. });
  88. },
  89. // 初始化数据
  90. initData: function(){
  91. var _self = this;
  92. var uuid = _self.$route.query.uuid;
  93. if(uuid != null){
  94. var modelDatas = localStorage.getItem(uuid);
  95. if(modelDatas != null){
  96. modelDatas = JSON.parse(modelDatas);
  97. console.log(modelDatas);
  98. if(modelDatas != undefined && modelDatas.length > 0){
  99. modelDatas.forEach(function(item){
  100. _self.modelDatas.push(item);
  101. });
  102. }
  103. }
  104. }
  105. },
  106. /**
  107. * 加载打印模板数据
  108. */
  109. loadTemplateData: function(){
  110. var _self = this;
  111. $.ajax({
  112. url : Common.getApiURL('printPageResource/loadCustomerTemplate'),
  113. type : 'get',
  114. dataType : 'json',
  115. beforeSend:function(request){
  116. Common.addTokenToRequest(request);
  117. },
  118. success : function(data){
  119. if(data.errorCode != 0) {
  120. Notify.error('提示', data.errorMessage, false);
  121. return;
  122. }
  123. if(data.datas != undefined && data.datas.length > 0){
  124. data.datas.forEach(function(item){
  125. item.label = item.name;
  126. item.value = item.id;
  127. });
  128. }
  129. _self.templates = data.datas;
  130. },
  131. error: function (XMLHttpRequest, textStatus, errorThrown){
  132. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  133. },
  134. });
  135. },
  136. print: function(){
  137. var recordIds = [];
  138. if(this.modelDatas != undefined && this.modelDatas.length > 0){
  139. this.modelDatas.forEach(function(item){
  140. recordIds.push(item.id);
  141. });
  142. }
  143. if(recordIds.length > 0){
  144. var path = './#/single/PrintPage?printApi=AssetInstanceResource%2Fprint&recordIds={RecordIds}';
  145. path = path.replace('{RecordIds}', recordIds);
  146. window.open(path);
  147. }else{
  148. Notify.error('错误', '没有可操作的数据', true);
  149. }
  150. },
  151. },
  152. };
  153. </script>
  154. <style scoped>
  155. .box {
  156. border: 1px #ccc solid;
  157. margin-bottom: 15px;
  158. padding-top: 10px;
  159. border-radius: 5px;
  160. background-color: #ffffff;
  161. }
  162. .div-form {
  163. margin-bottom: 10px;
  164. }
  165. </style>