DialogAssignment.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :visible="visible"
  5. :before-close="onHide"
  6. custom-class="assign-dialog">
  7. <div class="filter-container filter-view">
  8. <el-select
  9. style="min-width: 70px; max-width: 120px;"
  10. clearable
  11. v-model="filter.pageVo.assignmentStatus"
  12. placeholder="Status"
  13. @change="onSearch">
  14. <el-option
  15. v-for="(item, index) in statusOptions"
  16. :key="index"
  17. :label="item"
  18. :value="item"/>
  19. </el-select>
  20. <div style="flex: 1; min-width: 150px; max-width: 300px;">
  21. <el-input
  22. clearable
  23. v-model="filter.pageVo.criteria"
  24. placeholder="Search by Site Name or Service Provider"
  25. @keyup.enter.native="onSearch"/>
  26. </div>
  27. <el-button
  28. type="primary"
  29. @click="onSearch">
  30. Search
  31. </el-button>
  32. </div>
  33. <div class="assign-table-actions" v-if="isGroupAssign || isDyRateAssign">
  34. <el-button
  35. type="danger"
  36. :disabled="selectRow.length == 0"
  37. :loading="loading.unassign"
  38. @click="onClickUnassign">
  39. Batch Un-assign
  40. </el-button>
  41. <el-button
  42. type="accent"
  43. :disabled="selectRow.length == 0"
  44. :loading="loading.assign"
  45. @click="onClickAssign">
  46. Batch Assign
  47. </el-button>
  48. </div>
  49. <div class="table-view" v-loading="table.loading">
  50. <el-table
  51. :data="table.data"
  52. height="100%"
  53. class="no-border"
  54. @selection-change="changeSelection">
  55. <el-table-column
  56. align="center"
  57. label="Site Name"
  58. prop="siteName"
  59. min-width="120"/>
  60. <el-table-column
  61. align="center"
  62. label="Address"
  63. prop="address"
  64. min-width="120"/>
  65. <el-table-column
  66. align="center"
  67. label="Service Provider"
  68. min-width="120">
  69. <template slot-scope="{row}">
  70. <div v-for="item in row.serviceProviders" :key="item">{{item}}</div>
  71. </template>
  72. </el-table-column>
  73. <el-table-column
  74. align="center"
  75. label="Assignment Status"
  76. prop="assignmentStatus"
  77. min-width="120"/>
  78. <el-table-column
  79. align="center"
  80. label="Select"
  81. type="selection"/>
  82. </el-table>
  83. </div>
  84. <div class="center" style="margin-bottom: -20px;">
  85. <Pagination
  86. v-show="table.total"
  87. :total="table.total"
  88. :page.sync="filter.pageNo"
  89. :limit.sync="filter.pageSize"
  90. @pagination="getTableData"/>
  91. </div>
  92. </el-dialog>
  93. </template>
  94. <script>
  95. import apiGroup from '@/http/api/group'
  96. import apiRates from '@/http/api/rates'
  97. import Pagination from '@/components/Pagination'
  98. export default {
  99. name: "DialogAssignment",
  100. props: {
  101. title: {
  102. type: String,
  103. default: "ASSIGN SITES"
  104. },
  105. visible: {
  106. type: Boolean,
  107. default: false
  108. },
  109. group: {
  110. type: Object,
  111. default: () => ({})
  112. },
  113. rate: {
  114. type: Object,
  115. default: () => ({})
  116. }
  117. },
  118. components: {Pagination},
  119. data() {
  120. return {
  121. filter: {
  122. pageSize: 10,
  123. pageNo: 1,
  124. pageVo: {
  125. criteria: "",
  126. countryCode: "",
  127. assignmentStatus: ""
  128. }
  129. },
  130. table: {
  131. data: [],
  132. total: 0,
  133. loading: false
  134. },
  135. loading: {
  136. assign: false,
  137. unassign: false
  138. },
  139. statusOptions: [],
  140. selectRow: [],
  141. isGroupAssign: false,
  142. isDyRateAssign: false
  143. }
  144. },
  145. mounted() {
  146. this.getStatusOptions();
  147. //this.onSearch();
  148. },
  149. watch: {
  150. visible: {
  151. handler(n, o) {
  152. console.log("watch.visible", n, o);
  153. if (n) {
  154. if (this.group && this.group.groupPk) {
  155. this.isGroupAssign = true;
  156. this.isDyRateAssign = false;
  157. this.filter.pageVo.groupPk = this.group.groupPk
  158. this.filter.pageVo.countryCode = this.group.countryCode
  159. this.onSearch()
  160. } else if (this.rate && this.rate.dynamicRateId) {
  161. this.isGroupAssign = false;
  162. this.isDyRateAssign = true;
  163. this.filter.pageVo.countryCode = this.rate.countryCode
  164. this.filter.pageVo.dynamicRateId = this.rate.dynamicRateId
  165. this.onSearch()
  166. }
  167. }
  168. }
  169. }
  170. },
  171. methods: {
  172. onHide() {
  173. this.$emit("hide");
  174. },
  175. onSearch() {
  176. this.filter.pageNo = 1;
  177. this.getTableData();
  178. },
  179. getStatusOptions() {
  180. apiGroup.getAssignStatusOptions().then(res => {
  181. if (res.data) {
  182. this.statusOptions = res.data
  183. }
  184. }).catch(error => {
  185. this.$message({
  186. type: 'error',
  187. message: error
  188. })
  189. })
  190. },
  191. getTableData() {
  192. this.selectRow = []
  193. this.table.loading = true;
  194. const promise = this.isGroupAssign
  195. ? apiGroup.getAssignSitesPages(this.filter)
  196. : apiRates.getAssignSitesPages(this.filter)
  197. promise.then(res => {
  198. if (res.total && res.data) {
  199. this.table.total = res.total;
  200. this.table.data = res.data;
  201. } else {
  202. this.table.total = 0;
  203. this.table.data = [];
  204. }
  205. this.table.loading = false;
  206. }).catch(error => {
  207. this.$message({
  208. type: 'error',
  209. message: error
  210. })
  211. this.table.total = 0;
  212. this.table.data = [];
  213. this.table.loading = false;
  214. })
  215. },
  216. changeSelection(val) {
  217. this.selectRow = val;
  218. },
  219. getSelectIds() {
  220. const ids = [];
  221. this.selectRow.forEach(item => {
  222. ids.push(item.sitePk)
  223. })
  224. return ids;
  225. },
  226. onClickAssign() {
  227. if (this.isGroupAssign) {
  228. this.assignSites();
  229. } else if (this.isDyRateAssign) {
  230. this.assignRates();
  231. }
  232. },
  233. onClickUnassign() {
  234. if (this.isGroupAssign) {
  235. this.unassignSites();
  236. } else if (this.isDyRateAssign) {
  237. this.unassignRates();
  238. }
  239. },
  240. assignSites() {
  241. const params = {
  242. groupPk: this.group.groupPk,
  243. sitePks: this.getSelectIds()
  244. }
  245. this.loading.assign = true;
  246. apiGroup.assignSite2Group(params).then(res => {
  247. this.$message({
  248. type: 'success',
  249. message: res.msg || "Success"
  250. })
  251. this.getTableData()
  252. }).catch(error => {
  253. this.$message({
  254. type: 'error',
  255. message: error
  256. })
  257. }).finally(() => {
  258. this.loading.assign = false;
  259. })
  260. },
  261. unassignSites() {
  262. const params = {
  263. groupPk: this.group.groupPk,
  264. sitePks: this.getSelectIds()
  265. }
  266. this.loading.unassign = true;
  267. apiGroup.unassignSite2Group(params).then(res => {
  268. this.$message({
  269. type: 'success',
  270. message: res.msg || "Success"
  271. })
  272. this.getTableData()
  273. }).catch(error => {
  274. this.$message({
  275. type: 'error',
  276. message: error
  277. })
  278. }).finally(() => {
  279. this.loading.unassign = false;
  280. })
  281. },
  282. assignRates() {
  283. const params = {
  284. dynamicRateId: this.rate.dynamicRateId,
  285. sitePks: this.getSelectIds()
  286. }
  287. this.loading.assign = true;
  288. apiRates.assignRate2Site(params).then(res => {
  289. this.$message({
  290. type: 'success',
  291. message: res.msg || "Success"
  292. })
  293. this.getTableData()
  294. }).catch(error => {
  295. this.$message({
  296. type: 'error',
  297. message: error
  298. })
  299. }).finally(() => {
  300. this.loading.assign = false;
  301. })
  302. },
  303. unassignRates() {
  304. const params = {
  305. dynamicRateId: this.rate.dynamicRateId,
  306. sitePks: this.getSelectIds()
  307. }
  308. this.loading.unassign = true;
  309. apiRates.unassignRate2Site(params).then(res => {
  310. this.$message({
  311. type: 'success',
  312. message: res.msg || "Success"
  313. })
  314. this.getTableData()
  315. }).catch(error => {
  316. this.$message({
  317. type: 'error',
  318. message: error
  319. })
  320. }).finally(() => {
  321. this.loading.unassign = false;
  322. })
  323. }
  324. }
  325. }
  326. </script>
  327. <style>
  328. .assign-dialog {
  329. width: 65vw;
  330. height: 90vh;
  331. display: flex;
  332. max-width: 1200px;
  333. flex-direction: column;
  334. margin-top: 5vh !important;
  335. }
  336. .assign-dialog .el-dialog__header {
  337. padding: 20px 20px 0;
  338. font-weight: bold;
  339. }
  340. .assign-dialog .el-dialog__body {
  341. flex: 1;
  342. padding: 20px;
  343. display: flex;
  344. overflow: hidden;
  345. flex-direction: column;
  346. }
  347. .assign-table-actions {
  348. display: flex;
  349. padding-top: 5px;
  350. flex-wrap: wrap-reverse;
  351. align-items: center;
  352. justify-content: flex-end;
  353. }
  354. .table-view {
  355. flex: 1;
  356. overflow-y: auto;
  357. padding-top: 10px;
  358. margin-bottom: -10px;
  359. }
  360. @media screen and (max-width: 1200px) {
  361. .assign-dialog {
  362. width: 70vw;
  363. }
  364. }
  365. @media screen and (max-width: 1000px) {
  366. .assign-dialog {
  367. width: 80vw;
  368. }
  369. }
  370. @media screen and (max-width: 800px) {
  371. .assign-dialog {
  372. width: 90vw;
  373. }
  374. }
  375. @media screen and (max-width: 700px) {
  376. .assign-dialog {
  377. width: 99vw;
  378. }
  379. }
  380. @media screen and (max-width: 320px) {
  381. .assign-dialog {
  382. width: 100%;
  383. min-width: 300px;
  384. }
  385. }
  386. </style>