patrolDetails.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <view>
  3. <view
  4. style="box-shadow: 0px 0px 8px 0px rgba(165, 189, 251, 0.4);width: 96%;border-top-right-radius: 10rpx;margin: 10rpx auto;padding-top: 10rpx;">
  5. <span
  6. style="width: 10rpx;height: 40rpx;background-color: #2979ff;display: block;float: left;margin-top: 20rpx;"></span>
  7. <!-- <h4 style="width: 140rpx;border-radius: 200rpx;text-align: center;color: #2979ff;border: 2rpx solid #1785FF;float: right;margin-right: 10rpx;margin-top: 10rpx;">2222222</h4> -->
  8. <view style="width: 92%;margin: 0 auto;margin: 0 auto;">
  9. <view
  10. style="display: flex;justify-content: space-between;height: 80rpx;line-height: 80rpx;border-bottom: 1rpx solid #eff4ff;">
  11. <h3>基本信息</h3>
  12. </view>
  13. <view>
  14. <view style="width: 100%;height: 60rpx;line-height: 60rpx;">
  15. <view style="float: left;">仓库</view>
  16. <view style="float: right;">{{form.fWarehouseName}}</view>
  17. </view>
  18. <view style="width: 100%;height: 60rpx;line-height: 60rpx;">
  19. <view style="float: left;">计划日期</view>
  20. <view style="float: right;">{{form.fInspectionDatetime}}</view>
  21. </view>
  22. <view style="width: 100%;height: 60rpx;line-height: 60rpx;">
  23. <view style="float: left;">最新巡查日期</view>
  24. <view style="float: right;">{{form.fUpdateTime}}</view>
  25. </view>
  26. <view style="width: 100%;height: 60rpx;line-height: 60rpx;">
  27. <view style="float: left;">巡检员</view>
  28. <view style="float: right;">{{form.fInspectorName}}</view>
  29. </view>
  30. <view style="width: 100%;">
  31. <u-form-item label="备注" style="margin: 0;padding: 0;">
  32. <u-input v-model="form.fRemark" :disabled="true" height="70rpx" type="textarea"
  33. placeholder="" />
  34. </u-form-item>
  35. </view>
  36. </view>
  37. <!-- <view style="width: 100%;margin: 0 auto;height: 80rpx;margin: 0 auto;line-height: 80rpx;border-top: 1rpx solid #eff4ff;" @click="expenseDetails(item)">
  38. <view style="float: left;"><h3>立即巡检</h3></view>
  39. <view style="float: right;"><u-icon name="arrow-right"></u-icon></view>
  40. </view> -->
  41. </view>
  42. </view>
  43. <view
  44. style="box-shadow: 0px 0px 8px 0px rgba(165, 189, 251, 0.4);width: 96%;border-top-right-radius: 10rpx;margin: 10rpx auto;padding-top: 10rpx;">
  45. <span
  46. style="width: 10rpx;height: 40rpx;background-color: #2979ff;display: block;float: left;margin-top: 20rpx;"></span>
  47. <!-- <h4 style="width: 140rpx;border-radius: 200rpx;text-align: center;color: #2979ff;border: 2rpx solid #1785FF;float: right;margin-right: 10rpx;margin-top: 10rpx;">2222222</h4> -->
  48. <view style="width: 92%;margin: 0 auto;margin: 0 auto;">
  49. <view
  50. style="display: flex;justify-content: space-between;height: 80rpx;line-height: 80rpx;border-bottom: 1rpx solid #eff4ff;">
  51. <h3>{{deptName == '外部用户'?fileList.length == 0?'暂无附件':'附件':'上传附件'}}</h3>
  52. </view>
  53. <view>
  54. <u-upload style="width: 100%;" :action="action" @on-success="success" @on-remove="remove"
  55. :file-list="fileList" :header="headers" :deletable="deptName == '外部用户'?false:true"
  56. :max-count="deptName == '外部用户'?fileList.length:99" :before-upload="beforeUpload"></u-upload>
  57. </view>
  58. </view>
  59. </view>
  60. <view
  61. style="width: 100%;position:fixed; bottom:0;background-color: #FFFFFF;padding-left: 20px;padding-right: 20px;padding-bottom: 30rpx;z-index: 9999;">
  62. <u-button type="primary" @click="submit" v-if="deptName != '外部用户'">确认保存</u-button>
  63. </view>
  64. <view style="position: absolute;top: -999999px;">
  65. <view>
  66. <canvas style="width: 1000px;height: 1000px;" canvas-id="firstCanvas"></canvas>
  67. </view>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. export default {
  73. data() {
  74. return {
  75. action: this.$u.http.config.baseUrl + '/common/upload',
  76. headers: {
  77. Authorization: 'Bearer ' + this.$store.state.vuex_token
  78. },
  79. form: {},
  80. deptName: '',
  81. fileList: [],
  82. pictureEist: [],
  83. twarehousecheckdetailList: {}
  84. }
  85. },
  86. onLoad(option) {
  87. this.deptName = uni.getStorageSync('deptName')
  88. this.form = JSON.parse(option.form)
  89. let scope = {
  90. row: JSON.parse(option.form)
  91. }
  92. this.$u.get(this.deptName != '外部用户' ? '/warehouse/checkitemsdetails/list' :
  93. '/warehouse/checkitemsdetails/appList', {
  94. fItemFid: this.form.fId
  95. }).then(res => {
  96. console.log(res)
  97. let data = res.rows
  98. if (data.length === 0) {
  99. this.twarehousecheckdetailList = {
  100. fCheckFid: scope.row.fCheckFid,
  101. fItemFid: scope.row.fId,
  102. fWarehouseid: scope.row.fWarehouseFid, //仓库名称
  103. fCreateTime: '',
  104. fInspectorid: '',
  105. fRemark: '',
  106. fPhotoUrl: []
  107. }
  108. } else {
  109. this.twarehousecheckdetailList = res.rows[0]
  110. this.twarehousecheckdetailList.fWarehouseid = scope.row.fWarehouseFid
  111. this.fileList = []
  112. for (let item in JSON.parse(res.rows[0].fPhotoUrl)) {
  113. this.fileList.push(JSON.parse(res.rows[0].fPhotoUrl)[item])
  114. }
  115. this.pictureEist = this.fileList
  116. }
  117. })
  118. },
  119. created() {},
  120. methods: {
  121. submit() {
  122. // console.log(this.twarehousecheckdetailList)
  123. // console.log(this.fileList)
  124. // console.log(this.pictureEist)
  125. this.twarehousecheckdetailList.fPhotoUrl = []
  126. for (let item in this.pictureEist) {
  127. if (this.pictureEist[item].response) {
  128. this.twarehousecheckdetailList.fPhotoUrl.push({
  129. url: this.pictureEist[item].response.url
  130. })
  131. } else {
  132. this.twarehousecheckdetailList.fPhotoUrl.push({
  133. url: this.pictureEist[item].url
  134. })
  135. }
  136. }
  137. this.twarehousecheckdetailList.fPhotoUrl = JSON.stringify(this.twarehousecheckdetailList.fPhotoUrl)
  138. if (!this.twarehousecheckdetailList.fId) {
  139. this.$u.post('warehouse/checkitemsdetails', this.twarehousecheckdetailList).then(res => {
  140. uni.showToast({
  141. icon: 'none',
  142. title: '保存成功',
  143. position: "bottom"
  144. })
  145. })
  146. } else {
  147. this.$u.put('warehouse/checkitemsdetails', this.twarehousecheckdetailList).then(res => {
  148. uni.showToast({
  149. icon: 'none',
  150. title: '保存成功',
  151. position: "bottom"
  152. })
  153. })
  154. }
  155. },
  156. success(data, index, lists, name) {
  157. // console.log(lists)
  158. this.pictureEist = lists
  159. },
  160. remove(index, lists, name) {
  161. // console.log(lists)
  162. this.pictureEist = lists
  163. },
  164. // 上传照片
  165. async beforeUpload(index, list) {
  166. uni.showLoading({
  167. title: '上传中...',
  168. })
  169. var data = await this.getWatermark(index, list);
  170. uni.hideLoading()
  171. return data;
  172. },
  173. //照片添加水印
  174. getWatermark(index, list) {
  175. return new Promise((resolve, reject) => {
  176. var that = this;
  177. uni.getImageInfo({
  178. src: list[index].url,
  179. success: (ress) => {
  180. let ctx = uni.createCanvasContext('firstCanvas'); //创建画布
  181. //将图片src放到cancas内,宽高为图片大小
  182. ctx.drawImage(list[index].url, 0, 0, ress.width / 3, ress.height / 3)
  183. ctx.setFillStyle('#FFFFFF') //字体颜色
  184. let textToWidth = ress.width / 3 * 0.3; //字体宽度
  185. let textToHeight = ress.height / 3; //字体高度
  186. let address = ''
  187. //获取当前时间
  188. let dataTime = new Date().getFullYear() + '-' + Number(new Date()
  189. .getMonth() + 1) + '-' + new Date().getDate() + ' ' + new Date()
  190. .getHours() + ':' + new Date().getMinutes() + ':' + new Date()
  191. .getSeconds()
  192. // 获取地理位置
  193. uni.getLocation({
  194. type: 'gcj02',
  195. geocode: true,
  196. success: function(res) {
  197. address = res.address.province + res.address.city + res.address.district + res.address.street + res.address.streetNum
  198. if (uni.getSystemInfoSync().platform == 'ios') {
  199. ctx.setFontSize(34) //字体大小
  200. ctx.fillText("时间:" + dataTime, textToWidth * 0.2, textToHeight *
  201. 0.7) // 设置字体
  202. ctx.fillText("地址:"+address, textToWidth * 0.2,
  203. textToHeight * 0.7 + 34) // 设置字体
  204. } else {
  205. ctx.setFontSize(12) //字体大小
  206. ctx.fillText("时间:" + dataTime, textToWidth * 0.2, textToHeight *
  207. 0.95) // 设置字体
  208. ctx.fillText("地址:"+address, textToWidth * 0.2,
  209. textToHeight * 0.95 + 12) // 设置字体
  210. }
  211. ctx.draw(false, () => {
  212. setTimeout(() => { //使用定时是因为制作水印需要时间,设置定时才不会出bug
  213. uni.canvasToTempFilePath({ //将画布中内容转成图片,即水印与图片合成
  214. width: ress.width / 3, // 画布宽
  215. height: ress.height / 3, // 画布高
  216. canvasId: 'firstCanvas',
  217. success: (res) => {
  218. list[index].url = res
  219. .tempFilePath
  220. uni.saveImageToPhotosAlbum({ //保存到手机
  221. filePath: res
  222. .tempFilePath,
  223. success: (re) => {
  224. resolve(true);
  225. }
  226. })
  227. }
  228. })
  229. }, 500)
  230. });
  231. },
  232. fail: function(e) {
  233. uni.showToast({
  234. icon: 'none',
  235. title: '获取地址失败, 请检查是否开启定位权限',
  236. duration: 5000,
  237. position:'bottom'
  238. })
  239. if (uni.getSystemInfoSync().platform == 'ios') {
  240. ctx.setFontSize(34) //字体大小
  241. ctx.fillText("时间:" + dataTime, textToWidth * 0.2, textToHeight *
  242. 0.7) // 设置字体
  243. ctx.fillText("地址:"+address, textToWidth * 0.2,
  244. textToHeight * 0.7 + 34) // 设置字体
  245. } else {
  246. ctx.setFontSize(12) //字体大小
  247. ctx.fillText("时间:" + dataTime, textToWidth * 0.2, textToHeight *
  248. 0.95) // 设置字体
  249. ctx.fillText("地址:"+address, textToWidth * 0.2,
  250. textToHeight * 0.95 + 12) // 设置字体
  251. }
  252. ctx.draw(false, () => {
  253. setTimeout(() => { //使用定时是因为制作水印需要时间,设置定时才不会出bug
  254. uni.canvasToTempFilePath({ //将画布中内容转成图片,即水印与图片合成
  255. width: ress.width / 3, // 画布宽
  256. height: ress.height / 3, // 画布高
  257. canvasId: 'firstCanvas',
  258. success: (res) => {
  259. list[index].url = res
  260. .tempFilePath
  261. uni.saveImageToPhotosAlbum({ //保存到手机
  262. filePath: res
  263. .tempFilePath,
  264. success: (re) => {
  265. resolve(true);
  266. }
  267. })
  268. }
  269. })
  270. }, 500)
  271. });
  272. }
  273. });
  274. }
  275. })
  276. })
  277. }
  278. }
  279. }
  280. </script>
  281. <style>
  282. </style>