setPolling.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <view class="handler">
  3. <view class="body">
  4. <view class="scan-box">
  5. <view class="scan">
  6. <text class="newicon newicon-saoma icon" @click="scanCodes"></text>
  7. </view>
  8. </view>
  9. <view class="container">
  10. <view class="weight-class">可以通过扫一扫功能设置“巡检点”,扫描二维码后设置或选择巡检点。</view>
  11. <view class="weight-tip">查询巡检点结果:{{dataInfo.pollingData}}</view>
  12. <view class="weight-tip" v-if="dataInfo.newPollingData">选择巡检点为:<text class="red">{{dataInfo.newPollingData.name}}</text></view>
  13. </view>
  14. </view>
  15. <view class="foot_common_btns">
  16. <button v-if="dataInfo.type" @click="replace" type="default" class="primaryButton btn">选择巡检点</button>
  17. <button v-if="dataInfo.newPollingData" @click="save" type="default" class="primaryButton btn">保存</button>
  18. </view>
  19. <uni-popup ref="alertDialog" type="dialog" :mask-click="false">
  20. <view class="popup-content">
  21. <view class="tip">提示</view>
  22. <view class="content">{{dataInfo.content}}</view>
  23. </view>
  24. <view class="btn-box">
  25. <view @click="close" class="btn-item-50 color-close">取消</view>
  26. <view @click="dialogConfirm" class="btn-item-50 color">确认</view>
  27. </view>
  28. </uni-popup>
  29. </view>
  30. </template>
  31. <script setup>
  32. import { SM } from "@/http/http.js"
  33. import { ref, reactive, computed } from 'vue'
  34. import { onLoad, onUnload } from '@dcloudio/uni-app'
  35. import { api_inspectionNode, api_inspectionNodeEdit } from "@/http/api.js"
  36. import { defaultColor } from '@/static/js/theme.js'
  37. import { useSetTitle } from '@/share/useSetTitle.js'
  38. import { useGoBack } from '@/share/useGoBack.js'
  39. import { useLoginUserStore } from '@/stores/loginUser'
  40. import { post } from "@/http/http.js"
  41. import { join } from "lodash-es"
  42. useSetTitle();
  43. const loginUserStore = useLoginUserStore();
  44. const { goBack } = useGoBack();
  45. // 主题颜色
  46. const primaryColor = ref(defaultColor)
  47. const alertDialog = ref(null)
  48. // 数据
  49. const dataInfo = reactive({
  50. pollingData:'无',
  51. pollingId:null,
  52. newPollingData:null,
  53. content:'',
  54. type:false,
  55. bindingPolling:false
  56. })
  57. // 清空数据
  58. function setInfoData(){
  59. dataInfo.pollingData = '无'
  60. dataInfo.pollingId = null
  61. dataInfo.newPollingData = null
  62. dataInfo.content = ''
  63. dataInfo.type = false
  64. dataInfo.bindingPolling = false
  65. uni.removeStorageSync('pollingCode')
  66. }
  67. // 选择巡检点
  68. function replace(){
  69. // let data = {
  70. // code: 'inspection|$|703f3569-b80e-48df-aafd-5fcef36c96f0',
  71. // pollingData: '1东',
  72. // pollingId: 1,
  73. // }
  74. // uni.setStorageSync('pollingCode',JSON.stringify(data))
  75. uni.navigateTo({
  76. url: `/pages/setPolling/selectPolling`
  77. })
  78. }
  79. // 保存
  80. function save(){
  81. setTimeout(_=>{
  82. alertDialog.value.open()
  83. },100)
  84. }
  85. // 提交
  86. function dialogConfirm(){
  87. let data = JSON.parse(uni.getStorageSync('pollingCode'))
  88. let query = {
  89. inspectionNode:{
  90. updateInspectionNodeCode: 1,
  91. id: data.pollingId,
  92. updateId: dataInfo.newPollingData.id,
  93. code: data.code
  94. }
  95. }
  96. uni.showLoading({
  97. title: "加载中",
  98. mask: true,
  99. });
  100. api_inspectionNodeEdit(query).then((result) => {
  101. if (result.status == 200) {
  102. uni.hideLoading();
  103. uni.showToast({
  104. icon: 'none',
  105. title: result.msg
  106. });
  107. alertDialog.value.close()
  108. setTimeout(_=>{
  109. setInfoData()
  110. },1000)
  111. } else {
  112. uni.showToast({
  113. icon: 'none',
  114. title: result.msg
  115. });
  116. }
  117. });
  118. }
  119. // 关闭
  120. function close(){
  121. alertDialog.value.close()
  122. }
  123. // 扫码
  124. function scanCodes(){
  125. uni.showLoading({
  126. title: "加载中",
  127. mask: true,
  128. });
  129. SM().then((res) => {
  130. let query = {
  131. idx: 0,
  132. sum: 1,
  133. inspectionNode:{
  134. code:res
  135. }
  136. }
  137. api_inspectionNode(query).then((res2) => {
  138. uni.hideLoading();
  139. if (res2.status == 200) {
  140. if(res2.list.length>0){
  141. dataInfo.pollingData = res2.list[0].name
  142. dataInfo.pollingId = res2.list[0].id
  143. }
  144. let data = {
  145. code: res,
  146. pollingData: dataInfo.pollingData,
  147. pollingId: dataInfo.pollingId,
  148. }
  149. uni.setStorageSync('pollingCode',JSON.stringify(data))
  150. dataInfo.type = true
  151. } else {
  152. uni.showToast({
  153. icon: 'none',
  154. title: res2.msg || '请求数据失败!'
  155. });
  156. }
  157. });
  158. })
  159. }
  160. onLoad((option) => {
  161. if(option && option.data){
  162. let data = JSON.parse(option.data)
  163. dataInfo.newPollingData = data
  164. console.log(998,data)
  165. }
  166. if(uni.getStorageSync('pollingCode')){
  167. let data = JSON.parse(uni.getStorageSync('pollingCode'))
  168. dataInfo.pollingData = data.pollingData
  169. dataInfo.pollingId = data.pollingId
  170. dataInfo.content = `二维码绑定为“${dataInfo.newPollingData.name}”,原“${dataInfo.pollingData}”二维码被清空,您确认绑定吗?`
  171. }
  172. })
  173. onUnload(()=>{
  174. setInfoData()
  175. })
  176. </script>
  177. <style>
  178. >>> .uni-popup .uni-popup__wrapper{
  179. background-color: #fff !important;
  180. width: 90%;
  181. border-radius: 10rpx;
  182. }
  183. >>> .uni-popup__info{
  184. color: #333 !important;
  185. }
  186. >>>.uni-button-color{
  187. color: #49B856 !important;
  188. }
  189. </style>
  190. <style lang="scss" scoped>
  191. .handler{
  192. height: 89vh;
  193. .body{
  194. height: 100%;
  195. padding: 0 30rpx;
  196. .scan-box{
  197. padding: 40rpx 0 ;
  198. display: flex;
  199. justify-content: center;
  200. .scan{
  201. width: 150rpx;
  202. height: 150rpx;
  203. border-radius: 50%;
  204. text-align: center;
  205. line-height: 150rpx;
  206. background: linear-gradient( 300deg, #6BBF76 0%, #46B491 100%);
  207. .icon{
  208. color: #fff;
  209. }
  210. }
  211. }
  212. .container{
  213. text-align: center;
  214. .weight-class{
  215. font-size: 38rpx;
  216. font-weight: 600;
  217. margin-bottom: 20rpx;
  218. }
  219. .weight-tip{
  220. font-size: 32rpx;
  221. margin-bottom: 20rpx;
  222. }
  223. }
  224. }
  225. .popup-content{
  226. padding: 20rpx;
  227. text-align: center;
  228. .tip{
  229. font-size: 32rpx;
  230. color: #333;
  231. margin-bottom: 20rpx;
  232. }
  233. .content{
  234. color: #6C6C6C;
  235. padding: 20rpx;
  236. }
  237. }
  238. .btn-box{
  239. display: flex;
  240. border-top: 1px solid #E3E3E3;
  241. .btn-item-50{
  242. flex: 1;
  243. height: 90rpx;
  244. line-height: 90rpx;
  245. text-align: center;
  246. }
  247. .color-close{
  248. color: #606266;
  249. }
  250. .color{
  251. color: #49B856;
  252. border-left: 1px solid #E3E3E3;
  253. }
  254. }
  255. }
  256. </style>