main.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <el-dialog title="商品选择器" width="840px" :visible.sync="dialogVisible" :append-to-body="false"
  3. :modal-append-to-body="false" :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false"
  4. @closed="handleClose" class="purchasePlan-picker">
  5. <div class="purchasePlan-picker__body">
  6. <div class="purchasePlan-picker__filter">
  7. <div class="filter-item">
  8. <el-input v-model="searchParams.keyword" clearable placeholder="请输入单号" style="width: 160px" />
  9. </div>
  10. <div class="filter-item">
  11. <el-button type="primary" @click="handleSearch">搜索 </el-button>
  12. </div>
  13. </div>
  14. <el-table ref="purchasePlanTable" v-loading="loading" :data="purchasePlanData.data" border row-key="id"
  15. @selection-change="handleSelectionChange" @row-click="handleRowClick" max-height="400" style="width: 100%; min-height: 400px">
  16. <el-table-column v-if="limit === 1" label="选择" width="55" align="center">
  17. <template slot-scope="scope">
  18. <el-radio v-model="radioGuide" :label="scope.row"
  19. :disabled="selectedIds.some(v => v === scope.row.id)"></el-radio>
  20. </template>
  21. </el-table-column>
  22. <el-table-column v-else type="selection" label="选择" width="55" :selectable="checkDisable" reserve-selection
  23. align="center" />
  24. <el-table-column v-for="column in columns" :key="column.label" align="center" v-bind="column" />
  25. </el-table>
  26. <div class="purchasePlan-picker__tools">
  27. <div class="tools">
  28. </div>
  29. <el-pagination v-if="purchasePlanData.data_total" background :page-sizes="[10, 30, 50, 100]"
  30. :total="purchasePlanData.data_total" layout="total, sizes, prev, next, pager, jumper"
  31. @size-change="handleSizeChange" @current-change="handleCurrentChange" />
  32. </div>
  33. </div>
  34. <span slot="footer" class="dialog-footer">
  35. <el-button @click="handleCancel">取 消</el-button>
  36. <el-button type="primary" @click="handleConfirm">确 定</el-button>
  37. </span>
  38. </el-dialog>
  39. </template>
  40. <script>
  41. import * as DefaultOptions from './defaultOptions'
  42. import request from '@/utils/request'
  43. export default {
  44. name: 'EnPurchasePlan',
  45. props: {
  46. ...DefaultOptions.props
  47. },
  48. data() {
  49. return {
  50. ...DefaultOptions.data,
  51. dialogVisible: false,
  52. selected: [],
  53. radioGuide: '',
  54. purchasePlanParams: {
  55. page_no: 1,
  56. page_size: 10,
  57. market_enable: true,
  58. },
  59. searchParams: {
  60. sn: ''
  61. },
  62. purchasePlanData: {
  63. data: [],
  64. data_total: 0
  65. },
  66. // 加载采购计划列表
  67. loading: false
  68. }
  69. },
  70. mounted() {
  71. this.getGoodsList()
  72. },
  73. watch: {
  74. show: {
  75. immediate: true,
  76. handler(newVal) {
  77. this.$nextTick(() => {
  78. this.dialogVisible = newVal
  79. })
  80. }
  81. }
  82. },
  83. methods: {
  84. checkDisable(row, index) {
  85. return this.selectedIds.some(v => v === row.id) ? 0 : 1
  86. },
  87. // 关闭
  88. handleClose() {
  89. this.$nextTick(this.close)
  90. this.dialogVisible = false
  91. this.$emit('closed')
  92. },
  93. // 取消
  94. handleCancel() {
  95. this.dialogVisible = false
  96. this.$emit('cancel')
  97. typeof this.reject === 'function' && this.reject('取消了')
  98. },
  99. // 确认
  100. handleConfirm() {
  101. if (this.limit === 1) {
  102. if (!this.radioGuide) return this.$message.error('请选择采购计划')
  103. } else {
  104. if (!this.selected.length) return this.$message.error('请选择采购计划')
  105. }
  106. this.dialogVisible = false
  107. let purchasePlans = this.limit === 1 ? [this.radioGuide] : this.selected
  108. purchasePlans = JSON.parse(JSON.stringify(purchasePlans))
  109. this.$emit('confirm', purchasePlans)
  110. typeof this.resolve === 'function' && this.resolve(purchasePlans)
  111. this.$emit('close')
  112. },
  113. // 选择
  114. handleSelectionChange(val) {
  115. this.selected = val
  116. },
  117. // 分页大小发生改变
  118. handleSizeChange(size) {
  119. this.purchasePlanParams.page_size = size
  120. this.getGoodsList()
  121. },
  122. // 当前页数发生改版
  123. handleCurrentChange(current) {
  124. this.purchasePlanParams.page_no = current
  125. this.getGoodsList()
  126. },
  127. // 搜索
  128. handleSearch() {
  129. this.purchasePlanParams.page_no = 1
  130. this.purchasePlanParams = {
  131. ...this.purchasePlanParams,
  132. ...this.searchParams
  133. }
  134. this.getGoodsList()
  135. },
  136. // 点击了某行
  137. handleRowClick(row) {
  138. if (this.limit === 1) {
  139. this.radioGuide = row
  140. } else {
  141. this.$refs.purchasePlanTable.toggleRowSelection(row)
  142. }
  143. },
  144. // 获取采购计划列表
  145. async getGoodsList() {
  146. this.loading = true
  147. const params = JSON.parse(JSON.stringify(this.purchasePlanParams))
  148. console.log(params);
  149. request({
  150. url: this.goodsApi,
  151. method: 'get',
  152. loading: false,
  153. params: {
  154. ...params,
  155. ...this.purchasePlanApiParams,
  156. }
  157. }).then(response => {
  158. this.loading = false
  159. if(response.records==undefined){
  160. this.purchasePlanData = response
  161. }else{
  162. response.data=response.records
  163. response.data_total=response.total
  164. this.purchasePlanData = response
  165. }
  166. })
  167. }
  168. }
  169. }
  170. </script>
  171. <style lang="scss" scoped>
  172. .purchasePlan-picker {
  173. clear: both;
  174. .purchasePlan-picker__filter {
  175. float: right;
  176. }
  177. /deep/ {
  178. .el-dialog__body {
  179. padding-top: 20px;
  180. padding-bottom: 20px;
  181. }
  182. .el-dialog__header {
  183. padding: 9px 20px 10px;
  184. border-bottom: 1px solid #e5e5e5;
  185. text-shadow: 0 1px 0 #fff;
  186. background-color: #efefef;
  187. }
  188. .el-dialog__footer {
  189. border-top: solid 1px #e5e5e5;
  190. background: #f5f5f5;
  191. }
  192. .el-table .el-table__body-wrapper .el-table__row {
  193. cursor: pointer;
  194. }
  195. }
  196. &__filter {
  197. display: flex;
  198. align-items: center;
  199. background-color: #fff;
  200. border-right: none;
  201. position: relative;
  202. margin-bottom: 10px;
  203. .filter-item {
  204. display: flex;
  205. align-items: center;
  206. }
  207. .filter-item+.filter-item {
  208. margin-left: 10px;
  209. }
  210. .filter-item:last-child {
  211. flex: 1;
  212. margin-left: 20px;
  213. /deep/ .el-button {
  214. width: 100%;
  215. max-width: 120px;
  216. font-weight: bold;
  217. }
  218. }
  219. }
  220. &__body {
  221. max-height: 650px;
  222. overflow: hidden auto;
  223. }
  224. &__tools {
  225. display: flex;
  226. align-items: center;
  227. justify-content: space-between;
  228. margin-top: 10px;
  229. .tools {
  230. display: flex;
  231. }
  232. }
  233. }
  234. </style>