securityCheck.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <template>
  2. <!-- 入户安全检查 -->
  3. <view>
  4. <u-navbar title="入户安全检查" autoBack placeholder></u-navbar>
  5. <view class="card_order_details">
  6. <u--form labelPosition="top" :model="ruleForm" :rules="rules" ref="uForm" labelWidth="auto">
  7. <u-form-item label="入户检查图片" prop="homeCheckImg">
  8. <u-upload :fileList="fileList1" name="1" multiple :maxCount="10" @afterRead="afterRead"
  9. @delete="deletePic"></u-upload>
  10. </u-form-item>
  11. <u-form-item label="状态" prop="state">
  12. <u-radio-group v-model="ruleForm.state" placement="row">
  13. <u-radio shape="circle" :customStyle="{marginRight: '20px'}" v-for="(item, index) in radiolist"
  14. :key="index" :label="item.name" :name="item.value"></u-radio>
  15. </u-radio-group>
  16. </u-form-item>
  17. <u-form-item label="整改前照片" prop="beforeRectifyImg" v-if="ruleForm.state == 0">
  18. <u-upload :fileList="fileList2" name="2" multiple :maxCount="10" @afterRead="afterRead"
  19. @delete="deletePic"></u-upload>
  20. </u-form-item>
  21. <u-form-item label="客户签字" prop="customerImg">
  22. <view class="card_signs center_in" v-if="clientFlag" @click="goSignature('client')">客户签字</view>
  23. <u--image :showLoading="true" :src="imageData" width="200rpx" height="160rpx" v-else></u--image>
  24. </u-form-item>
  25. <u-form-item label="送气员签字" prop="signImg">
  26. <view class="card_signs center_in" v-if="aeratorFlag" @click="goSignature('aerator')">送气员签字</view>
  27. <u--image :showLoading="true" :src="aeratorData" width="200rpx" height="160rpx" v-else></u--image>
  28. </u-form-item>
  29. </u--form>
  30. <view class="card_plate">
  31. <view class="card_check">安全检查项目<span style="color: red;">*</span></view>
  32. <u-line></u-line>
  33. <view class="card_security">
  34. <view class="" v-for="(item,index) in checkEntry" :key="index">
  35. <view class="title_item_check">{{index + 1}}、{{item.label}}</view>
  36. <u-radio-group v-model="item.value" placement="row">
  37. <u-radio shape="circle" :customStyle="{marginRight: '20px'}"
  38. v-for="(item1, index1) in radioData" :key="index1" :label="item1.name"
  39. :name="item1.value"></u-radio>
  40. </u-radio-group>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <view style="width: 100%;height: 170rpx;"></view>
  46. <view class="check_btn">
  47. <view class="btn_submit">
  48. <u-button type="primary" text="提交" @click="entrySecurity"></u-button>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. const ENV = require('@/.env.js')
  55. import {
  56. check
  57. } from '@/static/js/announcements.js'
  58. export default {
  59. data() {
  60. return {
  61. fileList1: [],
  62. fileList2: [],
  63. radiolist: [{
  64. name: '合格',
  65. value: -1,
  66. disabled: false
  67. }, {
  68. name: '待整改',
  69. value: 0,
  70. disabled: false
  71. }],
  72. radioData: [{
  73. name: '合格',
  74. value: '0',
  75. disabled: false
  76. }, {
  77. name: '待整改',
  78. value: '1',
  79. disabled: false
  80. }],
  81. checkEntry: [],
  82. clientFlag: true,
  83. aeratorFlag: true,
  84. personnelType: '',
  85. imageData: '',
  86. aeratorData: '',
  87. ruleForm: {
  88. orderId: '',
  89. customerId: '',
  90. homeCheckImg: '',
  91. customerImg: '',
  92. signImg: '',
  93. state: -1,
  94. inspectExpandList: [],
  95. },
  96. rules: {
  97. 'homeCheckImg': {
  98. type: 'string',
  99. required: true,
  100. message: '请上传入户检查图片',
  101. trigger: ['blur', 'change']
  102. },
  103. 'customerImg': {
  104. type: 'string',
  105. required: true,
  106. message: '请上传客户签名',
  107. trigger: ['blur', 'change']
  108. },
  109. 'signImg': {
  110. type: 'string',
  111. required: true,
  112. message: '请上传送气员签名',
  113. trigger: ['blur', 'change']
  114. },
  115. },
  116. }
  117. },
  118. onLoad(e) {
  119. this.ruleForm.orderId = e.orderId
  120. this.ruleForm.customerId = e.customerId
  121. //注册监听事件
  122. uni.$on('sign', (data) => {
  123. //base64编码的图片
  124. if (this.personnelType == 'client') {
  125. this.clientFlag = false
  126. this.imageData = "data:" + data.replace(/[\r\n]/g, "");
  127. const blob = this.base64ToBlob(data);
  128. const url = URL.createObjectURL(blob);
  129. this.getUpload(url)
  130. } else {
  131. this.aeratorFlag = false
  132. this.aeratorData = "data:" + data.replace(/[\r\n]/g, "");
  133. const blob = this.base64ToBlob(data);
  134. const url = URL.createObjectURL(blob);
  135. this.getUpload(url)
  136. }
  137. //处理自己的业务逻辑
  138. })
  139. },
  140. //销毁监听事件
  141. onUnload() {
  142. uni.$off('sign');
  143. },
  144. mounted() {
  145. this.checkEntry = check()
  146. },
  147. methods: {
  148. // 提价入户安全检查项
  149. entrySecurity() {
  150. this.$refs.uForm.validate().then(res => {
  151. const param = {
  152. ...this.ruleForm
  153. }
  154. const arrList = []
  155. this.checkEntry.forEach(item => {
  156. const arr1 = {
  157. inspectItem: '',
  158. itemCode: '',
  159. }
  160. arr1.inspectItem = item.id
  161. arr1.itemCode = item.value
  162. arrList.push(arr1)
  163. })
  164. param.inspectExpandList = arrList
  165. this.$api.post('/api/inspect_record', param).then(res => {
  166. if (res.code == 200) {
  167. uni.$u.toast('操作成功')
  168. setTimeout(()=>{
  169. uni.navigateBack({
  170. delta: 1
  171. });
  172. },1500)
  173. }
  174. })
  175. }).catch(errors => {
  176. // uni.$u.toast('校验失败')
  177. })
  178. },
  179. // 删除图片
  180. deletePic(event) {
  181. this[`fileList${event.name}`].splice(event.index, 1)
  182. },
  183. // 签名板
  184. async getUpload(file) {
  185. const result = await this.uploadFilePromise(file)
  186. if (this.personnelType == 'client') {
  187. this.ruleForm.customerImg = result
  188. } else {
  189. this.ruleForm.signImg = result
  190. }
  191. },
  192. // 新增图片
  193. async afterRead(event) {
  194. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  195. let lists = [].concat(event.file)
  196. let fileListLen = this[`fileList${event.name}`].length
  197. lists.map((item) => {
  198. this[`fileList${event.name}`].push({
  199. ...item,
  200. status: 'uploading',
  201. message: '上传中'
  202. })
  203. })
  204. for (let i = 0; i < lists.length; i++) {
  205. const result = await this.uploadFilePromise(lists[i].url)
  206. let item = this[`fileList${event.name}`][fileListLen]
  207. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  208. status: 'success',
  209. message: '',
  210. url: result
  211. }))
  212. fileListLen++
  213. }
  214. if (event.name == '1') {
  215. var arr = []
  216. this.fileList1.forEach(item1 => {
  217. arr.push(item1.url)
  218. })
  219. this.ruleForm.homeCheckImg = arr.join()
  220. this.$refs.uForm.validateField('homeCheckImg')
  221. } else {
  222. var arr1 = []
  223. this.fileList2.forEach(item2 => {
  224. arr.push(item2.url)
  225. })
  226. this.ruleForm.beforeRectifyImg = arr1.join()
  227. this.$refs.uForm.validateField('beforeRectifyImg')
  228. }
  229. },
  230. base64ToBlob(base64Data) {
  231. const arr = base64Data.split(','); // 分割Base64字符串
  232. const mimeType = arr[0].match(/:(.*?);/)[1]; // 获取MIME类型
  233. const byteString = atob(arr[1]); // Base64解码
  234. let n;
  235. const dataLength = byteString.length;
  236. const uInt8Array = new Uint8Array(dataLength);
  237. for (n = 0; n < dataLength; ++n) {
  238. uInt8Array[n] = byteString.charCodeAt(n);
  239. }
  240. return new Blob([uInt8Array], {
  241. type: mimeType
  242. });
  243. },
  244. uploadFilePromise(url) {
  245. return new Promise((resolve, reject) => {
  246. let a = uni.uploadFile({
  247. url: ENV.APP_DEV_URL + '/api/upload', // 仅为示例,非真实的接口地址
  248. filePath: url,
  249. name: 'file',
  250. // formData: {
  251. // user: 'test'
  252. // },
  253. header: {
  254. 'Authorization': 'Bearer ' + uni.getStorageSync('access_token'),
  255. },
  256. success: (res) => {
  257. let state = JSON.parse(res.data)
  258. setTimeout(() => {
  259. if (state.code == 200) {
  260. resolve(state.data)
  261. }
  262. }, 1000)
  263. }
  264. });
  265. })
  266. },
  267. // 签字
  268. goSignature(title) {
  269. this.personnelType = title
  270. uni.navigateTo({
  271. url: '/pages/order/signatureBoard'
  272. });
  273. },
  274. }
  275. }
  276. </script>
  277. <style lang="scss" scoped>
  278. .card_order_details {
  279. margin: 20rpx 40rpx;
  280. }
  281. .card_plate {
  282. margin-top: 20rpx;
  283. margin-bottom: 40rpx;
  284. }
  285. .details_title {
  286. color: #333;
  287. font-size: 40rpx;
  288. font-weight: 500;
  289. }
  290. .card_check {
  291. font-size: 34rpx;
  292. font-weight: 500;
  293. margin-bottom: 20rpx;
  294. }
  295. .title_item_check {
  296. margin-top: 30rpx;
  297. font-size: 30rpx;
  298. margin-bottom: 15rpx;
  299. }
  300. .check_btn {
  301. position: fixed;
  302. display: flex;
  303. align-items: center;
  304. justify-content: center;
  305. left: 0;
  306. right: 0;
  307. bottom: 0;
  308. background-color: #fff;
  309. border-top: 1rpx solid #f7f7f7;
  310. padding-bottom: constant(safe-area-inset-bottom); //兼容 IOS<11.2
  311. padding-bottom: env(safe-area-inset-bottom); //兼容 IOS>11.2
  312. }
  313. .btn_submit {
  314. margin-top: 10rpx;
  315. padding-bottom: 20rpx;
  316. width: calc(100% - 80rpx);
  317. }
  318. .card_signs {
  319. width: 200rpx;
  320. height: 160rpx;
  321. background-color: #f4f5f7;
  322. color: #d3d4d6;
  323. font-size: 32rpx;
  324. border-radius: 4rpx;
  325. }
  326. </style>