inventoryCost.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <view class="content">
  3. <view class="cost-list" v-for="(item,index) in costList">
  4. <view style="display: flex;justify-content: space-between;">
  5. <view class="title">{{item.warehouseName}}</view>
  6. <view class="button" @click="toDetail(item.warehouseName)">详细记录</view>
  7. </view>
  8. <view class="goods-table">
  9. <view class="goods-table-title">
  10. <view class="font">货名</view>
  11. <view class="font">储量(吨)</view>
  12. <view class="font">价值(元)</view>
  13. </view>
  14. <view class="goods-table-content" v-for="(item1,index1) in item.goodList">
  15. <view class="font" :class="item.goodList.length>1&&index1==item.goodList.length-1?'active':''">
  16. {{item1.goodsName}}
  17. </view>
  18. <view class="font" :class="item.goodList.length>1&&index1==item.goodList.length-1?'active':''">
  19. {{item1.storage}}
  20. </view>
  21. <view class="font">{{item1.cost}}</view>
  22. </view>
  23. </view>
  24. </view>
  25. <u-modal class="record" v-model="isShowDetailBtn" :title-style="{fontSize: '18px',fontWeight:'500'}"
  26. :content-style="{fontSize: '14px',fontWeight:'400'}" confirm-color='#22C572' confirm-text='确定' title='导出记录'
  27. showCancelButton='false' @confirm="alertBtn" @cancel="cancelClick">
  28. <view>
  29. <u-radio-group v-model="value">
  30. <u-radio active-color="#22C572" @change="radioChange" v-for="(item, index) in list" :key="index"
  31. :name="item.name" :disabled="item.disabled">
  32. {{item.name}}
  33. </u-radio>
  34. </u-radio-group>
  35. <view class="modal-row">
  36. <view class="">查询日期</view>
  37. <view class="" @click="selectDate">
  38. {{parameter.endDate?parameter.startDate+' - '+parameter.endDate:'请选择查询日期'}}
  39. </view>
  40. </view>
  41. <view class="modal-row">
  42. <view class="">仓库名称</view>
  43. <view>{{parameter.warehouseName}}</view>
  44. </view>
  45. </view>
  46. </u-modal>
  47. <u-calendar v-model="show" :mode="mode" @change="change" range-color='#22C572' btn-type='success'
  48. range-bg-color='rgba(25, 190, 107, 0.13)' active-bg-color='#22C572'></u-calendar>
  49. <u-modal v-model="isShowAlert" :title-style="{fontSize: '18px',fontWeight:'500'}"
  50. :content-style="{fontSize: '14px',fontWeight:'400'}" confirm-color='#22C572' confirm-text='确定' title='提示'
  51. showCancelButton='false' :content="content" @confirm="alertBtn" @cancel="cancelClick"></u-modal>
  52. </view>
  53. </template>
  54. <script>
  55. import helper from '@/common/helper.js';
  56. import {
  57. mapState
  58. } from 'vuex';
  59. export default {
  60. data() {
  61. return {
  62. isShowAlert: false,
  63. content: '当前登录身份已失效,请重新登录!',
  64. parameter: {
  65. startDate: "",
  66. endDate: '',
  67. warehouseName: ''
  68. },
  69. show: false,
  70. mode: 'range',
  71. list: [{
  72. name: '入库记录',
  73. disabled: false
  74. },
  75. {
  76. name: '出库记录',
  77. disabled: false
  78. }
  79. ],
  80. // u-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中
  81. value: '入库记录',
  82. costList: [],
  83. isShowDetailBtn: false
  84. }
  85. },
  86. onLoad: function(option) {
  87. this.init()
  88. },
  89. computed: {
  90. ...mapState(['hasLogin', 'userInfo']),
  91. },
  92. methods: {
  93. alertBtn() {
  94. uni.navigateTo({
  95. url: '/pages/public/login'
  96. })
  97. },
  98. cancelClick() {
  99. this.isShowAlert = false
  100. },
  101. selectDate() {
  102. this.show = true
  103. },
  104. change(e) {
  105. this.parameter.startDate = e.startDate
  106. this.parameter.endDate = e.endDate
  107. },
  108. radioChange(e) {
  109. console.log(e);
  110. },
  111. alertBtn() {
  112. let _url = ''
  113. if (this.value == '入库记录') {
  114. _url = '/warehouseBaseInfo/exportphone'
  115. } else {
  116. _url = "/warehouseBaseInfo/exportPhoneOut"
  117. }
  118. uni.showLoading({
  119. title: '正在加载'
  120. })
  121. this.$api.doRequest('post', _url, {
  122. startDate: this.parameter.startDate,
  123. endDate: this.parameter.endDate,
  124. warehouseName: this.parameter.warehouseName
  125. }).then(res => {
  126. uni.hideLoading()
  127. console.log('-----------')
  128. console.log(res.data.data)
  129. uni.downloadFile({
  130. url: res.data.data,
  131. success: function(res) {
  132. var filePath = res.tempFilePath;
  133. uni.openDocument({
  134. filePath: filePath,
  135. showMenu: true,
  136. success: function(res) {
  137. console.log('打开文档成功');
  138. }
  139. });
  140. }
  141. });
  142. })
  143. },
  144. cancelClick() {
  145. this.isShowDetailBtn = false
  146. },
  147. toDetail(warehouseName) {
  148. this.parameter.warehouseName = warehouseName
  149. this.parameter.startDate = helper.getNowFormatDate()
  150. this.parameter.endDate = helper.getNowFormatDate()
  151. this.isShowDetailBtn = true
  152. },
  153. init() {
  154. debugger
  155. if (!this.hasLogin) {
  156. this.isShowAlert = true;
  157. } else {
  158. uni.showLoading({
  159. title: '正在加载'
  160. })
  161. this.$api.doRequest('get', '/costManagementInfo/selectCostManagementInfo', {
  162. compId: uni.getStorageSync('pcUserInfo').compId,
  163. warehouseType: 1
  164. }).then(res => {
  165. uni.hideLoading()
  166. if (res.data.data) {
  167. const results = this.makeGroupData(res.data.data, function(item) {
  168. return [item.warehouseName];
  169. });
  170. console.log('this.costList')
  171. console.log(this.costList)
  172. let _data = []
  173. for (let i = 0; i < results.length; i++) {
  174. let _obj = {}
  175. _obj.warehouseName = results[i][0].warehouseName
  176. // 大于两条添加合计行
  177. if (results[i].length > 1) {
  178. let _price = 0
  179. for (let k = 0; k < results[i].length; k++) {
  180. _price += results[i][k].storage
  181. }
  182. _price = _price.toFixed(2)
  183. results[i].push({
  184. 'goodsName': '合计',
  185. 'storage': _price
  186. })
  187. }
  188. _obj.goodList = results[i]
  189. _data.push(_obj)
  190. }
  191. console.log(_data)
  192. this.costList = _data
  193. }
  194. })
  195. }
  196. },
  197. makeGroupData(array, fn) {
  198. const groups = {};
  199. array.forEach(function(item) {
  200. const group = JSON.stringify(fn(item));
  201. groups[group] = groups[group] || [];
  202. groups[group].push(item);
  203. });
  204. return Object.keys(groups).map(function(group) {
  205. return groups[group];
  206. })
  207. }
  208. }
  209. }
  210. </script>
  211. <style scoped lang="scss">
  212. .active {
  213. font-size: 32rpx;
  214. font-weight: 700;
  215. }
  216. .modal-row {
  217. display: flex;
  218. justify-content: space-between;
  219. padding: 10rpx 60rpx;
  220. margin-top: 20rpx;
  221. margin-bottom: 20rpx;
  222. }
  223. .u-radio-group {
  224. width: 100%;
  225. display: flex;
  226. justify-content: space-between;
  227. }
  228. .u-radio {
  229. width: 50% !important;
  230. display: flex;
  231. justify-content: center;
  232. }
  233. .record {
  234. background: red;
  235. display: flex;
  236. justify-content: center;
  237. }
  238. .button {
  239. font-size: 24rpx;
  240. padding: 4rpx 20rpx;
  241. border-radius: 15px;
  242. background: #22C572;
  243. color: white;
  244. // margin: 0 10px;
  245. }
  246. .cost-list {
  247. margin: 20rpx;
  248. background: white;
  249. border-radius: 20rpx;
  250. padding: 20rpx;
  251. .title {
  252. font-size: 32rpx;
  253. font-weight: 500;
  254. color: #333333;
  255. }
  256. .goods-table {
  257. margin-top: 22rpx;
  258. }
  259. .goods-table-title {
  260. display: flex;
  261. border-bottom: 1px solid #EEEEEE;
  262. padding-bottom: 16rpx;
  263. // margin-bottom: ;
  264. .font {
  265. font-size: 27rpx;
  266. font-weight: 400;
  267. color: #B2B3BB;
  268. }
  269. .font:nth-of-type(1) {
  270. width: 40%;
  271. }
  272. .font:nth-of-type(2) {
  273. width: 30%;
  274. }
  275. .font:nth-of-type(3) {
  276. width: 30%;
  277. text-align: right;
  278. }
  279. }
  280. .goods-table-content {
  281. display: flex;
  282. margin: 22rpx;
  283. font-size: 28rpx;
  284. font-weight: 400;
  285. color: #333333;
  286. .font:nth-of-type(1) {
  287. width: 40%;
  288. }
  289. .font:nth-of-type(2) {
  290. width: 30%;
  291. }
  292. .font:nth-of-type(3) {
  293. width: 30%;
  294. text-align: right;
  295. }
  296. }
  297. }
  298. </style>