chooseProductModal.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 ref="searchBox" class="table-page-search-wrapper">
  16. <a-form layout="inline" @keyup.enter.native="searchForm">
  17. <a-row type="flex" :gutter="12" justify="start">
  18. <a-col flex="auto">
  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 flex="auto">
  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 :flex="2">
  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 flex="250px">
  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 flex="250px">
  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 flex="auto">
  44. <a-button type="primary" @click="searchForm" id="purchaseOrderEdit-refresh">查询</a-button>
  45. <a-button style="margin-left: 5px" @click="resetSearchForm" id="purchaseOrderEdit-reset">重置</a-button>
  46. </a-col>
  47. </a-row>
  48. </a-form>
  49. </div>
  50. <!-- 列表 -->
  51. <s-table
  52. v-if="hasVaild&&showTable"
  53. class="sTable"
  54. ref="table"
  55. size="small"
  56. :rowKey="(record) => record.id"
  57. :columns="columns"
  58. :data="loadData"
  59. :scroll="{ x: tableWidth , y:tableHeight }"
  60. @dblclick="handleAdd"
  61. :pageSize="30"
  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.packQty ? record.unit : '' }}/{{ 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. <div @dblclick.stop>
  89. <a-input-number
  90. size="small"
  91. v-model="record.qty"
  92. :precision="0"
  93. :min="0"
  94. :max="999999"
  95. style="width: 100%;"
  96. placeholder="请输入数量" />
  97. </div>
  98. </template>
  99. <!-- 操作 -->
  100. <template slot="action" slot-scope="text, record">
  101. <a-button
  102. size="small"
  103. type="link"
  104. class="button-primary"
  105. :loading="addLoading"
  106. @click="handleAdd(record)"
  107. v-if="record.purchasePrice>0"
  108. id="purchaseOrderEdit-add-btn">添加</a-button>
  109. <span v-else>--</span>
  110. </template>
  111. </s-table>
  112. <div v-else>
  113. <a-empty
  114. :image="simpleImage"
  115. :image-style="{
  116. height: '60px',
  117. }"
  118. >
  119. <span style="color:red" slot="description">请输入查询条件</span>
  120. </a-empty>
  121. </div>
  122. </div>
  123. </a-spin>
  124. </a-drawer>
  125. </template>
  126. <script>
  127. import { Empty } from 'ant-design-vue'
  128. import { commonMixin } from '@/utils/mixin'
  129. import { STable, VSelect } from '@/components'
  130. import ProductType from '../../common/productType.js'
  131. import ProductBrand from '../../common/productBrand.js'
  132. import defImg from '@/assets/def_img@2x.png'
  133. import { productListPurchase } from '@/api/product'
  134. export default {
  135. mixins: [commonMixin],
  136. components: {
  137. STable, VSelect, ProductType, ProductBrand
  138. },
  139. props: {
  140. showModal: {
  141. type: Boolean,
  142. default: false
  143. },
  144. width: {
  145. type: [String, Number],
  146. default: '70%'
  147. },
  148. zIndex: {
  149. type: Number,
  150. default: 1050
  151. },
  152. isDealerUp: {
  153. type: Boolean
  154. },
  155. purchaseBillSn: {
  156. type: String
  157. }
  158. },
  159. watch: {
  160. showModal (newValue, oldValue) {
  161. this.visible = newValue
  162. if (newValue) {
  163. this.resetSearchForm()
  164. this.$refs.searchProductCode.focus()
  165. this.setTableH()
  166. }
  167. },
  168. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  169. this.setTableH()
  170. }
  171. },
  172. data () {
  173. return {
  174. visible: this.showModal,
  175. title: '添加产品',
  176. tableHeight: 0,
  177. simpleImage: Empty.PRESENTED_IMAGE_SIMPLE,
  178. // 选择产品
  179. addLoading: false,
  180. spinning: false,
  181. productType: [],
  182. queryParam: {
  183. productBrandSn: undefined,
  184. code: '', // 产品编码
  185. name: '', // 产品名称
  186. origCode: '', // 原厂编码
  187. productTypeSn1: '', // 产品一级分类
  188. productTypeSn2: '', // 产品二级分类
  189. productTypeSn3: '' // 产品三级分类
  190. },
  191. advanced: false, // 高级搜索 展开/关闭
  192. disabled: false, // 查询、重置按钮是否可操作
  193. showTable: false,
  194. // 加载数据方法 必须为 Promise 对象
  195. loadData: parameter => {
  196. this.disabled = true
  197. return productListPurchase(Object.assign(parameter, this.queryParam, { purchaseBillSn: this.purchaseBillSn })).then(res => {
  198. const data = res.data
  199. const no = (data.pageNo - 1) * data.pageSize
  200. for (var i = 0; i < data.list.length; i++) {
  201. data.list[i].no = no + i + 1
  202. data.list[i].qty = 1
  203. data.list[i].qtyBackups = data.list[i].qty
  204. }
  205. this.disabled = false
  206. return data
  207. })
  208. },
  209. defImg
  210. }
  211. },
  212. computed: {
  213. hasVaild () {
  214. return this.queryParam.code || this.queryParam.name || this.queryParam.productBrandSn || this.queryParam.productTypeSn1
  215. },
  216. tableWidth () {
  217. let w = 1100
  218. if (this.isDealerUp) {
  219. w = 1200
  220. }
  221. if (this.$hasPermissions('M_ShowAllCost')) {
  222. w = this.isDealerUp ? 1200 : 1100
  223. }
  224. return w
  225. },
  226. columns () {
  227. const _this = this
  228. const arr = [
  229. { title: '产品编码', scopedSlots: { customRender: 'code' }, width: '150px', align: 'center', fixed: 'left' },
  230. { title: '产品名称', dataIndex: 'name', width: '250px', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  231. // { title: '原厂编码', dataIndex: 'origCode', width: '14%', align: 'center', customRender: function (text) { return text && text != ' ' ? text : '--' } },
  232. { title: '产品图片', scopedSlots: { customRender: 'imageUrl' }, width: '80px', align: 'center' },
  233. { title: '单位', dataIndex: 'unit', width: '60px', align: 'center', customRender: function (text) { return text || '--' } },
  234. { title: '包装数', scopedSlots: { customRender: 'baozh' }, width: '60px', align: 'center' },
  235. { title: '终端会员价', dataIndex: 'terminalPrice', width: '100px', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text, 2) : '--') } },
  236. { title: '车主零售价', dataIndex: 'carOwnersPrice', width: '100px', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text, 2) : '--') } },
  237. { title: '采购数量', dataIndex: 'qty', scopedSlots: { customRender: 'storageQuantity' }, width: '100px', align: 'center', fixed: 'right' },
  238. { title: '操作', scopedSlots: { customRender: 'action' }, width: '100px', align: 'center', fixed: 'right' }
  239. ]
  240. // 产品来源
  241. if (this.isDealerUp) {
  242. arr.splice(2, 0, { title: '产品来源', dataIndex: 'sysFlagDictValue', width: '100px', align: 'center', customRender: function (text) { return text || '--' } })
  243. }
  244. if (this.$hasPermissions('M_ShowAllCost')) {
  245. 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) : '--') } })
  246. }
  247. return arr
  248. }
  249. },
  250. methods: {
  251. // 查看产品
  252. handlePicDetail (row) {
  253. this.$router.push({ name: 'viewProduct', params: { sn: row.productSn } })
  254. },
  255. // 产品分类 change
  256. changeProductType (val, opt) {
  257. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  258. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  259. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  260. },
  261. // 查询
  262. searchForm () {
  263. if (this.hasVaild) {
  264. this.showTable = true
  265. this.$refs.table.refresh(true)
  266. } else {
  267. this.$message.info('请输入查询条件')
  268. }
  269. },
  270. // 重置产品库
  271. resetSearchForm () {
  272. this.queryParam = {
  273. productBrandSn: undefined,
  274. code: '', // 产品编码
  275. name: '', // 产品名称
  276. origCode: '', // 原厂编码
  277. productTypeSn1: '', // 产品一级分类
  278. productTypeSn2: '', // 产品二级分类
  279. productTypeSn3: '' // 产品三级分类
  280. }
  281. this.productType = []
  282. this.showTable = false
  283. },
  284. onClose () {
  285. this.$emit('close')
  286. },
  287. handleAdd (record) {
  288. this.spinning = true
  289. this.$emit('add', record, 0)
  290. },
  291. setTableH () {
  292. this.$nextTick(() => {
  293. const searchBoxH = this.$refs.searchBox.offsetHeight
  294. this.tableHeight = window.innerHeight - searchBoxH - 285
  295. })
  296. }
  297. }
  298. }
  299. </script>
  300. <style lang="less">
  301. .chooseProduct-drawer {
  302. .ant-drawer-header{
  303. padding: 13px 20px;
  304. }
  305. .ant-drawer-body {
  306. padding: 15px 20px;
  307. height: calc(100% - 50px);
  308. display: flex;
  309. flex-direction: column;
  310. overflow: auto;
  311. > div {
  312. height: 100%;
  313. }
  314. .noStock{
  315. text-decoration: line-through;
  316. color: red;
  317. }
  318. .ant-input-number-sm input{
  319. text-align: center;
  320. }
  321. }
  322. }
  323. </style>