schemeAdd.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <view class="mainBox">
  3. <uni-nav-bar background-color="#157A2C" color="#fff" fixed="true" statusBar="true" left-icon="back" title="方案信息"
  4. @clickLeft="back">
  5. </uni-nav-bar>
  6. <u-cell-group>
  7. <u-cell title="项目" arrow-direction="down">
  8. <uni-data-picker v-model="form.typeId" slot="value" :clear-icon='false' placeholder="请选择"
  9. :localdata="typeIdList" @change="typeOnchange">
  10. </uni-data-picker>
  11. </u-cell>
  12. <u-cell title="编码" arrow-direction="down">
  13. <u--input v-if="form.typeId != '2'" slot="value" placeholder="请输入" border="surround"
  14. v-model="form.code">
  15. </u--input>
  16. <view class="labels" slot="value" v-if="form.typeId == '2'">
  17. {{ form.code }}
  18. </view>
  19. </u-cell>
  20. <u-cell title="名称" arrow-direction="down">
  21. <u--input v-if="form.typeId == '2'" @click.native="selectProduct" slot="value" placeholder="请选择" border="surround"
  22. v-model="form.name">
  23. </u--input>
  24. <u--input slot="value" v-if="form.typeId != '2'" placeholder="请输入" border="surround" v-model="form.name"></u--input>
  25. </u-cell>
  26. <u-cell title="型号" arrow-direction="down">
  27. <u--input slot="value" v-if="form.typeId != '2'" placeholder="请输入" border="surround"
  28. v-model="form.categoryModel"></u--input>
  29. <view class="labels" slot="value" v-if="form.typeId == '2'">
  30. {{ form.categoryModel }}
  31. </view>
  32. </u-cell>
  33. <u-cell title="规格" arrow-direction="down">
  34. <u--input slot="value" v-if="form.typeId != '2'" placeholder="请输入" border="surround"
  35. v-model="form.specification"></u--input>
  36. <view class="labels" slot="value" v-if="form.typeId == '2'">
  37. {{ form.specification }}
  38. </view>
  39. </u-cell>
  40. <u-cell title="仓库" arrow-direction="down">
  41. <template>
  42. <uni-data-picker v-if="form.typeId != '2'" v-model="form.warehouseId" slot="value" :clear-icon='false' placeholder="请选择"
  43. :localdata="warehouseList" @change="warehouseOnchange">
  44. </uni-data-picker>
  45. <u--input v-if="form.typeId == '2'" slot="value" placeholder="请输入" border="surround" v-model="form.warehouseName"></u--input>
  46. </template>
  47. </u-cell>
  48. <u-cell title="库存" arrow-direction="down">
  49. <!-- <u--input slot="value" placeholder="请输入" border="surround" v-model="form.warehouseNum"></u--input> -->
  50. <view class="labels" slot="value">
  51. {{ form.warehouseNum }}
  52. </view>
  53. </u-cell>
  54. <u-cell title="单位" arrow-direction="down">
  55. <u--input slot="value" v-if="form.typeId != '2'" placeholder="请输入" border="surround"
  56. v-model="form.measureUnit"></u--input>
  57. <view class="labels" slot="value" v-if="form.typeId == '2'">
  58. {{ form.measureUnit }}
  59. </view>
  60. </u-cell>
  61. <u-cell title="数量" arrow-direction="down">
  62. <u--input slot="value" type="number" @input=" (val) =>inputChange(val,'totalCount')" placeholder="请输入"
  63. border="surround" v-model="form.totalCount"></u--input>
  64. </u-cell>
  65. <u-cell title="单价" arrow-direction="down">
  66. <u--input type="number" slot="value" @input="(val) =>inputChange(val,'singlePrice')" placeholder="请输入"
  67. border="surround" v-model="form.singlePrice"></u--input>
  68. </u-cell>
  69. <u-cell title="合计" arrow-direction="down">
  70. <view class="labels" slot="value">
  71. {{ form.settlementPrice }}
  72. </view>
  73. </u-cell>
  74. <u-cell title="详细内容" arrow-direction="down">
  75. <u--input slot="value" placeholder="请输入" border="surround" v-model="form.content"></u--input>
  76. </u-cell>
  77. <view class="footerButton">
  78. <u-button type="default" text="返回" @click="back"></u-button>
  79. <u-button type="primary" @click="save" text="保存"></u-button>
  80. </view>
  81. </u-cell-group>
  82. <u-toast ref="uToast"></u-toast>
  83. </view>
  84. </template>
  85. <script>
  86. export default {
  87. data() {
  88. return {
  89. form: {
  90. typeId: '2',
  91. code: '',
  92. name: '',
  93. categoryModel: '', // 型号
  94. specification: '', // 规格
  95. content: '', // 详细内容
  96. warehouseId: '', // 仓库
  97. warehouseNum: '', // 库存
  98. totalCount: '', // 数量
  99. measureUnit: '', // 单位
  100. singlePrice: '', // 单价
  101. settlementPrice: '', // 合计
  102. },
  103. typeIdList: [{
  104. text: '工时',
  105. value: '1'
  106. },
  107. {
  108. text: '零配件',
  109. value: '2'
  110. },
  111. {
  112. text: '差旅费',
  113. value: '3'
  114. }
  115. ],
  116. obtain: '主数据',
  117. warehouseList: [], // 仓库数据
  118. oldTypeId: '2', // 旧的项目选择
  119. }
  120. },
  121. onLoad(params) {
  122. let data = JSON.parse(params.data);
  123. if(data.code){
  124. this.form = data;
  125. }
  126. console.log(data,'params')
  127. this.obtain = params.obtain || '主数据'
  128. },
  129. created() {
  130. uni.$off('updateScheme');
  131. uni.$on('updateScheme', (data) => {
  132. this.form = {
  133. ...this.form,
  134. ...data
  135. };
  136. this.warehouseList = data.warehouseList.map((el) => {
  137. el.text = el.warehouse_name;
  138. el.value = el.warehouse_id;
  139. return el;
  140. });
  141. })
  142. },
  143. methods: {
  144. // 如果新的选择跟旧的一样 不做数据更改
  145. typeOnchange(e) {
  146. if (this.form.typeId == this.oldTypeId) {
  147. return;
  148. }
  149. this.oldTypeId = this.form.typeId;
  150. this.form = {
  151. typeId: e.detail.value[0].text,
  152. code: '',
  153. name: '',
  154. categoryModel: '', // 型号
  155. specification: '', // 规格
  156. content: '', // 详细内容
  157. warehouseId: '', // 仓库
  158. warehouseNum: '', // 库存
  159. totalCount: '', // 数量
  160. measureUnit: '', // 单位
  161. singlePrice: '', // 单价
  162. settlementPrice: '', // 合计
  163. }
  164. },
  165. warehouseOnchange(e) {
  166. },
  167. selectProduct() {
  168. uni.navigateTo({
  169. url: `/pages/salesServiceManagement/workOrder/components/selectProduct?obtain=${this.obtain}`
  170. })
  171. },
  172. save() {
  173. if(!this.form.name){
  174. this.$refs.uToast.show({
  175. type: "warning",
  176. message: "请填写名称",
  177. })
  178. return;
  179. }
  180. uni.$emit('updateInfo', this.form);
  181. this.back();
  182. },
  183. inputChange(e, field) {
  184. let value = e.replace(/[^\d]/g, '');
  185. if (value.startsWith('0') && value.length > 1) {
  186. value = value.replace(/^0+/, '');
  187. }
  188. this.form[field] = value;
  189. let num1 = this.form.totalCount ? this.form.totalCount - 0 : 0;
  190. let num2 = this.form.singlePrice ? this.form.singlePrice - 0 : 0;
  191. this.form.settlementPrice = num1 * num2;
  192. },
  193. }
  194. }
  195. </script>
  196. <style scoped lang="scss">
  197. /deep/.u-cell__body__content {
  198. flex: none;
  199. margin-right: 16rpx;
  200. }
  201. .mainBox {
  202. padding-bottom: 84rpx;
  203. .labels {
  204. padding-left: 18rpx;
  205. }
  206. }
  207. .footerButton {
  208. width: 100%;
  209. height: 84rpx;
  210. display: flex;
  211. position: fixed;
  212. bottom: 0;
  213. /deep/.u-button {
  214. height: 100%;
  215. }
  216. >view {
  217. flex: 1;
  218. }
  219. }
  220. </style>