AdminTicketShow.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <template>
  2. <div class="AdminTicketShow"
  3. :style="localOptions.style">
  4. <div class="title">
  5. <div class="static-title">
  6. مشاهده پیام
  7. </div>
  8. <div class="dynamic-title">
  9. <template v-if="entityLoading">
  10. <q-skeleton type="text"
  11. class="q-ml-lg"
  12. width="100px" />
  13. </template>
  14. <template v-else>
  15. {{ packageTitle }}
  16. </template>
  17. </div>
  18. <div class="back-action">
  19. <q-btn flat
  20. color="grey"
  21. @click="$router.go(-1)">
  22. بازگشت
  23. >
  24. </q-btn>
  25. </div>
  26. </div>
  27. <q-card class="form"
  28. flat>
  29. <entity-edit v-if="mounted"
  30. ref="entityEdit"
  31. v-model:value="inputs"
  32. title="اطلاعات کاربری"
  33. :api="api"
  34. :entity-id-key="entityIdKey"
  35. :entity-param-key="entityParamKey"
  36. :show-route-name="showRouteName"
  37. :show-close-button="false"
  38. :show-edit-button="false"
  39. :show-expand-button="false"
  40. :show-save-button="false"
  41. :show-reload-button="false"
  42. :default-layout="false"
  43. :redirect-after-edit="false"
  44. :before-load-input-data="beforeLoadInputData"
  45. :after-load-input-data="afterLoadInputData" />
  46. <div class="row q-mt-lg justify-end">
  47. <div class="col-md-4 col-12">
  48. <q-btn color="primary"
  49. class="full-width"
  50. :loading="entityLoading"
  51. @click="edit">
  52. ثبت تغییرات
  53. </q-btn>
  54. </div>
  55. </div>
  56. <q-card v-if="mounted"
  57. class="q-mt-md">
  58. <q-card-section>
  59. <div class="row justify-center">
  60. <div class="full-width">
  61. <q-skeleton v-if="entityLoading"
  62. type="rect"
  63. width="100%"
  64. height="200px" />
  65. <template v-else>
  66. <q-chat-message v-for="message in repliesInfo"
  67. :key="message.id"
  68. :avatar="message.creator_info.picture ? message.creator_info.picture : 'assets/images/web/sample-avatar.svg'"
  69. :name="message.creator_info.firstname + ' ' + message.creator_info.lastname"
  70. :text="[message.body]"
  71. :sent="!isUserMessage(authenticatedUser, message)">
  72. <template v-slot:stamp>
  73. <q-btn icon="clear"
  74. round
  75. color="red"
  76. flat
  77. size="xs"
  78. @click="removeMessage(message.id)" />
  79. <q-icon v-if="isUserMessage(authenticatedUser, message)"
  80. :name="message.read ? 'done_all' : 'done'" />
  81. </template>
  82. </q-chat-message>
  83. <div>
  84. <q-input v-model="replyText"
  85. bottom-slots
  86. autogrow
  87. :loading="entityLoading">
  88. <template v-slot:after>
  89. <q-btn round
  90. dense
  91. flat
  92. icon="send"
  93. :loading="entityLoading"
  94. @click="sendReply" />
  95. </template>
  96. </q-input>
  97. </div>
  98. </template>
  99. </div>
  100. </div>
  101. </q-card-section>
  102. </q-card>
  103. </q-card>
  104. <!-- <show-source :source-type="ticket.source_type"-->
  105. <!-- :source-id="ticket.source_id"-->
  106. <!-- :source="ticket.source" />-->
  107. <admin-invoice-show v-if="ticket.source_type === 'INVOICE' && ticket.source_id"
  108. :options="{invoiceId: ticket.source_id, showBackBtn: false}"
  109. class="q-mt-lg" />
  110. <q-card v-if="ticket.source_type === 'INVOICE' && ticket.source_id"
  111. class="q-mt-lg">
  112. <q-card-section>
  113. اقساط
  114. </q-card-section>
  115. <q-separator />
  116. <q-card-section>
  117. <installment-offers :installment-offers="instalmentOffers"
  118. :loading="entityLoading"
  119. :can-accept="false"
  120. :can-reject="false"
  121. @onReject="onReject"
  122. @onAccept="onAccept" />
  123. </q-card-section>
  124. <q-separator />
  125. <q-card-section>
  126. <create-installment :invoice-id="ticket.source_id"
  127. @onCreated="onCreateInstallmentOffer" />
  128. </q-card-section>
  129. </q-card>
  130. </div>
  131. </template>
  132. <script>
  133. import { shallowRef } from 'vue'
  134. import { EntityEdit } from 'quasar-crud'
  135. import { User } from 'src/models/User.js'
  136. import { Ticket } from 'src/models/Ticket.js'
  137. import { mixinWidget } from 'src/mixin/Mixins.js'
  138. import { APIGateway } from 'src/api/APIGateway.js'
  139. import { FormBuilderAssist } from 'quasar-form-builder'
  140. import BtnControl from 'src/components/Control/btn.vue'
  141. import { TicketCategoryList } from 'src/models/TicketCategory.js'
  142. import { InstalmentOfferList } from 'src/models/InstalmentOffer.js'
  143. // import ShowSource from 'src/components/Widgets/Ticket/AdminTicketShow/ShowSource.vue'
  144. import AdminInvoiceShow from 'src/components/Widgets/Invoice/AdminInvoiceShow/AdminInvoiceShow.vue'
  145. import InstallmentOffers from 'src/components/Widgets/Ticket/AdminTicketShow/InstallmentOffers.vue'
  146. import CreateInstallment from 'src/components/Widgets/Ticket/AdminTicketShow/CreateInstallment.vue'
  147. const BtnControlComp = shallowRef(BtnControl)
  148. export default {
  149. name: 'AdminTicketShow',
  150. components: {
  151. EntityEdit,
  152. // ShowSource,
  153. AdminInvoiceShow,
  154. CreateInstallment,
  155. InstallmentOffers
  156. },
  157. mixins: [mixinWidget],
  158. data: () => {
  159. return {
  160. replyText: null,
  161. mounted: false,
  162. entityLoading: true,
  163. packageTitle: '',
  164. ticket: new Ticket(),
  165. authenticatedUser: new User(),
  166. api: null,
  167. ticketCategoryList: new TicketCategoryList(),
  168. entityIdKey: 'id',
  169. entityParamKey: 'id',
  170. showRouteName: 'Admin.Ticket.Show',
  171. indexRouteName: 'Admin.Ticket.List',
  172. inputs: [
  173. { type: 'separator', name: 'space', label: 'مشخصات کاربر', className: 'custom-separator', col: 'col-12' },
  174. { type: 'hidden', name: 'userId', responseKey: 'creator_info.id', disable: true },
  175. { type: 'input', name: 'creator_info.firstname', responseKey: 'creator_info.firstname', label: 'نام', placeholder: ' ', disable: true, col: 'col-md-2 col-12' },
  176. { type: 'input', name: 'creator_info.lastname', responseKey: 'creator_info.lastname', label: 'نام خانوادگی', placeholder: ' ', disable: true, col: 'col-md-2 col-12' },
  177. { type: 'input', name: 'creator_info.mobile_number', responseKey: 'creator_info.mobile_number', label: 'شماره موبایل', placeholder: ' ', disable: true, col: 'col-md-3 col-12' },
  178. { type: 'input', name: 'creator_info.email', responseKey: 'creator_info.email', label: 'ایمیل', placeholder: ' ', disable: true, col: 'col-md-3 col-12' },
  179. { type: BtnControlComp, name: 'btn', responseKey: 'btn', label: 'مشخصات کاربر', placeholder: ' ', atClick: () => {}, col: 'col-md-2 col-12' },
  180. { type: 'separator', name: 'space', label: 'مشخصات تیکت', className: 'custom-separator', col: 'col-12' },
  181. {
  182. type: 'select',
  183. name: 'category_info__type',
  184. responseKey: 'category_info.type',
  185. options: [
  186. { label: 'مالی', value: 'FINANCIAL' },
  187. { label: 'آموزش', value: 'EDUCATIONAL' },
  188. { label: 'محتوا', value: 'CONTENT' },
  189. { label: 'عمومی', value: 'GENERAL' }
  190. ],
  191. label: 'معاونت',
  192. placeholder: ' ',
  193. col: 'col-md-4 col-12'
  194. },
  195. { type: 'select', name: 'category', responseKey: 'category', placeholder: ' ', options: [], label: 'دسته', col: 'col-md-4 col-12' },
  196. { type: 'select', name: 'status', responseKey: 'status', options: (new Ticket()).statusEnums, multiple: false, label: 'وضعیت', placeholder: ' ', readonly: true, col: 'col-md-4 col-12' },
  197. { type: 'input', name: 'title', responseKey: 'title', label: 'عنوان', placeholder: ' ', readonly: true, col: 'col-md-12 col-12' },
  198. { type: 'inputEditor', name: 'body', responseKey: 'body', label: 'متن', placeholder: ' ', readonly: true, col: 'col-md-12 col-12' },
  199. { type: 'hidden', name: 'source_type', responseKey: 'source_type', value: null },
  200. { type: 'hidden', name: 'source_id', responseKey: 'source_id', value: null },
  201. { type: 'hidden', name: 'id', responseKey: 'id' },
  202. { type: 'hidden', name: 'owner', responseKey: 'owner' },
  203. { type: 'hidden', name: 'replies_info', responseKey: 'replies_info' }
  204. ]
  205. }
  206. },
  207. computed: {
  208. selectedCategoryInfoType () {
  209. return FormBuilderAssist.getInputsByName(this.inputs, 'category_info__type')?.value
  210. },
  211. instalmentOffers () {
  212. return new InstalmentOfferList(this.ticket.source?.instalment_offers_info)
  213. },
  214. repliesInfo () {
  215. return this.inputs.find(input => input.name === 'replies_info').value
  216. }
  217. },
  218. watch: {
  219. selectedCategoryInfoType () {
  220. FormBuilderAssist.setAttributeByName(this.inputs, 'category', 'value', null)
  221. this.loadCategories()
  222. }
  223. },
  224. created() {
  225. const ticketId = this.$route.params.id
  226. this.api = APIGateway.ticket.APIAdresses.byId(ticketId)
  227. FormBuilderAssist.setAttributeByName(this.inputs, 'btn', 'atClick', () => {
  228. const userId = FormBuilderAssist.getInputsByName(this.inputs, 'userId').value
  229. this.$router.push({ name: 'Admin.User.Show', params: { id: userId } })
  230. })
  231. },
  232. mounted() {
  233. this.loadAuthData()
  234. this.checkSource()
  235. this.loadOptions()
  236. .then(() => {
  237. this.$nextTick(() => {
  238. this.mounted = true
  239. })
  240. })
  241. .catch(() => {
  242. this.mounted = true
  243. })
  244. },
  245. methods: {
  246. isUserMessage (authenticatedUser, message) {
  247. return authenticatedUser.id === message.creator_info.id
  248. },
  249. removeMessage (replyMessageId) {
  250. this.$q.dialog({
  251. title: 'توجه',
  252. message: 'آیا از حذف پیام اطمینان دارید؟',
  253. cancel: true,
  254. persistent: true
  255. }).onOk(() => {
  256. this.entityLoading = true
  257. APIGateway.ticket.deleteReplyMessage(replyMessageId)
  258. .then(() => {
  259. this.$refs.entityEdit.getData()
  260. })
  261. .catch(() => {
  262. this.entityLoading = true
  263. })
  264. })
  265. },
  266. onReject (offer) {
  267. this.entityLoading = true
  268. APIGateway.instalmentOffer.reject(offer.id)
  269. .then(() => {
  270. this.$refs.entityEdit.getData()
  271. })
  272. .catch(() => {
  273. this.$refs.entityEdit.getData()
  274. })
  275. },
  276. onAccept (offer) {
  277. this.entityLoading = true
  278. APIGateway.instalmentOffer.accept(offer.id)
  279. .then(() => {
  280. this.$refs.entityEdit.getData()
  281. })
  282. .catch(() => {
  283. this.$refs.entityEdit.getData()
  284. })
  285. },
  286. onCreateInstallmentOffer () {
  287. this.$refs.entityEdit.getData()
  288. },
  289. checkSource () {
  290. if (this.localOptions.defaultSourceType) {
  291. FormBuilderAssist.setAttributeByName(this.inputs, 'source_type', 'value', this.localOptions.defaultSourceType)
  292. }
  293. },
  294. loadAuthData () {
  295. this.authenticatedUser = this.$store.getters['Auth/user']
  296. },
  297. beforeLoadInputData (data) {
  298. this.entityLoading = false
  299. this.ticket = new Ticket(data)
  300. },
  301. afterLoadInputData () {
  302. this.$nextTick(() => {
  303. FormBuilderAssist.setAttributeByName(this.inputs, 'category', 'value', this.ticket.category)
  304. })
  305. },
  306. edit() {
  307. this.entityLoading = true
  308. this.$refs.entityEdit.editEntity()
  309. .then(() => {
  310. this.$refs.entityEdit.getData()
  311. })
  312. .catch(() => {
  313. this.$refs.entityEdit.getData()
  314. })
  315. },
  316. loadOptions () {
  317. return this.loadCategories()
  318. },
  319. loadCategories () {
  320. return new Promise((resolve, reject) => {
  321. const type = this.selectedCategoryInfoType
  322. // if (!type) {
  323. // return
  324. // }
  325. this.categoriesLoading = true
  326. APIGateway.ticketCategory.index({ type })
  327. .then(({ list }) => {
  328. const ticketCategoryList = list
  329. FormBuilderAssist.setAttributeByName(this.inputs, 'category', 'options', ticketCategoryList.list.map(item => {
  330. return {
  331. value: item.id,
  332. label: item.title
  333. }
  334. }))
  335. this.categoriesLoading = false
  336. this.$nextTick(() => {
  337. resolve()
  338. })
  339. })
  340. .catch(() => {
  341. this.categoriesLoading = false
  342. this.$nextTick(() => {
  343. reject()
  344. })
  345. })
  346. })
  347. },
  348. sendReply() {
  349. this.entityLoading = true
  350. APIGateway.ticket.reply({
  351. id: this.$route.params.id,
  352. body: this.replyText
  353. })
  354. .then(() => {
  355. this.$refs.entityEdit.getData()
  356. })
  357. .catch(() => {
  358. this.$refs.entityEdit.getData()
  359. })
  360. }
  361. }
  362. }
  363. </script>
  364. <style scoped lang="scss">
  365. .AdminTicketShow {
  366. .title {
  367. font-style: normal;
  368. font-weight: 700;
  369. font-size: 24px;
  370. line-height: 140%;
  371. color: #424242;
  372. margin-bottom: 27px;
  373. display: flex;
  374. flex-flow: row;
  375. position: relative;
  376. .static-title {
  377. }
  378. .dynamic-title {
  379. }
  380. .back-action {
  381. position: absolute;
  382. right: 0;
  383. top: 0;
  384. }
  385. }
  386. :deep(.form) {
  387. padding: 24px;
  388. }
  389. }
  390. </style>