goods.vue 6.1 KB

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