SelectProduct.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <el-dialog append-to-body :title="title" :visible.sync="innerVisible">
  3. <el-row>
  4. <el-col :span="24">
  5. <div style="float: right">
  6. <el-button size="mini" type="primary" @click="handleAdd">新建产品</el-button>
  7. <el-dropdown style="margin-left: 10px" trigger="click">
  8. <el-button icon="el-icon-more" size="mini" />
  9. <el-dropdown-menu slot="dropdown">
  10. <el-dropdown-item icon="el-icon-upload2">导入</el-dropdown-item>
  11. <el-dropdown-item icon="el-icon-download">导出</el-dropdown-item>
  12. </el-dropdown-menu>
  13. </el-dropdown>
  14. </div>
  15. </el-col>
  16. </el-row>
  17. <el-row>
  18. <el-col :span="24">
  19. <el-input
  20. v-model="queryForm.prodName"
  21. clearable
  22. placeholder="产品名称"
  23. style="width: 30%; margin-right: 10px"
  24. suffix-icon="el-icon-search" />
  25. <table-tool :check-list.sync="checkList" :columns="columns" style="float: right" />
  26. </el-col>
  27. </el-row>
  28. <el-table ref="table" v-loading="listLoading" :data="list" @selection-change="setSelectRows">
  29. <el-table-column align="center" type="selection" />
  30. <el-table-column
  31. v-for="(item, index) in finallyColumns"
  32. :key="index"
  33. align="center"
  34. :label="item.label"
  35. :prop="item.prop"
  36. show-overflow-tooltip
  37. :sortable="item.sortable"
  38. :width="item.width">
  39. <template #default="{ row }">
  40. <span v-if="item.prop === 'custStatus'">
  41. {{ row.custStatus == 10 ? '正常' : '异常' }}
  42. </span>
  43. <span v-else>{{ row[item.prop] }}</span>
  44. </template>
  45. </el-table-column>
  46. </el-table>
  47. <el-pagination
  48. background
  49. :current-page="queryForm.pageNo"
  50. :layout="layout"
  51. :page-size="queryForm.pageSize"
  52. :total="total"
  53. @current-change="handleCurrentChange"
  54. @size-change="handleSizeChange" />
  55. <span slot="footer">
  56. <el-button size="mini" type="primary" @click="save">保存</el-button>
  57. <el-button size="mini" @click="innerVisible = false">取消</el-button>
  58. </span>
  59. <!-- 新增编辑产品弹窗 -->
  60. <product-edit ref="edit" @fetch-data="fetchData" />
  61. </el-dialog>
  62. </template>
  63. <script>
  64. import productApi from '@/api/base/product'
  65. import TableTool from '@/components/table/TableTool'
  66. import ProductEdit from '@/views/base/product/components/ProductEdit'
  67. export default {
  68. name: 'SelectProduct',
  69. components: {
  70. TableTool,
  71. ProductEdit,
  72. },
  73. props: {
  74. title: {
  75. type: String,
  76. default: '选择',
  77. },
  78. multiple: Boolean,
  79. queryParams: {
  80. type: Object,
  81. default() {
  82. return {}
  83. },
  84. },
  85. },
  86. data() {
  87. return {
  88. innerVisible: false,
  89. queryForm: {
  90. prodName: '',
  91. type: '全部客户',
  92. pageNum: 1,
  93. pageSize: 10,
  94. },
  95. checkList: [],
  96. columns: [
  97. {
  98. label: '产品名称',
  99. width: 'auto',
  100. prop: 'prodName',
  101. // sortable: true,
  102. disableCheck: true,
  103. },
  104. {
  105. label: '产品类别',
  106. width: 'auto',
  107. prop: 'prodClass',
  108. },
  109. {
  110. label: '产品型号',
  111. width: 'auto',
  112. prop: 'prodCode',
  113. },
  114. {
  115. label: '签约代理价',
  116. width: 'auto',
  117. prop: 'agentPrice',
  118. },
  119. {
  120. label: '经销商价',
  121. width: 'auto',
  122. prop: 'distPrice',
  123. },
  124. {
  125. label: '建议成交价',
  126. width: 'auto',
  127. prop: 'guidPrice',
  128. },
  129. {
  130. label: '市场报价',
  131. width: 'auto',
  132. prop: 'marketPrice',
  133. },
  134. {
  135. label: '创建人',
  136. width: 'auto',
  137. prop: 'createdName',
  138. },
  139. {
  140. label: '创建时间',
  141. width: 'auto',
  142. prop: 'createdTime',
  143. // sortable: true,
  144. },
  145. ],
  146. list: [],
  147. listLoading: true,
  148. layout: 'total, sizes, prev, pager, next, jumper',
  149. total: 0,
  150. selectRows: [],
  151. }
  152. },
  153. computed: {
  154. finallyColumns() {
  155. return this.columns.filter((item) => this.checkList.includes(item.label))
  156. },
  157. },
  158. mounted() {
  159. this.fetchData()
  160. },
  161. methods: {
  162. open() {
  163. this.innerVisible = true
  164. },
  165. save() {
  166. this.innerVisible = false
  167. this.$emit('save', this.selectRows)
  168. },
  169. handleAdd() {
  170. this.$refs.edit.showEdit()
  171. },
  172. async fetchData() {
  173. this.listLoading = true
  174. let query = Object.assign(this.queryForm, this.queryParams)
  175. const {
  176. data: { list, total },
  177. } = await productApi.getList(query)
  178. this.list = list
  179. this.total = total
  180. this.listLoading = false
  181. },
  182. setSelectRows(val) {
  183. if (!this.multiple && val.length === this.list.length) {
  184. // 返回单条数据情况下-控制全选情况下单选第一条数据
  185. if (this.selectRows.length === 1) {
  186. this.$refs.table.clearSelection()
  187. return
  188. }
  189. this.$refs.table.clearSelection()
  190. this.$refs.table.toggleRowSelection(val.shift(), true)
  191. } else if (!this.multiple && val.length > 1) {
  192. // 返回单条数据情况下-控制选择当前点击数据
  193. this.$refs.table.clearSelection()
  194. this.$refs.table.toggleRowSelection(val.pop(), true)
  195. } else {
  196. this.selectRows = val
  197. }
  198. },
  199. handleSizeChange(val) {
  200. this.queryForm.pageSize = val
  201. this.fetchData()
  202. },
  203. handleCurrentChange(val) {
  204. this.queryForm.pageNo = val
  205. this.fetchData()
  206. },
  207. },
  208. }
  209. </script>
  210. <style scoped></style>