goods.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <view class="content">
  3. <!-- 自定义导航 -->
  4. <view class="navbar-box">
  5. <u-navbar title="选择物资" :safeAreaInsetTop="true" @leftClick="leftClick">
  6. </u-navbar>
  7. </view>
  8. <view class="screen-box">
  9. <view class="screen-class">
  10. <u-search
  11. placeholder="搜索"
  12. height="70"
  13. bg-color="#f7f7f7"
  14. v-model="keyword"
  15. @search="search"
  16. @custom="search"></u-search>
  17. </view>
  18. </view>
  19. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  20. <u-checkbox-group @change="checkboxGroupChange" active-color="#218AEC" style="display: block;">
  21. <view v-for="item in dataList" :key="item.id">
  22. <view class="item u-flex u-row-between u-border-bottom">
  23. <view class="left u-flex">
  24. <image :src="item.imgs|firstImg" mode="aspectFill"></image>
  25. <view class="text">
  26. <view class="name">{{item.mateName}}</view>
  27. <view class="u-tips-color">{{filterSpecName(item.specCode)}}*{{filterUnitName(item.unitCode)}}</view>
  28. </view>
  29. </view>
  30. <view class="right">
  31. <u-checkbox v-model="item.checked" :name="item.id"></u-checkbox>
  32. <!-- <u-number-box v-model="item.value" @change="valChange(item)"></u-number-box> -->
  33. </view>
  34. </view>
  35. </view>
  36. </u-checkbox-group>
  37. </mescroll-body>
  38. <view class="fixed-button">
  39. <u-button type="success" @click="confirmEven">确定</u-button>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import {otherApiUrl} from '@/common/apiurl.js';
  45. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  46. export default {
  47. mixins: [MescrollMixin], // 使用mixin
  48. components: {
  49. },
  50. data() {
  51. return {
  52. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  53. downOption: {
  54. },
  55. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  56. upOption: {
  57. page: {
  58. size: 10 // 每页数据的数量,默认10
  59. },
  60. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  61. empty: {
  62. tip: '暂无相关数据'
  63. }
  64. },
  65. keyword:'',
  66. // 列表数据
  67. dataList: [],
  68. checkboxList:[],
  69. choiceList:[],
  70. unitNameList:[],
  71. specNameList:[],
  72. }
  73. },
  74. onLoad() {
  75. this.unitNameDict();
  76. this.specNameDict();
  77. },
  78. computed:{
  79. filterUnitName(){
  80. return function(value){
  81. let v = '';
  82. for (let i = 0; i < this.unitNameList.length; i++){
  83. // console.log('value',value);
  84. // console.log('value',this.unitNameList[i]);
  85. let item = this.unitNameList[i];
  86. if (value == item.value) {
  87. v = item.label;
  88. break;
  89. }
  90. }
  91. return v
  92. }
  93. },
  94. filterSpecName(){
  95. return function(value){
  96. let v = '';
  97. for (let i = 0; i < this.specNameList.length; i++){
  98. // console.log('value',value);
  99. // console.log('value',this.specNameList[i]);
  100. let item = this.specNameList[i];
  101. if (value == item.value) {
  102. v = item.label;
  103. break;
  104. }
  105. }
  106. return v
  107. }
  108. },
  109. },
  110. methods: {
  111. /*上拉加载的回调*/
  112. upCallback(page) {
  113. let params ={
  114. pageNum:page.num,
  115. pageSize:page.size,
  116. keyword:this.keyword
  117. }
  118. this.$u.api.epiStoreInList(params).then(curPageData=>{
  119. // console.log('curPageData',curPageData)
  120. //联网成功的回调,隐藏下拉刷新和上拉加载的状态;
  121. // this.mescroll.endSuccess(curPageData.rows.total);
  122. this.mescroll.endBySize(curPageData.rows.length, curPageData.rows.total);
  123. //设置列表数据
  124. if(page.num == 1) this.dataList = []; //如果是第一页需手动制空列表
  125. this.dataList=this.dataList.concat(curPageData.rows); //追加新数据
  126. }).catch((err)=>{
  127. uni.showToast({
  128. title:'链接失败'
  129. });
  130. console.log('err',err)
  131. //联网失败, 结束加载
  132. this.mescroll.endErr();
  133. })
  134. },
  135. /*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/
  136. reloadList(){
  137. this.mescroll.resetUpScroll();
  138. },
  139. leftClick() {
  140. let canNavBack = getCurrentPages();
  141. if(canNavBack && canNavBack.length>1) {
  142. uni.navigateBack({
  143. delta: 1
  144. });
  145. } else {
  146. history.back();
  147. }
  148. },
  149. goCheck(item){
  150. this.$u.route({
  151. url: 'pages/check/checkItem/checkItem',
  152. params: {
  153. id: item.id
  154. }
  155. })
  156. console.log('goPutOut',item)
  157. },
  158. search(){
  159. this.mescroll.resetUpScroll();
  160. },
  161. // valChange(item){
  162. // console.log('valChange',item);
  163. // },
  164. // 物资选择完成事件
  165. confirmEven(){
  166. this.choiceList = []
  167. this.dataList.forEach(item => {
  168. if(this.checkboxList.indexOf(item.id) > -1) {
  169. this.choiceList.push({
  170. mateId: item.id,
  171. classTypeName: item.classTypeName,
  172. mateName: item.mateName,
  173. unitCode: item.unitCode,
  174. mateNum:1,
  175. })
  176. }
  177. })
  178. console.log('this.choiceList',this.choiceList);
  179. this.$u.vuex('putinList', this.choiceList)
  180. this.$u.route({
  181. url:'pages/putin/putin',
  182. })
  183. },
  184. // 选中任一checkbox时,由checkbox-group触发
  185. checkboxGroupChange(e) {
  186. this.checkboxList = e;
  187. console.log('this.checkboxList',this.checkboxList);
  188. },
  189. async unitNameDict() {
  190. let { code, data, msg} = await this.$u.get(otherApiUrl.getDict + 'goods_unit_name')
  191. if(code === 200) {
  192. this.unitNameList = data.map(item => {
  193. return {
  194. label: item.dictLabel,
  195. value: item.dictValue
  196. }
  197. })
  198. }
  199. },
  200. async specNameDict() {
  201. let { code, data, msg} = await this.$u.get(otherApiUrl.getDict + 'goods_spec_name')
  202. if(code === 200) {
  203. this.specNameList = data.map(item => {
  204. return {
  205. label: item.dictLabel,
  206. value: item.dictValue
  207. }
  208. })
  209. }
  210. },
  211. }
  212. }
  213. </script>
  214. <style lang="scss" scoped>
  215. .item{
  216. margin: 24rpx;
  217. padding-bottom: 24rpx;
  218. .left image {
  219. width: 120rpx;
  220. height: 120rpx;
  221. border-radius: 8rpx;
  222. margin-right: 12rpx;
  223. }
  224. }
  225. </style>