chooseProductModal.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <a-drawer
  3. :zIndex="zIndex"
  4. :title="title"
  5. placement="right"
  6. :visible="visible"
  7. :width="width"
  8. :get-container="false"
  9. :wrap-style="{ position: 'absolute' }"
  10. @close="onClose"
  11. wrapClassName="chooseProduct-drawer">
  12. <a-spin :spinning="spinning" tip="Loading...">
  13. <div class="chooseProduct-drawer-box">
  14. <!-- 搜索条件 -->
  15. <div class="table-page-search-wrapper">
  16. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  17. <a-row :gutter="15">
  18. <a-col :md="5" :sm="24">
  19. <a-form-model-item label="产品编码">
  20. <a-input id="purchaseOrderEdit-code" ref="searchProductCode" v-model.trim="queryParam.code" allowClear placeholder="请输入产品编码"/>
  21. </a-form-model-item>
  22. </a-col>
  23. <a-col :md="5" :sm="24">
  24. <a-form-model-item label="产品名称">
  25. <a-input id="purchaseOrderEdit-name" v-model.trim="queryParam.name" allowClear placeholder="请输入产品名称"/>
  26. </a-form-model-item>
  27. </a-col>
  28. <!-- <a-col :md="4" :sm="24">
  29. <a-form-model-item label="原厂编码">
  30. <a-input id="purchaseOrderEdit-origCode" v-model.trim="queryParam.origCode" allowClear placeholder="请输入原厂编码"/>
  31. </a-form-model-item>
  32. </a-col> -->
  33. <a-col :md="5" :sm="24">
  34. <a-form-item label="产品分类">
  35. <ProductType id="purchaseOrderEdit-productType" :isDealer="true" :tenantId="$route.params.dealerSn" @change="changeProductType" v-model="productType"></ProductType>
  36. </a-form-item>
  37. </a-col>
  38. <a-col :md="5" :sm="24">
  39. <a-form-item label="产品品牌">
  40. <ProductBrand id="purchaseOrderEdit-productBrand" :tenantId="$route.params.dealerSn" v-model="queryParam.productBrandSn"></ProductBrand>
  41. </a-form-item>
  42. </a-col>
  43. <a-col :md="4" :sm="24" style="margin-bottom: 10px;">
  44. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="purchaseOrderEdit-refresh">查询</a-button>
  45. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="purchaseOrderEdit-reset">重置</a-button>
  46. </a-col>
  47. </a-row>
  48. </a-form>
  49. </div>
  50. <!-- 列表 -->
  51. <s-table
  52. class="sTable"
  53. ref="table"
  54. size="small"
  55. :rowKey="(record) => record.id"
  56. :columns="columns"
  57. :data="loadData"
  58. :defaultLoadData="false"
  59. :scroll="{ x: tableWidth , y:tableHeight }"
  60. @dblclick="handleAdd"
  61. :pageSize="20"
  62. bordered>
  63. <!-- 产品图片 -->
  64. <template slot="imageUrl" slot-scope="text, record">
  65. <img
  66. :src="record.productMainPic && record.productMainPic.imageUrl?(record.productMainPic.imageUrl+'?x-oss-process=image/resize,h_30,m_lfit'):defImg"
  67. width="30"
  68. height="30"
  69. style="cursor: pointer;"
  70. @click="handlePicDetail(record)" />
  71. </template>
  72. <!-- 包装数 -->
  73. <template slot="baozh" slot-scope="text, record">
  74. {{ record.packQty||'--' }}/{{ record.packQtyUnit||'--' }}
  75. </template>
  76. <!-- 产品编码 -->
  77. <template slot="code" slot-scope="text, record">
  78. <a-tooltip placement="top" v-if="record.stockState=='NOT_ENOUGH'">
  79. <template slot="title">
  80. 该产品暂时缺货!
  81. </template>
  82. <span class="noStock">{{ record.code || '--' }}</span>
  83. </a-tooltip>
  84. <span v-else>{{ record.code || '--' }}</span>
  85. </template>
  86. <!-- 采购数量 -->
  87. <template slot="storageQuantity" slot-scope="text, record">
  88. <a-input-number
  89. size="small"
  90. v-model="record.qty"
  91. :precision="0"
  92. :min="0"
  93. :max="999999"
  94. style="width: 100%;"
  95. placeholder="请输入数量" />
  96. </template>
  97. <!-- 操作 -->
  98. <template slot="action" slot-scope="text, record">
  99. <a-button
  100. size="small"
  101. type="link"
  102. class="button-primary"
  103. :loading="addLoading"
  104. @click="handleAdd(record)"
  105. v-if="record.purchasePrice>0"
  106. id="purchaseOrderEdit-add-btn">添加</a-button>
  107. <span v-else>--</span>
  108. </template>
  109. </s-table>
  110. </div>
  111. </a-spin>
  112. </a-drawer>
  113. </template>
  114. <script>
  115. import { commonMixin } from '@/utils/mixin'
  116. import { STable, VSelect } from '@/components'
  117. import ProductType from '../../common/productType.js'
  118. import ProductBrand from '../../common/productBrand.js'
  119. import defImg from '@/assets/def_img@2x.png'
  120. import { productListPurchase } from '@/api/product'
  121. export default {
  122. mixins: [commonMixin],
  123. components: {
  124. STable, VSelect, ProductType, ProductBrand
  125. },
  126. props: {
  127. showModal: {
  128. type: Boolean,
  129. default: false
  130. },
  131. width: {
  132. type: [String, Number],
  133. default: '70%'
  134. },
  135. zIndex: {
  136. type: Number,
  137. default: 1050
  138. },
  139. isDealerUp: {
  140. type: Boolean
  141. },
  142. purchaseBillSn: {
  143. type: String
  144. }
  145. },
  146. watch: {
  147. showModal (newValue, oldValue) {
  148. this.visible = newValue
  149. if (newValue) {
  150. this.resetSearchForm()
  151. this.$refs.searchProductCode.focus()
  152. this.setTableH()
  153. }
  154. }
  155. },
  156. data () {
  157. return {
  158. visible: this.showModal,
  159. title: '添加产品',
  160. tableHeight: 0,
  161. // 选择产品
  162. addLoading: false,
  163. spinning: false,
  164. productType: [],
  165. queryParam: {
  166. productBrandSn: undefined,
  167. code: '', // 产品编码
  168. name: '', // 产品名称
  169. origCode: '', // 原厂编码
  170. productTypeSn1: '', // 产品一级分类
  171. productTypeSn2: '', // 产品二级分类
  172. productTypeSn3: '' // 产品三级分类
  173. },
  174. advanced: false, // 高级搜索 展开/关闭
  175. disabled: false, // 查询、重置按钮是否可操作
  176. // 加载数据方法 必须为 Promise 对象
  177. loadData: parameter => {
  178. this.disabled = true
  179. return productListPurchase(Object.assign(parameter, this.queryParam, { purchaseBillSn: this.purchaseBillSn })).then(res => {
  180. const data = res.data
  181. const no = (data.pageNo - 1) * data.pageSize
  182. for (var i = 0; i < data.list.length; i++) {
  183. data.list[i].no = no + i + 1
  184. data.list[i].qty = 1
  185. }
  186. this.disabled = false
  187. return data
  188. })
  189. },
  190. defImg
  191. }
  192. },
  193. computed: {
  194. tableWidth () {
  195. let w = 1100
  196. if (this.isDealerUp) {
  197. w = 1200
  198. }
  199. if (this.$hasPermissions('M_ShowAllCost')) {
  200. w = this.isDealerUp ? 1200 : 1100
  201. }
  202. return w
  203. },
  204. columns () {
  205. const _this = this
  206. const arr = [
  207. { title: '产品编码', scopedSlots: { customRender: 'code' }, width: '150px', align: 'center', fixed: 'left' },
  208. { title: '产品名称', dataIndex: 'name', width: '250px', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  209. // { title: '原厂编码', dataIndex: 'origCode', width: '14%', align: 'center', customRender: function (text) { return text && text != ' ' ? text : '--' } },
  210. { title: '产品图片', scopedSlots: { customRender: 'imageUrl' }, width: '80px', align: 'center' },
  211. { title: '单位', dataIndex: 'unit', width: '60px', align: 'center', customRender: function (text) { return text || '--' } },
  212. { title: '包装数', scopedSlots: { customRender: 'baozh' }, width: '60px', align: 'center' },
  213. { title: '终端会员价', dataIndex: 'terminalPrice', width: '100px', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text, 2) : '--') } },
  214. { title: '车主零售价', dataIndex: 'carOwnersPrice', width: '100px', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text, 2) : '--') } },
  215. { title: '采购数量', dataIndex: 'qty', scopedSlots: { customRender: 'storageQuantity' }, width: '100px', align: 'center', fixed: 'right' },
  216. { title: '操作', scopedSlots: { customRender: 'action' }, width: '100px', align: 'center', fixed: 'right' }
  217. ]
  218. // 产品来源
  219. if (this.isDealerUp) {
  220. arr.splice(2, 0, { title: '产品来源', dataIndex: 'sysFlagDictValue', width: '100px', align: 'center', customRender: function (text) { return text || '--' } })
  221. }
  222. if (this.$hasPermissions('M_ShowAllCost')) {
  223. arr.splice(this.isDealerUp ? 3 : 2, 0, { title: '成本价', dataIndex: 'purchasePrice', width: '100px', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text, 2) : '--') } })
  224. }
  225. return arr
  226. }
  227. },
  228. methods: {
  229. // 查看产品
  230. handlePicDetail (row) {
  231. this.$router.push({ name: 'viewProduct', params: { sn: row.productSn } })
  232. },
  233. // 产品分类 change
  234. changeProductType (val, opt) {
  235. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  236. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  237. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  238. },
  239. // 重置产品库
  240. resetSearchForm () {
  241. this.queryParam = {
  242. productBrandSn: undefined,
  243. code: '', // 产品编码
  244. name: '', // 产品名称
  245. origCode: '', // 原厂编码
  246. productTypeSn1: '', // 产品一级分类
  247. productTypeSn2: '', // 产品二级分类
  248. productTypeSn3: '' // 产品三级分类
  249. }
  250. this.productType = []
  251. this.$refs.table.refresh(true)
  252. },
  253. onClose () {
  254. this.$emit('close')
  255. },
  256. handleAdd (record) {
  257. this.spinning = true
  258. this.$emit('add', record, 0)
  259. },
  260. setTableH () {
  261. this.tableHeight = window.innerHeight - 330
  262. }
  263. }
  264. }
  265. </script>
  266. <style lang="less">
  267. .chooseProduct-drawer {
  268. .ant-drawer-header{
  269. padding: 13px 20px;
  270. }
  271. .ant-drawer-body {
  272. padding: 15px 20px;
  273. height: calc(100% - 55px);
  274. display: flex;
  275. flex-direction: column;
  276. overflow: auto;
  277. > div {
  278. height: 100%;
  279. }
  280. }
  281. }
  282. </style>