list.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <a-card :bordered="false" class="productInfoList-wrap">
  3. <!-- 搜索条件 -->
  4. <div class="table-page-search-wrapper">
  5. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  6. <a-row :gutter="15">
  7. <a-col :md="6" :sm="24">
  8. <a-form-item label="产品编码">
  9. <a-input id="productInfoList-productCode" v-model.trim="queryParam.productCode" allowClear placeholder="请输入产品编码"/>
  10. </a-form-item>
  11. </a-col>
  12. <a-col :md="6" :sm="24">
  13. <a-form-item label="产品名称">
  14. <a-input id="productInfoList-productName" v-model.trim="queryParam.productName" allowClear placeholder="请输入产品名称"/>
  15. </a-form-item>
  16. </a-col>
  17. <a-col :md="6" :sm="24">
  18. <a-form-item label="原厂编码">
  19. <a-input id="productInfoList-origCode" v-model.trim="queryParam.origCode" allowClear placeholder="请输入原厂编码"/>
  20. </a-form-item>
  21. </a-col>
  22. <template v-if="advanced">
  23. <a-col :md="6" :sm="24">
  24. <a-form-item label="产品品牌">
  25. <a-select placeholder="请选择" id="productInfoList-productBrandSn" allowClear v-model="queryParam.productBrandSn" :showSearch="true" option-filter-prop="children" :filter-option="filterOption">
  26. <a-select-option v-for="item in productBrandList" :key="item.productBrandSn" :value="item.productBrandSn">{{ item.productBrandName }}</a-select-option>
  27. </a-select>
  28. </a-form-item>
  29. </a-col>
  30. <a-col :md="6" :sm="24">
  31. <a-form-item label="产品类别">
  32. <a-cascader @change="changeProductType" change-on-select :options="productTypeList" :fieldNames="{ label: 'productTypeName', value: 'id', children: 'children' }" id="productInfoList-productType" placeholder="请选择产品类别" allowClear />
  33. </a-form-item>
  34. </a-col>
  35. <a-col :md="6" :sm="24">
  36. <a-form-item label="状态">
  37. <v-select code="ENABLED_FLAG" id="productInfoList-enabledFlag" v-model="queryParam.enabledFlag" allowClear placeholder="请选择状态"></v-select>
  38. </a-form-item>
  39. </a-col>
  40. <a-col :md="6" :sm="24">
  41. <a-form-item label="创建时间">
  42. <a-range-picker
  43. style="width:100%"
  44. id="customerManagementList-creatTime"
  45. :disabledDate="disabledDate"
  46. @change="creatTimechange"
  47. :format="dateFormat"
  48. :placeholder="['开始时间', '结束时间']" />
  49. </a-form-item>
  50. </a-form-item>
  51. </a-col>
  52. </template>
  53. <a-col :md="6" :sm="24">
  54. <a-button style="margin-bottom: 18px;" type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="productInfoList-refresh">查询</a-button>
  55. <a-button style="margin: 0 0 18px 8px" @click="resetSearchForm" :disabled="disabled" id="productInfoList-reset">重置</a-button>
  56. <a-button style="margin: 0 0 18px 8px" type="danger" @click="handleExport" :disabled="disabled" :loading="exportLoading" id="inventoryQueryList-export">导出</a-button>
  57. <a @click="advanced=!advanced" style="margin-left: 8px">
  58. {{ advanced ? '收起' : '展开' }}
  59. <a-icon :type="advanced ? 'up' : 'down'"/>
  60. </a>
  61. </a-col>
  62. </a-row>
  63. </a-form>
  64. </div>
  65. <!-- 操作按钮 -->
  66. <div class="table-operator">
  67. <a-button id="productInfoList-add" type="primary" @click="handleEdit()">新增产品</a-button>
  68. <a-button id="productInfoList-import" @click="handleImport" style="margin: 0 15px;">批量导入产品</a-button>
  69. </div>
  70. <!-- 列表 -->
  71. <s-table
  72. class="sTable"
  73. ref="table"
  74. size="default"
  75. :rowKey="(record) => record.id"
  76. :columns="columns"
  77. :data="loadData"
  78. bordered>
  79. <!-- 产品类别 -->
  80. <!-- 自定义表头 -->
  81. <template slot="productTypeCustomTitle">
  82. <a-tooltip placement="top">
  83. <template slot="title">
  84. <span>列表中只显示第三级分类的名称,鼠标移动至文字上,查看上级分类。“>”为分隔符</span>
  85. </template>
  86. 产品类别<a-icon type="question-circle" :style="{ color: '#ed1c24', marginLeft: '10px' }" />
  87. </a-tooltip>
  88. </template>
  89. <template slot="productType" slot-scope="text, record">
  90. <a-tooltip placement="top">
  91. <template slot="title">
  92. <span>{{record.productTypeName}}</span>
  93. </template>
  94. {{record.productTypeName3}}
  95. </a-tooltip>
  96. </template>
  97. <!-- 状态 -->
  98. <template slot="enabledFlag" slot-scope="text, record">
  99. <a-switch
  100. id="productBrandList-enable"
  101. checkedChildren="启用"
  102. unCheckedChildren="禁用"
  103. @change="changeStatus(record)"
  104. :checked="record.enabledFlag == 1 ? true : false" />
  105. <!-- <span :class="record.enabledFlag==1?'green':'red'" v-else> {{ record.enabledFlag==1? '已启用': '已禁用' }} </span> -->
  106. </template>
  107. <!-- 操作 -->
  108. <template slot="action" slot-scope="text, record">
  109. <a-button type="primary" @click="handleEdit(record)" id="productInfoList-edit-btn">编辑</a-button>
  110. <a-button @click="handleDetail(record)" id="productInfoList-detail-btn" style="margin-left: 15px;">详情</a-button>
  111. </template>
  112. </s-table>
  113. <!-- 产品详情 -->
  114. <product-info-detail-modal :openModal="openModal" :itemId="itemId" @close="closeModal" />
  115. </a-card>
  116. </template>
  117. <script>
  118. import moment from 'moment'
  119. import { dealerProductBrandQuery } from '@/api/dealerProductBrand'
  120. import { dealerProductTypeQuery } from '@/api/dealerProductType'
  121. import { dealerProductList, dealerProductUpdate, dealerProductExport } from '@/api/dealerProduct'
  122. import { STable, VSelect } from '@/components'
  123. import productInfoDetailModal from './detailModal.vue'
  124. export default {
  125. components: { STable, VSelect, productInfoDetailModal },
  126. data () {
  127. return {
  128. advanced: false, // 高级搜索 展开/关闭
  129. queryParam: { // 查询条件
  130. productCode: '', // 产品编码
  131. productName: '', // 产品名称
  132. origCode: '', // 原厂编码
  133. productBrandSn: undefined, // 产品品牌
  134. productTypeSn1: '', // 产品一级类别
  135. productTypeSn2: '', // 产品二级类别
  136. productTypeSn3: '', // 产品三级类别
  137. enabledFlag: undefined, // 状态
  138. beginDate: '', // 创建时间 开始时间
  139. endDate: '', // 创建时间 结束时间
  140. },
  141. disabled: false, // 查询、重置按钮是否可操作
  142. exportLoading: false, // 导出loading
  143. dateFormat: 'YYYY-MM-DD',
  144. columns: [
  145. { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
  146. { title: '产品编码', dataIndex: 'productCode', width: 200, align: 'center' },
  147. { title: '产品名称', dataIndex: 'productName', width: 160, align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  148. { title: '原厂编码', dataIndex: 'origCode', width: 200, align: 'center', customRender: function (text) { return text || '--' } },
  149. { title: '产品品牌', dataIndex: 'productBrandName', width: 200, align: 'center', customRender: function (text) { return text || '--' } },
  150. { slots: { title: 'productTypeCustomTitle' }, scopedSlots: { customRender: 'productType' }, width: 180, align: 'center' },
  151. { title: '终端价', dataIndex: 'terminalPrice', width: 180, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  152. { title: '创建时间', dataIndex: 'createDate', width: 180, align: 'center' },
  153. { title: '状态', scopedSlots: { customRender: 'enabledFlag' }, width: 180, align: 'center' },
  154. { title: '操作', scopedSlots: { customRender: 'action' }, width: 240, align: 'center' }
  155. ],
  156. // 加载数据方法 必须为 Promise 对象
  157. loadData: parameter => {
  158. this.disabled = true
  159. return dealerProductList( Object.assign(parameter, this.queryParam) ).then(res => {
  160. const data = res.data
  161. const no = (data.pageNo - 1) * data.pageSize
  162. for (var i = 0; i < data.list.length; i++) {
  163. data.list[i].no = no + i + 1
  164. const productTypeName1 = data.list[i].productTypeName1 ? data.list[i].productTypeName1 : ''
  165. const productTypeName2 = data.list[i].productTypeName2 ? ' > ' + data.list[i].productTypeName2 : ''
  166. const productTypeName3 = data.list[i].productTypeName3 ? ' > ' + data.list[i].productTypeName3 : ''
  167. data.list[i].productTypeName = productTypeName1 + productTypeName2 + productTypeName3
  168. }
  169. this.disabled = false
  170. return data
  171. })
  172. },
  173. openModal: false, // 查看客户详情 弹框
  174. itemId: '', // 当前产品id
  175. productBrandList: [], // 品牌下拉数据
  176. productTypeList: [], // 类别下拉数据
  177. }
  178. },
  179. methods: {
  180. // 不可选日期
  181. disabledDate (date, dateStrings) {
  182. return date && date.valueOf() > Date.now()
  183. },
  184. // 创建时间 change
  185. creatTimechange(dates, dateStrings){
  186. this.queryParam.beginDate = dateStrings[0]
  187. this.queryParam.endDate = dateStrings[1]
  188. },
  189. // 重置
  190. resetSearchForm () {
  191. this.queryParam.productCode = ''
  192. this.queryParam.productName = ''
  193. this.queryParam.origCode = ''
  194. this.queryParam.productBrandSn = undefined
  195. this.queryParam.productTypeSn1 = ''
  196. this.queryParam.productTypeSn2 = ''
  197. this.queryParam.productTypeSn3 = ''
  198. this.queryParam.enabledFlag = undefined
  199. this.queryParam.beginDate = ''
  200. this.queryParam.endDate = ''
  201. this.$refs.table.refresh(true)
  202. },
  203. // 新增/编辑
  204. handleEdit(row){
  205. if(row){ // 编辑
  206. this.$router.push({ path: `/productManagement/productInfo/edit/${row.id}` })
  207. }else{ // 新增
  208. this.$router.push({ path: '/productManagement/productInfo/add' })
  209. }
  210. },
  211. // 批量导入
  212. handleImport(){
  213. },
  214. filterOption(input, option) {
  215. return (
  216. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  217. )
  218. },
  219. // 详情
  220. handleDetail(row){
  221. this.itemId = row.id
  222. this.openModal = true
  223. },
  224. // 关闭弹框
  225. closeModal(){
  226. this.itemId = ''
  227. this.openModal = false
  228. },
  229. // 产品类别 change
  230. changeProductType(val, opt){
  231. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  232. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  233. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  234. },
  235. // 启用 禁用
  236. changeStatus (record) {
  237. if (record.enabledFlag=='1') {
  238. this.$confirm({
  239. title: '提示',
  240. content: '产品被禁用后,不能再销售,确定禁用吗?',
  241. onOk: () => {
  242. this.setEnable(record)
  243. }
  244. })
  245. } else {
  246. this.setEnable(record)
  247. }
  248. },
  249. // 启用 禁用
  250. setEnable (record) {
  251. const params = {
  252. id: record.id,
  253. enabledFlag: record.enabledFlag == 1 ? '0' : '1'
  254. }
  255. dealerProductUpdate(params).then(res => {
  256. if (res.status == 200) {
  257. this.$message.success(res.message)
  258. this.$refs.table.refresh()
  259. } else {
  260. this.$refs.table.refresh()
  261. }
  262. })
  263. },
  264. // 导出
  265. handleExport () {
  266. this.exportLoading = true
  267. dealerProductExport(this.queryParam).then(res => {
  268. this.exportLoading = false
  269. this.download(res)
  270. })
  271. },
  272. download (data) {
  273. if (!data) { return }
  274. const url = window.URL.createObjectURL(new Blob([data]))
  275. const link = document.createElement('a')
  276. link.style.display = 'none'
  277. link.href = url
  278. const a = moment().format('YYYYMMDDHHmmss')
  279. const fname = '自建产品列表' + a
  280. link.setAttribute('download', fname + '.xlsx')
  281. document.body.appendChild(link)
  282. link.click()
  283. },
  284. // 产品品牌 列表
  285. getProductBrand(){
  286. dealerProductBrandQuery({}).then(res => {
  287. if(res.status == 200){
  288. this.productBrandList = res.data
  289. }else{
  290. this.productBrandList = []
  291. }
  292. })
  293. },
  294. // 产品类别 列表
  295. getProductType(){
  296. dealerProductTypeQuery({}).then(res => {
  297. if(res.status == 200){
  298. this.productTypeList = res.data
  299. }else{
  300. this.productTypeList = []
  301. }
  302. })
  303. },
  304. },
  305. beforeRouteEnter(to, from, next) {
  306. next(vm => {
  307. vm.getProductBrand()
  308. vm.getProductType()
  309. })
  310. }
  311. }
  312. </script>
  313. <style lang="less">
  314. .productInfoList-wrap{
  315. .sTable{
  316. table{
  317. width: auto;
  318. }
  319. }
  320. }
  321. </style>