SelectCheckProject.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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="items.length>0">
  8. <checkbox-group @change="checkboxChange" >
  9. <uni-list-item v-for="(item,index) in items" :key="index">
  10. <!-- 自定义 header -->
  11. <view slot="header" style="width: 10%;">
  12. <checkbox :value="item.diCode" />
  13. </view>
  14. <!-- 自定义 body -->
  15. <view slot="body" style="width: 25%;">
  16. {{item.dnCode=='10034'?'质量检查':item.dnCode=='10035'?'安全检查':'材料检查'}}
  17. </view>
  18. <view slot="footer" style="width: 65%;">
  19. {{item.diName}}
  20. </view>
  21. </uni-list-item>
  22. </checkbox-group>
  23. </uni-list>
  24. <uni-list v-else>
  25. <checkbox-group @change="checkboxChange" >
  26. <uni-list-item >
  27. <!-- 自定义 body -->
  28. <view slot="body" class="slot-box">
  29. </view>
  30. </uni-list-item>
  31. </checkbox-group>
  32. </uni-list>
  33. <view class="uni-btn-v uni-column">
  34. <button type="primary" form-type="submit" style="border-radius: 15px;">选择成功,确认</button>
  35. </view>
  36. </uni-forms>
  37. </view>
  38. </template>
  39. <script>
  40. import {GetQualityAndSafeItems} from '@/common/api/SafeQualityCheckApi.js';
  41. export default {
  42. data() {
  43. return {
  44. items: [],
  45. checkboxValues: [],
  46. searchVal: ''
  47. }
  48. },
  49. onLoad: function() {
  50. this.$util.persistLogin(this);
  51. },
  52. created: function() {
  53. this.getItems();
  54. },
  55. methods: {
  56. getItems: function() {
  57. var that = this;
  58. let type=-1;
  59. let searchVal=that.searchVal;
  60. if(that.$util.getQuery("type")!=undefined&&that.$util.getQuery("type")!=""){
  61. type=that.$util.getQuery("type");
  62. }
  63. uni.showLoading({
  64. title: "页面努力加载中,请稍候...",
  65. mask: true
  66. });
  67. console.info('getitems type:',type);
  68. console.info('getitems searchVal:',searchVal);
  69. GetQualityAndSafeItems(type,searchVal).then((res) => {
  70. uni.hideLoading();
  71. console.info('GetQualityAndSafeItems',res);
  72. //console.info(projectCode);
  73. that.items=[];
  74. //return;
  75. res.forEach(function(item, index, array) {
  76. that.$set(that.items, index, item);
  77. });
  78. });
  79. },
  80. checkboxChange: function(e) {
  81. var items = this.items,
  82. values = e.detail.value;
  83. this.checkboxValues = values.join(',');
  84. console.info("values",values);
  85. console.info(this.checkboxValues);
  86. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  87. const item = items[i]
  88. if (values.includes(item.value)) {
  89. this.$set(item, 'checked', true)
  90. } else {
  91. this.$set(item, 'checked', false)
  92. }
  93. }
  94. },
  95. submitForm(e) {
  96. console.info('submitForm',this.checkboxValues);
  97. if(this.checkboxValues.length<=0){
  98. uni.showToast({
  99. title:'请选择检查项目',
  100. icon:'none',
  101. duration:3000
  102. });
  103. return;
  104. }
  105. //先记录值,下面this指向会不一样
  106. let relationContractCodes = this.checkboxValues;
  107. let arr=relationContractCodes.split(',');
  108. //console.info('relationContractCodes',relationContractCodes);
  109. //console.info('this.items',this.items);
  110. //return;
  111. let selectChecked=[];
  112. this.items.forEach(function(item,index,array){
  113. arr.forEach(function(item1,index1,array1){
  114. if(item.diCode==item1){
  115. selectChecked.push(item);
  116. }
  117. });
  118. });
  119. console.info('submitForm selectChecked',selectChecked);
  120. //将数据发射到父级监听事件中
  121. uni.$emit('items', selectChecked);
  122. //关闭当前窗口
  123. uni.navigateBack({});
  124. },
  125. search(res) { //回车搜索
  126. this.searchvalue = res.value; //赋值
  127. this.getItems(); //调用搜索方法
  128. },
  129. input(res) {
  130. this.searchVal = res.value
  131. },
  132. cancel(res) {
  133. console.info('点击取消,输入值为:' + res.value);
  134. }
  135. }
  136. }
  137. </script>
  138. <style scoped>
  139. .slot-box {
  140. margin: 5px 5px;
  141. }
  142. .uni-btn-v {
  143. position: fixed;
  144. bottom: 0;
  145. width: 100%;
  146. }
  147. uni-view{
  148. font-size:15px;
  149. }
  150. </style>