addGoods.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <view class="container">
  3. <!-- 输入框区域 -->
  4. <view class="search">
  5. <img src="../../static/images/repairsImg/search.png" @click="handleSearch" />
  6. <input type="text" placeholder="请输入搜索内容" v-model="searchValue" />
  7. </view>
  8. <!-- 耗材区域 -->
  9. <view class="body">
  10. <view class="body_left">
  11. <view class="left_item" :class="{ active: activeIndex === index }" v-for="(item, index) in list" :key="index" @click="handleChange(index)">{{ item }}</view>
  12. </view>
  13. <view class="body_right">
  14. <view class="right_item" :class="{ active: ele.isCheck }" v-for="(ele, index2) in list2" :key="index2" @click="handleChange2(index2)">
  15. {{ ele.name }}
  16. </view>
  17. </view>
  18. </view>
  19. <!-- 备注区域 -->
  20. <view class="notes" v-if="list[activeIndex] === '其他'">
  21. <view class="notes_title">备注</view>
  22. <view class="notes_textarea">
  23. <textarea placeholder-style="color:#CCCCCC" placeholder="请输入您的备注" maxlength="150" v-model="textareaValue" @input="handleInput"></textarea>
  24. <view class="notes_num">{{ textLength }}/150</view>
  25. </view>
  26. </view>
  27. <view class="btn" v-if="list[activeIndex] === '其他'" @click="handleAffirm">确认</view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. // 搜索框绑定数据
  35. searchValue: '',
  36. // 备注输入框绑定数据
  37. textareaValue: '',
  38. // 输入框当前输入数据的长度
  39. textLength: 0,
  40. // 左边数组的索引
  41. activeIndex: 0,
  42. // 左边数组
  43. list: [],
  44. // 右边数组的索引
  45. activeIndex2: null,
  46. // 右边数组
  47. list2: [],
  48. // 校区id
  49. schoolId: '',
  50. // 所有数据
  51. allList: [],
  52. // 默认选择id
  53. activeList: []
  54. }
  55. },
  56. onLoad(options) {
  57. const userInfo = uni.getStorageSync('repairsUserInfo')
  58. this.schoolId = userInfo.schoolId
  59. this.activeList = JSON.parse(options.activeList)
  60. this.getData()
  61. },
  62. methods: {
  63. handleSearch() {
  64. this.activeIndex = 0
  65. this.activeIndex2 = null
  66. this.getData()
  67. },
  68. // 获取耗材列表数据
  69. async getData() {
  70. const res = await this.$myRequest_repairs({
  71. url: '/repairArticleType/queryConsumeMaterial',
  72. data: {
  73. schoolId: this.schoolId,
  74. keyWord: this.searchValue
  75. }
  76. })
  77. // console.log(res)
  78. if (res.code === '200') {
  79. this.allList = res.data
  80. this.list = this.allList.map((ele) => ele.name)
  81. this.list2 = this.allList[this.activeIndex].consumes || []
  82. this.list2.forEach((ele, index) => {
  83. if (this.activeList.includes(ele.id)) {
  84. ele.isCheck = true
  85. }
  86. })
  87. }
  88. },
  89. // 确认按钮回调
  90. async handleAffirm() {
  91. if (this.textareaValue) {
  92. const res = await this.$myRequest_repairs({
  93. url: '/repairConsume/insertRepairAssociation',
  94. method: 'post',
  95. data: {
  96. name: this.textareaValue,
  97. articleId: this.allList[this.activeIndex].id,
  98. schoolId: this.schoolId
  99. }
  100. })
  101. // console.log(res)
  102. if (res.code === '200') {
  103. this.textareaValue = ''
  104. uni.showToast({
  105. title: '添加成功',
  106. icon: 'success'
  107. })
  108. setTimeout(() => {
  109. this.getData()
  110. }, 1500)
  111. }
  112. } else {
  113. uni.showToast({
  114. title: '请输入备注',
  115. icon: 'none'
  116. })
  117. }
  118. },
  119. // 左边数组切换回调
  120. handleChange(index) {
  121. this.activeIndex = index
  122. this.activeIndex2 = null
  123. this.list2 = this.allList[this.activeIndex].consumes || []
  124. this.list2.forEach((ele, index) => {
  125. if (this.activeList.includes(ele.id)) {
  126. ele.isCheck = true
  127. }
  128. })
  129. },
  130. // 右边数组切换回调
  131. handleChange2(index) {
  132. this.activeIndex2 = index
  133. uni.$emit('addConsumable', {
  134. data: this.list2[this.activeIndex2],
  135. articleId: this.allList[this.activeIndex].id
  136. })
  137. uni.navigateBack(1)
  138. },
  139. // 输入框输入值变化回调
  140. handleInput(e) {
  141. this.textLength = e.detail.value.length
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. .container {
  148. display: flex;
  149. flex-direction: column;
  150. width: 100vw;
  151. height: 100vh;
  152. font-size: 32rpx;
  153. overflow-y: auto;
  154. .search {
  155. display: flex;
  156. align-items: center;
  157. margin: 30rpx auto 30rpx;
  158. width: 690rpx;
  159. height: 80rpx;
  160. border-radius: 4rpx;
  161. background-color: #f2f2f2;
  162. img {
  163. margin: 0 20rpx;
  164. width: 40rpx;
  165. height: 40rpx;
  166. }
  167. input {
  168. flex: 1;
  169. padding: 10rpx;
  170. }
  171. }
  172. .body {
  173. display: flex;
  174. height: 686rpx;
  175. border-top: 1rpx solid #e5e5e5;
  176. .body_left {
  177. box-sizing: border-box;
  178. padding: 20rpx 30rpx 30rpx;
  179. width: 199rpx;
  180. border-right: 1rpx solid #cccccc;
  181. overflow-y: auto;
  182. .left_item {
  183. display: flex;
  184. align-items: center;
  185. margin-bottom: 10rpx;
  186. height: 80rpx;
  187. font-weight: bold;
  188. }
  189. .active {
  190. color: #6fb6b8;
  191. }
  192. }
  193. .body_right {
  194. flex: 1;
  195. box-sizing: border-box;
  196. padding: 35rpx 30rpx;
  197. overflow-y: auto;
  198. .right_item {
  199. float: left;
  200. box-sizing: border-box;
  201. padding: 10rpx 30rpx;
  202. margin: 0 20rpx 37rpx 0;
  203. height: 50rpx;
  204. line-height: 30rpx;
  205. text-align: center;
  206. color: #808080;
  207. // font-size: 28rpx;
  208. border-radius: 53rpx;
  209. background-color: #e6e6e6;
  210. overflow: hidden;
  211. white-space: nowrap;
  212. text-overflow: ellipsis;
  213. }
  214. .active {
  215. color: #fff;
  216. background-color: #6fb6b8;
  217. }
  218. }
  219. }
  220. .notes {
  221. box-sizing: border-box;
  222. padding: 0 30rpx;
  223. border-top: 1rpx solid #e5e5e5;
  224. .notes_title {
  225. display: flex;
  226. align-items: center;
  227. height: 88rpx;
  228. font-size: 32rpx;
  229. font-weight: bold;
  230. }
  231. .notes_textarea {
  232. position: relative;
  233. height: 284rpx;
  234. border: 1rpx solid #e5e5e5;
  235. textarea {
  236. box-sizing: border-box;
  237. padding: 16rpx 20rpx 75rpx;
  238. width: 100%;
  239. font-size: 32rpx;
  240. }
  241. .notes_num {
  242. position: absolute;
  243. right: 20rpx;
  244. bottom: 14rpx;
  245. color: #a6a6a6;
  246. font-size: 32rpx;
  247. }
  248. }
  249. }
  250. .btn {
  251. display: flex;
  252. justify-content: center;
  253. align-items: center;
  254. margin: 55rpx auto 65rpx;
  255. width: 690rpx;
  256. height: 100rpx;
  257. color: #fff;
  258. font-size: 32rpx;
  259. border-radius: 12rpx;
  260. background-color: #6fb6b8;
  261. }
  262. }
  263. </style>