batchAdd.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <view class="picker-card">
  3. <view class="picker-btn">
  4. <view class="btn">
  5. <button type="primary" @click="sureChooseSpare">
  6. {{$t('settings.confirmText')}}
  7. </button>
  8. </view>
  9. </view>
  10. <view class="choose-wrap">
  11. <!-- 选择大类 -->
  12. <view class="item">
  13. <view class="search-wrap">
  14. <u-input v-model="keyword" @change="getOptions" :placeholder="$t('base.search.keySearch')" />
  15. </view>
  16. </view>
  17. <view class="step" @click="parentlist.length?stepBack():''">
  18. <u-icon name="arrow-left" color="#008cff" size="15" v-if="parentlist.length"></u-icon>
  19. {{parentlist.length?'返回上一层':'根层级'}}
  20. </view>
  21. <template v-if="currentTreeData.length || spareList.length">
  22. <view class="tree" v-if="currentTreeData.length">
  23. <view class="tree-item" v-for="item in currentTreeData" :key="item.id" @click="getSpare(item)">
  24. <view class="icon">
  25. <uni-icons custom-prefix="elicon" type="el-icon-folder-opened" size="18" color="#fff"></uni-icons>
  26. </view>
  27. {{item.name}}
  28. </view>
  29. </view>
  30. <view class="tree">
  31. <u-checkbox-group v-model="detailList" placement="column" iconPlacement="right">
  32. <u-checkbox :customStyle="{padding: '8px 0'}" v-for="(item, index) in spareList" :key="index" :label="`${item.code}_${item.name}_${item.spec}_${getLabel(item.unit,unitList)}`" :name="item.content">
  33. </u-checkbox>
  34. </u-checkbox-group>
  35. </view>
  36. </template>
  37. <template v-else>
  38. <u-empty mode="list" :text="$t('base.common.noData')" icon="https://cdn.uviewui.com/uview/empty/list.png">
  39. </u-empty>
  40. </template>
  41. </view>
  42. <view class="card-oper">
  43. <!-- <view class="btn">
  44. <u-button @click="showPicker = false">{{$t('settings.cancelText')}}</u-button>
  45. </view>
  46. <view class="btn">
  47. <u-button type='primary' @click="spareConfirm">{{$t('settings.confirmText')}}</u-button>
  48. </view> -->
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import { getLabel } from "../../utils/util";
  54. import { request } from "../../utils/request";
  55. import { fetchTree, getSpareOption } from "../../api/stock";
  56. export default {
  57. data() {
  58. return {
  59. getLabel,
  60. spareList: [], //备件列表
  61. treeData: [], //备件大类树
  62. currentTreeData: [],
  63. detailList: [], //选择的备件
  64. spareKeyword: "",
  65. keyword: "",
  66. unitList: [],
  67. parentlist:[],
  68. fullCodeList:[],
  69. index:0,
  70. };
  71. },
  72. onLoad(options) {
  73. this.getSpareTree();
  74. },
  75. methods: {
  76. //确定选择备件
  77. sureChooseSpare(){
  78. let pages = getCurrentPages();
  79. let prevPage = pages[pages.length - 2]; //上一个页面
  80. console.log(prevPage,'======');
  81. prevPage.$vm.detailList = this.detailList;
  82. prevPage.$vm.spareConfirm()
  83. uni.navigateBack();
  84. },
  85. //返回上一层
  86. stepBack(){
  87. this.currentTreeData = JSON.parse(JSON.stringify(this.parentlist[this.index-1]))
  88. this.parentlist.splice(this.index-1,1)
  89. let data = {
  90. fullCode: this.fullCodeList[this.index-2],
  91. };
  92. this.fullCodeList.splice(this.index-1,1)
  93. if(this.fullCodeList.length){
  94. getSpareOption(data, this.spareKeyword).then((res) => {
  95. if (res.data.code == 0) {
  96. this.spareList = res.data.data;
  97. this.spareList.forEach((item) => {
  98. item.content = JSON.stringify(item);
  99. });
  100. }
  101. });
  102. }else{
  103. this.spareList = []
  104. }
  105. console.log(this.parentlist,this.fullCodeList);
  106. this.index-=1
  107. },
  108. //备件大类
  109. getSpareTree() {
  110. fetchTree().then((res) => {
  111. if (res.data.code == 0) {
  112. this.treeData = res.data.data;
  113. this.currentTreeData = res.data.data;
  114. }
  115. });
  116. //获取单位
  117. request({
  118. url: "/admin/dict/type/spare_unit",
  119. method: "get",
  120. }).then((res) => {
  121. if (res.data.code == 0) {
  122. this.unitList = res.data.data;
  123. }
  124. });
  125. },
  126. //获取产品选项
  127. getSpare(item) {
  128. this.index+=1
  129. this.parentlist.push(JSON.parse(JSON.stringify(this.currentTreeData)))
  130. this.currentTreeData = item.children;
  131. this.fullCodeList.push(item.fullCode)
  132. console.log(this.parentlist,this.fullCodeList);
  133. let data = {
  134. fullCode: item.fullCode,
  135. };
  136. getSpareOption(data, this.spareKeyword).then((res) => {
  137. if (res.data.code == 0) {
  138. this.spareList = res.data.data;
  139. this.spareList.forEach((item) => {
  140. item.content = JSON.stringify(item);
  141. });
  142. }
  143. });
  144. },
  145. },
  146. };
  147. </script>
  148. <style lang="scss" scoped>
  149. view {
  150. display: flex;
  151. box-sizing: border-box;
  152. flex-direction: column;
  153. }
  154. page {
  155. background-color: #f8f8f8;
  156. }
  157. .picker-card {
  158. // padding: 32rpx;
  159. background-color: #fff;
  160. .picker-btn{
  161. padding: 32rpx;
  162. position: fixed;
  163. bottom: 0;
  164. width: 100%;
  165. flex-direction: row;
  166. justify-content: space-between;
  167. background-color: #fff;
  168. z-index: 100;
  169. .btn{
  170. width: 100%;
  171. }
  172. }
  173. .item{
  174. padding: 32rpx;
  175. }
  176. .step{
  177. padding:0 32rpx;
  178. flex-direction: row;
  179. background-color: #f2f2f2;
  180. line-height: 80rpx;
  181. font-size: 15px;
  182. color: rgb(0, 140, 255);
  183. }
  184. .tree {
  185. padding: 0 32rpx;
  186. .tree-item {
  187. padding: 6px 0;
  188. font-size: 15px;
  189. color: rgb(96, 98, 102);
  190. flex-direction: row;
  191. line-height: 60rpx;
  192. .icon {
  193. width: 60rpx;
  194. height: 60rpx;
  195. background-color: rgb(0, 140, 255);
  196. border-radius: 10rpx;
  197. display: flex;
  198. justify-content: space-around;
  199. align-items: center;
  200. margin-right: 10rpx;
  201. }
  202. }
  203. }
  204. }
  205. </style>