product.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view class="main-container">
  5. <wk-nav-bar :title="navTitle">
  6. <!-- #ifndef MP-WEIXIN -->
  7. <button class="button white-btn" @click="handleConfirm">
  8. 确定
  9. </button>
  10. <!-- #endif -->
  11. </wk-nav-bar>
  12. <wk-search-box @search="handleSearch" />
  13. <view class="list-scroll">
  14. <wk-scroll-view
  15. :status="listStatus"
  16. :refresh="false"
  17. class="list-scroll"
  18. @loadmore="getList()">
  19. <wk-select-list
  20. v-if="listData.length > 0"
  21. v-model="defaultVal"
  22. :list="listData"
  23. :label-field="typeObj.labelField"
  24. :value-field="typeObj.valueField"
  25. :max="bridge.maxlength"
  26. @change="handleChange">
  27. <template v-slot:default="{ scopeData }">
  28. <view>{{ scopeData.name }}</view>
  29. <view class="desc-text">
  30. {{ scopeData.categoryName }}
  31. </view>
  32. </template>
  33. </wk-select-list>
  34. </wk-scroll-view>
  35. </view>
  36. <!-- #ifdef MP-WEIXIN -->
  37. <view class="footer-btn-group">
  38. <button class="button" @click="handleConfirm">
  39. 确定
  40. </button>
  41. </view>
  42. <!-- #endif -->
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import { GetSaleList } from 'API/crm/product'
  48. import { deepCopy } from '@/utils/lib.js'
  49. export default {
  50. name: 'ProductChoose',
  51. data() {
  52. return {
  53. listData: [],
  54. selectedList: [],
  55. defaultVal: [],
  56. listStatus: 'more',
  57. params: {
  58. page: 0,
  59. limit: 15,
  60. search: '',
  61. type: 4
  62. },
  63. typeObj: {
  64. labelField: 'name',
  65. valueField: 'productId'
  66. },
  67. routerQuery: {},
  68. bridge: {}
  69. }
  70. },
  71. computed: {
  72. navTitle() {
  73. return this.bridge.title || '选择产品'
  74. }
  75. },
  76. onLoad(options) {
  77. this.routerQuery = options || {}
  78. this.bridge = getApp().globalData.selectedValBridge.product || {}
  79. this.defaultVal = this.bridge.defaultVal || []
  80. this.handleChange(this.defaultVal)
  81. this.getList()
  82. },
  83. onUnload() {
  84. getApp().globalData.selectedValBridge = {}
  85. },
  86. methods: {
  87. /**
  88. * 获取选项列表
  89. */
  90. getList() {
  91. if (!this.$isEmpty(this.bridge.list)) {
  92. this.listData = this.bridge.list
  93. return
  94. }
  95. const otherParams = this.bridge.params || {} // 附加参数
  96. const request = this.bridge.request || GetSaleList
  97. if (!request) return
  98. this.params.page++
  99. this.listStatus = 'loading'
  100. request({
  101. ...this.params,
  102. ...otherParams
  103. }).then(res => {
  104. if (this.params.page === 1) {
  105. this.listData = []
  106. }
  107. console.log(res.list)
  108. this.listData = this.listData.concat(res.list)
  109. this.listStatus = res.lastPage ? 'noMore' : 'more'
  110. }).catch(() => {
  111. this.listStatus = 'more'
  112. })
  113. },
  114. /**
  115. * 搜索
  116. * @param {String} keyword
  117. */
  118. handleSearch(keyword = '') {
  119. this.params.search = keyword || ''
  120. this.params.page = 0
  121. this.getList()
  122. },
  123. /**
  124. * 保存记录选择的项
  125. * @param {Object} data
  126. */
  127. handleChange(data) {
  128. this.selectedList = data
  129. },
  130. /**
  131. * 确认选择,通知上一级页面,员工已经选择
  132. */
  133. handleConfirm() {
  134. const data = {
  135. guid: this.bridge.guid,
  136. bridge: this.bridge,
  137. data: this.selectedList
  138. }
  139. if (this.bridge.config && this.bridge.config.checkFn) {
  140. const res = this.bridge.config.checkFn(data)
  141. if (!res) return
  142. }
  143. uni.$emit('selected-product', data)
  144. this.$Router.navigateBack()
  145. }
  146. }
  147. }
  148. </script>
  149. <style scoped lang="scss">
  150. .main-container {
  151. display: flex;
  152. flex-direction: column;
  153. overflow: hidden;
  154. .list-scroll {
  155. flex: 1;
  156. overflow: auto;
  157. padding-bottom: 20rpx;
  158. .desc-text {
  159. font-size: 22rpx;
  160. color: #666666;
  161. }
  162. }
  163. }
  164. </style>