inventoryCost.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <view class="content">
  3. <view @click='goposition(item)' 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. goposition(item){
  99. uni.navigateTo({
  100. url: '/pages/user/contractLook/position?warehouse='+item.warehouseName+'&warehouseType='+item.warehouseType
  101. })
  102. },
  103. cancelClick() {
  104. this.isShowAlert = false
  105. },
  106. selectDate() {
  107. this.show = true
  108. },
  109. change(e) {
  110. this.parameter.startDate = e.startDate
  111. this.parameter.endDate = e.endDate
  112. },
  113. radioChange(e) {
  114. console.log(e);
  115. },
  116. alertBtn() {
  117. let _url = ''
  118. if (this.value == '入库记录') {
  119. _url = '/warehouseBaseInfo/exportphone'
  120. } else {
  121. _url = "/warehouseBaseInfo/exportPhoneOut"
  122. }
  123. uni.showLoading({
  124. title: '正在加载'
  125. })
  126. this.$api.doRequest('post', _url, {
  127. startDate: this.parameter.startDate,
  128. endDate: this.parameter.endDate,
  129. warehouseName: this.parameter.warehouseName
  130. }).then(res => {
  131. uni.hideLoading()
  132. console.log('-----------')
  133. console.log(res.data.data)
  134. uni.downloadFile({
  135. url: res.data.data,
  136. success: function(res) {
  137. var filePath = res.tempFilePath;
  138. uni.openDocument({
  139. filePath: filePath,
  140. showMenu: true,
  141. success: function(res) {
  142. console.log('打开文档成功');
  143. }
  144. });
  145. }
  146. });
  147. })
  148. },
  149. cancelClick() {
  150. this.isShowDetailBtn = false
  151. },
  152. toDetail(warehouseName) {
  153. this.parameter.warehouseName = warehouseName
  154. this.parameter.startDate = helper.getNowFormatDate()
  155. this.parameter.endDate = helper.getNowFormatDate()
  156. this.isShowDetailBtn = true
  157. },
  158. init() {
  159. if (!this.hasLogin) {
  160. this.isShowAlert = true;
  161. } else {
  162. uni.showLoading({
  163. title: '正在加载'
  164. })
  165. this.$api.doRequest('get', '/costManagementInfo/selectCostManagementInfo', {
  166. compId: uni.getStorageSync('pcUserInfo').compId,
  167. warehouseType: 1
  168. }).then(res => {
  169. uni.hideLoading()
  170. if (res.data.data) {
  171. const results = this.makeGroupData(res.data.data, function(item) {
  172. return [item.warehouseName];
  173. });
  174. console.log('this.costList')
  175. console.log(this.costList)
  176. let _data = []
  177. for (let i = 0; i < results.length; i++) {
  178. let _obj = {}
  179. _obj.warehouseName = results[i][0].warehouseName
  180. // 大于两条添加合计行
  181. if (results[i].length > 1) {
  182. let _price = 0
  183. for (let k = 0; k < results[i].length; k++) {
  184. _price += results[i][k].storage
  185. }
  186. _price = _price.toFixed(2)
  187. results[i].push({
  188. 'goodsName': '合计',
  189. 'storage': _price
  190. })
  191. }
  192. _obj.goodList = results[i]
  193. _data.push(_obj)
  194. }
  195. console.log(_data)
  196. this.costList = _data
  197. }
  198. })
  199. }
  200. },
  201. makeGroupData(array, fn) {
  202. const groups = {};
  203. array.forEach(function(item) {
  204. const group = JSON.stringify(fn(item));
  205. groups[group] = groups[group] || [];
  206. groups[group].push(item);
  207. });
  208. return Object.keys(groups).map(function(group) {
  209. console.log(groups,groups[group])
  210. return groups[group];
  211. })
  212. }
  213. }
  214. }
  215. </script>
  216. <style scoped lang="scss">
  217. .active {
  218. font-size: 32rpx;
  219. font-weight: 700;
  220. }
  221. .modal-row {
  222. display: flex;
  223. justify-content: space-between;
  224. padding: 10rpx 60rpx;
  225. margin-top: 20rpx;
  226. margin-bottom: 20rpx;
  227. }
  228. .u-radio-group {
  229. width: 100%;
  230. display: flex;
  231. justify-content: space-between;
  232. }
  233. .u-radio {
  234. width: 50% !important;
  235. display: flex;
  236. justify-content: center;
  237. }
  238. .record {
  239. background: red;
  240. display: flex;
  241. justify-content: center;
  242. }
  243. .button {
  244. font-size: 24rpx;
  245. padding: 4rpx 20rpx;
  246. border-radius: 15px;
  247. background: #22C572;
  248. color: white;
  249. // margin: 0 10px;
  250. }
  251. .cost-list {
  252. margin: 20rpx;
  253. background: white;
  254. border-radius: 20rpx;
  255. padding: 20rpx;
  256. .title {
  257. font-size: 32rpx;
  258. font-weight: 500;
  259. color: #333333;
  260. }
  261. .goods-table {
  262. margin-top: 22rpx;
  263. }
  264. .goods-table-title {
  265. display: flex;
  266. border-bottom: 1px solid #EEEEEE;
  267. padding-bottom: 16rpx;
  268. // margin-bottom: ;
  269. .font {
  270. font-size: 27rpx;
  271. font-weight: 400;
  272. color: #B2B3BB;
  273. }
  274. .font:nth-of-type(1) {
  275. width: 40%;
  276. }
  277. .font:nth-of-type(2) {
  278. width: 30%;
  279. }
  280. .font:nth-of-type(3) {
  281. width: 30%;
  282. text-align: right;
  283. }
  284. }
  285. .goods-table-content {
  286. display: flex;
  287. margin: 22rpx;
  288. font-size: 28rpx;
  289. font-weight: 400;
  290. color: #333333;
  291. .font:nth-of-type(1) {
  292. width: 40%;
  293. }
  294. .font:nth-of-type(2) {
  295. width: 30%;
  296. }
  297. .font:nth-of-type(3) {
  298. width: 30%;
  299. text-align: right;
  300. }
  301. }
  302. }
  303. </style>