subsidyAddModal.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <a-drawer
  3. title="新增"
  4. placement="right"
  5. :visible="isShow"
  6. width="80%"
  7. :get-container="false"
  8. :wrap-style="{ position: 'absolute' }"
  9. @close="isShow = false"
  10. wrapClassName="subsidyAdd-modal jg-page-wrap"
  11. >
  12. <a-spin :spinning="spinning" tip="Loading...">
  13. <!-- 搜索条件 -->
  14. <div ref="searchBox" class="table-page-search-wrapper">
  15. <a-form-model
  16. ref="ruleForm"
  17. class="form-model-con"
  18. layout="inline">
  19. <a-row :gutter="5" type="flex" justify="center">
  20. <a-col :md="6" :sm="24">
  21. <a-form-model-item label="产品编码">
  22. <a-input id="subsidyAdd-code" ref="searchProductCode" v-model.trim="queryParam.productCode" allowClear placeholder="请输入产品编码"/>
  23. </a-form-model-item>
  24. </a-col>
  25. <a-col :md="6" :sm="24">
  26. <a-form-model-item label="原厂编码">
  27. <a-input id="subsidyAdd-productOrigCode" ref="productOrigCode" v-model.trim="queryParam.productOrigCode" allowClear placeholder="请输入原厂编码"/>
  28. </a-form-model-item>
  29. </a-col>
  30. <a-col :md="6" :sm="24">
  31. <a-form-model-item label="产品名称">
  32. <a-input id="subsidyAdd-name" v-model.trim="queryParam.productName" allowClear placeholder="请输入产品名称"/>
  33. </a-form-model-item>
  34. </a-col>
  35. <a-col :md="6" :sm="24">
  36. <a-form-model-item label="产品分类">
  37. <productType id="subsidyAdd-productType" :isDealer="true" @change="changeProductType" v-model="productType"></productType>
  38. </a-form-model-item>
  39. </a-col>
  40. <a-col :md="6" :sm="24">
  41. <a-form-model-item label="产品品牌">
  42. <productBrand id="subsidyAdd-productBrandSn" v-model="queryParam.productBrandSn"></productBrand>
  43. </a-form-model-item>
  44. </a-col>
  45. <a-col flex="auto" style="margin-bottom: 10px;">
  46. <a-button type="primary" @click="$refs.table.refresh(true)" id="subsidyAdd-refresh">查询</a-button>
  47. <a-button style="margin-left: 5px" @click="resetSearchForm" id="subsidyAdd-reset">重置</a-button>
  48. </a-col>
  49. </a-row>
  50. </a-form-model>
  51. </div>
  52. <div class="subsidyAdd-modal-table">
  53. <div class="table-operator">
  54. <span class="subsidyRequired">*</span>产品抵扣<a-input-number
  55. id="subsidyAdd-name"
  56. v-model.trim="subsidyAmount"
  57. style="width: 20%;margin:0 10px;"
  58. :min="0.01"
  59. :max="99999999"
  60. :precision="2"
  61. :step="1"
  62. placeholder="请输入"/>元
  63. <a-button id="subsidyAdd-handlePlAdd" style="margin:0 10px;" type="primary" @click="handlePlAdd">批量添加</a-button>
  64. <span style="margin-left: 10px;" v-if="selectTotal">已选{{ selectTotal }}项</span>
  65. </div>
  66. <!-- 列表 -->
  67. <s-table
  68. class="sTable"
  69. ref="table"
  70. size="small"
  71. :rowKey="(record) => record.id"
  72. :columns="columns"
  73. :data="loadData"
  74. :style="{ height: 580+'px' }"
  75. :scroll="{ y: 530 }"
  76. :defaultLoadData="false"
  77. :row-selection="{ columnWidth: 40 }"
  78. @rowSelection="rowSelectionFun"
  79. bordered>
  80. <!-- 产品分类 -->
  81. <template slot="productType" slot-scope="text, record">
  82. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  83. <span v-else>--</span>
  84. </template>
  85. <!-- 包装数 -->
  86. <template slot="baozh" slot-scope="text, record">
  87. {{ record.packQty||'--' }}{{ record.packQty ? record.unit : '' }}/{{ record.packQtyUnit||'--' }}
  88. </template>
  89. </s-table>
  90. </div>
  91. </a-spin>
  92. </a-drawer>
  93. </template>
  94. <script>
  95. import { commonMixin } from '@/utils/mixin'
  96. import { STable } from '@/components'
  97. // 组件
  98. import productType from '@/views/common/productType.js'
  99. import productBrand from '@/views/common/productBrand.js'
  100. // 接口
  101. import { queryProductPageList } from '@/api/shopProductSubsidy'
  102. export default {
  103. name: 'SubsidyAddModal',
  104. components: { STable, productType, productBrand },
  105. mixins: [commonMixin],
  106. props: {
  107. openModal: {
  108. // 弹框显示状态
  109. type: Boolean,
  110. default: false
  111. }
  112. },
  113. data () {
  114. const _this = this
  115. return {
  116. spinning: false,
  117. isShow: this.openModal, // 是否打开弹框
  118. productType: [], // 产品分类
  119. category: [], // 商城类目val
  120. // 查询条件
  121. queryParam: {
  122. productName: '', // 产品名称
  123. productCode: '', // 产品编码
  124. productOrigCode: '', // 原厂编码
  125. productBrandSn: undefined, // 产品品牌
  126. productTypeSn1: '', // 产品一级分类
  127. productTypeSn2: '', // 产品二级分类
  128. productTypeSn3: '' // 产品三级分类
  129. },
  130. subsidyAmount: undefined, // 产品抵扣
  131. rowSelectionInfo: null, // 已选产品
  132. columns: [
  133. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  134. { title: '产品编码', dataIndex: 'productCode', width: '13%', align: 'center', customRender: function (text) { return text || '--' } },
  135. { title: '产品名称', dataIndex: 'productName', width: '20%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  136. { title: '原厂编码', dataIndex: 'productOrigCode', width: '13%', align: 'center', customRender: function (text) { return text || '--' } },
  137. { title: '商城售价', dataIndex: 'price', width: '10%', align: 'center', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  138. { title: '终端价', dataIndex: 'terminalPrice', width: '10%', align: 'center', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  139. { title: '品牌', dataIndex: 'productBrandName', width: '13%', align: 'center', customRender: function (text) { return text || '--' } },
  140. { title: '产品分类', width: '15%', align: 'center', scopedSlots: { customRender: 'productType' } },
  141. { title: '包装数', width: '10%', align: 'center', scopedSlots: { customRender: 'baozh' } },
  142. { title: '单位', dataIndex: 'unit', width: '10%', align: 'center', customRender: function (text) { return text || '--' } }
  143. ],
  144. // 加载数据方法 必须为 Promise 对象
  145. loadData: parameter => {
  146. this.disabled = true
  147. this.spinning = true
  148. const queryParams = Object.assign(parameter, this.queryParam)
  149. return queryProductPageList(queryParams).then(res => {
  150. let data
  151. if (res.status == 200) {
  152. data = res.data
  153. const no = (data.pageNo - 1) * data.pageSize
  154. for (var i = 0; i < data.list.length; i++) {
  155. data.list[i].no = no + i + 1
  156. }
  157. this.disabled = false
  158. }
  159. this.spinning = false
  160. return data
  161. })
  162. }
  163. }
  164. },
  165. computed: {
  166. // 已选数量
  167. selectTotal () {
  168. return this.rowSelectionInfo && this.rowSelectionInfo.selectedRows.length
  169. }
  170. },
  171. methods: {
  172. // 表格选中项
  173. rowSelectionFun (obj) {
  174. this.rowSelectionInfo = obj || null
  175. },
  176. // 产品分类 change
  177. changeProductType (val, opt) {
  178. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  179. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  180. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  181. },
  182. // 批量添加
  183. handlePlAdd () {
  184. if (!this.selectTotal) {
  185. this.$message.info('请选择产品')
  186. return
  187. }
  188. if (!this.subsidyAmount) {
  189. this.$message.info('产品抵扣金额不能为空')
  190. return
  191. }
  192. const chooseList = JSON.parse(JSON.stringify(this.rowSelectionInfo.selectedRows))
  193. const newList = chooseList.map(item => {
  194. item.subsidyAmount = this.subsidyAmount
  195. delete item.id
  196. return item
  197. })
  198. this.$emit('plAdd', newList)
  199. },
  200. // 重置
  201. resetSearchForm () {
  202. this.queryParam.productName = ''
  203. this.queryParam.productCode = ''
  204. this.queryParam.productOrigCode = ''
  205. this.queryParam.productBrandSn = undefined
  206. this.queryParam.productTypeSn1 = ''
  207. this.queryParam.productTypeSn2 = ''
  208. this.queryParam.productTypeSn3 = ''
  209. this.subsidyAmount = undefined
  210. this.productType = []
  211. this.category = []
  212. this.rowSelectionInfo = null
  213. this.$refs.table.clearSelected()
  214. this.$refs.table.refresh()
  215. }
  216. },
  217. watch: {
  218. // 父页面传过来的弹框状态
  219. openModal (newValue, oldValue) {
  220. this.isShow = newValue
  221. },
  222. // 重定义的弹框状态
  223. isShow (newValue, oldValue) {
  224. if (!newValue) {
  225. this.$emit('close')
  226. } else {
  227. this.resetSearchForm()
  228. }
  229. }
  230. }
  231. }
  232. </script>
  233. <style lang="less" scoped>
  234. .subsidyAdd-modal {
  235. .ant-drawer-body {
  236. padding: 10px 20px;
  237. .subsidyAdd-modal-table{
  238. padding-top: 10px;
  239. }
  240. }
  241. .table-operator{
  242. .subsidyRequired{
  243. margin-right: 5px;
  244. color:#ED1c24;
  245. }
  246. }
  247. }
  248. </style>