add.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <div class="associatedProduct-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="associatedProduct-head" @back="handleBack" >
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="salesEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  8. <span style="margin: 0 15px;color: #666;">供应商名称:{{ decodeURI($route.params.name) }}</span>
  9. </template>
  10. </a-page-header>
  11. <!-- 列表 -->
  12. <a-card size="small" :bordered="false">
  13. <!-- 搜索条件 -->
  14. <div ref="tableSearch" class="table-page-search-wrapper">
  15. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  16. <a-row :gutter="15">
  17. <a-col :md="6" :sm="24">
  18. <a-form-item label="产品名称">
  19. <a-input id="associatedProduct-name" v-model.trim="queryParam.product.name" allowClear placeholder="请输入产品名称"/>
  20. </a-form-item>
  21. </a-col>
  22. <a-col :md="6" :sm="24">
  23. <a-form-item label="产品编码/原厂编码">
  24. <a-input id="associatedProduct-queryWord" v-model.trim="queryParam.product.queryWord" allowClear placeholder="请输入产品编码/原厂编码"/>
  25. </a-form-item>
  26. </a-col>
  27. <a-col :md="6" :sm="24">
  28. <a-form-item label="品牌">
  29. <ProductBrand id="associatedProduct-productBrandSn" v-model="queryParam.product.productBrandSn"></ProductBrand>
  30. </a-form-item>
  31. </a-col>
  32. <template v-if="advanced">
  33. <a-col :md="6" :sm="24">
  34. <a-form-item label="产品分类">
  35. <ProductType id="associatedProduct-productType" v-model="productType" @change="changeProductType"></ProductType>
  36. </a-form-item>
  37. </a-col>
  38. </template>
  39. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  40. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="associatedProduct-refresh">查询</a-button>
  41. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="associatedProduct-reset">重置</a-button>
  42. <a @click="advanced=!advanced" style="margin-left: 5px">
  43. {{ advanced ? '收起' : '展开' }}
  44. <a-icon :type="advanced ? 'up' : 'down'"/>
  45. </a>
  46. </a-col>
  47. </a-row>
  48. </a-form>
  49. </div>
  50. <!-- 操作按钮 -->
  51. <div class="table-operator">
  52. <a-button id="associatedProduct-addProduct-btn" type="primary" class="button-error" @click="choosePModal">增加产品</a-button>
  53. <a-button
  54. id="associatedProduct-addProduct-import-btn"
  55. type="primary"
  56. class="button-info"
  57. @click="openGuideModal=
  58. true">导入产品</a-button>
  59. <!-- <a-button id="associatedProduct-import-btn" type="primary" class="button-success">批量导入</a-button> -->
  60. </div>
  61. <!-- 列表 -->
  62. <s-table
  63. class="sTable fixPagination"
  64. ref="table"
  65. :style="{ height: tableHeight+84.5+'px' }"
  66. size="small"
  67. :rowKey="(record) => record.id"
  68. :columns="columns"
  69. :data="loadData"
  70. :scroll="{ y: tableHeight }"
  71. :defaultLoadData="false"
  72. bordered>
  73. <!-- 产品分类 -->
  74. <template slot="productType" slot-scope="text, record">
  75. <span v-if="record.product.productTypeName2 || record.product.productTypeName3">{{ record.product.productTypeName2 }} {{ record.product.productTypeName3 ? '>' : '' }} {{ record.product.productTypeName3 }}</span>
  76. <span v-else>--</span>
  77. </template>
  78. <!-- 操作 -->
  79. <template slot="action" slot-scope="text, record">
  80. <a-button
  81. size="small"
  82. type="link"
  83. class="button-info"
  84. @click="handleSetPrice(record)"
  85. id="associatedProduct-setCostPrice-btn">设置成本价</a-button>
  86. <a-button
  87. size="small"
  88. type="link"
  89. class="button-error"
  90. @click="handleDel(record)"
  91. id="associatedProduct-del-btn">删除</a-button>
  92. </template>
  93. </s-table>
  94. </a-card>
  95. </a-spin>
  96. <!-- 设置成本价 -->
  97. <SettingCost ref="settingCost" :openModal="openModal" @ok="$refs.table.refresh()" @close="openModal=false"></SettingCost>
  98. <!-- 选择产品 -->
  99. <chooseProductsModal type="supplier" :openModal="newProduct" :chooseData="chooseProducts" @close="newProduct=false" @ok="handleProductsOk" />
  100. <!-- 导入产品 -->
  101. <importGuideModal :openModal="openGuideModal" :params="{supplierSn: $route.params.sn}" @close="openGuideModal=false" @ok="handleGuideOk" />
  102. </div>
  103. </template>
  104. <script>
  105. import { STable, VSelect } from '@/components'
  106. import { supplierProductList, deleteProduct, addProduct, supplierProductSnList, supplierProductBatchInsert } from '@/api/supplier'
  107. import ProductType from '@/views/common/productType.js'
  108. import ProductBrand from '@/views/common/productBrand.js'
  109. import SettingCost from './settingCost.vue'
  110. import ImportGuideModal from './importGuideModal.vue'
  111. import ChooseProductsModal from '@/views/common/chooseProductsModal.vue'
  112. export default {
  113. components: { STable, VSelect, ProductBrand, ProductType, SettingCost, ChooseProductsModal, ImportGuideModal },
  114. data () {
  115. return {
  116. spinning: false,
  117. disabled: false,
  118. advanced: true,
  119. tableHeight: 0,
  120. openModal: false, // 设置价格 弹框
  121. newProduct: false, // 选择产品 弹框
  122. queryParam: { // 查询条件
  123. product: {
  124. name: '', // 产品名称
  125. queryWord: '', // 产品编码/原厂编码
  126. productBrandSn: undefined, // 产品品牌
  127. productTypeSn1: '', // 产品一级分类
  128. productTypeSn2: '', // 产品二级分类
  129. productTypeSn3: '' // 产品三级分类
  130. }
  131. },
  132. productType: [],
  133. columns: [
  134. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  135. { title: '产品品牌', dataIndex: 'product.productBrandName', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  136. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: '15%', align: 'center' },
  137. { title: '产品名称', dataIndex: 'product.name', align: 'center', width: '25%', ellipsis: true, customRender: function (text) { return text || '--' } },
  138. { title: '产品编码', dataIndex: 'product.code', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  139. { title: '原厂编码', dataIndex: 'product.origCode', width: '16%', align: 'center', customRender: function (text) { return text || '--' } },
  140. { title: '成本价', dataIndex: 'cost', width: '10%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  141. { title: '操作', scopedSlots: { customRender: 'action' }, width: '13%', align: 'center' }
  142. ],
  143. // 加载数据方法 必须为 Promise 对象
  144. loadData: parameter => {
  145. this.disabled = true
  146. this.spinning = true
  147. this.queryParam.supplierSn = this.$route.params.sn
  148. return supplierProductList(Object.assign(parameter, this.queryParam)).then(res => {
  149. const data = res.data
  150. const no = (data.pageNo - 1) * data.pageSize
  151. for (var i = 0; i < data.list.length; i++) {
  152. data.list[i].no = no + i + 1
  153. }
  154. this.disabled = false
  155. this.spinning = false
  156. return data
  157. })
  158. },
  159. chooseProducts: [], // 所选产品
  160. openGuideModal: false // 导入产品引导
  161. }
  162. },
  163. methods: {
  164. // 返回
  165. handleBack () {
  166. this.$router.push({ path: '/supplierManagement/supplierInfo/list', query: { closeLastOldTab: true } })
  167. },
  168. // 产品分类 change
  169. changeProductType (val, opt) {
  170. this.queryParam.product.productTypeSn1 = val[0] ? val[0] : ''
  171. this.queryParam.product.productTypeSn2 = val[1] ? val[1] : ''
  172. this.queryParam.product.productTypeSn3 = val[2] ? val[2] : ''
  173. },
  174. // 重置
  175. resetSearchForm () {
  176. this.queryParam.product.name = ''
  177. this.queryParam.product.queryWord = ''
  178. this.queryParam.product.productBrandSn = undefined
  179. this.queryParam.product.productTypeSn1 = ''
  180. this.queryParam.product.productTypeSn2 = ''
  181. this.queryParam.product.productTypeSn3 = ''
  182. this.productType = []
  183. this.$refs.table.refresh(true)
  184. },
  185. // 删除
  186. handleDel (row) {
  187. const _this = this
  188. this.$confirm({
  189. title: '提示',
  190. content: '确认要删除吗?',
  191. centered: true,
  192. closable: true,
  193. onOk () {
  194. _this.spinning = true
  195. deleteProduct({ sn: row.supplierProductSn }).then(res => {
  196. if (res.status == 200) {
  197. _this.$message.success(res.message)
  198. _this.$refs.table.refresh()
  199. _this.spinning = false
  200. } else {
  201. _this.spinning = false
  202. }
  203. })
  204. }
  205. })
  206. },
  207. // 设置成本价
  208. handleSetPrice (row) {
  209. this.openModal = true
  210. this.$refs.settingCost.setData(row)
  211. },
  212. // 增加产品
  213. choosePModal () {
  214. // 查询所有已选sn
  215. this.spinning = true
  216. supplierProductSnList({ sn: this.$route.params.sn }).then(res => {
  217. if (res.status == 200) {
  218. this.chooseProducts = res.data // 包含先前所选产品
  219. this.spinning = false
  220. this.newProduct = true
  221. } else {
  222. this.spinning = false
  223. }
  224. })
  225. },
  226. // 产品
  227. handleProductsOk (obj) {
  228. this.chooseProducts = obj
  229. if (obj.length > 0) {
  230. this.addProduct()
  231. }
  232. },
  233. // 添加产品 数据处理
  234. addProduct () {
  235. this.spinning = true
  236. addProduct({
  237. supplierSn: this.$route.params.sn,
  238. productSnList: this.chooseProducts
  239. }).then(res => {
  240. if (res.status == 200) {
  241. this.$message.success(res.message)
  242. this.$refs.table.refresh()
  243. this.newProduct = false
  244. this.spinning = false
  245. } else {
  246. this.spinning = false
  247. }
  248. })
  249. },
  250. // 导入产品
  251. handleGuideOk (obj) {
  252. supplierProductBatchInsert(obj).then(res => {
  253. if (res.status == 200) {
  254. this.$refs.table.refresh(true)
  255. }
  256. })
  257. },
  258. pageInit () {
  259. const _this = this
  260. this.$nextTick(() => { // 页面渲染完成后的回调
  261. _this.setTableH()
  262. })
  263. },
  264. setTableH () {
  265. const tableSearchH = this.$refs.tableSearch.offsetHeight
  266. this.tableHeight = window.innerHeight - tableSearchH - 295
  267. }
  268. },
  269. watch: {
  270. advanced (newValue, oldValue) {
  271. const _this = this
  272. setTimeout(() => {
  273. _this.setTableH()
  274. }, 400)
  275. }
  276. },
  277. mounted () {
  278. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  279. this.pageInit()
  280. this.resetSearchForm()
  281. }
  282. },
  283. activated () {
  284. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  285. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  286. this.pageInit()
  287. this.resetSearchForm()
  288. }
  289. },
  290. beforeRouteEnter (to, from, next) {
  291. next(vm => {})
  292. }
  293. }
  294. </script>
  295. <style lang="less">
  296. .associatedProduct-wrap{
  297. .associatedProduct-head{
  298. margin-bottom: 10px;
  299. }
  300. }
  301. </style>