123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <template>
- <div class="veTableCon">
- <a-spin :spinning="spinning" tip="Loading...">
- <s-table
- class="sTable"
- ref="table"
- size="small"
- :rowKey="(record) => record.id"
- :columns="columns"
- :data="loadData"
- :row-selection="{ columnWidth: 40 }"
- @rowSelection="rowSelectionFun"
- :defaultLoadData="false"
- :style="{ maxHeight: 300+'px' }"
- :scroll="{ y:230 }"
- bordered>
- <template slot="price" slot-scope="text,record">
- <a-input-number
- :min="0"
- :step="1"
- :precision="2"
- :max="99999999"
- @blur="editAllPrice(record,'price')"
- placeholder="请输入"
- :disabled="disabledVal"
- v-model="record.price"
- :id="'productTable-price'+record.id "
- size="small"/>
- </template>
- <template slot="ruleValue" slot-scope="text,record">
- <a-input-number
- :min="0"
- :step="1"
- :precision="2"
- :max="99999999"
- :disabled="disabledVal"
- @blur="editAllPrice(record,'ruleValue')"
- placeholder="请输入"
- v-model="record.ruleValue"
- :id="'productTable-ruleValue'+record.id "
- size="small"/>
- </template>
- <!-- 操作 -->
- <template slot="action" slot-scope="text,record">
- <a-button
- size="small"
- type="link"
- class="button-error"
- :id="'productTable-del-btn'+record.id "
- :disabled="disabledVal"
- @click="handleDel(record)"
- >删除</a-button>
- </template>
- </s-table>
- </a-spin>
- </div>
- </template>
- <script>
- import { commonMixin } from '@/utils/mixin'
- import { STable } from '@/components'
- import { promoRuleProductList, deleteBatch, promoUpdateBatch } from '@/api/promoActive'
- export default {
- name: 'ProductTable',
- mixins: [commonMixin],
- components: { STable },
- props: {
- promoActiveSn: {
- type: String,
- default: ''
- },
- disabledVal: {
- type: Boolean,
- default: false
- }
- },
- data () {
- return {
- spinning: false,
- rowSelectionInfo: null,
- queryParam: {},
- dataListQty: '0',
- columns: [
- { title: '序号', dataIndex: 'no', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
- { title: '产品编码', dataIndex: 'productCode', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
- { title: '产品名称', dataIndex: 'productName', width: '20%', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
- { title: '原厂编码', dataIndex: 'origCode', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
- { title: '活动价', scopedSlots: { customRender: 'price' }, width: '10%', align: 'right' },
- { title: '返券金额', scopedSlots: { customRender: 'ruleValue' }, width: '10%', align: 'right' },
- { title: '参考终端价', dataIndex: 'terminalPrice', width: '10%', align: 'right', customRender: text => { return ((text || text == 0) ? this.toThousands(text) : '--') } },
- { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
- ],
- // 加载数据方法 必须为 Promise 对象
- loadData: parameter => {
- this.disabled = true
- this.spinning = true
- const params = Object.assign(parameter, this.queryParam)
- params.promoActiveSn = this.promoActiveSn
- return promoRuleProductList(params).then(res => {
- let data
- if (res.status == 200) {
- data = res.data
- const no = (data.pageNo - 1) * data.pageSize
- for (var i = 0; i < data.list.length; i++) {
- data.list[i].no = no + i + 1
- if (!data.list[i].price) {
- data.list[i].price = data.list[i].terminalPrice
- } else {
- data.list[i].price = data.list[i].price
- }
- }
- this.disabled = false
- this.dataListQty = res.data.count
- }
- this.spinning = false
- return data
- })
- }
- }
- },
- methods: {
- // 表格选中项
- rowSelectionFun (obj) {
- this.rowSelectionInfo = obj || null
- },
- // 批量修改价格
- editAllPrice (row, typeName) {
- let ajaxData = []
- if (typeName != 'all') {
- ajaxData.push({
- id: row.id,
- price: typeName === 'price' ? row.price : undefined,
- ruleValue: typeName === 'ruleValue' ? row.ruleValue : undefined
- })
- } else {
- ajaxData = row || []
- }
- promoUpdateBatch(ajaxData).then(res => {
- if (res.status == 200) {
- this.$refs.table.refresh(true)
- this.$refs.table.clearSelected() // 清空表格选中项
- }
- })
- },
- editMorePrice (numInfo) {
- if (!this.rowSelectionInfo || (this.rowSelectionInfo && this.rowSelectionInfo.selectedRows && this.rowSelectionInfo.selectedRows.length === 0)) {
- this.$message.warning('请选择要修改的产品!')
- return
- }
- const ajaxArr = this.rowSelectionInfo.selectedRows.map(item => { return { id: item.id, ruleValue: numInfo } })
- this.editAllPrice(ajaxArr, 'all')
- },
- // 删除
- handleDel (row) {
- const _this = this
- _this.spinning = true
- deleteBatch([row.id]).then(res => {
- if (res.status == 200) {
- _this.$message.success(res.message)
- _this.$refs.table.refresh()
- _this.spinning = false
- } else {
- _this.spinning = false
- }
- })
- },
- getDataNum () {
- return this.dataListQty
- },
- pageInit () {
- this.$nextTick(() => {
- this.$refs.table.refresh(true)
- })
- }
- },
- mounted () {
- this.pageInit()
- },
- activated () {
- this.pageInit()
- },
- beforeRouteEnter (to, from, next) {
- next(vm => {})
- }
- }
- </script>
- <style>
- /* form input[type='radio'], form input[type='checkbox'] {
- width: 15px;
- height: 14px;
- } */
- </style>
|