relationMaterialAdd.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <view>
  3. <view>
  4. <uni-search-bar :radius="100" @confirm="search" @input="input" @cancel="cancel"></uni-search-bar>
  5. </view>
  6. <uni-forms ref="form" @submit="submitForm">
  7. <uni-list v-if="materials.length>0">
  8. <checkbox-group @change="checkboxChange" >
  9. <uni-list-item v-for="(item,index) in materials" :key="index">
  10. <!-- 自定义 header -->
  11. <view slot="header" class="slot-box">
  12. <checkbox :value="item.materialCode" />
  13. </view>
  14. <!-- 自定义 body -->
  15. <view slot="body" class="slot-box">
  16. {{item.materialName}}
  17. </view>
  18. <!-- 自定义 footer-->
  19. <view slot="footer" class="slot-box">
  20. {{item.unit}}
  21. </view>
  22. </uni-list-item>
  23. </checkbox-group>
  24. </uni-list>
  25. <uni-list v-else>
  26. <checkbox-group @change="checkboxChange" >
  27. <uni-list-item >
  28. <!-- 自定义 body -->
  29. <view slot="body" class="slot-box">
  30. 没有材料
  31. </view>
  32. </uni-list-item>
  33. </checkbox-group>
  34. </uni-list>
  35. <view class="uni-btn-v uni-column">
  36. <button type="primary" form-type="submit" style="border-radius: 15px;">关联材料添加</button>
  37. </view>
  38. </uni-forms>
  39. </view>
  40. </template>
  41. <script>
  42. import {GetMaterialList} from '@/common/api/commonApi.js';
  43. import {
  44. InsertZRelationSafeQualityCheckMaterial
  45. } from "@/common/api/SafeQualityCheckApi.js";
  46. export default {
  47. data() {
  48. return {
  49. materials: [],
  50. checkboxValues: [],
  51. searchVal: ''
  52. }
  53. },
  54. onLoad: function() {
  55. //console.info('授权');
  56. //console.info(this.$auth);
  57. this.$util.persistLogin(this);
  58. },
  59. created: function() {
  60. this.getMaterials();
  61. },
  62. methods: {
  63. getMaterials: function() {
  64. var that = this;
  65. let searchVal=that.searchVal;
  66. uni.showLoading({
  67. title: "页面努力加载中,请稍候...",
  68. mask: true
  69. });
  70. GetMaterialList(searchVal).then((res) => {
  71. uni.hideLoading();
  72. console.info('GetMaterialList',res);
  73. //console.info(projectCode);
  74. that.materials=[];
  75. //return;
  76. res.forEach(function(item, index, array) {
  77. that.$set(that.materials, index, item);
  78. });
  79. });
  80. },
  81. checkboxChange: function(e) {
  82. var items = this.materials,
  83. values = e.detail.value;
  84. this.checkboxValues = values.join(',');
  85. console.info("values",values);
  86. console.info(this.checkboxValues);
  87. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  88. const item = items[i]
  89. if (values.includes(item.value)) {
  90. this.$set(item, 'checked', true)
  91. } else {
  92. this.$set(item, 'checked', false)
  93. }
  94. }
  95. },
  96. submitForm(e) {
  97. console.info('submitForm',this.checkboxValues);
  98. let _this=this;
  99. if(this.checkboxValues.length<=0){
  100. uni.showToast({
  101. title:'请选择材料',
  102. icon:'none',
  103. duration:3000
  104. });
  105. return;
  106. }
  107. //先记录值,下面this指向会不一样
  108. let relationContractCodes = this.checkboxValues;
  109. let SafeQualityCheckCode=_this.$util.getQuery("SafeQualityCheckCode");
  110. let arr=relationContractCodes.split(',');
  111. for (let i = 0; i < arr.length; i++) {
  112. var zRelationSafeQualityCheckMaterial={safeQualityCheckCode:SafeQualityCheckCode,materialCode:arr[i]};
  113. InsertZRelationSafeQualityCheckMaterial(zRelationSafeQualityCheckMaterial);
  114. }
  115. //跳转
  116. uni.navigateTo({
  117. url:'../GetRelationMaterialList/GetRelationMaterialList?id='+SafeQualityCheckCode
  118. });
  119. },
  120. search(res) { //回车搜索
  121. this.searchvalue = res.value; //赋值
  122. this.getMaterials(); //调用搜索方法
  123. },
  124. input(res) {
  125. this.searchVal = res.value
  126. },
  127. cancel(res) {
  128. console.info('点击取消,输入值为:' + res.value);
  129. }
  130. }
  131. }
  132. </script>
  133. <style scoped>
  134. .slot-box {
  135. margin: 5px 5px;
  136. }
  137. .uni-btn-v {
  138. position: fixed;
  139. bottom: 0;
  140. width: 100%;
  141. }
  142. uni-view{
  143. font-size:15px;
  144. }
  145. </style>