selectmaterials.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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.standardPrice}} 元
  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 {GetMaterials} from '@/common/api/MaterialInOut.js';
  43. export default {
  44. data() {
  45. return {
  46. materials: [],
  47. checkboxValues: [],
  48. searchVal: ''
  49. }
  50. },
  51. onLoad: function() {
  52. //console.info('授权');
  53. //console.info(this.$auth);
  54. this.$util.persistLogin(this);
  55. },
  56. created: function() {
  57. this.getMaterials();
  58. },
  59. methods: {
  60. getMaterials: function() {
  61. var that = this;
  62. var projectCode = this.$store.state.projectCode;
  63. let contractCode = this.$util.getQuery("contractCode");
  64. let searchVal=that.searchVal;
  65. uni.showLoading({
  66. title: "页面努力加载中,请稍候...",
  67. mask: true
  68. });
  69. GetMaterials(projectCode, contractCode,searchVal).then((res) => {
  70. uni.hideLoading();
  71. console.info('GetMaterials',res);
  72. //console.info(projectCode);
  73. that.materials=[];
  74. //return;
  75. res.forEach(function(item, index, array) {
  76. that.$set(that.materials, index, item);
  77. });
  78. });
  79. },
  80. checkboxChange: function(e) {
  81. var items = this.materials,
  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. let selectChecked=[];
  109. this.materials.forEach(function(item,index,array){
  110. arr.forEach(function(item1,index1,array1){
  111. if(item.materialCode==item1){
  112. item.inQty=0.00;
  113. item.noQty=0.00;
  114. selectChecked.push(item);
  115. }
  116. });
  117. });
  118. console.info('submitForm selectChecked',this.selectChecked);
  119. //将数据发射到父级监听事件中
  120. uni.$emit('materials', selectChecked);
  121. //关闭当前窗口
  122. uni.navigateBack({});
  123. },
  124. search(res) { //回车搜索
  125. this.searchvalue = res.value; //赋值
  126. this.getMaterials(); //调用搜索方法
  127. },
  128. input(res) {
  129. this.searchVal = res.value
  130. },
  131. cancel(res) {
  132. console.info('点击取消,输入值为:' + res.value);
  133. }
  134. }
  135. }
  136. </script>
  137. <style scoped>
  138. .slot-box {
  139. margin: 5px 5px;
  140. }
  141. .uni-btn-v {
  142. position: fixed;
  143. bottom: 0;
  144. width: 100%;
  145. }
  146. uni-view{
  147. font-size:15px;
  148. }
  149. </style>