addGoods.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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: activeIndex2 === index2 }" 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: 0,
  46. // 右边数组
  47. List2: [],
  48. // 校区id
  49. schoolId: '',
  50. // 所有数据
  51. allList: []
  52. }
  53. },
  54. onLoad() {
  55. const userInfo = uni.getStorageSync('repairsUserInfo')
  56. this.schoolId = userInfo.schoolId
  57. this.getData()
  58. },
  59. methods: {
  60. handleSearch() {
  61. this.activeIndex = 0
  62. this.activeIndex2 = null
  63. this.getData()
  64. },
  65. async getData() {
  66. const res = await this.$myRequest_repairs({
  67. url: '/repairArticleType/queryConsumeMaterial',
  68. data: {
  69. schoolId: this.schoolId,
  70. keyWord: this.searchValue
  71. }
  72. })
  73. // console.log(res)
  74. if (res.code === '200') {
  75. this.allList = res.data
  76. this.list = this.allList.map((ele) => ele.name)
  77. this.List2 = this.allList[this.activeIndex].consumes || []
  78. }
  79. },
  80. // 确认按钮回调
  81. async handleAffirm() {
  82. if (this.textareaValue) {
  83. const res = await this.$myRequest_repairs({
  84. url: '/repairConsume/insertRepairAssociation',
  85. method: 'post',
  86. data: {
  87. name: this.textareaValue,
  88. articleId: this.allList[this.activeIndex].id,
  89. schoolId: this.schoolId
  90. }
  91. })
  92. // console.log(res)
  93. if (res.code === '200') {
  94. this.textareaValue = ''
  95. uni.showToast({
  96. title: '添加成功',
  97. icon: 'success'
  98. })
  99. setTimeout(() => {
  100. this.getData()
  101. }, 1500)
  102. }
  103. } else {
  104. uni.showToast({
  105. title: '请输入备注',
  106. icon: 'none'
  107. })
  108. }
  109. },
  110. // 左边数组切换回调
  111. handleChange(index) {
  112. this.activeIndex = index
  113. this.activeIndex2 = null
  114. this.List2 = this.allList[this.activeIndex].consumes || []
  115. },
  116. // 右边数组切换回调
  117. handleChange2(index) {
  118. this.activeIndex2 = index
  119. uni.$emit('addConsumable', {
  120. data: this.List2[this.activeIndex2],
  121. articleId: this.allList[this.activeIndex].id
  122. })
  123. uni.navigateBack(1)
  124. },
  125. // 输入框输入值变化回调
  126. handleInput(e) {
  127. this.textLength = e.detail.value.length
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .container {
  134. display: flex;
  135. flex-direction: column;
  136. width: 100vw;
  137. height: 100vh;
  138. font-size: 32rpx;
  139. overflow-y: auto;
  140. .search {
  141. display: flex;
  142. align-items: center;
  143. margin: 30rpx auto 30rpx;
  144. width: 690rpx;
  145. height: 80rpx;
  146. border-radius: 4rpx;
  147. background-color: #f2f2f2;
  148. img {
  149. margin: 0 20rpx;
  150. width: 40rpx;
  151. height: 40rpx;
  152. }
  153. input {
  154. flex: 1;
  155. padding: 10rpx;
  156. }
  157. }
  158. .body {
  159. display: flex;
  160. height: 686rpx;
  161. border-top: 1rpx solid #e5e5e5;
  162. .body_left {
  163. box-sizing: border-box;
  164. padding: 30rpx;
  165. width: 199rpx;
  166. border-right: 1rpx solid #cccccc;
  167. overflow-y: auto;
  168. .left_item {
  169. height: 80rpx;
  170. // font-size: 28rpx;
  171. font-weight: bold;
  172. }
  173. .active {
  174. color: #6fb6b8;
  175. }
  176. }
  177. .body_right {
  178. flex: 1;
  179. box-sizing: border-box;
  180. padding: 35rpx 30rpx;
  181. overflow-y: auto;
  182. .right_item {
  183. float: left;
  184. box-sizing: border-box;
  185. padding: 10rpx 30rpx;
  186. margin: 0 20rpx 37rpx 0;
  187. height: 50rpx;
  188. line-height: 30rpx;
  189. text-align: center;
  190. color: #808080;
  191. // font-size: 28rpx;
  192. border-radius: 53rpx;
  193. background-color: #e6e6e6;
  194. overflow: hidden;
  195. white-space: nowrap;
  196. text-overflow: ellipsis;
  197. }
  198. .active {
  199. color: #fff;
  200. background-color: #6fb6b8;
  201. }
  202. }
  203. }
  204. .notes {
  205. box-sizing: border-box;
  206. padding: 0 30rpx;
  207. border-top: 1rpx solid #e5e5e5;
  208. .notes_title {
  209. display: flex;
  210. align-items: center;
  211. height: 88rpx;
  212. font-size: 32rpx;
  213. font-weight: bold;
  214. }
  215. .notes_textarea {
  216. position: relative;
  217. height: 284rpx;
  218. border: 1rpx solid #e5e5e5;
  219. textarea {
  220. box-sizing: border-box;
  221. padding: 16rpx 20rpx 75rpx;
  222. width: 100%;
  223. font-size: 32rpx;
  224. }
  225. .notes_num {
  226. position: absolute;
  227. right: 20rpx;
  228. bottom: 14rpx;
  229. color: #a6a6a6;
  230. font-size: 32rpx;
  231. }
  232. }
  233. }
  234. .btn {
  235. display: flex;
  236. justify-content: center;
  237. align-items: center;
  238. margin: 55rpx auto 65rpx;
  239. width: 690rpx;
  240. height: 100rpx;
  241. color: #fff;
  242. font-size: 32rpx;
  243. border-radius: 12rpx;
  244. background-color: #6fb6b8;
  245. }
  246. }
  247. </style>