chooseActive.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <a-modal
  3. centered
  4. :footer="null"
  5. :maskClosable="false"
  6. title="促销品列表"
  7. v-model="isShow"
  8. @cancle="cansel"
  9. width="80%">
  10. <a-card size="small" :bordered="false" class="productInfoList-wrap">
  11. <!-- 列表 -->
  12. <s-table
  13. class="sTable"
  14. ref="table"
  15. size="small"
  16. :row-selection="{
  17. selectedRowKeys: selectedRowKeys,
  18. onChange: onChange,
  19. onSelect: onSelectChange,
  20. onSelectAll: onSelectAllChange,
  21. getCheckboxProps: record => ({
  22. props: {
  23. disabled: record.cost == undefined||record.cost==0||record.productPrice==0||record.productPrice==undefined, // Column configuration not to be checked
  24. }
  25. })
  26. }"
  27. :rowKey="(record) => record.id"
  28. :columns="columns"
  29. :data="loadData"
  30. :defaultLoadData="false"
  31. :scroll="{ x: 900, y: 350 }"
  32. bordered>
  33. <!-- 销售数量 -->
  34. <template slot="salesNums" slot-scope="text, record">
  35. <a-input-number
  36. size="small"
  37. :max="999999"
  38. :min="1"
  39. v-model="record.qty"
  40. :precision="0"
  41. :step="1"
  42. />
  43. </template>
  44. </s-table>
  45. <div style="display: flex;justify-content: center;padding: 10px 0;">
  46. <a-button
  47. size="large"
  48. type="primary"
  49. :loading="newLoading"
  50. class="button-primary"
  51. @click="handleSubmit"
  52. style="padding: 0 60px;">
  53. 确定
  54. </a-button>
  55. <a-button size="large" :loading="newLoading" style="padding: 0 60px;margin-left: 15px;font-size: 12px;" @click="cansel">
  56. 取消
  57. </a-button>
  58. </div>
  59. </a-card>
  60. </a-modal>
  61. </template>
  62. <script>
  63. import { STable, VSelect } from '@/components'
  64. import { getPromoGoodsList } from '@/api/salesDetail'
  65. export default {
  66. name: 'ChooseProduct',
  67. components: { STable, VSelect },
  68. props: {
  69. openModal: { // 弹框显示状态
  70. type: Boolean,
  71. default: false
  72. },
  73. newLoading: Boolean
  74. },
  75. data () {
  76. return {
  77. isShow: this.openModal,
  78. selectedRowKeys: [], // Check here to configure the default column
  79. selectedRows: [],
  80. spinning: false,
  81. list: [],
  82. salesBillDetailSn: null,
  83. buyerSn: '',
  84. nowData: null,
  85. // 加载数据方法 必须为 Promise 对象
  86. loadData: parameter => {
  87. this.spinning = true
  88. return getPromoGoodsList(Object.assign(parameter, { salesBillDetailSn: this.nowData.salesBillDetailSn || undefined, buyerSn: this.buyerSn })).then(res => {
  89. let data
  90. if (res.status == 200) {
  91. data = res.data
  92. const no = (data.pageNo - 1) * data.pageSize
  93. for (var i = 0; i < data.list.length; i++) {
  94. data.list[i].no = no + i + 1
  95. data.list[i].qty = 1
  96. data.list[i].promotionSourceSn = this.nowData.salesBillDetailSn
  97. }
  98. }
  99. this.spinning = false
  100. return data
  101. })
  102. }
  103. }
  104. },
  105. computed: {
  106. columns () {
  107. const arr = [
  108. { title: '产品编码', dataIndex: 'code', align: 'center', customRender: function (text) { return text || '--' } },
  109. { title: '产品名称', dataIndex: 'name', align: 'center', customRender: function (text) { return text || '--' } },
  110. // { title: '原售价', dataIndex: 'productPrice', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  111. // { title: '促销价', dataIndex: 'promoRuleGoods.goodsPrice', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  112. { title: '数量', dataIndex: 'qty', scopedSlots: { customRender: 'salesNums' }, width: 100, align: 'center' },
  113. { title: '单位', dataIndex: 'unit', width: 60, align: 'center', customRender: function (text) { return text || '--' } },
  114. { title: '促销类型', dataIndex: 'promoRuleGoods.promoRuleTypeName', width: 100, align: 'center', customRender: function (text) { return text || '--' } }
  115. ]
  116. if (this.$hasPermissions('B_isShowCost')) { // 成本价权限
  117. arr.splice(2, 0, { title: '成本价', dataIndex: 'cost', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  118. }
  119. if (this.$hasPermissions('B_isShowPrice')) { // 售价权限
  120. const ind = this.$hasPermissions('B_isShowCost') ? 3 : 2
  121. arr.splice(ind, 0, { title: '原售价', dataIndex: 'productPrice', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  122. arr.splice(ind + 1, 0, { title: '促销价', dataIndex: 'promoRuleGoods.goodsPrice', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  123. }
  124. return arr
  125. }
  126. },
  127. methods: {
  128. onChange (selectedRowKeys, selectedRows) {
  129. this.selectedRowKeys = selectedRowKeys
  130. },
  131. onSelectChange (record, selected, selectedRows, nativeEvent) {
  132. if (selected) { // 选择
  133. this.selectedRows.push(record)
  134. } else { // 取消
  135. this.selectedRows = selectedRows
  136. }
  137. },
  138. // 本页全选/取消全选
  139. onSelectAllChange (selected, selectedRows, changeRows) {
  140. const _this = this
  141. if (selected) { // 选择
  142. this.selectedRows = [...this.selectedRows, ...changeRows]
  143. } else { // 取消
  144. const arrId = []
  145. this.selectedRows.map((item, index) => {
  146. this.selectedRows.map((subItem, ind) => {
  147. if (item.id == subItem.id) {
  148. arrId.push(index)
  149. }
  150. })
  151. })
  152. arrId.map((item, index) => {
  153. _this.selectedRows = _this.selectedRows.slice(item, item + 1)
  154. })
  155. }
  156. },
  157. // 选择产品
  158. handleSubmit () {
  159. const _this = this
  160. if (_this.selectedRowKeys.length < 1) {
  161. _this.$message.warning('请选择促销品!')
  162. return
  163. }
  164. const obj = []
  165. _this.selectedRows.map(item => {
  166. obj.push({
  167. showCost: item.cost,
  168. price: item.promoRuleGoods.goodsPrice,
  169. origPrice: item.productPrice,
  170. packQty: item.packQty,
  171. productSn: item.productSn,
  172. promotionSourceSn: item.promotionSourceSn,
  173. promotionActivitySn: item.promoRuleGoods.promoActiveSn,
  174. promotionActivityName: item.promoRuleGoods.promoActiveName,
  175. promotionRules: item.promoRuleGoods.promoRuleSn,
  176. promoGoodsType: item.promoRuleGoods.promoGoodsType,
  177. qty: item.qty,
  178. promotableFlag: 0, // 可促销标记 有活动的传1,没活动的传0
  179. promotionFlag: 1 // 促销标记 正品传0,促销品传1
  180. })
  181. })
  182. _this.$emit('ok', obj)
  183. },
  184. cansel () {
  185. this.$emit('close')
  186. },
  187. getData (data, buyerSn) {
  188. const _this = this
  189. _this.buyerSn = buyerSn
  190. _this.nowData = data
  191. setTimeout(() => (
  192. _this.$refs.table.refresh(true)
  193. ), 300)
  194. }
  195. },
  196. watch: {
  197. // 父页面传过来的弹框状态
  198. openModal (newValue, oldValue) {
  199. this.isShow = newValue
  200. },
  201. // 重定义的弹框状态
  202. isShow (newValue, oldValue) {
  203. if (!newValue) {
  204. this.selectedRows = []
  205. this.selectedRowKeys = []
  206. this.$emit('close')
  207. }
  208. }
  209. }
  210. }
  211. </script>