list.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <a-card size="small" :bordered="false" class="shelfSetList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div ref="tableSearch" class="table-page-search-wrapper">
  6. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  7. <a-row :gutter="15">
  8. <a-col :md="6" :sm="24">
  9. <a-form-item label="模板名称">
  10. <a-input id="shelfPlList-templateName" v-model.trim="queryParam.templateName" allowClear placeholder="请输入模板名称"/>
  11. </a-form-item>
  12. </a-col>
  13. <a-col :md="6" :sm="24">
  14. <a-form-item label="模板类型">
  15. <v-select
  16. id="shelfPlList-sysFlag"
  17. v-model="queryParam.sysFlag"
  18. code="SHELF_TEMPLATE_SYS_FLAG"
  19. placeholder="请选择模板类型"
  20. allowClear></v-select>
  21. </a-form-item>
  22. </a-col>
  23. <a-col :md="6" :sm="24" style="margin-bottom: 10px">
  24. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="shelfPlList-refresh">查询</a-button>
  25. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="shelfPlList-reset">重置</a-button>
  26. </a-col>
  27. </a-row>
  28. </a-form>
  29. </div>
  30. <div class="table-operator">
  31. <a-button v-if="orgData.length<20" type="primary" class="button-error" @click="addTemp" id="shelfPlList-addTemp">新增</a-button>
  32. </div>
  33. <!-- 列表 -->
  34. <s-table
  35. class="sTable fixPagination"
  36. ref="table"
  37. :style="{ height: tableHeight+84.5+'px' }"
  38. size="small"
  39. :rowKey="(record) => record.id"
  40. :columns="columns"
  41. :data="loadData"
  42. :scroll="{ y: tableHeight }"
  43. :defaultLoadData="false"
  44. bordered>
  45. <!-- 模板名称 -->
  46. <template slot="templateName" slot-scope="text, record">
  47. <span class="table-td-link" id="shelfPlList-links" @click="handleDetail(record)">{{ record.templateName }}</span>
  48. </template>
  49. <!-- 操作 -->
  50. <template slot="action" slot-scope="text, record">
  51. <div>
  52. <a-button
  53. :id="'shelfPlList-edit-'+record.id"
  54. size="small"
  55. v-if="record.sysFlag==0"
  56. type="link"
  57. class="button-primary"
  58. @click="addTemp(record)">更改名称</a-button>
  59. <a-button
  60. v-if="orgData.length<20"
  61. :id="'shelfPlList-copy-'+record.id"
  62. size="small"
  63. type="link"
  64. class="button-primary"
  65. @click="handleCopy(record)">复制</a-button>
  66. <a-button
  67. :id="'shelfPlList-del-'+record.id"
  68. size="small"
  69. v-if="record.sysFlag==0"
  70. type="link"
  71. class="button-error"
  72. @click="handleCancel(record)">删除</a-button>
  73. </div>
  74. </template>
  75. </s-table>
  76. </a-spin>
  77. <!-- 基础设置弹框 -->
  78. <basic-info-modal :openModal="openModal" :nowData="nowData" @ok="saveOk" @close="openModal=false" />
  79. </a-card>
  80. </template>
  81. <script>
  82. import { commonMixin } from '@/utils/mixin'
  83. import { STable, VSelect } from '@/components'
  84. import basicInfoModal from './basicInfoModal.vue'
  85. import commonModal from '@/views/common/commonModal.vue'
  86. import { shelfTemplateList, shelfTemplateCopy, shelfTemplateDel } from '@/api/shelfTemplate'
  87. export default {
  88. name: 'ShelfProductTemplList',
  89. components: { STable, VSelect, basicInfoModal, commonModal },
  90. mixins: [commonMixin],
  91. data () {
  92. return {
  93. spinning: false,
  94. tableHeight: 0,
  95. disabled: false, // 查询、重置按钮是否可操作
  96. queryParam: {
  97. templateName: '', // 模板名称
  98. sysFlag: undefined // 模板类型
  99. },
  100. columns: [
  101. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  102. { title: '模板类型', dataIndex: 'sysFlagDictValue', width: '20%', align: 'center' },
  103. { title: '模板名称', scopedSlots: { customRender: 'templateName' }, width: '50%', align: 'left', ellipsis: true },
  104. { title: '产品款数', dataIndex: 'productCategory', width: '15%', align: 'center' },
  105. { title: '操作', scopedSlots: { customRender: 'action' }, width: '11%', align: 'center' }
  106. ],
  107. // 加载数据方法 必须为 Promise 对象
  108. loadData: parameter => {
  109. this.disabled = true
  110. this.spinning = true
  111. return shelfTemplateList(Object.assign(parameter, this.queryParam)).then(res => {
  112. let data
  113. if (res.status == 200) {
  114. data = res.data
  115. const no = (data.pageNo - 1) * data.pageSize
  116. for (var i = 0; i < data.list.length; i++) {
  117. data.list[i].no = no + i + 1
  118. }
  119. this.disabled = false
  120. }
  121. this.spinning = false
  122. this.orgData = data.list
  123. return data
  124. })
  125. },
  126. orgData: [], // 原始列表数据
  127. openModal: false, // 打开新增编辑弹框
  128. nowData: null // 当前操作数据
  129. }
  130. },
  131. methods: {
  132. // 新增/修改模板
  133. addTemp (row) {
  134. this.nowData = row || {}
  135. this.openModal = true
  136. },
  137. // 模板详情设置
  138. handleDetail (data) {
  139. this.$router.push({ name: 'shelfProductTemplSetting', params: { sn: data.templateSn } })
  140. },
  141. // 复制模板
  142. handleCopy (record) {
  143. const _this = this
  144. this.$confirm({
  145. title: '提示',
  146. content: '复制选择的内置模板,将在列表生成一条相同的模板,可进行编辑!是否确认生成?',
  147. centered: true,
  148. closable: true,
  149. onOk () {
  150. _this.spinning = true
  151. shelfTemplateCopy({
  152. templateSn: record.templateSn
  153. }).then(res => {
  154. if (res.status == 200) {
  155. _this.$message.success(res.message)
  156. _this.resetSearchForm()
  157. }
  158. _this.spinning = false
  159. })
  160. }
  161. })
  162. },
  163. // 删除模板
  164. handleCancel (record) {
  165. const _this = this
  166. this.$confirm({
  167. title: '提示',
  168. content: '删除模板后,模板信息将全部清除,是否确认删除?',
  169. centered: true,
  170. closable: true,
  171. onOk () {
  172. _this.spinning = true
  173. shelfTemplateDel({
  174. templateSn: record.templateSn
  175. }).then(res => {
  176. if (res.status == 200) {
  177. _this.$message.success(res.message)
  178. _this.$refs.table.refresh()
  179. }
  180. _this.spinning = false
  181. })
  182. }
  183. })
  184. },
  185. // 保存成功
  186. saveOk () {
  187. this.$refs.table.refresh(true)
  188. this.openModal = false
  189. },
  190. // 重置
  191. resetSearchForm () {
  192. this.queryParam.templateName = ''
  193. this.queryParam.sysFlag = undefined
  194. this.$refs.table.refresh(true)
  195. },
  196. // 表格高度
  197. setTableH () {
  198. const tableSearchH = this.$refs.tableSearch.offsetHeight
  199. this.tableHeight = window.innerHeight - tableSearchH - 235
  200. },
  201. // 初始化页面
  202. pageInit () {
  203. const _this = this
  204. this.$nextTick(() => { // 页面渲染完成后的回调
  205. _this.setTableH()
  206. })
  207. }
  208. },
  209. mounted () {
  210. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  211. this.pageInit()
  212. this.resetSearchForm()
  213. }
  214. },
  215. watch: {
  216. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  217. this.setTableH()
  218. }
  219. },
  220. activated () {
  221. // 如果是新页签打开,则重置当前页面
  222. if (this.$store.state.app.isNewTab) {
  223. this.pageInit()
  224. this.resetSearchForm()
  225. }
  226. // 仅刷新列表,不重置页面
  227. if (this.$store.state.app.updateList) {
  228. this.pageInit()
  229. this.$refs.table.refresh()
  230. }
  231. }
  232. }
  233. </script>