inventoryCost.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. if (!this.hasLogin) {
  155. this.isShowAlert = true;
  156. } else {
  157. uni.showLoading({
  158. title: '正在加载'
  159. })
  160. this.$api.doRequest('get', '/costManagementInfo/selectCostManagementInfo', {
  161. compId: uni.getStorageSync('pcUserInfo').compId,
  162. warehouseType: 1
  163. }).then(res => {
  164. uni.hideLoading()
  165. if (res.data.data) {
  166. const results = this.makeGroupData(res.data.data, function(item) {
  167. return [item.warehouseName];
  168. });
  169. console.log('this.costList')
  170. console.log(this.costList)
  171. let _data = []
  172. for (let i = 0; i < results.length; i++) {
  173. let _obj = {}
  174. _obj.warehouseName = results[i][0].warehouseName
  175. // 大于两条添加合计行
  176. if (results[i].length > 1) {
  177. let _price = 0
  178. for (let k = 0; k < results[i].length; k++) {
  179. _price += results[i][k].storage
  180. }
  181. _price = _price.toFixed(2)
  182. results[i].push({
  183. 'goodsName': '合计',
  184. 'storage': _price
  185. })
  186. }
  187. _obj.goodList = results[i]
  188. _data.push(_obj)
  189. }
  190. console.log(_data)
  191. this.costList = _data
  192. }
  193. })
  194. }
  195. },
  196. makeGroupData(array, fn) {
  197. const groups = {};
  198. array.forEach(function(item) {
  199. const group = JSON.stringify(fn(item));
  200. groups[group] = groups[group] || [];
  201. groups[group].push(item);
  202. });
  203. return Object.keys(groups).map(function(group) {
  204. return groups[group];
  205. })
  206. }
  207. }
  208. }
  209. </script>
  210. <style scoped lang="scss">
  211. .active {
  212. font-size: 32rpx;
  213. font-weight: 700;
  214. }
  215. .modal-row {
  216. display: flex;
  217. justify-content: space-between;
  218. padding: 10rpx 60rpx;
  219. margin-top: 20rpx;
  220. margin-bottom: 20rpx;
  221. }
  222. .u-radio-group {
  223. width: 100%;
  224. display: flex;
  225. justify-content: space-between;
  226. }
  227. .u-radio {
  228. width: 50% !important;
  229. display: flex;
  230. justify-content: center;
  231. }
  232. .record {
  233. background: red;
  234. display: flex;
  235. justify-content: center;
  236. }
  237. .button {
  238. font-size: 24rpx;
  239. padding: 4rpx 20rpx;
  240. border-radius: 15px;
  241. background: #22C572;
  242. color: white;
  243. // margin: 0 10px;
  244. }
  245. .cost-list {
  246. margin: 20rpx;
  247. background: white;
  248. border-radius: 20rpx;
  249. padding: 20rpx;
  250. .title {
  251. font-size: 32rpx;
  252. font-weight: 500;
  253. color: #333333;
  254. }
  255. .goods-table {
  256. margin-top: 22rpx;
  257. }
  258. .goods-table-title {
  259. display: flex;
  260. border-bottom: 1px solid #EEEEEE;
  261. padding-bottom: 16rpx;
  262. // margin-bottom: ;
  263. .font {
  264. font-size: 27rpx;
  265. font-weight: 400;
  266. color: #B2B3BB;
  267. }
  268. .font:nth-of-type(1) {
  269. width: 40%;
  270. }
  271. .font:nth-of-type(2) {
  272. width: 30%;
  273. }
  274. .font:nth-of-type(3) {
  275. width: 30%;
  276. text-align: right;
  277. }
  278. }
  279. .goods-table-content {
  280. display: flex;
  281. margin: 22rpx;
  282. font-size: 28rpx;
  283. font-weight: 400;
  284. color: #333333;
  285. .font:nth-of-type(1) {
  286. width: 40%;
  287. }
  288. .font:nth-of-type(2) {
  289. width: 30%;
  290. }
  291. .font:nth-of-type(3) {
  292. width: 30%;
  293. text-align: right;
  294. }
  295. }
  296. }
  297. </style>