productTable.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <div class="veTableCon">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <s-table
  5. class="sTable"
  6. ref="table"
  7. size="small"
  8. :rowKey="(record) => record.id"
  9. :columns="columns"
  10. :data="loadData"
  11. :row-selection="{ columnWidth: 40 }"
  12. @rowSelection="rowSelectionFun"
  13. :defaultLoadData="false"
  14. :style="{ maxHeight: 300+'px' }"
  15. :scroll="{ y:230 }"
  16. bordered>
  17. <template slot="price" slot-scope="text,record">
  18. <a-input-number
  19. :min="0"
  20. :step="1"
  21. :precision="2"
  22. :max="99999999"
  23. @blur="editAllPrice(record,'price')"
  24. placeholder="请输入"
  25. :disabled="disabledVal"
  26. v-model="record.price"
  27. :id="'productTable-price'+record.id "
  28. size="small"/>
  29. </template>
  30. <template slot="ruleValue" slot-scope="text,record">
  31. <a-input-number
  32. :min="0"
  33. :step="1"
  34. :precision="2"
  35. :max="99999999"
  36. :disabled="disabledVal"
  37. @blur="editAllPrice(record,'ruleValue')"
  38. placeholder="请输入"
  39. v-model="record.ruleValue"
  40. :id="'productTable-ruleValue'+record.id "
  41. size="small"/>
  42. </template>
  43. <!-- 操作 -->
  44. <template slot="action" slot-scope="text,record">
  45. <a-button
  46. size="small"
  47. type="link"
  48. class="button-error"
  49. :id="'productTable-del-btn'+record.id "
  50. :disabled="disabledVal"
  51. @click="handleDel(record)"
  52. >删除</a-button>
  53. </template>
  54. </s-table>
  55. </a-spin>
  56. </div>
  57. </template>
  58. <script>
  59. import { commonMixin } from '@/utils/mixin'
  60. import { STable } from '@/components'
  61. import { promoRuleProductList, deleteBatch, promoUpdateBatch } from '@/api/promoActive'
  62. export default {
  63. name: 'ProductTable',
  64. mixins: [commonMixin],
  65. components: { STable },
  66. props: {
  67. promoActiveSn: {
  68. type: String,
  69. default: ''
  70. },
  71. disabledVal: {
  72. type: Boolean,
  73. default: false
  74. }
  75. },
  76. data () {
  77. return {
  78. spinning: false,
  79. rowSelectionInfo: null,
  80. queryParam: {},
  81. dataListQty: '0',
  82. columns: [
  83. { title: '序号', dataIndex: 'no', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  84. { title: '产品编码', dataIndex: 'productCode', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  85. { title: '产品名称', dataIndex: 'productName', width: '20%', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  86. { title: '原厂编码', dataIndex: 'origCode', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  87. { title: '活动价', scopedSlots: { customRender: 'price' }, width: '10%', align: 'right' },
  88. { title: '返券金额', scopedSlots: { customRender: 'ruleValue' }, width: '10%', align: 'right' },
  89. { title: '参考终端价', dataIndex: 'terminalPrice', width: '10%', align: 'right', customRender: text => { return ((text || text == 0) ? this.toThousands(text) : '--') } },
  90. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  91. ],
  92. // 加载数据方法 必须为 Promise 对象
  93. loadData: parameter => {
  94. this.disabled = true
  95. this.spinning = true
  96. const params = Object.assign(parameter, this.queryParam)
  97. params.promoActiveSn = this.promoActiveSn
  98. return promoRuleProductList(params).then(res => {
  99. let data
  100. if (res.status == 200) {
  101. data = res.data
  102. const no = (data.pageNo - 1) * data.pageSize
  103. for (var i = 0; i < data.list.length; i++) {
  104. data.list[i].no = no + i + 1
  105. if (!data.list[i].price) {
  106. data.list[i].price = data.list[i].terminalPrice
  107. } else {
  108. data.list[i].price = data.list[i].price
  109. }
  110. }
  111. this.disabled = false
  112. this.dataListQty = res.data.count
  113. }
  114. this.spinning = false
  115. return data
  116. })
  117. }
  118. }
  119. },
  120. methods: {
  121. // 表格选中项
  122. rowSelectionFun (obj) {
  123. this.rowSelectionInfo = obj || null
  124. },
  125. // 批量修改价格
  126. editAllPrice (row, typeName) {
  127. let ajaxData = []
  128. if (typeName != 'all') {
  129. ajaxData.push({
  130. id: row.id,
  131. price: typeName === 'price' ? row.price : undefined,
  132. ruleValue: typeName === 'ruleValue' ? row.ruleValue : undefined
  133. })
  134. } else {
  135. ajaxData = row || []
  136. }
  137. promoUpdateBatch(ajaxData).then(res => {
  138. if (res.status == 200) {
  139. this.$refs.table.refresh(true)
  140. this.$refs.table.clearSelected() // 清空表格选中项
  141. }
  142. })
  143. },
  144. editMorePrice (numInfo) {
  145. if (!this.rowSelectionInfo || (this.rowSelectionInfo && this.rowSelectionInfo.selectedRows && this.rowSelectionInfo.selectedRows.length === 0)) {
  146. this.$message.warning('请选择要修改的产品!')
  147. return
  148. }
  149. const ajaxArr = this.rowSelectionInfo.selectedRows.map(item => { return { id: item.id, ruleValue: numInfo } })
  150. this.editAllPrice(ajaxArr, 'all')
  151. },
  152. // 删除
  153. handleDel (row) {
  154. const _this = this
  155. _this.spinning = true
  156. deleteBatch([row.id]).then(res => {
  157. if (res.status == 200) {
  158. _this.$message.success(res.message)
  159. _this.$refs.table.refresh()
  160. _this.spinning = false
  161. } else {
  162. _this.spinning = false
  163. }
  164. })
  165. },
  166. getDataNum () {
  167. return this.dataListQty
  168. },
  169. pageInit () {
  170. this.$nextTick(() => {
  171. this.$refs.table.refresh(true)
  172. })
  173. }
  174. },
  175. mounted () {
  176. this.pageInit()
  177. },
  178. activated () {
  179. this.pageInit()
  180. },
  181. beforeRouteEnter (to, from, next) {
  182. next(vm => {})
  183. }
  184. }
  185. </script>
  186. <style>
  187. /* form input[type='radio'], form input[type='checkbox'] {
  188. width: 15px;
  189. height: 14px;
  190. } */
  191. </style>