index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <view class="page detail">
  3. <uni-card>
  4. <view class="form-content">
  5. <uni-forms ref="formRef" :model-value="form" :rules="rules" err-show-type="toast" labelWidth="140px">
  6. <!-- 设备 -->
  7. <uni-forms-item class="form-item align-center" name="deviceName" :label="$t('statusChange.form.device')" required
  8. @click="selectDevice">
  9. <uni-easyinput v-model="form.deviceName" :inputBorder="false" :clearable="false"
  10. :styles="{disableColor:'#fff'}" :placeholder="$t('statusChange.form.deviceHint')"
  11. style="text-align: right" @click.prevent="selectDevice" />
  12. </uni-forms-item>
  13. <!-- 设备状态 -->
  14. <uni-forms-item class="form-item align-center" name="status" :label="$t('statusChange.form.status')" required>
  15. <uni-data-picker v-model="form.status" :popup-title="$t('statusChange.form.statusTitle')"
  16. :localdata="statusList" :map="{ text: 'label', value: 'value' }" />
  17. </uni-forms-item>
  18. <!-- 调整原因 -->
  19. <uni-forms-item class="form-item align-center" name="reason" :label="$t('statusChange.form.reason')" required>
  20. <uni-easyinput style="text-align: right" :autoHeight="true" :inputBorder="false"
  21. :clearable="false" :styles="{ disableColor:'#fff' }"
  22. :placeholder="$t('statusChange.form.reasonHint')" v-model="form.reason" />
  23. </uni-forms-item>
  24. </uni-forms>
  25. </view>
  26. </uni-card>
  27. <button class="submit-btn" type="primary" @click="submit">{{ $t('operation.submit') }}</button>
  28. <uni-popup ref="popup" type="bottom">
  29. <z-paging class="z-page-popup" style="top: 200px">
  30. <template #top>
  31. <view>
  32. <uni-row class="flex-row justify-center" style="margin-top: 30px">
  33. <text>{{ $t('statusChange.form.selectDevice') }}</text>
  34. </uni-row>
  35. <view style="margin-top: 18px; padding-left: 30px; padding-right: 30px">
  36. <uni-easyinput v-model="keywords" :styles="inputStyles" :placeholderStyle="placeholderStyle"
  37. :placeholder="$t('statusChange.form.searchHint')" :input-border="false"
  38. @input="onKeywordsChanged" />
  39. </view>
  40. <view class="choice-row flex-row flex-wrap align-center justify-start" style="margin: 0 28px">
  41. <view class="choice-item align-center justify-center" v-for="item in selectedList"
  42. @click="onItemDelete(item)">
  43. {{item.deviceName}}
  44. <uni-icons class="choice-close-icon" type="closeempty" color="#fff"></uni-icons>
  45. </view>
  46. </view>
  47. </view>
  48. </template>
  49. <template #bottom>
  50. <button class="submit-btn" type="primary" @click="confirmDevice">
  51. {{ $t('operation.confirm') }}
  52. </button>
  53. </template>
  54. <view v-for="item of filterList" :key="item.id">
  55. <view class="device-item" :class="item.selected ? 'selected' : undefined"
  56. @click="onSelectedItem(item)">
  57. {{ `${item.deviceCode} (${item.deviceName})` }}
  58. </view>
  59. <view class="divider" />
  60. </view>
  61. </z-paging>
  62. </uni-popup>
  63. </view>
  64. </template>
  65. <script setup>
  66. import { reactive, ref, onMounted, nextTick, getCurrentInstance } from 'vue'
  67. import { useDataDictStore } from "@/store/modules/dataDict"
  68. import { getAllDeviceList } from "@/api"
  69. import { submitDeviceChangeRecord } from "@/api/statusChange";
  70. import { getDeptId } from '@/utils/auth';
  71. const { appContext } = getCurrentInstance()
  72. const t = appContext.config.globalProperties.$t
  73. const { getDataDictList } = useDataDictStore()
  74. const statusList = ref([])
  75. const formRef = ref()
  76. const form = reactive({
  77. deviceName: '',
  78. status: '',
  79. reason: '',
  80. })
  81. const rules = reactive({
  82. deviceName: {
  83. rules: [{
  84. required: true,
  85. errorMessage: t('statusChange.form.deviceError')
  86. }]
  87. },
  88. status: {
  89. rules: [{
  90. required: true,
  91. errorMessage: t('statusChange.form.statusError')
  92. }]
  93. },
  94. reason: {
  95. rules: [{
  96. required: true,
  97. errorMessage: t('statusChange.form.reasonError')
  98. }]
  99. },
  100. })
  101. const popup = ref()
  102. const selectDevice = () => {
  103. popup.value.open('bottom')
  104. }
  105. const placeholderStyle = ref('color: #ADADAD; font-weight: 500; font-size: 12px')
  106. const inputStyles = reactive({
  107. backgroundColor: '#F5F5F5',
  108. borderRadius: '4px',
  109. color: '#797979',
  110. fontSize: '12px',
  111. })
  112. const keywords = ref('')
  113. const onKeywordsChanged = (text) => {
  114. filterList.value = deviceList.value.filter(item => item.deviceCode.includes(text) || item.deviceName.includes(
  115. text))
  116. }
  117. const selectedList = ref([])
  118. const onSelectedItem = (row) => {
  119. row.selected = !row.selected
  120. if (row.selected) {
  121. selectedList.value.push(row)
  122. } else {
  123. selectedList.value = selectedList.value.filter(item => item.id !== row.id)
  124. }
  125. }
  126. const onItemDelete = (item) => {
  127. const index = selectedList.value.findIndex((v) => v.id === item.id)
  128. item.selected = !item.selected
  129. if (index > -1) {
  130. selectedList.value.splice(index, 1)
  131. }
  132. }
  133. const confirmDevice = () => {
  134. form.deviceName = selectedList.value.map(item => item.deviceName).join(',')
  135. popup.value.close('bottom')
  136. }
  137. const submit = async () => {
  138. try {
  139. const valid = await formRef.value.validate()
  140. if (!valid) return
  141. const list = []
  142. for (const item of selectedList.value) {
  143. list.push({
  144. deviceId: item.id,
  145. status: form.status,
  146. reason: form.reason,
  147. })
  148. }
  149. // const requests = []
  150. // for (const item of selectedList.value) {
  151. // requests.push(submitDeviceChangeRecord({
  152. // deviceId: item.id,
  153. // oldStatus: item.deviceStatus,
  154. // newStatus: form.status,
  155. // reason: form.reason
  156. // }))
  157. // }
  158. const response = await submitDeviceChangeRecord(list)
  159. // const response = await Promise.all(requests)
  160. if (response.code === 0) {
  161. uni.showToast({ title: t('statusChange.form.success'), icon: 'none' })
  162. uni.navigateBack()
  163. uni.$emit('update')
  164. }
  165. } catch (e) {
  166. console.log(e)
  167. }
  168. }
  169. const deviceList = ref([])
  170. const filterList = ref([])
  171. onMounted(async () => {
  172. statusList.value = getDataDictList('pms_device_status')
  173. // const deptList = (await getAllDeptList()).data
  174. // for (const dept of deptList) {
  175. // if (dept.name === '科瑞石油技术') {
  176. const locale = uni.getLocale()
  177. // deviceList.value = (await getAllDeviceList(getDeptId())).data.map((item) => {
  178. // if (item.deviceName.includes('~~') && item.deviceName.includes('**')) {
  179. // const s = item.deviceName.split('~~')
  180. // if (locale.startsWith('zh')) {
  181. // item.deviceName = s[0]
  182. // } else if (locale.startsWith('ru')) {
  183. // const s2 = s[2].split('**')
  184. // item.deviceName = s2[1]
  185. // } else {
  186. // const s1 = s[1].split('**')
  187. // item.deviceName = s1[1]
  188. // }
  189. // }
  190. // return JSON.parse(JSON.stringify(item))
  191. // })
  192. deviceList.value = (await getAllDeviceList(getDeptId())).data
  193. filterList.value = deviceList.value
  194. // break
  195. // }
  196. // }
  197. await nextTick(() => {
  198. const inputViews = document.getElementsByClassName('uni-input-input');
  199. inputViews[0].readOnly = true
  200. })
  201. })
  202. </script>
  203. <style lang="scss" scoped>
  204. @import "@/style/choose-device.scss";
  205. .form-item{
  206. min-height: 45px;
  207. }
  208. .segmented-control {
  209. margin-bottom: 15px;
  210. }
  211. .button-group {
  212. margin-top: 15px;
  213. display: flex;
  214. justify-content: space-around;
  215. }
  216. .button {
  217. display: flex;
  218. align-items: center;
  219. height: 35px;
  220. line-height: 35px;
  221. margin-left: 10px;
  222. }
  223. :deep(.input-value-border) {
  224. border: 0 !important;
  225. }
  226. :deep(.input-value) {
  227. text-align: end;
  228. }
  229. :deep(.selected-list) {
  230. display: block;
  231. }
  232. :deep(.selected-area) {
  233. display: block;
  234. margin-right: 5px;
  235. }
  236. :deep(.uni-data-pickerview .selected-area) {
  237. display: none;
  238. }
  239. :deep(.tab-c) {
  240. margin-left: 30px;
  241. margin-right: 30px;
  242. border-top: 1px dashed #CACCCF;
  243. .item {
  244. border-bottom: 1px dashed #CACCCF;
  245. }
  246. }
  247. :deep(.uni-forms-item) {
  248. margin-bottom: 0;
  249. border-bottom: 1px dashed #CACCCF;
  250. }
  251. :deep(.uni-card) {
  252. padding: 0 !important;
  253. margin: 0 0 10px 0 !important;
  254. }
  255. .popup-content {
  256. height: 500px;
  257. }
  258. .device-item {
  259. height: 35px;
  260. line-height: 35px;
  261. padding: 0 30px;
  262. font-size: 13px;
  263. color: #333333;
  264. border-bottom: 1px #CACCCF;
  265. }
  266. .selected {
  267. color: #004098;
  268. }
  269. .divider {
  270. height: 0.5px;
  271. margin: 0 28px;
  272. background-color: #CACCCF;
  273. }
  274. .z-page-popup {
  275. padding: 0;
  276. background: white;
  277. border-radius: 10px 10px 0 0;
  278. }
  279. .submit-btn {
  280. width: 100%;
  281. height: 48px;
  282. border-radius: 0;
  283. }
  284. </style>