tables.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <template>
  2. <!-- tables -->
  3. <div class="tables_grid">
  4. <el-table ref="tableRef" style="width: 100%" tooltip-effect="dark myTooltips" :show-header="showHeader"
  5. class="table-style" :data="tableData" :border="border" :row-key="(val) => rowKey(val)" @cell-click="cellClick"
  6. @selection-change="handleSelectionChange">
  7. <template v-for="(item,index) in tableList">
  8. <el-table-column :fixed="suspension ? 'right' : false" :label="item.label" :width="item.colWidth" align="center"
  9. v-if="item.field == 'action'">
  10. <template slot-scope="scope">
  11. <div style="display: flex;align-items: center;justify-content: center;">
  12. <div v-for="disk in item.labelButton" :key="disk.key" class="btn_table">
  13. <el-button :class="disk.modality" :type="disk.style" :icon="disk.icon" size="mini"
  14. :disabled="jurisdiction(scope.row,disk.type)" @click="buttonData(scope.row,disk.type)">
  15. {{ disk.label }}
  16. </el-button>
  17. </div>
  18. </div>
  19. </template>
  20. </el-table-column>
  21. <el-table-column class="card_unpack_btn" :fixed="suspension ? 'right' : false" :label="item.label"
  22. :width="unpackWidth" align="center" v-else-if="item.field == 'unpackBtn'">
  23. <template slot="header" slot-scope="scope">
  24. <div class="unpack_card">
  25. <div v-if="!iconFlag">{{item.label}}</div>
  26. <i class="card_unpack" :class="iconFlag ? 'el-icon-s-fold' : 'el-icon-s-unfold'" @click="getUnpack"></i>
  27. </div>
  28. </template>
  29. <template slot-scope="scope">
  30. <div class="center_in" v-if="!iconFlag">
  31. <div style="display: flex;" v-for="disk in item.labelButton" :key="disk.key" class="btn_table">
  32. <el-button :class="disk.modality" :type="disk.style" :icon="disk.icon" size="mini"
  33. :disabled="jurisdiction(scope.row,disk.type)" @click="buttonData(scope.row,disk.type)">
  34. {{ disk.label }}
  35. </el-button>
  36. </div>
  37. </div>
  38. <div v-else :key="index">
  39. <el-popover placement="top" width="460" trigger="click">
  40. <div class="center_in">
  41. <div v-for="disk in item.labelButton" :key="disk.key" class="btn_table">
  42. <el-button :class="disk.modality" :type="disk.style" :icon="disk.icon" size="mini"
  43. :disabled="jurisdiction(scope.row,disk.type)" @click="buttonData(scope.row,disk.type)">
  44. {{ disk.label }}
  45. </el-button>
  46. </div>
  47. </div>
  48. <el-tag style="cursor: pointer;" size="mini" slot="reference">操作</el-tag>
  49. </el-popover>
  50. </div>
  51. </template>
  52. </el-table-column>
  53. <el-table-column :prop="item.field" :label="item.label" :width="item.colWidth" :align="item.align"
  54. v-else-if="['provUser.isorders','provUser.userType','customer.type','tbFillData.productMediaId'].includes(item.field)">
  55. <template slot-scope="scope">
  56. <div>{{initDictvalue(scope.row,item.options,item.field)}}</div>
  57. </template>
  58. </el-table-column>
  59. <el-table-column :prop="item.field" :label="item.label" :width="item.colWidth" :align="item.align"
  60. v-else-if="['userId', 'type', 'status', 'storeId', 'personCode', 'optType', 'corrosion', 'crackle', 'deform', 'damage', 'safeAnnex', 'gasPressure', 'bodyDeform', 'fillingLeak', 'bodyTemperature', 'filledLeak', 'warnSign', 'fillLabel', 'seal','fill_media'].includes(item.field)">
  61. <template slot-scope="scope">
  62. <div :style="{color: filterColor(scope.row,item.options,item.field)}">
  63. {{initDictvalueil(scope.row,item.options,item.field)}}
  64. </div>
  65. </template>
  66. </el-table-column>
  67. <el-table-column :prop="item.field" :label="item.label" :width="item.colWidth" :align="item.align"
  68. v-else-if="item.field == 'myStatus'">
  69. <template slot-scope="scope">
  70. <div :style="{color: myfilterColor(scope.row,item.options,item.field)}">
  71. {{myInitDictvalueil(scope.row,item.options,item.field)}}
  72. </div>
  73. </template>
  74. </el-table-column>
  75. <el-table-column :prop="item.field" :label="item.label" :width="item.colWidth" :align="item.align"
  76. v-else-if="item.field == 'region'">
  77. <template slot-scope="scope">
  78. <div>{{scope.row.provinceName}}{{scope.row.cityName}}{{scope.row.regionName}}</div>
  79. </template>
  80. </el-table-column>
  81. <el-table-column type="index" :fixed="item.boxhead ? true : false" width="80px" :label="item.label"
  82. :align="item.align" v-else-if="item.field == 'index'">
  83. </el-table-column>
  84. <el-table-column type="selection" v-model="selectionList" reserve-selection width="55"
  85. v-else-if="item.field == 'selection'"></el-table-column>
  86. <el-table-column :show-overflow-tooltip="true" :prop="item.field" :label="item.label" :width="item.colWidth"
  87. :align="item.align" v-else>
  88. </el-table-column>
  89. </template>
  90. </el-table>
  91. </div>
  92. </template>
  93. <script>
  94. import {
  95. orderStatus,
  96. rectificationState
  97. } from '@/assets/js/blockSort'
  98. export default {
  99. props: {
  100. // 是否显示表头
  101. showHeader: {
  102. type: Boolean,
  103. default: () => true,
  104. },
  105. // 表格边框
  106. border: {
  107. type: Boolean,
  108. default: () => false,
  109. },
  110. // 表格数据
  111. tableList: {
  112. type: Array,
  113. default: () => [],
  114. },
  115. // 表格label数据
  116. tableData: {
  117. type: Array,
  118. default: () => [],
  119. },
  120. // 网关数据
  121. detailGateway: {
  122. type: Array,
  123. default: () => [],
  124. },
  125. // 语言数据
  126. detailLanguage: {
  127. type: Array,
  128. default: () => [],
  129. },
  130. // 是否悬浮
  131. suspension: {
  132. type: Boolean,
  133. default: () => false,
  134. }
  135. },
  136. data() {
  137. return {
  138. orderStatusList: orderStatus(),
  139. waybillIds: [],
  140. selectionList: [],
  141. iconFlag: false,
  142. unpackWidth: '460px',
  143. visible: false,
  144. }
  145. },
  146. methods: {
  147. // 文字匹配
  148. initDictvalue(value, list, type) {
  149. let propertyName = type.split(".")
  150. let name = ''
  151. if (list) {
  152. list.forEach(item => {
  153. if (value[propertyName[0]][propertyName[1]] == item.value) {
  154. name = item.label
  155. }
  156. })
  157. }
  158. return name
  159. },
  160. // 普通类型文字匹配
  161. initDictvalueil(value, list, type) {
  162. let name = ''
  163. if (list) {
  164. list.forEach(item => {
  165. if (value[type] === item.value) {
  166. name = item.label
  167. }
  168. })
  169. }
  170. return name
  171. },
  172. // tag颜色获取
  173. filterColor(value, list, type) {
  174. let color = ''
  175. if (list) {
  176. list.forEach(item => {
  177. if (value[type] === item.value) {
  178. color = item.bgcolor
  179. }
  180. })
  181. }
  182. return color
  183. },
  184. // 我的订单
  185. myInitDictvalueil(value, list, type) {
  186. if ([1].includes(value.status)) {
  187. return list[0].label
  188. } else if ([2, 3, 9].includes(value.status)) {
  189. return list[1].label
  190. } else if ([4, 5, 6, 7, 10, 11].includes(value.status)) {
  191. return list[2].label
  192. } else if (value.status == 8) {
  193. return list[3].label
  194. }
  195. },
  196. myfilterColor(value, list, type) {
  197. if ([1].includes(value.status)) {
  198. return list[0].bgcolor
  199. } else if ([2, 3, 9].includes(value.status)) {
  200. return list[1].bgcolor
  201. } else if ([4, 5, 6, 7, 10, 11].includes(value.status)) {
  202. return list[2].bgcolor
  203. } else if (value.status == 8) {
  204. return list[3].bgcolor
  205. }
  206. },
  207. // 城市筛选
  208. cityScreening(value, list, type) {
  209. function getChildById(parentArray, id) {
  210. for (let i = 0; i < parentArray.length; i++) {
  211. if (parentArray[i].value === id) { // 如果当前元素的ID与目标ID相等,则返回该元素
  212. return parentArray[i];
  213. } else if (parentArray[i].children && Array.isArray(parentArray[i].children)) { // 判断当前元素是否有子节点且类型为数组
  214. const result = getChildById(parentArray[i].children, id); // 对子节点进行递归调用
  215. if (result !== null) { // 若子节点存在结果,则返回该结果
  216. return result;
  217. }
  218. }
  219. }
  220. return null; // 没有找到符合条件的元素时返回null
  221. }
  222. var name = getChildById(list, value[type])
  223. if (name != null) {
  224. return name.label
  225. }
  226. },
  227. // 权限按钮
  228. jurisdiction(row, type) {
  229. const arr = localStorage.getItem('userList')
  230. const userArr = JSON.parse(arr)
  231. if (row.waybillNo) {
  232. if (userArr.userType == 'customer' && type == 'edit' || type == 'del') {
  233. if ([1, 2, 3, 9].includes(row.status)) {
  234. return false
  235. } else {
  236. return true
  237. }
  238. } else if (type == 'send' || type == 'del') {
  239. if (row.status == 1 || row.status == 2 || row.status == 3 || row.status == 9) {
  240. return false
  241. } else {
  242. return true
  243. }
  244. } else if (type == 'pdf') {
  245. if (row.status == 8) {
  246. return false
  247. } else {
  248. return true
  249. }
  250. } else if (type == 'print') {
  251. if (row.status == 2 || row.status == 3 || row.status == 9) {
  252. return false
  253. } else {
  254. return true
  255. }
  256. }
  257. }
  258. },
  259. // 选择tables某一项
  260. cellClick(row) {
  261. this.$emit('cellClick', row)
  262. },
  263. // 选择多行数据
  264. handleSelectionChange(row) {
  265. this.selectionList = row
  266. let arrID = []
  267. const arr = row
  268. arr.forEach(item => {
  269. // const option = {
  270. // id: item.id,
  271. // status: item.status,
  272. // }
  273. // arrID.push(option)
  274. // arrID.push(item.id)
  275. arrID.push(item)
  276. })
  277. this.waybillIds = JSON.parse(JSON.stringify(arrID))
  278. },
  279. // 操作按钮
  280. buttonData(row, type) {
  281. this.$emit("buttonData", row, type);
  282. },
  283. // 清空选中项
  284. clearSelected() {
  285. this.$nextTick(() => {
  286. this.$refs.tableRef.clearSelection();
  287. })
  288. },
  289. rowKey(val) {
  290. if (val.id) {
  291. return val.id
  292. } else {
  293. if (val.T_id) {
  294. return val.T_id + Math.random()
  295. } else {
  296. return val.T_sn
  297. }
  298. }
  299. },
  300. // 展开收起
  301. getUnpack() {
  302. if (this.iconFlag) {
  303. this.unpackWidth = '460px'
  304. this.iconFlag = false
  305. } else {
  306. this.unpackWidth = '70px'
  307. this.iconFlag = true
  308. }
  309. }
  310. }
  311. }
  312. </script>
  313. <style scoped lang="scss">
  314. ::v-deep .el-table__fixed-right {
  315. transition: width 0.15s;
  316. -webkit-transition: width 0.15s;
  317. -moz-transition: width 0.15s;
  318. -webkit-transition: width 0.15s;
  319. -o-transition: width 0.15s;
  320. }
  321. .btn_table:nth-of-type(n+2) {
  322. margin-left: 10px;
  323. }
  324. .el-button--mini {
  325. padding: 5px;
  326. }
  327. .deleteBtn {
  328. color: #ff6665;
  329. }
  330. .icon_play {
  331. font-size: 25px;
  332. color: #83FF00;
  333. }
  334. .icon_pause {
  335. font-size: 25px;
  336. color: #FF9494;
  337. }
  338. .title_play {
  339. font-size: 15px;
  340. color: #83FF00;
  341. margin-left: 10px;
  342. }
  343. .title_pause {
  344. font-size: 15px;
  345. color: #FF9494;
  346. margin-left: 10px;
  347. }
  348. .card_operation {
  349. display: flex;
  350. align-items: center;
  351. justify-content: center;
  352. cursor: pointer;
  353. }
  354. .gateway_title {
  355. color: #59fe6d;
  356. }
  357. .gateway_title1 {
  358. color: #34d9f4;
  359. }
  360. .operator_title {
  361. color: #fff;
  362. }
  363. .unpack_card {
  364. display: flex;
  365. align-items: center;
  366. justify-content: center;
  367. }
  368. .card_unpack {
  369. cursor: pointer;
  370. font-size: 25px;
  371. margin-left: 10px;
  372. }
  373. </style>
  374. <style>
  375. .myTooltips {
  376. max-width: 50%;
  377. }
  378. </style>